UnfoldMakie.RelativeAxis
— TypeRelativeAxis(fig, p::NTuple{4, Float64}; kwargs...)
Returns an Axis
whose position is relative to a GridLayout
element (via BBox
) and not relative to the Scene
. Default behavior is Axis(..., bbox=BBox())
.
p::NTuple{4,Float64}
: specify the position relative to the GridPosition left:right; bottom:top, typical numbers between 0 and 1, e.g. (0.25, 0.75, 0.25, 0.75) would center anAxis
inside thisGridPosition
.kwargs...
- inserted into the axis.f = Figure() ax = RelativeAxis(f[1,2], (0.25, 0.75, 0.25, 0.75)) # returns Axis centered within f[1,2]
Return Value: Axis
.
UnfoldMakie.eeg_topoplot_series
— Functioneeg_topoplot_series(data::DataFrame,
fig,
data::DataFrame,
Δbin;
y = :erp,
label = :label,
col = :time,
row = nothing,
col_labels = false,
row_labels = false,
rasterize_heatmaps = true,
combinefun = mean,
xlim_topo,
ylim_topo,
topoplot_attributes...,
)
eeg_topoplot_series!(fig, data::DataFrame, Δbin; kwargs..)
Plot a series of topoplots. The function automatically takes the combinefun = mean
over the :time
column of data
in Δbin
steps.
fig
Figure object.data::DataFrame
Needs the columns:time
andy(=:erp)
, andlabel(=:label)
.
Ifdata
is a matrix, it is automatically cast to a dataframe, time bins are in samples, labels arestring.(1:size(data,1))
.Δbin = :time
In:time
units, specifying the time steps. All other keyword arguments are passed to theEEG_TopoPlot
recipe.
In most cases, the user should specify the electrode positions withpositions = pos
.col
,row = :time
Specify the field to be divided into columns and rows. The default iscol=:time
to split by the time field androw = nothing
.
Useful to split by a condition, e.g....(..., col=:time, row=:condition)
would result in multiple (as many as different values indf.condition
) rows of topoplot series.row_labels
,col_labels = false
Indicate whether there should be labels in the plots in the first column to indicate the row value and in the last row to indicate the time (typically timerange).
Example
df = DataFrame(:erp => repeat(1:63, 100), :time => repeat(1:20, 5 * 63), :label => repeat(1:63, 100)) # simulated data
pos = [(1:63) ./ 63 .* (sin.(range(-2 * pi, 2 * pi, 63))) (1:63) ./ 63 .* cos.(range(-2 * pi, 2 * pi, 63))] .* 0.5 .+ 0.5 # simulated electrode positions
pos = [Point2.(pos[k, 1], pos[k, 2]) for k in 1:size(pos, 1)]
eeg_topoplot_series(df, 5; positions = pos)
Return Value: Tuple{Figure, Vector{Any}}
.
UnfoldMakie.config_kwargs!
— Functionconfig_kwargs!(cfg::PlotConfig; kwargs...)
Takes named tuple of Key => NamedTuple
as kwargs and merges the fields with the defaults.
UnfoldMakie.eeg_matrix_to_dataframe
— Functioneeg_matrix_to_dataframe(data::Matrix, label)
Helper function converting a matrix (channel x times) to a tidy DataFrame
with columns :estimate
, :time
and :label
.
Return Value: DataFrame
.
UnfoldMakie.rel_to_abs_bbox
— Functionrel_to_abs_bbox(org, rel)
Takes a rectangle org
and applies the relative transformation tuple rel
.
Return Value: Makie.BBox
.
UnfoldMakie.to_positions
— Functionto_positions(x, y, z; sphere = [0, 0, 0.])
to_positions(pos::AbstractMatrix; sphere = [0, 0, 0.])
Projects 3D electrode positions to a 2D layout. Reimplementation of the MNE algorithm.
Assumes size(pos) = (3, nChannels)
when input is AbstractMatrix
.
Tip: You can get positions directly from an MNE object after loading PyMNE and enabling the UnfoldMakie PyMNE extension.
Return Value: Vector{Point2{Float64}}
.
UnfoldMakie.df_timebin
— Functiondf_timebin(df, Δbin; col_y = :erp, fun = mean, grouping = [])
Split or combine DataFrame
according to equally spaced time bins.
Arguments:
df::AbstractTable
With columns:time
andcol_y
(default:erp
), and all columns ingrouping
;Δbin
Bin size in:time
units;col_y = :erp
The column to combine over (withfun
);fun = mean()
Function to combine.grouping = []
Vector of symbols or strings, columns to group the data by before aggregation. Values ofnothing
are ignored.
Return Value: DataFrame
.
UnfoldMakie.cart3d_to_spherical
— Functioncart3d_to_spherical(x, y, z)
Convert x, y, z electrode positions on a scalp to spherical coordinate representation.
Return Value: Matrix
.