Skip to content
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

WIP: Warn if untested NIRX device #7905

Merged
merged 2 commits into from
Jun 23, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 38 additions & 29 deletions mne/io/nirx/nirx.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
def read_raw_nirx(fname, preload=False, verbose=None):
"""Reader for a NIRX fNIRS recording.

This function has only been tested with NIRScout devices.

Parameters
----------
fname : str
Expand Down Expand Up @@ -70,6 +72,9 @@ def __init__(self, fname, preload=False, verbose=None):
if fname.endswith('.hdr'):
fname = op.dirname(op.abspath(fname))

if not op.isdir(fname):
raise RuntimeError('The path you specified does not exist.')

# Check if required files exist and store names for later use
files = dict()
keys = ('evt', 'hdr', 'inf', 'set', 'tpl', 'wl1', 'wl2',
Expand All @@ -92,35 +97,6 @@ def __init__(self, fname, preload=False, verbose=None):
for line in fid:
last_sample += 1

# Read participant information file
inf = ConfigParser(allow_no_value=True)
inf.read(files['inf'])
inf = inf._sections['Subject Demographics']

# Store subject information from inf file in mne format
# Note: NIRX also records "Study Type", "Experiment History",
# "Additional Notes", "Contact Information" and this information
# is currently discarded
subject_info = {}
names = inf['name'].split()
if len(names) > 0:
subject_info['first_name'] = \
inf['name'].split()[0].replace("\"", "")
if len(names) > 1:
subject_info['last_name'] = \
inf['name'].split()[-1].replace("\"", "")
if len(names) > 2:
subject_info['middle_name'] = \
inf['name'].split()[-2].replace("\"", "")
# subject_info['birthday'] = inf['age'] # TODO: not formatted properly
subject_info['sex'] = inf['gender'].replace("\"", "")
# Recode values
if subject_info['sex'] in {'M', 'Male', '1'}:
subject_info['sex'] = FIFF.FIFFV_SUBJ_SEX_MALE
elif subject_info['sex'] in {'F', 'Female', '2'}:
subject_info['sex'] = FIFF.FIFFV_SUBJ_SEX_FEMALE
# NIRStar does not record an id, or handedness by default

# Read header file
# The header file isn't compliant with the configparser. So all the
# text between comments must be removed before passing to parser
Expand All @@ -135,6 +111,10 @@ def __init__(self, fname, preload=False, verbose=None):
["\"15.0\"", "\"15.2\""]):
raise RuntimeError('MNE does not support this NIRStar version'
' (%s)' % (hdr['GeneralInfo']['NIRStar'],))
if "NIRScout" not in hdr['GeneralInfo']['Device']:
warn("Only import of data from NIRScout devices have been "
"thoroughly tested. You are using a %s device. " %
hdr['GeneralInfo']['Device'])

# Parse required header fields

Expand All @@ -161,6 +141,35 @@ def __init__(self, fname, preload=False, verbose=None):
# Extract sampling rate
samplingrate = float(hdr['ImagingParameters']['SamplingRate'])

# Read participant information file
inf = ConfigParser(allow_no_value=True)
inf.read(files['inf'])
inf = inf._sections['Subject Demographics']

# Store subject information from inf file in mne format
# Note: NIRX also records "Study Type", "Experiment History",
# "Additional Notes", "Contact Information" and this information
# is currently discarded
subject_info = {}
names = inf['name'].split()
if len(names) > 0:
subject_info['first_name'] = \
inf['name'].split()[0].replace("\"", "")
if len(names) > 1:
subject_info['last_name'] = \
inf['name'].split()[-1].replace("\"", "")
if len(names) > 2:
subject_info['middle_name'] = \
inf['name'].split()[-2].replace("\"", "")
# subject_info['birthday'] = inf['age'] # TODO: not formatted properly
subject_info['sex'] = inf['gender'].replace("\"", "")
# Recode values
if subject_info['sex'] in {'M', 'Male', '1'}:
subject_info['sex'] = FIFF.FIFFV_SUBJ_SEX_MALE
elif subject_info['sex'] in {'F', 'Female', '2'}:
subject_info['sex'] = FIFF.FIFFV_SUBJ_SEX_FEMALE
# NIRStar does not record an id, or handedness by default

# Read information about probe/montage/optodes
# A word on terminology used here:
# Sources produce light
Expand Down
7 changes: 7 additions & 0 deletions mne/io/nirx/tests/test_nirx.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,13 @@ def test_nirx_hdr_load():
assert raw.info['sfreq'] == 12.5


@requires_testing_data
def test_nirx_missing_warn():
"""Test reading NIRX files when missing data."""
with pytest.raises(RuntimeError, match='The path you'):
read_raw_nirx(fname_nirx_15_2_short + "1", preload=True)


@requires_testing_data
def test_nirx_dat_warn(tmpdir):
"""Test reading NIRX files when missing data."""
Expand Down