Kit2Fiff Tutorial

There are multiple files produced before and during magnetoencephalography. We will use the following here:

  • Headscan basic surface .txt

  • Headscan points .txt

  • HPI coils Marker measurements (x2 files atleast) .mrk (each .mrk contains the position of 5 fiducial points on the face)

  • MEG recording .con

Kit2Fiff

The first step is to convert the recording into a standard format for analysis in MNE, the premier software suite for M/EEG analysis.

  1. Launch your terminal and activate your anaconda environment for MNE analysis. If you haven’t set up an environment yet, do so.

  2. In your terminal, run mne kit2fiff. This will launch a GUI with the following interface:

  3. Using the diagram here as a guide, join the files listed above:

AI generated MEG-system image

After the files are all loaded, you will see the headscan plotted in the gray panel in the middle of the GUI. You can rotate it around. A small sanity check should be performed here to see if the markers are in their expected position around the head.

Note

The parameters indicated by the red circle below should be set according to the experiment control software.

AI generated MEG-system image

For experiments run in PsycoPy, the events should be indicated as “Trough”, and for experiments run in Presentation, the triggers should be indicated as “Peak”. Click “Find Events”. If you find a list of events, you probably do have triggers indicating stimuli times. Hooray! If not, make sure the parameters in red are set as shown here. If that doesn’t fix it, triggers were not sent properly.

  1. After making sure the correct event type is selected for the experiment control software used, save the file by clicking on “Save Fiff”. MNE suggests a filename; it is good practice to use the following naming convention: subjID_experimentname-raw.fiff.

  2. When the .fiff has been saved, close the GUI.

Coreg without native MRI

In your terminal, run mne coreg. This will launch a GUI with the following interface.

AI generated MEG-system image
  1. Navigate to the MRI folder for your experiment in the spot indicated by the blue arrow. If this is the first coreg you are processing for this dataset, you will need to put the fsaverage in the MRI folder to serve as a basis for transformations of your subjects’ heads.

  2. In Digitization Source, put the .fiff created from earlier for the appropriate subject.

Note

This part of the preprocessing takes the most subjective judgment and hard work thus far.

You will need to align the white net of dots (representing the MEG recording linked with the subject headshape) to the fsaverage headshape. You will do this by manipulating two parameters: translation of the net and transformation of the fsaverage headshape. The former is done with the controls in blue. Current versions of MNE allow the translation to be performed automatically by hitting the buttons marked “Fit (ICP)” and “Fit Fid.”. Fit (ICP) will fit the white dots to the headshape. Fit Fid will fit the markers/points to the headshape markers/points. This approach should be alternated with transforming the headshape using the controls in red. First, you should change Scaling mode to “3-axis”. This will allow the headshape to be transformed in three dimensions independently. To transform, hit Fit (ICP) within red.

Note

If a subject had a particularly thick hairstyle, you can add hair by putting a number (in mm) in green. You can also omit white dots that are too far

3. Navigate to the MRI folder for your experiment in the spot indicated by the blue arrow. If this is the first coreg you are processing for this dataset, you will need to put the fsaverage (average headshape and MRI) in the MRI folder to serve as a basis for transformations of your subjects’ heads. To do this, under the MRI folder, there is a button for fsaverage=SUBJECTS_DIR. You’ll need to set fsaverage as the headshape using the dropdown menu below the MRI folder selection; if there are any processed datasets already in the MRI folder, it will try to set those subjects as the base. Make sure your base is always fsaverage. In Digitization Source, put the fiff created from earlier for the appropriate subject 4. This part of the preprocessing takes the most subjective judgment and hard work thus far. You will need to align the white net of dots (representing the MEG recording linked with the subject headshape) to the fsaverage headshape. You will do this by manipulating two parameters: translation of the net and transformation of the fsaverage headshape. The former is done with the controls in blue. Current versions of MNE allow the translation to be performed automatically by hitting the buttons marked “Fit (ICP)” and “Fit Fid.”. Fit (ICP) will fit the white dots to the headshape. Fit Fid will fit the markers/points to the headshape markers/points. This approach should be alternated with transforming the headshape using the controls in red. First, you should change Scaling mode to “3-axis”. This will allow the headshape to be transformed in three dimensions independently. To transform, hit Fit (ICP) within red. If a subject had a particularly thick hairstyle, you can add hair by putting a number (in mm) in green. You can also omit white dots that are too far from the headshape that occasionally result from a bad headscan.

