2727from ..io .pick import channel_type , pick_info , pick_types , pick_channels
2828from ..cov import (compute_whitener , _read_cov , _write_cov , Covariance ,
2929 prepare_noise_cov )
30- from ..epochs import BaseEpochs
30+ from ..epochs import BaseEpochs , EpochsArray
3131from ..evoked import EvokedArray , Evoked
3232from ..forward import (compute_depth_prior , _read_forward_meas_info ,
3333 is_fixed_orient , compute_orient_prior ,
@@ -883,6 +883,8 @@ def apply_inverse(evoked, inverse_operator, lambda2=1. / 9., method="dSPM",
883883 --------
884884 apply_inverse_raw : Apply inverse operator to raw object.
885885 apply_inverse_epochs : Apply inverse operator to epochs object.
886+ apply_inverse_tfr_epochs : Apply inverse operator to epochs tfr object.
887+ apply_inverse_cov : Apply inverse operator to covariance object.
886888
887889 Notes
888890 -----
@@ -1067,8 +1069,10 @@ def apply_inverse_raw(raw, inverse_operator, lambda2, method="dSPM",
10671069
10681070 See Also
10691071 --------
1070- apply_inverse_epochs : Apply inverse operator to epochs object.
10711072 apply_inverse : Apply inverse operator to evoked object.
1073+ apply_inverse_epochs : Apply inverse operator to epochs object.
1074+ apply_inverse_tfr_epochs : Apply inverse operator to epochs tfr object.
1075+ apply_inverse_cov : Apply inverse operator to covariance object.
10721076 """
10731077 _validate_type (raw , BaseRaw , 'raw' )
10741078 _check_reference (raw , inverse_operator ['info' ]['ch_names' ])
@@ -1257,13 +1261,15 @@ def apply_inverse_epochs(epochs, inverse_operator, lambda2, method="dSPM",
12571261
12581262 Returns
12591263 -------
1260- stc : list of (SourceEstimate | VectorSourceEstimate | VolSourceEstimate)
1264+ stcs : list of (SourceEstimate | VectorSourceEstimate | VolSourceEstimate)
12611265 The source estimates for all epochs.
12621266
12631267 See Also
12641268 --------
12651269 apply_inverse_raw : Apply inverse operator to raw object.
12661270 apply_inverse : Apply inverse operator to evoked object.
1271+ apply_inverse_tfr_epochs : Apply inverse operator to epochs tfr object.
1272+ apply_inverse_cov : Apply inverse operator to a covariance object.
12671273 """
12681274 stcs = _apply_inverse_epochs_gen (
12691275 epochs , inverse_operator , lambda2 , method = method , label = label ,
@@ -1277,6 +1283,85 @@ def apply_inverse_epochs(epochs, inverse_operator, lambda2, method="dSPM",
12771283 return stcs
12781284
12791285
1286+ def _apply_inverse_tfr_epochs_gen (epochs_tfr , inverse_operator , lambda2 ,
1287+ method , label , nave , pick_ori , prepared ,
1288+ method_params , use_cps ):
1289+ for freq_idx in range (epochs_tfr .freqs .size ):
1290+ epochs = EpochsArray (epochs_tfr .data [:, :, freq_idx , :],
1291+ epochs_tfr .info , events = epochs_tfr .events ,
1292+ tmin = epochs_tfr .tmin )
1293+ this_inverse_operator = inverse_operator [freq_idx ] if \
1294+ isinstance (inverse_operator , (list , tuple )) else inverse_operator
1295+ stcs = _apply_inverse_epochs_gen (
1296+ epochs , this_inverse_operator , lambda2 , method = method ,
1297+ label = label , nave = nave , pick_ori = pick_ori , prepared = prepared ,
1298+ method_params = method_params , use_cps = use_cps )
1299+ yield stcs
1300+
1301+
1302+ @verbose
1303+ def apply_inverse_tfr_epochs (epochs_tfr , inverse_operator , lambda2 ,
1304+ method = "dSPM" , label = None , nave = 1 , pick_ori = None ,
1305+ return_generator = False , prepared = False ,
1306+ method_params = None , use_cps = True , verbose = None ):
1307+ """Apply inverse operator to EpochsTFR.
1308+
1309+ Parameters
1310+ ----------
1311+ epochs_tfr : EpochsTFR object
1312+ Single trial, phase-amplitude (complex-valued), time-frequency epochs.
1313+ inverse_operator : list of dict | dict
1314+ The inverse operator for each frequency or a single inverse operator
1315+ to use for all frequencies.
1316+ lambda2 : float
1317+ The regularization parameter.
1318+ method : "MNE" | "dSPM" | "sLORETA" | "eLORETA"
1319+ Use minimum norm, dSPM (default), sLORETA, or eLORETA.
1320+ label : Label | None
1321+ Restricts the source estimates to a given label. If None,
1322+ source estimates will be computed for the entire source space.
1323+ nave : int
1324+ Number of averages used to regularize the solution.
1325+ Set to 1 on single Epoch by default.
1326+ %(pick_ori)s
1327+ return_generator : bool
1328+ Return a generator object instead of a list. This allows iterating
1329+ over the stcs without having to keep them all in memory.
1330+ prepared : bool
1331+ If True, do not call :func:`prepare_inverse_operator`.
1332+ method_params : dict | None
1333+ Additional options for eLORETA. See Notes of :func:`apply_inverse`.
1334+ %(use_cps_restricted)s
1335+ %(verbose)s
1336+
1337+ Returns
1338+ -------
1339+ stcs : list of list of (SourceEstimate | VectorSourceEstimate | VolSourceEstimate)
1340+ The source estimates for all frequencies (outside list) and for
1341+ all epochs (inside list).
1342+
1343+ See Also
1344+ --------
1345+ apply_inverse_raw : Apply inverse operator to raw object.
1346+ apply_inverse : Apply inverse operator to evoked object.
1347+ apply_inverse_epochs : Apply inverse operator to epochs object.
1348+ apply_inverse_cov : Apply inverse operator to a covariance object.
1349+ """ # noqa E501
1350+ from ..time_frequency .tfr import _check_tfr_complex
1351+ _check_tfr_complex (epochs_tfr )
1352+ if isinstance (inverse_operator , (list , tuple )) and \
1353+ len (inverse_operator ) != epochs_tfr .freqs .size :
1354+ raise ValueError (f'Expected { epochs_tfr .freqs .size } inverse '
1355+ f'operators, got { len (inverse_operator )} ' )
1356+ stcs = _apply_inverse_tfr_epochs_gen (
1357+ epochs_tfr , inverse_operator , lambda2 ,
1358+ method , label , nave , pick_ori , prepared ,
1359+ method_params , use_cps )
1360+ if not return_generator :
1361+ stcs = [[stc for stc in tfr_stcs ] for tfr_stcs in stcs ]
1362+ return stcs
1363+
1364+
12801365@verbose
12811366def apply_inverse_cov (cov , info , inverse_operator , nave = 1 , lambda2 = 1 / 9 ,
12821367 method = "dSPM" , pick_ori = None , prepared = False ,
@@ -1319,6 +1404,7 @@ def apply_inverse_cov(cov, info, inverse_operator, nave=1, lambda2=1 / 9,
13191404 apply_inverse : Apply inverse operator to evoked object.
13201405 apply_inverse_raw : Apply inverse operator to raw object.
13211406 apply_inverse_epochs : Apply inverse operator to epochs object.
1407+ apply_inverse_tfr_epochs : Apply inverse operator to epochs tfr object.
13221408
13231409 Notes
13241410 -----
0 commit comments