Skip to content

Commit

Permalink
Warn if untested NIRX device
Browse files Browse the repository at this point in the history
  • Loading branch information
rob-luke committed Jun 23, 2020
1 parent 64499b7 commit 6d7306a
Showing 1 changed file with 38 additions and 29 deletions.
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

0 comments on commit 6d7306a

Please sign in to comment.