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

ENH: Support TD data #11064

Draft
wants to merge 40 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 19 commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
3f875d3
adding the new snirf data types to the constants
Zahra-M-Aghajan Aug 11, 2021
cc92adc
more places to add the data types and constants
Zahra-M-Aghajan Aug 11, 2021
0d2fe87
adding constants for the allowed dataTypeLabels for the processed dat…
Zahra-M-Aghajan Aug 11, 2021
21ecb90
updating the snirf reader to accept other data types: gated histogram…
Zahra-M-Aghajan Aug 11, 2021
4491064
setting the formatter line length
Zahra-M-Aghajan Aug 11, 2021
dbdcebc
the reordering of the channels does not make much sense, need to inquire
Zahra-M-Aghajan Aug 12, 2021
80de954
Merge remote-tracking branch 'upstream/main' into feature/TD-nirs_snirf
Zahra-M-Aghajan Aug 19, 2021
32c5496
Merge remote-tracking branch 'upstream/main' into feature/TD-nirs_snirf
larsoner Aug 21, 2022
a35822a
MAINT: Simpler with .item
larsoner Aug 21, 2022
c2c217c
WIP: Constants
larsoner Aug 21, 2022
ac52bc0
FIX: Flake
larsoner Aug 21, 2022
da275f1
FIX: Consistent
larsoner Aug 21, 2022
3986b96
FIX: Missed
larsoner Aug 21, 2022
ce8b3af
FIX: Better code
larsoner Aug 21, 2022
1244add
FIX: Scale
larsoner Aug 21, 2022
3944254
FIX: Missing
larsoner Aug 21, 2022
967dddd
FIX: Flake
larsoner Aug 21, 2022
e97367d
FIX: Syntax
larsoner Aug 21, 2022
4b963cd
Merge remote-tracking branch 'upstream/main' into feature/TD-nirs_snirf
larsoner Aug 23, 2022
15e2878
Merge remote-tracking branch 'upstream/main' into feature/TD-nirs_snirf
larsoner Mar 1, 2023
d26ff8a
FIX: shape
larsoner Mar 1, 2023
f84fe27
FIX: Slash
larsoner Mar 1, 2023
50f3064
FIX: Bad merge
larsoner Mar 1, 2023
495bdf7
Merge branch 'main' into feature/TD-nirs_snirf
larsoner Mar 2, 2023
a076e23
Merge remote-tracking branch 'upstream/main' into feature/TD-nirs_snirf
larsoner Mar 9, 2023
698d2a6
FIX: Add tests
larsoner Mar 9, 2023
d3b75ab
FIX: Reg
larsoner Mar 9, 2023
b1cf310
Merge branch 'main' into feature/TD-nirs_snirf
larsoner Mar 14, 2023
0c4f886
MAINT: Revert
larsoner Oct 28, 2024
34c36f5
Merge remote-tracking branch 'upstream/main' into feature/TD-nirs_snirf
larsoner Oct 28, 2024
b5e9967
Empty commit for credit
larsoner Oct 28, 2024
34dffbf
DOC: Change
larsoner Oct 28, 2024
d62dbb1
MAINT: Mailmap
larsoner Oct 28, 2024
880356e
FIX: SI
larsoner Oct 28, 2024
4f0e8e6
FIX: Oops
larsoner Oct 28, 2024
a5c97b8
FIX: Oops
larsoner Oct 28, 2024
fba1ffa
FIX: idx
larsoner Oct 28, 2024
9f4234d
WIP
larsoner Oct 28, 2024
b3b3f2e
FIX: Test
larsoner Oct 28, 2024
9723621
Merge remote-tracking branch 'upstream/main' into feature/TD-nirs_snirf
larsoner Oct 28, 2024
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
20 changes: 16 additions & 4 deletions mne/cov.py
Original file line number Diff line number Diff line change
Expand Up @@ -1237,9 +1237,11 @@ def _auto_low_rank_model(data, mode, n_jobs, method_params, cv,
class _RegCovariance(BaseEstimator):
"""Aux class."""

def __init__(self, info, grad=0.1, mag=0.1, eeg=0.1, seeg=0.1,
def __init__(self, info, grad=0.1, mag=0.1, eeg=0.1, *, seeg=0.1,
ecog=0.1, hbo=0.1, hbr=0.1, fnirs_cw_amplitude=0.1,
fnirs_fd_ac_amplitude=0.1, fnirs_fd_phase=0.1, fnirs_od=0.1,
fnirs_td_gated_amplitude=0.1,
fnirs_td_moments_amplitude=0.1,
csd=0.1, dbs=0.1, store_precision=False,
assume_centered=False):
self.info = info
Expand Down Expand Up @@ -1540,9 +1542,12 @@ def _smart_eigh(C, info, rank, scalings=None, projs=None,

@verbose
def regularize(cov, info, mag=0.1, grad=0.1, eeg=0.1, exclude='bads',
proj=True, seeg=0.1, ecog=0.1, hbo=0.1, hbr=0.1,
proj=True, *, seeg=0.1, ecog=0.1, hbo=0.1, hbr=0.1,
fnirs_cw_amplitude=0.1, fnirs_fd_ac_amplitude=0.1,
fnirs_fd_phase=0.1, fnirs_od=0.1, csd=0.1, dbs=0.1,
fnirs_fd_phase=0.1, fnirs_od=0.1,
fnirs_td_gated_amplitude=0.1,
fnirs_td_moments_amplitude=0.1,
csd=0.1, dbs=0.1,
rank=None, scalings=None, verbose=None):
"""Regularize noise covariance matrix.

Expand Down Expand Up @@ -1590,6 +1595,10 @@ def regularize(cov, info, mag=0.1, grad=0.1, eeg=0.1, exclude='bads',
Regularization factor for fNIRS raw phase signals.
fnirs_od : float (default 0.1)
Regularization factor for fNIRS optical density signals.
fnirs_td_gated_amplitude : float (default 0.1)
Regularization factor for fNIRS time domain gated amplitude signals.
fnirs_td_moments_amplitude : float (default 0.1)
Regularization factor for fNIRS time domain moments amplitude signals.
csd : float (default 0.1)
Regularization factor for EEG-CSD signals.
dbs : float (default 0.1)
Expand Down Expand Up @@ -1623,7 +1632,10 @@ def regularize(cov, info, mag=0.1, grad=0.1, eeg=0.1, exclude='bads',
regs = dict(eeg=eeg, seeg=seeg, dbs=dbs, ecog=ecog, hbo=hbo, hbr=hbr,
fnirs_cw_amplitude=fnirs_cw_amplitude,
fnirs_fd_ac_amplitude=fnirs_fd_ac_amplitude,
fnirs_fd_phase=fnirs_fd_phase, fnirs_od=fnirs_od, csd=csd)
fnirs_fd_phase=fnirs_fd_phase, fnirs_od=fnirs_od,
fnirs_td_gated_amplitude=fnirs_td_gated_amplitude,
fnirs_td_moments_amplitude=fnirs_td_moments_amplitude,
csd=csd)

if exclude is None:
raise ValueError('exclude must be a list of strings or "bads"')
Expand Down
31 changes: 23 additions & 8 deletions mne/defaults.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,34 +12,47 @@
exci='k', ias='k', syst='k', seeg='saddlebrown', dbs='seagreen',
dipole='k', gof='k', bio='k', ecog='k', hbo='#AA3377', hbr='b',
fnirs_cw_amplitude='k', fnirs_fd_ac_amplitude='k',
fnirs_fd_phase='k', fnirs_od='k', csd='k', whitened='k'),
fnirs_fd_phase='k', fnirs_od='k',
fnirs_td_gated_amplitude='k',
fnirs_td_moments_amplitude='k',
csd='k', whitened='k'),
si_units=dict(mag='T', grad='T/m', eeg='V', eog='V', ecg='V', emg='V',
misc='AU', seeg='V', dbs='V', dipole='Am', gof='GOF',
bio='V', ecog='V', hbo='M', hbr='M', ref_meg='T',
fnirs_cw_amplitude='V', fnirs_fd_ac_amplitude='V',
fnirs_fd_phase='rad', fnirs_od='V', csd='V/m²',
whitened='Z'),
fnirs_fd_phase='rad', fnirs_od='V',
# TODO: These units and scalings are wrong
fnirs_td_gated_amplitude='Au',
fnirs_td_moments_amplitude='Au',
csd='V/m²', whitened='Z'),
units=dict(mag='fT', grad='fT/cm', eeg='µV', eog='µV', ecg='µV', emg='µV',
misc='AU', seeg='mV', dbs='µV', dipole='nAm', gof='GOF',
bio='µV', ecog='µV', hbo='µM', hbr='µM', ref_meg='fT',
fnirs_cw_amplitude='V', fnirs_fd_ac_amplitude='V',
fnirs_fd_phase='rad', fnirs_od='V', csd='mV/m²',
whitened='Z'),
fnirs_fd_phase='rad', fnirs_od='V',
fnirs_td_gated_amplitude='Au',
larsoner marked this conversation as resolved.
Show resolved Hide resolved
fnirs_td_moments_amplitude='Au',
csd='mV/m²', whitened='Z'),
# scalings for the units
scalings=dict(mag=1e15, grad=1e13, eeg=1e6, eog=1e6, emg=1e6, ecg=1e6,
misc=1.0, seeg=1e3, dbs=1e6, ecog=1e6, dipole=1e9, gof=1.0,
bio=1e6, hbo=1e6, hbr=1e6, ref_meg=1e15,
fnirs_cw_amplitude=1.0, fnirs_fd_ac_amplitude=1.0,
fnirs_fd_phase=1., fnirs_od=1.0, csd=1e3, whitened=1.),
fnirs_fd_phase=1., fnirs_od=1.0,
fnirs_td_gated_amplitude=1.,
fnirs_td_moments_amplitude=1.,
csd=1e3, whitened=1.),
# rough guess for a good plot
scalings_plot_raw=dict(mag=1e-12, grad=4e-11, eeg=20e-6, eog=150e-6,
ecg=5e-4, emg=1e-3, ref_meg=1e-12, misc='auto',
stim=1, resp=1, chpi=1e-4, exci=1, ias=1, syst=1,
seeg=1e-4, dbs=1e-4, bio=1e-6, ecog=1e-4, hbo=10e-6,
hbr=10e-6, whitened=10., fnirs_cw_amplitude=2e-2,
fnirs_fd_ac_amplitude=2e-2, fnirs_fd_phase=2e-1,
fnirs_od=2e-2, csd=200e-4,
dipole=1e-7, gof=1e2),
fnirs_od=2e-2,
fnirs_td_gated_amplitude=1.,
fnirs_td_moments_amplitude=1.,
csd=200e-4, dipole=1e-7, gof=1e2),
scalings_cov_rank=dict(mag=1e12, grad=1e11, eeg=1e5, # ~100x scalings
seeg=1e1, dbs=1e4, ecog=1e4, hbo=1e4, hbr=1e4),
ylim=dict(mag=(-600., 600.), grad=(-200., 200.), eeg=(-200., 200.),
Expand All @@ -54,6 +67,8 @@
fnirs_fd_ac_amplitude='fNIRS (FD AC amplitude)',
fnirs_fd_phase='fNIRS (FD phase)',
fnirs_od='fNIRS (OD)', hbr='Deoxyhemoglobin',
fnirs_td_gated_amplitude='fNIRS (TD amplitude)',
fnirs_td_moments_amplitude='fNIRS (TD moment)',
gof='Goodness of fit', csd='Current source density',
stim='Stimulus',
),
Expand Down
6 changes: 5 additions & 1 deletion mne/io/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -916,6 +916,8 @@
FIFF.FIFFV_COIL_FNIRS_FD_AC_AMPLITUDE = 304 # fNIRS frequency domain AC amplitude
FIFF.FIFFV_COIL_FNIRS_FD_PHASE = 305 # fNIRS frequency domain phase
FIFF.FIFFV_COIL_FNIRS_RAW = FIFF.FIFFV_COIL_FNIRS_CW_AMPLITUDE # old alias
FIFF.FIFFV_COIL_FNIRS_TD_GATED_AMPLITUDE = 306 # fNIRS time-domain gated amplitude
FIFF.FIFFV_COIL_FNIRS_TD_MOMENTS_AMPLITUDE = 307 # fNIRS time-domain moments amplitude

FIFF.FIFFV_COIL_MCG_42 = 1000 # For testing the MCG software

Expand Down Expand Up @@ -1002,7 +1004,9 @@
FIFF.FIFFV_COIL_DIPOLE, FIFF.FIFFV_COIL_FNIRS_HBO,
FIFF.FIFFV_COIL_FNIRS_HBR, FIFF.FIFFV_COIL_FNIRS_RAW,
FIFF.FIFFV_COIL_FNIRS_OD, FIFF.FIFFV_COIL_FNIRS_FD_AC_AMPLITUDE,
FIFF.FIFFV_COIL_FNIRS_FD_PHASE, FIFF.FIFFV_COIL_MCG_42,
FIFF.FIFFV_COIL_FNIRS_FD_PHASE, FIFF.FIFFV_COIL_FNIRS_TD_GATED_AMPLITUDE,
FIFF.FIFFV_COIL_FNIRS_TD_MOMENTS_AMPLITUDE,
FIFF.FIFFV_COIL_MCG_42,
FIFF.FIFFV_COIL_POINT_MAGNETOMETER, FIFF.FIFFV_COIL_AXIAL_GRAD_5CM,
FIFF.FIFFV_COIL_VV_PLANAR_W, FIFF.FIFFV_COIL_VV_PLANAR_T1,
FIFF.FIFFV_COIL_VV_PLANAR_T2, FIFF.FIFFV_COIL_VV_PLANAR_T3,
Expand Down
24 changes: 19 additions & 5 deletions mne/io/pick.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,14 @@ def get_channel_type_constants(include_defaults=False):
kind=FIFF.FIFFV_FNIRS_CH,
unit=FIFF.FIFF_UNIT_V,
coil_type=FIFF.FIFFV_COIL_FNIRS_CW_AMPLITUDE),
fnirs_td_gated_amplitude=dict(
kind=FIFF.FIFFV_FNIRS_CH,
unit=FIFF.FIFF_UNIT_V,
coil_type=FIFF.FIFFV_COIL_FNIRS_TD_GATED_AMPLITUDE),
fnirs_td_moments_amplitude=dict(
kind=FIFF.FIFFV_FNIRS_CH,
unit=FIFF.FIFF_UNIT_V,
coil_type=FIFF.FIFFV_COIL_FNIRS_TD_MOMENTS_AMPLITUDE),
fnirs_fd_ac_amplitude=dict(
kind=FIFF.FIFFV_FNIRS_CH,
unit=FIFF.FIFF_UNIT_V,
Expand Down Expand Up @@ -160,6 +168,10 @@ def get_channel_type_constants(include_defaults=False):
FIFF.FIFFV_COIL_FNIRS_FD_PHASE:
'fnirs_fd_phase',
FIFF.FIFFV_COIL_FNIRS_OD: 'fnirs_od',
FIFF.FIFFV_COIL_FNIRS_TD_GATED_AMPLITUDE:
'fnirs_td_gated_amplitude',
FIFF.FIFFV_COIL_FNIRS_TD_MOMENTS_AMPLITUDE:
'fnirs_td_moments_amplitude',
}),
'eeg': ('coil_type', {FIFF.FIFFV_COIL_EEG: 'eeg',
FIFF.FIFFV_COIL_EEG_BIPOLAR: 'eeg',
Expand Down Expand Up @@ -717,9 +729,8 @@ def channel_indices_by_type(info, picks=None):
"""
idx_by_type = {key: list() for key in _PICK_TYPES_KEYS if
key not in ('meg', 'fnirs')}
idx_by_type.update(mag=list(), grad=list(), hbo=list(), hbr=list(),
fnirs_cw_amplitude=list(), fnirs_fd_ac_amplitude=list(),
fnirs_fd_phase=list(), fnirs_od=list())
idx_by_type.update(mag=list(), grad=list())
idx_by_type.update((key, list()) for key in _FNIRS_CH_TYPES_SPLIT)
picks = _picks_to_idx(info, picks,
none='all', exclude=(), allow_empty=True)
for k in picks:
Expand Down Expand Up @@ -914,8 +925,11 @@ def _check_excludes_includes(chs, info=None, allow_bads=False):
dbs=True)
_PICK_TYPES_KEYS = tuple(list(_PICK_TYPES_DATA_DICT) + ['ref_meg'])
_MEG_CH_TYPES_SPLIT = ('mag', 'grad', 'planar1', 'planar2')
_FNIRS_CH_TYPES_SPLIT = ('hbo', 'hbr', 'fnirs_cw_amplitude',
'fnirs_fd_ac_amplitude', 'fnirs_fd_phase', 'fnirs_od')
_FNIRS_CH_TYPES_SPLIT = (
'hbo', 'hbr', 'fnirs_cw_amplitude',
'fnirs_fd_ac_amplitude', 'fnirs_fd_phase', 'fnirs_od',
'fnirs_td_gated_amplitude', 'fnirs_td_moments_amplitude',
)
_DATA_CH_TYPES_ORDER_DEFAULT = (
'mag', 'grad', 'eeg', 'csd', 'eog', 'ecg', 'resp', 'emg', 'ref_meg',
'misc', 'stim', 'chpi', 'exci', 'ias', 'syst', 'seeg', 'bio', 'ecog',
Expand Down
Loading