osl_dynamics.meeg.source_recon#

Source reconstruction.

Functions#

lcmv_beamformer(fns[, data, chantypes, data_cov, ...])

Compute LCMV spatial filter.

apply_lcmv_beamformer(fns[, raw, ...])

Apply an LCMV beamformer.

Module Contents#

osl_dynamics.meeg.source_recon.lcmv_beamformer(fns, data=None, chantypes=None, data_cov=None, noise_cov=None, pick_ori='max-power-pre-weight-norm', rank='info', noise_rank='info', reduce_rank=True, frequency_range=None, **kwargs)[source]#

Compute LCMV spatial filter.

Parameters:
  • fns (OSLFilenames) – Container for OSL filenames.

  • data (str | instance of mne.Raw | mne.Epochs, optional) – The measurement data to specify the channels to include. Bad channels in info[‘bads’] are not used. Will also be used to calculate data_cov. If None, fns.preproc_file is used.

  • chantypes (list or str) – List of channel types to use to calculate the noise covariance. E.g. [‘eeg’], [‘mag’, ‘grad’], [‘eeg’, ‘mag’, ‘grad’].

  • data_cov (instance of mne.Covariance | None) – The noise covariance matrix used to whiten. If None will be computed from data.

  • noise_cov (instance of mne.Covariance | None) – The noise covariance matrix used to whiten. If None will be computed from data as a diagonal matrix with variances set to the average of all sensors of that type.

  • pick_ori (None | 'normal' | 'max-power' | max-power-pre-weight-norm) – The source orientation to compute the beamformer in.

  • rank (dict) – Calculate the rank only for a subset of channel types, and explicitly specify the rank for the remaining channel types. This can be extremely useful if you already know the rank of (part of) your data, for instance in case you have calculated it earlier. This parameter must be a dictionary whose keys correspond to channel types in the data (e.g. ‘meg’, ‘mag’, ‘grad’, ‘eeg’), and whose values are integers representing the respective ranks. For example, {‘mag’: 90, ‘eeg’: 45} will assume a rank of 90 and 45 for magnetometer data and EEG data, respectively. The ranks for all channel types present in the data, but not specified in the dictionary will be estimated empirically. That is, if you passed a dataset containing magnetometer, gradiometer, and EEG data together with the dictionary from the previous example, only the gradiometer rank would be determined, while the specified magnetometer and EEG ranks would be taken for granted.

  • noise_rank (dict | None | 'full' | 'info') – This controls the rank computation that can be read from the measurement info or estimated from the data. When a noise covariance is used for whitening, this should reflect the rank of that covariance, otherwise amplification of noise components can occur in whitening (e.g., often during source localization).

  • reduce_rank (bool) – Whether to reduce the rank by one during computation of the filter.

  • frequency_range (list) – Lower and upper range (in Hz) for frequency range to bandpass filter. If None, no filtering is performed.

  • **kwargs (keyword arguments) – Keyword arguments that will be passed to mne.beamformer.make_lcmv.

Returns:

filters – Dictionary containing filter weights from LCMV beamformer. See: https://mne.tools/stable/generated/mne.beamformer.make_lcmv.html

Return type:

instance of mne.beamformer.Beamformer

osl_dynamics.meeg.source_recon.apply_lcmv_beamformer(fns, raw=None, reject_by_annotation='omit', spatial_resolution=None, reference_brain='mni')[source]#

Apply an LCMV beamformer.

Parameters:
  • fns (OSLFilenames) – Container for OSL filenames.

  • raw (instance of mne.io.Raw or mne.Epochs, optional) – The data to apply the LCMV filter to. If None, fns.preproc_file is used.

  • reject_by_annotation (str | list of str | None) – If string, the annotation description to use to reject epochs. If list of str, the annotation descriptions to use to reject epochs. If None, do not reject epochs.

  • spatial_resolution (int, optional) – Resolution to use for the reference brain in mm (must be an integer, or will be cast to nearest int). If None, then the gridstep used to create the forward model is used.

  • reference_brain (str, optional) – Either ‘head’ or ‘mni’.

Returns:

  • voxel_data (np.ndarray) – Voxel data in the space specified by the ‘reference_brain’ argument. Shape is (voxels, time) for a Raw object or (voxels, time, epochs) for an Epochs object.

  • coords (np.ndarray) – Coordinates for each voxel in the reference brain space. Shape is (voxels, 3).

Return type:

tuple[numpy.ndarray, numpy.ndarray]