Skip to content

Commit

Permalink
update co registration docs
Browse files Browse the repository at this point in the history
  • Loading branch information
laurabpaulsen committed Dec 13, 2024
1 parent 0988a9e commit 62851c2
Show file tree
Hide file tree
Showing 4 changed files with 91 additions and 22 deletions.
83 changes: 83 additions & 0 deletions docs/co-registration/co-reg_alpha1_helmet.md
Original file line number Diff line number Diff line change
@@ -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
10 changes: 0 additions & 10 deletions docs/co-registration/code_example.md

This file was deleted.

5 changes: 3 additions & 2 deletions docs/co-registration/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@ title: Co-registration
nav_order: 4
layout: default
---
# hej
hej


To allow for source reconstruction of the data, the sensor positions need to be co-registered to a structural image of the participants brain.
15 changes: 5 additions & 10 deletions docs/digitising/polhemus_digitisation.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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

0 comments on commit 62851c2

Please sign in to comment.