laMEG laMEG: laminar inference with MEG#

Introduction#

Toolbox for laminar inference with MEG, powered by FreeSurfer (https://surfer.nmr.mgh.harvard.edu/fswiki) and SPM (spm/) for Python 3.7.

The source code of the project is hosted on Github at the following address: danclab/laMEG

To get started, follow the installation instructions.

For guidelines on MRI sequences, head-cast construction, and co-registration, see the wiki

Available modules#

Here is a list of the modules available in laMEG:

invert

Laminar source inversion and MEG-MRI coregistration tools using SPM.

laminar

Laminar analysis tools for MEG source reconstruction and depth-resolved model comparison.

simulate

Simulation tools for MEG data generation using SPM.

surf

Tools for generating, managing, and postprocessing laminar cortical surfaces.

util

Utility functions for SPM, MEG sensor data management, and neuroanatomical processing.

viz

Visualization and color mapping utilities for laminar and cortical surface data.

Tutorials#

A collection of tutorials is available:

Operating system#

  • Windows: Tested on WSL (using Ubuntu 24.04.1), follow instructions here

  • Mac: May work, not tested

  • Linux: Tested on Ubuntu and Debian

Requirements#

Upgrade Notice (v0.1.0)#

If you used laMEG versions prior to v0.1.0, the internal format of laminar surface directories has changed. They are now stored within <SUBJECTS_DIR>/<subject_id>/surf/laminar, and <SUBJECTS_DIR>/<subject_id>/mri/orig.mgz is automatically used for co-registration. Older surfaces must be converted before they can be loaded with the new LayerSurfaceSet interface.

Run the conversion script:

python convert_legacy_surfaces.py <subject_id> <path_to_old_lameg_surf_dir>

For example:

python convert_legacy_surfaces.py sub-104 /data/old_surfaces/sub-104

This will rebuild the standardized hierarchy under:

<SUBJECTS_DIR>/<subject_id>/surf/laminar

and generate complete metadata for each processing stage.

After conversion, you can validate the new structure:

from lameg.surf import LayerSurfaceSet
surf_set = LayerSurfaceSet('sub-104', 11)
surf_set.validate()

Installation#

  1. Install git and curl if needed:

    sudo apt-get install git curl
    
  2. Create a conda environment:

    conda create -n <env name> python=3.7
    

    replacing <env name> with the name of the environment you would like to create (i.e. ‘lameg’, or the name of your project)

  3. Activate the environment:

    conda activate <env name>
    

    replacing <env name> with name of the environment you created.

  4. Install FreeSurfer, following the instructions on this page

  5. To install laMEG, run:

    pip install lameg
    

    Then run the post-installation script:

    lameg-postinstall
    

    This installs SPM standalone and Matlab runtime, which can take some time depending on your connection speed.

  6. Before using, deactivate and reactivate the environment for changes to environment variables to take effect:

    conda deactivate
    conda activate <env name>
    
  7. If you want to run the tutorials, download and extract the test data

Indices and tables#

Funding#

Supported by the European Research Council (ERC) under the European Union’s Horizon 2020 research and innovation programme grant agreement 864550, and a seed grant from the Fondation pour l’Audition.

ERC FPA