AI generated MEG-system image

5. You can check the fit of the headshape by rotating the head around in the grey panel with your mouse. The goal is to have the white net of dots lying flush with the surface of the head with minimal gaps between the dots and headshape, and with minimal embedding of the dots inside the headshape. Don’t be too concerned with aligning the point of the net marked with the black arrow below; that isn’t part of the subject’s head. It is part of the neckbrace.

AI generated MEG-system image

6. When you are satisfied with the fit, hit Save. This produces many files, and takes a fair amount of time. It generates the BEM (Boundary Element Model)1 files, the anatomical files, and a .trans file that maps the anatomicals of the fsaverage to the subject. 7. When this is finished, close the GUI

To see if something needs to be kit2fiffed, see if there is a -raw.fif file. To see if something needs to be coreged, see if there is a -trans.fif file

  1. Fit(ICP)

  2. Scaling mode = 3-axis

  3. Fit(ICP) scaling parameters

  4. Back and forth Fit

  5. Screenshot all five views to put in coreg reports

Software stack

MEG data analysis:

  • LabMaestroSimulator

  • BEESA

  • MNE Python library

Example:

Samantha’s experiment called Arabic Tark_VpixxEdit contains a .sce, .exp, .tem

What is Tark Localizer?

they are called Tark_Localiser.sce Task_localiser.exp Tark_Loc_Main_Trial_GR.tem

When you open the .sce, you see a code that define the name of the scenario, font size, active buttons

Everytime the experiment is ran, a logfile seems to be created in

Output:

On the computer of the MEG MAIN PC, an experiment can yield different files:

  • a .con file shows the signals on top of each other, and the strength of the magnetic field on what part of the brain the unit can be
    • pT: picoTesla

    • fT: femtoTesla

  • a .mrk file

This website adds quite a few details to these extensions https://mne.tools/stable/auto_tutorials/io/10_reading_meg_data.html

The files can be opened with MEG Lab

BESA Software

The following steps are primary to process MEG data using the BESA MRI and BESA Research suite

You have MRI data of your participant

Open BESA MRI, start a new segmentation project, check all the segmentation options (especially BEM and FEM), pick the landmarks for segmentation and start the process. Once done, BESA will save the segmentation, BEM, FEM model outputs.

In BESA MRI, start a new coregistration project.

Open BESA Research, load your MEG data from a .fif format.

Generic processing pipeline

Manual labelling of “bad” channels

Denoising

Awareness of the many sources of noise:

  • Related to the site in which the MEG system is installed

  • Related to conditions that could happen from time to time (parking garage nearby,)

Once the reasons are understood, we can identify the pattern that the noise makes.

With training data of the different possible noises, it is very possible to train a neural classifier that could identify the noise coming from the different sources and be able to denoise it from the MEG data.

Independent component analysis

Independent component analysis (ICA) is commonly used to generate what is supposed a set of independent signals from a given set of assumingly correlated signals.

The signals produced by MEG are highly correlated, therefore ICA is suitable to reduce correlation. Given a set of MEG signal X(t), ICA learns a matrix W and the output signals S(t) such that

add latex here: X(t) = W.S(t)

ICA can perform well to identify the noise signals that has a certain long lasting continuous-time pattern, but less efficient when the noise is a single event, happening at irregular periods of time.

Calling ICA withint a Python pipeline
 projs, raw.info['projs'] = raw.info['projs'], []
 ica.fit(raw)
 raw.info['projs'] = projs

Frequency Analysis

Fast-oscillating signals means high frequencies, while slow oscillations are low frequencies. In fourier space (signal represented by its Fourier transform) we can see the frequency components constituting the signal. FFT (Fast Fourier Transform) algorithm is commonly to identify the frequency components.

Research showed that signals at different frequencies have different functions at different locations of the brain. In other words, given a region of the brain, signals of frequency 8Hz are responsible of an activity that is much different than signals with frequency 20 Hz

Brain Source Estimate

When neurons become active, they do so in large groups.

Code Overview

The code for an example.

This installs dependencies
# Install required Meg-pipeline dependencies
import matplotlib as plt
import mne