Skip to content

Commit

Permalink
MAINT: Check raw class attributes (mne-tools#11826)
Browse files Browse the repository at this point in the history
  • Loading branch information
larsoner authored Jul 25, 2023
1 parent 74f3f18 commit fc88fe5
Show file tree
Hide file tree
Showing 13 changed files with 320 additions and 274 deletions.
2 changes: 2 additions & 0 deletions mne/io/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,8 @@ class BaseRaw(
(only needed for types that support on-demand disk reads)
"""

_extra_attributes = ()

@verbose
def __init__(
self,
Expand Down
2 changes: 2 additions & 0 deletions mne/io/brainvision/brainvision.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ class RawBrainVision(BaseRaw):
mne.io.Raw : Documentation of attributes and methods.
"""

_extra_attributes = ("impedances",)

@verbose
def __init__(
self,
Expand Down
2 changes: 1 addition & 1 deletion mne/io/bti/bti.py
Original file line number Diff line number Diff line change
Expand Up @@ -1086,7 +1086,7 @@ def __init__(
sort_by_ch_name=sort_by_ch_name,
eog_ch=eog_ch,
)
self.bti_ch_labels = [c["chan_label"] for c in bti_info["chs"]]
bti_info["bti_ch_labels"] = [c["chan_label"] for c in bti_info["chs"]]
# make Raw repr work if we have a BytesIO as input
if isinstance(pdf_fname, BytesIO):
pdf_fname = repr(pdf_fname)
Expand Down
6 changes: 4 additions & 2 deletions mne/io/bti/tests/test_bti.py
Original file line number Diff line number Diff line change
Expand Up @@ -285,10 +285,12 @@ def test_info_no_rename_no_reorder_no_pdf():
preload=True,
)

sort_idx = [raw1.bti_ch_labels.index(ch) for ch in raw2.bti_ch_labels]
bti_ch_labels_1 = raw1._raw_extras[0]["bti_ch_labels"]
bti_ch_labels_2 = raw2._raw_extras[0]["bti_ch_labels"]
sort_idx = [bti_ch_labels_1.index(ch) for ch in bti_ch_labels_2]
raw1._data = raw1._data[sort_idx]
assert_array_equal(raw1._data, raw2._data)
assert_array_equal(raw2.bti_ch_labels, raw2.ch_names)
assert_array_equal(bti_ch_labels_2, raw2.ch_names)


def test_no_conversion():
Expand Down
18 changes: 8 additions & 10 deletions mne/io/ctf/ctf.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,9 +193,8 @@ def __init__(
)
annot = marker_annot if annot is None else annot + marker_annot
self.set_annotations(annot)

if clean_names:
self._clean_names()
_clean_names_inst(self)

def _read_segment_file(self, data, idx, fi, start, stop, cals, mult):
"""Read a chunk of raw data."""
Expand All @@ -222,15 +221,14 @@ def _read_segment_file(self, data, idx, fi, start, stop, cals, mult):
_mult_cal_one(data_view, this_data, idx, cals, mult)
offset += n_read

def _clean_names(self):
"""Clean up CTF suffixes from channel names."""
mapping = dict(zip(self.ch_names, _clean_names(self.ch_names)))

self.rename_channels(mapping)

for comp in self.info["comps"]:
for key in ("row_names", "col_names"):
comp["data"][key] = _clean_names(comp["data"][key])
def _clean_names_inst(inst):
"""Clean up CTF suffixes from channel names."""
mapping = dict(zip(inst.ch_names, _clean_names(inst.ch_names)))
inst.rename_channels(mapping)
for comp in inst.info["comps"]:
for key in ("row_names", "col_names"):
comp["data"][key] = _clean_names(comp["data"][key])


def _get_sample_info(fname, res4, system_clock):
Expand Down
2 changes: 2 additions & 0 deletions mne/io/egi/egi.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,8 @@ def read_raw_egi(
class RawEGI(BaseRaw):
"""Raw object from EGI simple binary file."""

_extra_attributes = ("event_id",)

@verbose
def __init__(
self,
Expand Down
2 changes: 2 additions & 0 deletions mne/io/egi/egimff.py
Original file line number Diff line number Diff line change
Expand Up @@ -432,6 +432,8 @@ def _read_raw_egi_mff(
class RawMff(BaseRaw):
"""RawMff class."""

_extra_attributes = ("event_id",)

@verbose
def __init__(
self,
Expand Down
9 changes: 9 additions & 0 deletions mne/io/eyelink/tests/test_eyelink.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

from mne.datasets.testing import data_path, requires_testing_data
from mne.io import read_raw_eyelink
from mne.io.tests.test_raw import _test_raw_reader
from mne.io.constants import FIFF
from mne.io.pick import _DATA_CH_TYPES_SPLIT
from mne.utils import _check_pandas_installed, requires_pandas
Expand Down Expand Up @@ -189,3 +190,11 @@ def test_find_overlaps():
assert len(overlap_df["eye"].unique()) == 3 # ['both', 'left', 'right']
assert len(overlap_df) == 5 # ['both', 'L', 'R', 'L', 'L']
assert overlap_df["eye"].iloc[0] == "both"


@pytest.mark.xfail(reason="Attributes and test_preloading fail")
@requires_testing_data
@pytest.mark.parametrize("this_fname", (fname, fname_href))
def test_basics(this_fname):
"""Test basics of reading."""
_test_raw_reader(read_raw_eyelink, fname=this_fname)
6 changes: 6 additions & 0 deletions mne/io/fiff/raw.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,12 @@ class Raw(BaseRaw):
%(verbose)s
"""

_extra_attributes = (
"fix_mag_coil_types",
"acqparser",
"_read_raw_file", # this would be ugly to move, but maybe we should
)

@verbose
def __init__(
self,
Expand Down
Loading

0 comments on commit fc88fe5

Please sign in to comment.