Commit 50264b91 authored by Marian Dovgialo's avatar Marian Dovgialo

#45153 fixed readmanager for MNE version 0.17.0

parent 54073cef
Pipeline #16945 passed with stages
in 57 seconds
......@@ -30,7 +30,7 @@ def add_stim_chnl(raw):
stim_data = numpy.zeros((1, len(raw.times)))
info = mne.create_info(['OBCI_STIM'], raw.info['sfreq'], ['stim'])
stim_raw = mne.io.RawArray(stim_data, info)
raw.add_channels([stim_raw], force_update_info=True)
raw.add_channels([stim_raw], force_update_info=False)
def _description_from_tag(tag):
......@@ -47,9 +47,6 @@ def tags_from_mne_annotations(ans):
Returns tags (list of dicts).
"""
tags = []
orig_time = ans.orig_time
if orig_time is None:
orig_time = 0
for onset, duration, desc in zip(ans.onset, ans.duration, ans.description):
# try to load annotations, as they would be exported by ReadManager
# if there is no our annotations reformat them to tags
......@@ -59,8 +56,8 @@ def tags_from_mne_annotations(ans):
except (json.decoder.JSONDecodeError, AssertionError):
# MNE created not in OBCI
tag = {'name': desc, 'desc': {}, 'channels': ''}
tag['start_timestamp'] = onset - orig_time
tag['end_timestamp'] = onset + duration - orig_time
tag['start_timestamp'] = onset
tag['end_timestamp'] = onset + duration
tags.append(tag)
return tags
......@@ -178,7 +175,8 @@ class ReadManagerMNEMixin:
except ValueError:
meas_date_us = 0
meas_date = numpy.array([meas_date_s, meas_date_us], dtype=numpy.int32)
meas_date = (meas_date_s, meas_date_us)
print('hhhhh', meas_date)
info['meas_date'] = meas_date
def mne_annotations(self):
......@@ -225,5 +223,5 @@ class ReadManagerMNEMixin:
add_stim_chnl(raw)
ans = self.mne_annotations()
events, _ = self.mne_events()
raw.annotations = ans
raw.set_annotations(ans, sync_orig=False)
raw.add_events(events)
......@@ -13,7 +13,7 @@ test_requirements = [
'pytest-catchlog>=1.2.2',
'flaky>=3.3.0',
'nose>=1.3.7',
'mne>=0.17.0',
'mne~=0.17.0',
'scipy',
'matplotlib',
]
......@@ -50,6 +50,6 @@ setup(
tests_require=test_requirements,
setup_requires=setup_requires,
extras_require={
'test': pytest_runner_requirement + test_requirements,
},
)
'test': pytest_runner_requirement + test_requirements,
},
)
......@@ -3,10 +3,13 @@ import os
import math
from obci_readmanager.signal_processing.balance.wii_preprocessing import wii_filter_signal, wii_downsample_signal, wii_cut_fragments
from obci_readmanager.signal_processing.balance.wii_analysis import (wii_COP_path, wii_max_sway_AP_MP, wii_mean_COP_sway_AP_ML,
wii_RMS_AP_ML, wii_confidence_ellipse_area, wii_mean_velocity,
wii_get_percentages_values)
from obci_readmanager.signal_processing.balance.wii_preprocessing import wii_filter_signal, wii_downsample_signal, \
wii_cut_fragments
from obci_readmanager.signal_processing.balance.wii_analysis import (wii_COP_path, wii_max_sway_AP_MP,
wii_mean_COP_sway_AP_ML,
wii_RMS_AP_ML, wii_confidence_ellipse_area,
wii_mean_velocity,
wii_get_percentages_values)
from obci_readmanager.signal_processing.balance.wii_read_manager import WBBReadManager
import matplotlib.pyplot as py
......@@ -35,7 +38,6 @@ def test_wii_analysis(plot=False):
def test_wbb_tutorial():
# inicjalizacja klasy WBBReadManager - utwórz obiekt podając na wejściu ścieżki do
# odpowiednich plików :
pth = __file__
......@@ -225,5 +227,6 @@ def test_wbb_tutorial_calculations():
assert math.isclose(bottom_right, 23.487261146496824)
assert math.isclose(bottom_left, 18.232484076433121)
if __name__ == '__main__':
test_wii_analysis(plot=True)
<?xml version="1.0" encoding="UTF-8"?>
<tagFile formatVersion="1.0">
<paging blocks_per_page="5" page_size="20.0" />
<tagData>
<tags>
<tag channelNumber="-1" length="1.0046250820159912" name="trigger" position="0.36085605621337891">
<value>1</value>
<semicolon_test>1;2;3</semicolon_test>
</tag>
<tag channelNumber="-1" length="1.9283778667449951" name="trigger" position="1.3654811382293701">
<value>0</value>
<semicolon_test>1;2;3</semicolon_test>
</tag>
<tag channelNumber="-1" length="1.5430161952972412" name="trigger" position="3.2938590049743652">
<value>1</value>
<semicolon_test>1;2;3</semicolon_test>
</tag>
<tag channelNumber="-1" length="1.7950088977813721" name="trigger" position="4.8368752002716064">
<value>0</value>
<semicolon_test>1;2;3</semicolon_test>
</tag>
<tag channelNumber="-1" length="1.6539919376373291" name="trigger" position="6.6318840980529785">
<value>1</value>
<semicolon_test>1;2;3</semicolon_test>
</tag>
<tag channelNumber="-1" length="1.6060090065002441" name="trigger" position="8.2858760356903076">
<value>0</value>
<semicolon_test>1;2;3</semicolon_test>
</tag>
<tag channelNumber="-1" length="1.7079939842224121" name="trigger" position="9.8918850421905518">
<value>1</value>
<semicolon_test>1;2;3</semicolon_test>
</tag>
<tag channelNumber="-1" length="1.5549831390380859" name="trigger" position="11.599879026412964">
<value>0</value>
<semicolon_test>1;2;3</semicolon_test>
</tag>
<tag channelNumber="-1" length="1.5930259227752686" name="trigger" position="13.15486216545105">
<value>1</value>
</tag>
<tag channelNumber="-1" length="1.0129780769348145" name="trigger" position="14.747888088226318">
<value>0</value>
</tag>
<tag channelNumber="-1" length="1.7710130214691162" name="trigger" position="15.760866165161133">
<value>1</value>
</tag>
<tag channelNumber="-1" length="1.6369898319244385" name="trigger" position="17.531879186630249">
<value>0</value>
</tag>
<tag channelNumber="-1" length="1.8520011901855469" name="trigger" position="19.168869018554688">
<value>1</value>
</tag>
<tag channelNumber="-1" length="1.6960029602050781" name="trigger" position="21.020870208740234">
<value>0</value>
</tag>
<tag channelNumber="-1" length="1.8960099220275879" name="trigger" position="22.716873168945312">
<value>1</value>
</tag>
<tag channelNumber="-1" length="1.799976110458374" name="trigger" position="24.6128830909729">
<value>0</value>
</tag>
<tag channelNumber="-1" length="1.9080259799957275" name="trigger" position="26.412859201431274">
<value>1</value>
</tag>
<tag channelNumber="-1" length="1.0279920101165771" name="trigger" position="28.320885181427002">
<value>0</value>
</tag>
<tag channelNumber="-1" length="1.3869879245758057" name="trigger" position="29.348877191543579">
<value>1</value>
</tag>
<tag channelNumber="-1" length="1.1030158996582031" name="trigger" position="30.735865116119385">
<value>0</value>
</tag>
<tag channelNumber="-1" length="1.6669991016387939" name="trigger" position="31.838881015777588">
<value>1</value>
</tag>
<tag channelNumber="-1" length="1.0890018939971924" name="trigger" position="33.505880117416382">
<value>0</value>
</tag>
<tag channelNumber="-1" length="1.9470040798187256" name="trigger" position="34.594882011413574">
<value>1</value>
</tag>
<tag channelNumber="-1" length="1.1589961051940918" name="trigger" position="36.5418860912323">
<value>0</value>
</tag>
<tag channelNumber="-1" length="1.0949859619140625" name="trigger" position="37.700882196426392">
<value>1</value>
</tag>
<tag channelNumber="-1" length="1.389995813369751" name="trigger" position="38.795868158340454">
<value>0</value>
</tag>
<tag channelNumber="-1" length="1.7900252342224121" name="trigger" position="40.185863971710205">
<value>1</value>
</tag>
<tag channelNumber="-1" length="1.6329929828643799" name="trigger" position="41.975889205932617">
<value>0</value>
</tag>
<tag channelNumber="-1" length="1.0870018005371094" name="trigger" position="43.608882188796997">
<value>1</value>
</tag>
<tag channelNumber="-1" length="1.217008113861084" name="trigger" position="44.695883989334106">
<value>0</value>
</tag>
<tag channelNumber="-1" length="1.7229928970336914" name="trigger" position="45.91289210319519">
<value>1</value>
</tag>
<tag channelNumber="-1" length="1.7080001831054688" name="trigger" position="47.635885000228882">
<value>0</value>
</tag>
<tag channelNumber="-1" length="1.3120009899139404" name="trigger" position="49.343885183334351">
<value>1</value>
</tag>
<tag channelNumber="-1" length="1.8303978443145752" name="trigger" position="50.655886173248291">
<value>0</value>
</tag>
<tag channelNumber="-1" length="1.077592134475708" name="trigger" position="52.486284017562866">
<value>1</value>
</tag>
<tag channelNumber="-1" length="1.9700009822845459" name="trigger" position="53.563876152038574">
<value>0</value>
</tag>
<tag channelNumber="-1" length="1.8099980354309082" name="trigger" position="55.53387713432312">
<value>1</value>
</tag>
<tag channelNumber="-1" length="1.9740610122680664" name="trigger" position="57.343875169754028">
<value>0</value>
</tag>
<tag channelNumber="-1" length="1.7009468078613281" name="trigger" position="59.317936182022095">
<value>1</value>
</tag>
<tag channelNumber="-1" length="1.2930071353912354" name="trigger" position="61.018882989883423">
<value>0</value>
</tag>
<tag channelNumber="-1" length="1.4469950199127197" name="trigger" position="62.311890125274658">
<value>1</value>
</tag>
<tag channelNumber="-1" length="1.8379850387573242" name="trigger" position="63.758885145187378">
<value>0</value>
</tag>
<tag channelNumber="-1" length="1.9000129699707031" name="trigger" position="65.596870183944702">
<value>1</value>
</tag>
<tag channelNumber="-1" length="1.3319909572601318" name="trigger" position="67.496883153915405">
<value>0</value>
</tag>
<tag channelNumber="-1" length="1.8179960250854492" name="trigger" position="68.828874111175537">
<value>1</value>
</tag>
<tag channelNumber="-1" length="1.2369940280914307" name="trigger" position="70.646870136260986">
<value>0</value>
</tag>
<tag channelNumber="-1" length="1.4687058925628662" name="trigger" position="71.883864164352417">
<value>1</value>
</tag>
<tag channelNumber="-1" length="2.0003170967102051" name="trigger" position="73.352570056915283">
<value>0</value>
</tag>
<tag channelNumber="-1" length="1.9999959468841553" name="trigger" position="75.352887153625488">
<value>1</value>
</tag>
<tag channelNumber="-1" length="1.6439969539642334" name="trigger" position="77.352883100509644">
<value>0</value>
</tag>
<tag channelNumber="-1" length="1.0243129730224609" name="trigger" position="78.996880054473877">
<value>1</value>
</tag>
</tags>
</tagData>
</tagFile>
......@@ -6,6 +6,8 @@ import os
import mne
import numpy
import pytest
from obci_readmanager.signal_processing.read_manager import ReadManager
from obci_readmanager.signal_processing import smart_tags_manager as mgr
......@@ -13,6 +15,17 @@ from obci_readmanager.signal_processing.tags import smart_tag_definition as df
from test_smart_tags_manager import fabricate_data_file, fabricate_info_file
@pytest.mark.skip('To fix')
def test_mne_semicolon():
pth = os.path.abspath(__file__)
fname = os.path.join(pth[:-len(os.path.basename(pth))], 'data', 'data.obci')
read_manager = ReadManager(fname + '.info',
fname + '.dat',
fname + '_semicolon.tags')
read_manager.get_mne_raw()
def test_mne_compat():
"""Minimal test which just reads file and checks if mne can do something with it"""
pth = os.path.abspath(__file__)
......@@ -70,14 +83,13 @@ def test_mne_and_back(tmpdir):
file3 = os.path.join(str(tmpdir), 'test_rm_mne')
rm3 = ReadManager(file3 + '.obci.xml',
file3 + '.obci.raw',
file3 + '.obci.tag',)
file3 + '.obci.tag', )
_assert_rms_similar(rm2, rm3)
_assert_tags_ok(read_manager, rm3)
def test_mne_epochs(tmpdir):
d = df.SmartTagDurationDefinition(start_tag_name='trigger', start_offset=-0.15,
end_offset=0, duration=1.0)
pth = __file__
......
......@@ -11,7 +11,8 @@ import numpy
from obci_readmanager.signal_processing import smart_tags_manager as mgr
from obci_readmanager.signal_processing.tags import smart_tag_definition as df
from obci_readmanager.signal_processing.smart_tags_manager import SmartTagsManager
from obci_readmanager.signal_processing.tags.smart_tag_definition import SmartTagDurationDefinition, SmartTagEndTagDefinition
from obci_readmanager.signal_processing.tags.smart_tag_definition import SmartTagDurationDefinition, \
SmartTagEndTagDefinition
from obci_readmanager.signal_processing.read_manager import ReadManager
......@@ -123,13 +124,13 @@ def test_legacy_doctest():
tss_tags = [t.get_start_tag() for t in tss]
assert tss_tags ==\
[{'channels': '', 'start_timestamp': 6.0999999999999996, 'desc': {u'y': u'456', u'x': u'123', u'z': u'789'},
'name': u'B', 'end_timestamp': 6.5}, {'channels': '', 'start_timestamp': 7.0,
'desc': {u'y': u'456', u'x': u'123', u'z': u'789'}, 'name': u'B',
'end_timestamp': 7.0},
{'channels': '', 'start_timestamp': 7.5, 'desc': {u'y': u'456', u'x': u'123', u'z': u'789'},
'name': u'B', 'end_timestamp': 8.6999999999999993}]
assert tss_tags == \
[{'channels': '', 'start_timestamp': 6.0999999999999996, 'desc': {u'y': u'456', u'x': u'123', u'z': u'789'},
'name': u'B', 'end_timestamp': 6.5}, {'channels': '', 'start_timestamp': 7.0,
'desc': {u'y': u'456', u'x': u'123', u'z': u'789'}, 'name': u'B',
'end_timestamp': 7.0},
{'channels': '', 'start_timestamp': 7.5, 'desc': {u'y': u'456', u'x': u'123', u'z': u'789'},
'name': u'B', 'end_timestamp': 8.6999999999999993}]
assert tss[0].get_all_samples()[0][0] == 780.0
......@@ -144,11 +145,11 @@ def test_legacy_doctest():
tss_tags = [t.get_start_tag() for t in tss]
assert tss_tags ==\
[{'channels': '', 'start_timestamp': 10.199999999999999, 'desc': {u'y': u'456', u'x': u'123', u'z': u'789'},
'name': u'B', 'end_timestamp': 11.0}, {'channels': '', 'start_timestamp': 12.0,
'desc': {u'y': u'456', u'x': u'123', u'z': u'789'}, 'name': u'B',
'end_timestamp': 12.5}]
assert tss_tags == \
[{'channels': '', 'start_timestamp': 10.199999999999999, 'desc': {u'y': u'456', u'x': u'123', u'z': u'789'},
'name': u'B', 'end_timestamp': 11.0}, {'channels': '', 'start_timestamp': 12.0,
'desc': {u'y': u'456', u'x': u'123', u'z': u'789'}, 'name': u'B',
'end_timestamp': 12.5}]
for fl in glob.glob('tescik*'):
os.remove(fl)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment