MCPcopy
hub / github.com/mne-tools/mne-python / _get_mf_picks_fix_mags

Function _get_mf_picks_fix_mags

mne/preprocessing/maxwell.py:1425–1483  ·  view source on GitHub ↗

Pick types for Maxwell filtering and fix magnetometers.

(info, int_order, ext_order, ignore_ref=False, verbose=None)

Source from the content-addressed store, hash-verified

1423
1424@verbose
1425def _get_mf_picks_fix_mags(info, int_order, ext_order, ignore_ref=False, verbose=None):
1426 """Pick types for Maxwell filtering and fix magnetometers."""
1427 # Check for T1/T2 mag types
1428 mag_inds_T1T2 = _get_T1T2_mag_inds(info, use_cal=True)
1429 if len(mag_inds_T1T2) > 0:
1430 fix_mag_coil_types(info, use_cal=True)
1431 # Get indices of channels to use in multipolar moment calculation
1432 ref = not ignore_ref
1433 meg_picks = pick_types(info, meg=True, ref_meg=ref, exclude=[])
1434 meg_info = pick_info(_simplify_info(info), meg_picks)
1435 del info
1436 good_mask = np.zeros(
1437 len(
1438 meg_picks,
1439 ),
1440 bool,
1441 )
1442 good_mask[pick_types(meg_info, meg=True, ref_meg=ref, exclude="bads")] = 1
1443 n_bases = _get_n_moments([int_order, ext_order]).sum()
1444 if n_bases > good_mask.sum():
1445 raise ValueError(
1446 f"Number of requested bases ({n_bases}) exceeds number of "
1447 f"good sensors ({good_mask.sum()})"
1448 )
1449 recons = [ch for ch in meg_info["bads"]]
1450 if len(recons) > 0:
1451 msg = f" Bad MEG channels being reconstructed: {recons}"
1452 else:
1453 msg = " No bad MEG channels"
1454 logger.info(msg)
1455 ref_meg = False if ignore_ref else "mag"
1456 mag_picks = pick_types(meg_info, meg="mag", ref_meg=ref_meg, exclude=[])
1457 ref_meg = False if ignore_ref else "grad"
1458 grad_picks = pick_types(meg_info, meg="grad", ref_meg=ref_meg, exclude=[])
1459 assert len(mag_picks) + len(grad_picks) == len(meg_info["ch_names"])
1460 # Determine which are magnetometers for external basis purposes
1461 mag_or_fine = np.zeros(len(meg_picks), bool)
1462 mag_or_fine[mag_picks] = True
1463 # KIT gradiometers are marked as having units T, not T/M (argh)
1464 # We need a separate variable for this because KIT grads should be
1465 # treated mostly like magnetometers (e.g., scaled by 100) for reg
1466 coil_types = np.array([ch["coil_type"] for ch in meg_info["chs"]])
1467 mag_or_fine[(coil_types & 0xFFFF) == FIFF.FIFFV_COIL_KIT_GRAD] = False
1468 # The same thing goes for CTF gradiometers...
1469 ctf_grads = [
1470 FIFF.FIFFV_COIL_CTF_GRAD,
1471 FIFF.FIFFV_COIL_CTF_REF_GRAD,
1472 FIFF.FIFFV_COIL_CTF_OFFDIAG_REF_GRAD,
1473 ]
1474 mag_or_fine[np.isin(coil_types, ctf_grads)] = False
1475 msg = (
1476 f" Processing {len(grad_picks)} gradiometers "
1477 f"and {len(mag_picks)} magnetometers"
1478 )
1479 n_kit = len(mag_picks) - mag_or_fine.sum()
1480 if n_kit > 0:
1481 msg += f" (of which {n_kit} are actually KIT gradiometers)"
1482 logger.info(msg)

Callers 3

average_movementsFunction · 0.85
_setup_ext_projFunction · 0.85
_prep_maxwell_filterFunction · 0.85

Calls 8

_get_T1T2_mag_indsFunction · 0.85
fix_mag_coil_typesFunction · 0.85
pick_typesFunction · 0.85
pick_infoFunction · 0.85
_simplify_infoFunction · 0.85
_get_n_momentsFunction · 0.85
infoMethod · 0.80
sumMethod · 0.45

Tested by

no test coverage detected