Skip to content

Commit

Permalink
added docs, fix bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
behinger committed Sep 11, 2023
1 parent bd6b0d7 commit 3e2427a
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 8 deletions.
1 change: 1 addition & 0 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ ImageFiltering = "6a3955dd-da59-5b1f-98d4-e7296123deb5"
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
Makie = "ee78f7c6-11fb-53f2-987a-cfe4a2b5a57a"
SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf"
StaticArrays = "90137ffa-7385-5640-81b9-e52037218182"
Statistics = "10745b16-79ce-11e8-11f9-7d13ad32a3b2"
TopoPlots = "2bdbdf9c-dbd8-403f-947b-1a4e0dd41a7a"
Unfold = "181c99d8-e21b-4ff3-b70b-c233eddec679"
Expand Down
1 change: 1 addition & 0 deletions docs/Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ Documenter = "e30172f5-a6a5-5a46-863b-614d45cd2de4"
Glob = "c27321d9-0574-5035-807b-f59d2c89b15c"
Literate = "98b081ad-f1c9-55d3-8b20-4c87d4299306"
MakieThemes = "e296ed71-da82-5faf-88ab-0034a9761098"
PyMNE = "6c5003b2-cbe8-491c-a0d1-70088e6a0fd6"
StatsModels = "3eaba693-59b7-5ba5-a881-562e759f1c8d"
TopoPlots = "2bdbdf9c-dbd8-403f-947b-1a4e0dd41a7a"
Unfold = "181c99d8-e21b-4ff3-b70b-c233eddec679"
Expand Down
23 changes: 23 additions & 0 deletions docs/src/literate/reference/positions.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
using UnfoldMakie
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)
6 changes: 3 additions & 3 deletions ext/UnfoldMakiePyMNEExt.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ module UnfoldMakiePyMNEExt

using GeometryBasics
using PyMNE

using UnfoldMakie
"""
toPositions(raw::PyMNE.Py;kwargs...)
to_positions(raw::PyMNE.Py;kwargs...)
calls MNE-pythons make_eeg_layout (with optional kwargs)
Returns an array of Points
"""
function toPositions(raw::PyMNE.Py;kwargs...)
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]

Expand Down
4 changes: 3 additions & 1 deletion src/UnfoldMakie.jl
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ using DataStructures
using DataFrames
using SparseArrays
using CategoricalArrays # for cut for TopoPlotSeries
using StaticArrays

using CoordinateTransformations # for 3D positions to 2D

Expand Down Expand Up @@ -65,5 +66,6 @@ export plot_circulareegtopoplot!
export plot_topoplotseries
export plot_topoplotseries!

export nonnumeric
export to_positions
export nonnumeric # reexport from AoG
end
10 changes: 6 additions & 4 deletions src/eeg_positions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -380,15 +380,17 @@ end


"""
toPositions(x,y,z;sphere=[0,0,0.])
toPositions(pos::AbstractMatrix;sphere=[0,0,0.])
to_positions(x,y,z;sphere=[0,0,0.])
to_positions(pos::AbstractMatrix;sphere=[0,0,0.])
Projects 3D electrode positions to a 2D layout.
The matrix case, assumes `size(pos) = (3,nChannels)`
Re-implementation of the MNE algorithm.
Tipp: You can directly get positions from an MNE object after loading PyMNE and thus activating the UnfoldMakie PyMNE extension
"""
toPositions(pos::AbstractMatrix;kwargs...) = toPositions(pos[1,:],pos[2,:],pos[3,:];kwargs)
function toPositions(x,y,z;sphere=[0,0,0.])
to_positions(pos::AbstractMatrix;kwargs...) = to_positions(pos[1,:],pos[2,:],pos[3,:];kwargs...)
function to_positions(x,y,z;sphere=[0,0,0.])
#cart3d_to_spherical(x,y,z)

# translate to sphere origin
Expand Down

0 comments on commit 3e2427a

Please sign in to comment.