-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #60 from unfoldtoolbox/positions
3D to 2D locations + pymne extension
- Loading branch information
Showing
7 changed files
with
124 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
using UnfoldMakie | ||
using CairoMakie | ||
using TopoPlots | ||
using PyMNE | ||
|
||
|
||
# # get MNE-positions | ||
# Generate a fake MNE structure | ||
# [taken from mne documentation](https://mne.tools/0.24/auto_examples/visualization/eeglab_head_sphere.html) | ||
|
||
biosemi_montage = PyMNE.channels.make_standard_montage("biosemi64") | ||
n_channels = length(biosemi_montage.ch_names) | ||
fake_info = PyMNE.create_info(ch_names=biosemi_montage.ch_names, sfreq=250., | ||
ch_types="eeg") | ||
data = rand(n_channels,1) * 1e-6 | ||
fake_evoked = PyMNE.EvokedArray(data, fake_info) | ||
fake_evoked.set_montage(biosemi_montage) | ||
|
||
pos = UnfoldMakie.toPositions(fake_evoked) | ||
|
||
# # project from 3D electrode locations to 2D | ||
pos3d = hcat(values(pyconvert(Dict,biosemi_montage.get_positions()["ch_pos"]))...) | ||
|
||
pos2 = to_positions(pos3d) | ||
|
||
f = Figure(resolution=(600,300)) | ||
scatter(f[1,1],pos3d[1:2,:]) | ||
scatter(f[1,2],pos2) | ||
f | ||
# as one can see, the "naive" transform of just dropping the third dimension doesnt really work (left). We rather have to project the chanels to a sphere and unfold it (right) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
module UnfoldMakiePyMNEExt | ||
|
||
using GeometryBasics | ||
using PyMNE | ||
using UnfoldMakie | ||
""" | ||
to_positions(raw::PyMNE.Py;kwargs...) | ||
calls MNE-pythons make_eeg_layout (with optional kwargs) | ||
Returns an array of Points | ||
""" | ||
function UnfoldMakie.to_positions(raw::PyMNE.Py;kwargs...) | ||
layout_from_raw = PyMNE.channels.make_eeg_layout(raw.info;kwargs...).pos | ||
positions = pyconvert(Array,layout_from_raw)[:,1:2] | ||
|
||
points = map(GeometryBasics.Point{2,Float64},eachrow(positions)) | ||
return points | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters