From 62851c2a1bbb4495f1e849978f4959fac95babcd Mon Sep 17 00:00:00 2001 From: laurabpaulsen <202005791@post.au.dk> Date: Fri, 13 Dec 2024 11:35:46 +0100 Subject: [PATCH] update co registration docs --- docs/co-registration/co-reg_alpha1_helmet.md | 83 ++++++++++++++++++++ docs/co-registration/code_example.md | 10 --- docs/co-registration/index.md | 5 +- docs/digitising/polhemus_digitisation.md | 15 ++-- 4 files changed, 91 insertions(+), 22 deletions(-) create mode 100644 docs/co-registration/co-reg_alpha1_helmet.md delete mode 100644 docs/co-registration/code_example.md diff --git a/docs/co-registration/co-reg_alpha1_helmet.md b/docs/co-registration/co-reg_alpha1_helmet.md new file mode 100644 index 0000000..0d1dc2d --- /dev/null +++ b/docs/co-registration/co-reg_alpha1_helmet.md @@ -0,0 +1,83 @@ +--- +title: Co-registering OPM sensors in Fieldline Alpha1 semi-rigid helmet to MR +nav_order: 1 +parent: Co-registration +layout: default +--- +Knowing the position (and orientation in the case of sensors measuring magnetic fields) is crucial to allow for reconstruction of neural sources from the data measured at the sensors. + +Here we show an example of co-registering 4 OPM sensors placed in the Fieldline Alpha1 semi-rigid helmet to an MR of the participants brain. + +First, we load modules we need + +```python +from pyvista import Plotter + +from OPM_lab.mne_integration import add_dig_montage, add_device_to_head, add_sensor_layout +from OPM_lab.sensor_position import OPMSensorLayout, FL_alpha1_helmet + +from mne.viz import plot_alignment +from mne.utils._bunch import NamedInt +import mne +import pandas as pd +``` + +The next step is to load both the raw OPM data, as well as the digitised points (i.e., the output after [Digitising sensor positions]({{ site.url }}{% link digitising/index.md %})) +```python +opm_path = "path_to_your_data.fif" +raw = mne.io.read_raw(opm_path, preload=True) + +dig_path = "path_to_the_dig_file.csv" +points = pd.read_csv(dig_path) +``` + + +Next, rename the channels in the raw OPM data to correspond to the label of the sensor slot in the semi-rigid helmet +```python +raw.pick(["00:01-BZ_CL", '00:02-BZ_CL', "00:03-BZ_CL", "00:04-BZ_CL"]) + +mne.rename_channels( + raw.info, + { + "00:01-BZ_CL" : "FL3", + "00:02-BZ_CL" : "FL10", + "00:03-BZ_CL" : "FL16", + "00:04-BZ_CL" : "FL62" + } +) +``` + +Define a variable with the depth measurements. It is important that the depth measurements are in the same order as the label input in the next code chunk!! +``` +depth_meas = [40/1000, 47/1000, 44/1000, 40/1000] # mm converted to meter (order = 3, 10, 16, 62) +``` + + +If you are using another type of sensor (e.g. not the default "FieldLine OPM sensor Gen1 size = 2.00 mm") remember to specify it here using the `coil_type` flag. +```python +sensor_layout = OPMSensorLayout( + label=["FL3", "FL10", "FL16", "FL62"], + depth=depth_meas, + helmet_template=FL_alpha1_helmet, + # coil_type=NamedInt("SQ20950N", 3024) # useful for plotting as orientation of OPMs (default coil types) are difficult to see on alignment plot + +) +``` + +```python +add_dig_montage(raw, points) +``` + +```python +add_sensor_layout(raw, sensor_layout) +``` + +```python +add_device_to_head(raw, points) + +```python +fig = plot_alignment(raw.info, meg=("sensors"), dig = True, coord_frame="head", verbose = True) +Plotter().show() +``` + +# TO DO - add code for rest of co-registration pipeline \ No newline at end of file diff --git a/docs/co-registration/code_example.md b/docs/co-registration/code_example.md deleted file mode 100644 index e4b0b78..0000000 --- a/docs/co-registration/code_example.md +++ /dev/null @@ -1,10 +0,0 @@ ---- -title: Code example -nav_order: 1 -parent: Co-registration -layout: default ---- - - -# Integration with MNE -sådan tjek tjek tjek \ No newline at end of file diff --git a/docs/co-registration/index.md b/docs/co-registration/index.md index 9b9c896..ca788d3 100644 --- a/docs/co-registration/index.md +++ b/docs/co-registration/index.md @@ -3,5 +3,6 @@ title: Co-registration nav_order: 4 layout: default --- -# hej -hej \ No newline at end of file + + +To allow for source reconstruction of the data, the sensor positions need to be co-registered to a structural image of the participants brain. \ No newline at end of file diff --git a/docs/digitising/polhemus_digitisation.md b/docs/digitising/polhemus_digitisation.md index b9b751c..f1b49c6 100644 --- a/docs/digitising/polhemus_digitisation.md +++ b/docs/digitising/polhemus_digitisation.md @@ -5,14 +5,17 @@ parent: Digtising layout: default --- # Polhemus digitisation -To digtise using this module,first you need to initialise a FastrakConnector object where you specify the USB port the device is connected to. Afterwards you prepare for digitisation, which will return the fastrak to factory settings, set the output to metric, clear any incoming data and check whether the stylus and head receiver are connected properly. +To digtise using this module, first you need to initialise a FastrakConnector object where you specify the USB port the device is connected to. Afterwards you prepare for digitisation, which will return the fastrak to factory settings, set the output to metric, clear any incoming data and check whether the stylus and head receiver are connected properly. ```python connector = FastrakConnector(usb_port='/dev/cu.usbserial-110') connector.prepare_for_digitisation() ``` -The next step is to setup the digitiser object and add any points you would like to digitise +The next step is to setup the digitiser object and add any points you would like to digitise. Currently, two types of digitistation schemes are available, and can be set using the `dig_type` flag. +- `single`: Takes a category (for example "OPM") and a list of labels (["FL1", "FL2", "FL3"]). Thus this function is useful for marking marking points with a label attached to them (i.e. if you need to know which specific sensor or fiducial). If you want to re-digtise a point just press the stylus 30 cm away from the head. +- `continuous`: Used for marking a specified amount of points with out any specific label. This could for example be 60 points distributed across the head of the participant. This function allows to keep the button of the stylus pressed down continuosly to mark consecutive points, that do not need to be distinguished from eachother. + ```python digitiser = Digitiser(connector=connector) @@ -33,11 +36,3 @@ digitiser.run_digitisation() digitiser.save_digitisation(output_path='insert/your/path/here.csv') ``` -Note on dig_type argument in the Digtiser.add() function: -- `single`: Takes a category (for example "OPM") and a list of labels (["FL1", "FL2", "FL3"]). Thus this function is useful for marking marking points with a label attached to them (i.e. if you need to know which specific sensor or fiducial). If you want to re-digtise a point just press the stylus 30 cm away from the head. -- `continuous`: Used for marking a specified amount of points with out any specific label. This could for example be 60 points distributed across the head of the participant. This function allows to keep the button of the stylus pressed down continuosly to mark consecutive points. - -The digitisation will be shown using matplotlib - however sometimes the plot takes a bit to update, and the plot does not show until the first point is made - - -Note: during digitisation some sounds are played to provide feedback. However this functionally currently only works on mac \ No newline at end of file