Hi, thank you for the quick reply.
Thank you, Iāll make sure to read those tutorials in detail. Iād found them earlier, but didnāt think they necessarily applied to fNIRS as well.
Iām using data from a research project. The data was collected using NIRSport2, which gives you data in .snirf format. Iāll provide an example of manipulating one .snirf file, here:
# load file (called sub)
raw = mne.io.read_raw_snirf(sub)
#renaming triggers
raw.annotations.rename({'70': 'Visual',
'71': 'Visual',
'72': 'Visual',
'61': 'Auditory',
'62': 'Auditory',
'63': 'Auditory'})
# choosing long channels
picks = mne.pick_types(raw.info, meg=False, fnirs=True)
dists = mne.preprocessing.nirs.source_detector_distances(
raw.info, picks=picks)
raw.pick(picks[dists > 0.01])
# converting to optical density
raw_od = mne.preprocessing.nirs.optical_density(raw)
# applying SCI
sci = mne.preprocessing.nirs.scalp_coupling_index(raw_od)
# marking 'bad channels'
raw_od.info['bads'] = list(compress(raw_od.ch_names, sci < 0.2))
# trying to fix bad channels
raw_od.interpolate_bads(reset_bads = False, method = dict(fnirs = 'nearest'))
# error code
---------------------------------------------------------------------------
RuntimeError Traceback (most recent call last)
/var/folders/b0/t62rjb510wb79fxb5ch9n3kc0000gn/T/ipykernel_41185/3770898462.py in <module>
1 # trying to fix bad channels
----> 2 raw_od.interpolate_bads(reset_bads = False, method = dict(fnirs = 'nearest'))
3
4 #doesn't work
<decorator-gen-42> in interpolate_bads(self, reset_bads, mode, origin, method, exclude, verbose)
~/opt/anaconda3/lib/python3.9/site-packages/mne/channels/channels.py in interpolate_bads(self, reset_bads, mode, origin, method, exclude, verbose)
1179 return self
1180 logger.info('Interpolating bad channels')
-> 1181 origin = _check_origin(origin, self.info)
1182 if method['eeg'] == 'spline':
1183 _interpolate_bads_eeg(self, origin=origin, exclude=exclude)
~/opt/anaconda3/lib/python3.9/site-packages/mne/bem.py in _check_origin(origin, info, coord_frame, disp)
993 'not %s' % (origin,))
994 if coord_frame == 'head':
--> 995 R, origin = fit_sphere_to_headshape(info, verbose=False,
996 units='m')[:2]
997 logger.info(' Automatic origin fit: head of radius %0.1f mm'
<decorator-gen-60> in fit_sphere_to_headshape(info, dig_kinds, units, verbose)
~/opt/anaconda3/lib/python3.9/site-packages/mne/bem.py in fit_sphere_to_headshape(info, dig_kinds, units, verbose)
847 if not isinstance(units, str) or units not in ('m', 'mm'):
848 raise ValueError('units must be a "m" or "mm"')
--> 849 radius, origin_head, origin_device = _fit_sphere_to_headshape(
850 info, dig_kinds)
851 if units == 'mm':
<decorator-gen-62> in _fit_sphere_to_headshape(info, dig_kinds, verbose)
~/opt/anaconda3/lib/python3.9/site-packages/mne/bem.py in _fit_sphere_to_headshape(info, dig_kinds, verbose)
931 def _fit_sphere_to_headshape(info, dig_kinds, verbose=None):
932 """Fit a sphere to the given head shape."""
--> 933 hsp = get_fitting_dig(info, dig_kinds)
934 radius, origin_head = _fit_sphere(np.array(hsp), disp=False)
935 # compute origin in device coordinates
<decorator-gen-61> in get_fitting_dig(info, dig_kinds, exclude_frontal, verbose)
~/opt/anaconda3/lib/python3.9/site-packages/mne/bem.py in get_fitting_dig(info, dig_kinds, exclude_frontal, verbose)
891 # try "extra" first
892 try:
--> 893 return get_fitting_dig(info, 'extra')
894 except ValueError:
895 pass
<decorator-gen-61> in get_fitting_dig(info, dig_kinds, exclude_frontal, verbose)
~/opt/anaconda3/lib/python3.9/site-packages/mne/bem.py in get_fitting_dig(info, dig_kinds, exclude_frontal, verbose)
908 hsp = [p['r'] for p in info['dig'] if p['kind'] in dig_kinds]
909 if any(p['coord_frame'] != FIFF.FIFFV_COORD_HEAD for p in info['dig']):
--> 910 raise RuntimeError('Digitization points not in head coordinates, '
911 'contact mne-python developers')
912
RuntimeError: Digitization points not in head coordinates, contact mne-python developers
#plot
raw_od.plot_sensors()
Best,
Sigrid