Consultation on the method of bad derivative interpolation

  • MNE version: 1.8.0
  • operating system: Windows 11

:fountain_pen: To get the correct formatting, paste your Python code, then select it, and click on the Preformatted text toolbar button.

I used MNE to analyze brain magnetic experiment data, and the probe used was based on the OPM principle. Since I didn’t know what type of probe to choose, I directly chose QUSPIN, as follows:

for j in range(n_signals):
        # The kind of channel
        rawData.info['dig'][j]['kind'] = 4
        rawData.info['chs'][j]['kind'] = mne.io.constants.FIFF.FIFFV_MEG_CH
        rawData.info['chs'][j]['unit'] = mne.io.constants.FIFF.FIFF_UNIT_T
        # The first three elements always store the nominal channel position. The remaining 9 elements
        # in MEG, contain the EX, EY, and EZ normal triplets(columns) of the coil rotation/orientation matrix.
        rawData.info['chs'][j]['loc'][3:12] = np.array([1., 0., 0., 0., 1., 0., 0., 0., 1.])
        rawData.info['chs'][j]['coil_type'] = mne.io.constants.FIFF.FIFFV_COIL_QUSPIN_ZFOPM_MAG2

When I used the interpolate_bads method to interpolate my bad derivatives, I found that it called the function templates=-read_comil_defs (verbose=False) and directly generated the corresponding template. I want to know how this is obtained, what calculation method do you use to interpolate bad derivatives, and do you have any relevant references or web pages?

 if kind == "meg":
        templates = _read_coil_defs(verbose=False)
        coils_from = _create_meg_coils(
            info_from["chs"], "normal", info_from["dev_head_t"], templates
        )
        coils_to = _create_meg_coils(
            info_to["chs"], "normal", info_to["dev_head_t"], templates
        )
        pinv_method = "tsvd"
        miss = 1e-4
    else:
        coils_from = _create_eeg_els(info_from["chs"])
        coils_to = _create_eeg_els(info_to["chs"])
        pinv_method = "tikhonov"
        miss = 1e-1
        if _has_eeg_average_ref_proj(info_from) and not _has_eeg_average_ref_proj(
            info_to
        ):
            raise RuntimeError(
                "info_to must have an average EEG reference projector if "
                "info_from has one"
            )
    origin = _check_origin(origin, info_from)
    #
    # Step 2. Calculate the dot products
    #
    int_rad, noise, lut_fun, n_fact = _setup_dots(mode, info_from, coils_from, kind)
    logger.info(
        f"    Computing dot products for {len(coils_from)} "
        f"{kind.upper()} channel{_pl(coils_from)}..."
    )
    self_dots = _do_self_dots(
        int_rad, False, coils_from, origin, kind, lut_fun, n_fact, n_jobs=None
    )
    logger.info(
        f"    Computing cross products for {len(coils_from)} → "
        f"{len(coils_to)} {kind.upper()} channel{_pl(coils_to)}..."
    )
    cross_dots = _do_cross_dots(
        int_rad, False, coils_from, coils_to, origin, kind, lut_fun, n_fact
    ).T

    ch_names = [c["ch_name"] for c in info_from["chs"]]
    fmd = dict(
        kind=kind,
        ch_names=ch_names,
        origin=origin,
        noise=noise,
        self_dots=self_dots,
        surface_dots=cross_dots,
        int_rad=int_rad,
        miss=miss,
        pinv_method=pinv_method,
    )

    #
    # Step 3. Compute the mapping matrix
    #
    mapping = _compute_mapping_matrix(fmd, info_from)
    return mapping