Skip to content

Commit

Permalink
Assign EEG sensors to hemispheres based on x ordinate
Browse files Browse the repository at this point in the history
  • Loading branch information
caiw committed Mar 8, 2024
1 parent c80d69d commit 27b75c0
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 3 deletions.
26 changes: 26 additions & 0 deletions kymata/plot/layouts.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from pathlib import Path
from typing import NamedTuple

import yaml
from mne.io import Raw
from matplotlib import pyplot as plt

Expand Down Expand Up @@ -33,6 +34,31 @@ def get_meg_sensor_xy() -> dict[str, Point2d]:
return d


def get_eeg_sensor_xy() -> dict[str, Point2d]:
d = dict()
with Path(Path(__file__).parent.parent.parent, "kymata-toolbox-data", "sensor_locations",
"EEG1005.lay").open("r") as layout_file:
for line in layout_file:
parts = line.strip().split("\t")
x = float(parts[1])
y = float(parts[2])
name = parts[-1].lower()
d[name] = Point2d(x, y)
# Get name mapping
with Path(Path(__file__).parent.parent.parent, "kymata-toolbox-data", "sensor_locations",
"EEG-layout-channel-mappings.yaml").open("r") as eeg_name_mapping_file:
mapping = yaml.safe_load(eeg_name_mapping_file)
mapping = {k.lower(): v.lower() for k, v in mapping.items()}
inverted_mapping = {v: k for k, v in mapping.items()}
# Apply name mapping
new_d = {
inverted_mapping[name]: point
for name, point in d.items()
if name in inverted_mapping.keys()
}
return new_d


def eeg_sensors() -> list[str]:
"""The names of all EEG sensors."""
return [f"EEG{i:03}" for i in range(1, 65)]
Expand Down
14 changes: 11 additions & 3 deletions kymata/plot/plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
from kymata.math.p_values import p_to_logp
from kymata.entities.functions import Function
from kymata.math.rounding import round_down, round_up
from kymata.plot.layouts import get_meg_sensor_xy, eeg_sensors
from kymata.plot.layouts import get_meg_sensor_xy, eeg_sensors, get_eeg_sensor_xy

# log scale: 10 ** -this will be the ytick interval and also the resolution to which the ylims will be rounded
_MAJOR_TICK_SIZE = 50
Expand Down Expand Up @@ -56,13 +56,21 @@ class AxisAssignment(NamedTuple):
sensor
for sensor, (x, y) in get_meg_sensor_xy().items()
if x <= 0
] + eeg_sensors()),
] + [
sensor
for sensor, (x, y) in get_eeg_sensor_xy().items()
if x <= 0
]),
AxisAssignment(axis_name="right",
axis_channels=[
sensor
for sensor, (x, y) in get_meg_sensor_xy().items()
if x >= 0
] + eeg_sensors()),
] + [
sensor
for sensor, (x, y) in get_eeg_sensor_xy().items()
if x >= 0
]),
)


Expand Down

0 comments on commit 27b75c0

Please sign in to comment.