Skip to content

Commit feb7def

Browse files
committed
test for epoched recording
1 parent 2495cd9 commit feb7def

2 files changed

Lines changed: 53 additions & 13 deletions

File tree

mne/io/curry/curry.py

Lines changed: 33 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -191,13 +191,27 @@ def _get_curry_epoch_info(fname):
191191
def _get_curry_meg_normals(fname):
192192
fname_hdr = _check_curry_header_filename(fname)
193193
normals_str = fname_hdr.read_text().split("\n")
194-
i_start, i_stop = [
194+
# i_start, i_stop = [
195+
# i
196+
# for i, ll in enumerate(normals_str)
197+
# if ("NORMALS" in ll and "START_LIST" in ll)
198+
# or ("NORMALS" in ll and "END_LIST" in ll)
199+
# ]
200+
# normals_str = [nn.split("\t") for nn in normals_str[i_start + 1 : i_stop]]
201+
i_list = [
195202
i
196203
for i, ll in enumerate(normals_str)
197204
if ("NORMALS" in ll and "START_LIST" in ll)
198205
or ("NORMALS" in ll and "END_LIST" in ll)
199206
]
200-
normals_str = [nn.split("\t") for nn in normals_str[i_start + 1 : i_stop]]
207+
assert len(i_list) % 2 == 0
208+
i_start_list = i_list[::2]
209+
i_stop_list = i_list[1::2]
210+
normals_str = [
211+
nn.split("\t")
212+
for i_start, i_stop in zip(i_start_list, i_stop_list)
213+
for nn in normals_str[i_start + 1 : i_stop]
214+
]
201215
return np.array([[float(nnn.strip()) for nnn in nn] for nn in normals_str])
202216

203217

@@ -296,10 +310,18 @@ def _extract_curry_info(fname):
296310
ch_names = [
297311
ch_names_full[i] for i in np.argsort(chaninfile_full) if i not in i_drop
298312
]
313+
ch_pos = np.array(
314+
[
315+
ch_pos[i]
316+
for i in np.argsort(chaninfile_full)
317+
if (i not in i_drop) and (i < len(ch_pos))
318+
]
319+
)
299320
ch_types = [ch_types[i] for i in np.argsort(chaninfile_full) if i not in i_drop]
300321
units = [units[i] for i in np.argsort(chaninfile_full) if i not in i_drop]
301322

302323
assert len(ch_types) == len(units) == len(ch_names) == n_ch
324+
assert len(ch_pos) == ch_types.count("eeg") + ch_types.count("mag")
303325

304326
# finetune channel types (e.g. stim, eog etc might be identified by name)
305327
# TODO?
@@ -370,8 +392,9 @@ def _make_curry_montage(ch_names, ch_types, ch_pos, landmarks, landmarkslabels):
370392
ch_pos /= 1000.0
371393
landmarks /= 1000.0
372394
# channel locations
373-
# TODO - what about misc without pos? can they mess things up if unordered?
395+
# what about misc without pos? can they mess things up if unordered?
374396
assert len(ch_pos) >= (ch_types.count("mag") + ch_types.count("eeg"))
397+
assert len(ch_pos) == (ch_types.count("mag") + ch_types.count("eeg"))
375398
ch_pos_eeg = {
376399
ch_names[i]: ch_pos[i, :3] for i, t in enumerate(ch_types) if t == "eeg"
377400
}
@@ -417,8 +440,9 @@ def _set_chanloc_curry(inst, ch_types, ch_pos, landmarks, landmarkslabels):
417440
ch_pos /= 1000.0
418441
landmarks /= 1000.0
419442
# channel locations
420-
# TODO - what about misc without pos? can they mess things up if unordered?
443+
# what about misc without pos? can they mess things up if unordered?
421444
assert len(ch_pos) >= (ch_types.count("mag") + ch_types.count("eeg"))
445+
assert len(ch_pos) == (ch_types.count("mag") + ch_types.count("eeg"))
422446
ch_pos_meg = {
423447
ch_names[i]: ch_pos[i, :3] for i, t in enumerate(ch_types) if t == "mag"
424448
}
@@ -433,24 +457,24 @@ def _set_chanloc_curry(inst, ch_types, ch_pos, landmarks, landmarkslabels):
433457
landmark_dict[k] = None
434458
if len(landmarkslabels) > 0:
435459
hpi_pos = landmarks[
436-
[i for i, n in enumerate(landmarkslabels) if re.match("HPI[1-99]", n)],
460+
[i for i, n in enumerate(landmarkslabels) if re.match("HPI.?[1-99]", n)],
437461
:,
438462
]
439463
else:
440464
hpi_pos = None
441465
if len(landmarkslabels) > 0:
442466
hsp_pos = landmarks[
443-
[i for i, n in enumerate(landmarkslabels) if re.match("H[1-99]", n)], :
467+
[i for i, n in enumerate(landmarkslabels) if re.match("H.?[1-99]", n)], :
444468
]
445469
else:
446470
hsp_pos = None
447471

448472
add_missing_fiducials = (
449473
True
450474
if (
451-
not landmark_dict["Nas"]
452-
and not landmark_dict["LPA"]
453-
and not landmark_dict["LPA"]
475+
isinstance(landmark_dict["Nas"], type(None))
476+
and isinstance(landmark_dict["LPA"], type(None))
477+
and isinstance(landmark_dict["RPA"], type(None))
454478
)
455479
else False # raises otherwise
456480
)

mne/io/curry/tests/test_curry.py

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
# License: BSD-3-Clause
44
# Copyright the MNE-Python contributors.
55

6-
76
import numpy as np
87
import pytest
98
from numpy import empty
@@ -12,9 +11,14 @@
1211
from mne.annotations import events_from_annotations, read_annotations
1312
from mne.channels import DigMontage
1413
from mne.datasets import testing
14+
from mne.epochs import Epochs
1515
from mne.event import find_events
1616
from mne.io.curry import read_impedances_curry, read_montage_curry, read_raw_curry
17-
from mne.io.curry.curry import _check_curry_filename, _check_curry_header_filename
17+
from mne.io.curry.curry import (
18+
RawCurry,
19+
_check_curry_filename,
20+
_check_curry_header_filename,
21+
)
1822
from mne.io.edf import read_raw_bdf
1923
from mne.io.tests.test_raw import _test_raw_reader
2024
from mne.transforms import Transform
@@ -30,6 +34,7 @@
3034
curry8_bdf_ascii_file = curry_dir / "test_bdf_stim_channel Curry 8 ASCII.cdt"
3135
Ref_chan_omitted_file = curry_dir / "Ref_channel_omitted Curry7.dat"
3236
Ref_chan_omitted_reordered_file = curry_dir / "Ref_channel_omitted reordered Curry7.dat"
37+
epoched_file = curry_dir / "Epoched.cdt"
3338

3439

3540
@pytest.fixture(scope="session")
@@ -72,7 +77,19 @@ def test_read_raw_curry(fname, tol, preload, bdf_curry_ref):
7277
bdf_curry_ref.get_data(picks=picks, start=start, stop=stop),
7378
rtol=tol,
7479
)
75-
# assert raw.info["dev_head_t"] is None # TODO do we need this value?
80+
assert raw.info["dev_head_t"] == Transform("meg", "head")
81+
82+
83+
@testing.requires_testing_data
84+
def test_read_raw_curry_epoched():
85+
"""Test reading epoched file."""
86+
ep = read_raw_curry(epoched_file)
87+
assert isinstance(ep, Epochs)
88+
assert len(ep.events) == 26
89+
assert len(ep.annotations) == 0
90+
raw = read_raw_curry(epoched_file, import_epochs_as_events=True)
91+
assert isinstance(raw, RawCurry)
92+
assert len(raw.annotations) == 26
7693

7794

7895
@testing.requires_testing_data
@@ -117,7 +134,6 @@ def test_read_events_curry_are_same_as_bdf(fname):
117134
"""Test events from curry annotations recovers the right events."""
118135
EVENT_ID = {str(ii): ii for ii in range(5)}
119136
REF_EVENTS = find_events(read_raw_bdf(bdf_file, preload=True))
120-
# TODO!
121137
raw = read_raw_curry(fname)
122138
events, _ = events_from_annotations(raw, event_id=EVENT_ID)
123139
assert_allclose(events, REF_EVENTS)

0 commit comments

Comments
 (0)