Skip to content

Source modelling and reconstruction

Build forward models and reconstruct source activity from sensor-space recordings.

almkanal.almkanal_steps.headmodel_utils.ForwardModel

Bases: AlmKanalStep

Build an MEG forward model for source reconstruction.

The forward model combines the sensor geometry, MEG-to-MRI coregistration, source space, and boundary-element model (BEM).

Individual FreeSurfer reconstructions are expected under subjects_dir / 'freesurfer' / subject_id. When template anatomy is used, fsaverage is scaled to the participant and stored as <subject_id>_from_template.

Parameters:

Name Type Description Default
subject_id str

Subject identifier.

required
subjects_dir str | Path

AlmKanal working directory. FreeSurfer subjects are stored under subjects_dir / 'freesurfer' and coregistration outputs under subjects_dir / 'headmodels'.

required
pick_dict dict | None

Channel selection passed to :func:mne.pick_types before coregistration. If None, channel picks are taken from the pipeline information when available.

required
source (surface, volume)

Type of source space used for the forward model. Default is 'surface'.

'surface'
redo_hdm bool

If True, recompute the MEG-to-MRI coregistration and, when using template anatomy, rescale fsaverage. If False, use the previously saved transform. Default is True.

required
spacing str

Source-space spacing used for surface source spaces based on an individual MRI, for example 'oct6' or 'ico5'. Default is 'oct6'.

required
source_ico int

Icosahedral subdivision level of the fsaverage surface source space used for template-based forward models and as the common surface source space for morphing. This controls source-space density and is independent of the BEM surface resolution. Default is 4.

required
bem_conductivity float | Sequence[float]

Conductivity value or values passed to :func:mne.make_bem_model. A one-layer BEM is typically used for MEG, whereas EEG requires a three-layer BEM. Default is (0.3,).

required
volume_pos float

Grid spacing in millimetres for volume source spaces. The same spacing is used when preparing the corresponding fsaverage volume source space for morphing. Default is 5.0.

required
min_dist_src float

Minimum distance in millimetres between sources and the inner skull used when computing the forward solution. Default is 5.0.

required
use_template_mri bool

If True, use a participant-specific scaling of fsaverage as the anatomical model. If False, use the participant's existing FreeSurfer reconstruction. Default is True.

required
meg bool

Include MEG channels in the forward solution. Default is True.

required
eeg bool

Include EEG channels in the forward solution. EEG forward models require a three-layer BEM conductivity specification. Default is False.

required
Notes

The BEM surface resolution is fixed internally and is independent of source_ico. source_ico controls the number of cortical source locations, not the resolution of the BEM geometry.

An fsaverage source space corresponding to the requested surface or volume resolution is prepared so that later source estimates can be morphed to a common source space.

Returns:

Type Description
Forward

almkanal.almkanal_steps.src_recon_utils.SourceReconstruction

Bases: AlmKanalStep

Perform source reconstruction using a preceding ForwardModel.

The source space, FreeSurfer subject, and FreeSurfer subjects directory are taken from the preceding ForwardModel to ensure that source reconstruction uses the same anatomical model and source geometry.

Parameters:

Name Type Description Default
filters Beamformer | None

Spatial filter to apply. If None, use the filters produced by the preceding SpatialFilter step.

required
return_parc bool

Whether to parcellate the reconstructed source estimates. Default is False.

required
label_mode str

Extraction mode used for surface parcellation. Volume parcellation uses mode='auto'. Default is 'pca_flip'.

required
atlas (glasser, dk, destrieux)

Atlas used when return_parc=True. Default is 'glasser'.

'glasser'
morph2fsaverage bool

Whether to morph source estimates to the common fsaverage source space prepared by ForwardModel before returning or parcellating them. Default is True.

required

Returns:

Type Description
dict | SourceEstimate | dict | VolSourceEstimate

Source time courses or parcellated data.