Skip to content

add OTB (EMG) reader #13303

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft

add OTB (EMG) reader #13303

wants to merge 2 commits into from

Conversation

drammock
Copy link
Member

This implements a Raw reader for OTB files (EMG data). There are 2 formats, OTB4 and OTB+; so far only OTB+ implemented. Based in part on a MATLAB reader, with permission to translate and relicense as BSD-3, granted here: OTBioelettronica/OTB-Python#2 (comment)

  • add support for OTB4 format
  • decide whether this belongs in MNE-Python, MNE-BIDS, or a separate package. I don't have strong feelings here; I implemented in MNE-Python first because it was easiest, but I'm happy to migrate the code.
  • add data files from Python file reader (or permission to port MATLAB file reader)? OTBioelettronica/OTB-Python#2 (comment) to mne-testing-data
  • add tests. May need help from someone with a MATLAB license, as I can't get the MATLAB-based reader to work in Octave. Would be great to have .mat files with source-of-truth for the signal values from the test data files.
  • handle annotations (marker files); in my example file they're empty.

cc @OTBioelettronica @klotz-t @pranavm19 @agramfort

from ...utils import _check_fname, fill_doc, logger, verbose, warn
from ..base import BaseRaw

OTB_PLUS_DTYPE = np.int16 # the file I have is int16; TBD if *all* OTB+ are like that
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@OTBioelettronica there are several TODO items in the code here that maybe you can easily answer. Here's the first: are the data in .sig files always 16-bit signed integer?

Comment on lines +31 to +33
# TODO English-centric; any value of "sex" not starting with "m" or "f" will get
# classed as "unknown". TBD if non-English-like values in the XML are possible
# (e.g. maybe the recording GUI is localized but the XML values are not?)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@OTBioelettronica is "sex" always "M" or "F" in these files or can users input whatever they like in this field? If left unspecified, will the <sex> node just be missing from the XML file?

Comment on lines +86 to +87
# TODO verify these are the only non-data channel IDs
NON_DATA_CHS = ("Quaternion", "BufferChannel", "RampChannel")
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@OTBioelettronica we need to distinguish which channels are EMG data from other channel types. Are these 3 the only non-EMG channel IDs, or are there others?

fnames = fid.getnames()
# the .sig file is the binary channel data
sig_fname = [_fname for _fname in fnames if _fname.endswith(".sig")]
assert len(sig_fname) == 1 # TODO is this a valid assumption?
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is there guaranteed to be only 1 .sig file in each OTB+ archive? The MATLAB code suggests "yes" but it's not totally clear.

Comment on lines +136 to +137
# TODO better to call these "emg_1" etc? should we left-zeropad ix?
ch_names.append(f"{ch_id}_{ix}" if ch_id in dupl_ids else ch_id)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

right now we get channel names like "HD10MM0804_0", "HD10MM0804_1", etc. Seems like "EMG_000", "EMG_001" might be more user-friendly.

Comment on lines +141 to +142
# TODO verify ch_type for quats, buffer channel, and ramp channel
ch_types.append("misc" if ch_id in NON_DATA_CHS else "emg")
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@larsoner is misc the right channel type for these?

Comment on lines +221 to +224
# TODO is the factor of 1000 (copied from the MATLAB code) to convert Volts
# milliVolts? If so we should remove it (in MNE we always store in SI units, so
# we should keep it in V)
self._data = _data * (1000 * power_supply / 2**bit_depth / gains)[:, np.newaxis]
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@OTBioelettronica can you verify that the data in the .sig file are recorded in Volts?

@larsoner
Copy link
Member

decide whether this belongs in MNE-Python, MNE-BIDS, or a separate package. I don't have strong feelings here; I implemented in MNE-Python first because it was easiest, but I'm happy to migrate the code.

I think MNE-Python is better scope-wise than MNE-BIDS. Might make sense to add a MNE-EMG (or another package?) like we have MNE-NIRS if we expect a lot of EMG-specific functionality. In that case, the reader could live here or there. I think my vote is to start this MNE-EMG package with the hopes that EMG-specific functionality can grow there...

@sappelhoff
Copy link
Member

I think MNE-Python is better scope-wise than MNE-BIDS.

agreed

I think my vote is to start this MNE-EMG package with the hopes that EMG-specific functionality can grow there...

Yes, I think following what we have with mne-nirs would be good.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants