Skip to content

Commit

Permalink
MRG: Change orig_format for EGI, BrainVision ASCII and artemis123 rec…
Browse files Browse the repository at this point in the history
…ordings to "single" (mne-tools#10851)

* check orig_format against a list of valid values

* set original type to "single"

* add test

* replace egi "float" type by "single"

* fix orig_format for brainvision files in ASCII fmt

* add changelog entry

* fix artemis123 reader

* use double quotes for all edited lines [ci skip]
  • Loading branch information
mscheltienne authored Jun 30, 2022
1 parent 386d4cf commit 7e71888
Show file tree
Hide file tree
Showing 8 changed files with 16 additions and 5 deletions.
2 changes: 2 additions & 0 deletions doc/changes/latest.inc
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,8 @@ Bugs

- Correctly report the number of available projections when printing measurement info in a Jupyter notebook (:gh:`10471` by `Clemens Brunner`_)

- Fix value set in ``raw.orig_format`` for readers of BrainVision (ASCII format), EGI and Artemis123 files (:gh:`10851` by `Mathieu Scheltienne`_)


API and behavior changes
~~~~~~~~~~~~~~~~~~~~~~~~
Expand Down
2 changes: 1 addition & 1 deletion mne/io/artemis123/artemis123.py
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,7 @@ def __init__(self, input_fname, preload=False, verbose=None,

super(RawArtemis123, self).__init__(
info, preload, filenames=[input_fname], raw_extras=[header_info],
last_samps=last_samps, orig_format=np.float32,
last_samps=last_samps, orig_format="single",
verbose=verbose)

if add_head_trans:
Expand Down
4 changes: 4 additions & 0 deletions mne/io/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,10 @@ def __init__(self, info, preload=False,
% self._read_comp_grade)
self._comp = None
self._filenames = list(filenames)
_validate_type(orig_format, str, "orig_format")
_check_option(
"orig_format", orig_format, ("double", "single", "int", "short")
)
self.orig_format = orig_format
# Sanity check and set original units, if provided by the reader:

Expand Down
3 changes: 2 additions & 1 deletion mne/io/brainvision/brainvision.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,11 +92,12 @@ def __init__(self, vhdr_fname,
offsets = None
n_samples = n_samples // (dtype_bytes * n_data_ch)

orig_format = "single" if isinstance(fmt, dict) else fmt
raw_extras = dict(
offsets=offsets, fmt=fmt, order=order, n_samples=n_samples)
super(RawBrainVision, self).__init__(
info, last_samps=[n_samples - 1], filenames=[data_fname],
orig_format=fmt, preload=preload, verbose=verbose,
orig_format=orig_format, preload=preload, verbose=verbose,
raw_extras=[raw_extras], orig_units=orig_units)

self.set_montage(montage)
Expand Down
1 change: 1 addition & 0 deletions mne/io/brainvision/tests/test_brainvision.py
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,7 @@ def test_ascii(tmp_path, data_sep):
return

raw = read_raw_brainvision(ascii_vhdr_path)
assert isinstance(raw.orig_format, str)
data_new, times_new = raw[:]
assert_allclose(data_new, data, atol=1e-15)
assert_allclose(times_new, times)
Expand Down
4 changes: 3 additions & 1 deletion mne/io/egi/egi.py
Original file line number Diff line number Diff line change
Expand Up @@ -258,8 +258,10 @@ def __init__(self, input_fname, eog=None, misc=None,
info['chs'] = chs
info._unlocked = False
info._update_redundant()
orig_format = egi_info["orig_format"] \
if egi_info["orig_format"] != "float" else "single"
super(RawEGI, self).__init__(
info, preload, orig_format=egi_info['orig_format'],
info, preload, orig_format=orig_format,
filenames=[input_fname], last_samps=[egi_info['n_samples'] - 1],
raw_extras=[egi_info], verbose=verbose)

Expand Down
2 changes: 1 addition & 1 deletion mne/io/egi/egimff.py
Original file line number Diff line number Diff line change
Expand Up @@ -548,7 +548,7 @@ def __init__(self, input_fname, eog=None, misc=None,
self._raw_extras = [egi_info]

super(RawMff, self).__init__(
info, preload=preload, orig_format='float', filenames=[file_bin],
info, preload=preload, orig_format="single", filenames=[file_bin],
first_samps=first_samps, last_samps=last_samps,
raw_extras=[egi_info], verbose=verbose)

Expand Down
3 changes: 2 additions & 1 deletion mne/io/egi/tests/test_egi.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ def test_io_egi_mff():
"""Test importing EGI MFF simple binary files."""
raw = read_raw_egi(egi_mff_fname, include=None)
assert ('RawMff' in repr(raw))
assert raw.orig_format == "single"
include = ['DIN1', 'DIN2', 'DIN3', 'DIN4', 'DIN5', 'DIN7']
raw = _test_raw_reader(read_raw_egi, input_fname=egi_mff_fname,
include=include, channel_naming='EEG %03d',
Expand Down Expand Up @@ -198,7 +199,7 @@ def test_io_egi():
)

assert 'eeg' in raw

assert raw.orig_format == "single"
eeg_chan = [c for c in raw.ch_names if c.startswith('E')]
assert len(eeg_chan) == 256
picks = pick_types(raw.info, eeg=True)
Expand Down

0 comments on commit 7e71888

Please sign in to comment.