Skip to content

Commit

Permalink
markersize, relate weidth and height of topo, drop the grid
Browse files Browse the repository at this point in the history
  • Loading branch information
vladdez committed Sep 6, 2023
1 parent 7f7df74 commit 31b0f26
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/plot_erp.jl
Original file line number Diff line number Diff line change
Expand Up @@ -131,11 +131,12 @@ function plot_erp!(f::Union{GridPosition,Figure}, plotData::DataFrame; positions
# add topoLegend

if (config.extra.topoLegend)
topoAxis = Axis(f_grid, width=Relative(0.25), height=Relative(0.25), halign=0.05, valign=0.95, aspect=1)
topoAxis = Axis(f_grid, width=Relative(config.extra.topowidth), height=Relative(config.extra.topoheigth), halign=0.05, valign=0.95, aspect=1)
topoplotLegend(config, topoAxis, allPositions)
end
# no extra legend
mainAxis = Axis(f_grid; config.axis...)
hidedecorations!(mainAxis, label = false, ticks = false, ticklabels = false)

if isnothing(colors)
drawing = draw!(mainAxis, plotEquation)
Expand Down Expand Up @@ -184,7 +185,7 @@ function topoplotLegend(config, axis, allPositions)
colorrange=(0, length(allPositions)), # add the 0 for the white-first color
colormap=specialColors,
head=(color=:black, linewidth=1, model=topoMatrix),
label_scatter=(markersize=10, strokewidth=0.5,))
label_scatter=(markersize=config.extra.markersize, strokewidth=0.5,))

hidedecorations!(current_axis())
hidespines!(current_axis())
Expand Down
3 changes: 3 additions & 0 deletions src/plotconfig.jl
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,9 @@ function PlotConfig(T::Val{:butterfly})
showLegend=false
), extra=(;
topoLegend=true,
markersize=10,
topowidth=0.25,
topoheigth=0.25,
topoPositionToColorFunction=x -> posToColorRomaO(x)
), mapping=(;
color=(:channel, :channels, :trial, :trials,),
Expand Down
66 changes: 66 additions & 0 deletions test/example_data.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
using UnfoldSim
using TopoPlots
using Unfold
"""
Makes use of TopoPlots example data (originating from eegvis matlab toolbox).
type ==
"TopoPlots.jl"(default) Returns tidy DataFrame with two conditions, 64 channels and 800ms of data. This is an average over many subjects.
"""

function example_data(example="TopoPlots.jl")

if example == "UnfoldLinearModel"
# load and generate a simulated Unfold Design
data,evts = UnfoldSim.predef_eeg(;noiselevel=10,return_epoched=true)
data = reshape(data,1,size(data)...)
f = @formula 0~1+condition+continuous
# generate ModelStruct
se_solver =(x,y)->Unfold.solver_default(x,y,stderror=true)
return fit(UnfoldModel,(Dict(Any=>(f,range(0,length=size(data,2),step=1/100)))) ,evts,data;solver=se_solver)
elseif example == "UnfoldLinearModelMultiChannel"
# load and generate a simulated Unfold Design
cAll = DataFrame()
sfreq = 100
for ch = 1:5
data,evts = UnfoldSim.predef_eeg(;p1 = (p100(;sfreq=sfreq), @formula(0~1),[5],Dict()),

n1 = (n170(;sfreq=sfreq), @formula(0~1+condition),[5,-ch*0.5],Dict()),
p3 = (p300(;sfreq=sfreq), @formula(0~1+continuous),[ch,1],Dict()),
return_epoched=true)
data = reshape(data,1,size(data)...)
f = @formula 0~1+condition+continuous
# generate ModelStruct

m= fit(UnfoldModel,(Dict(Any=>(f,range(0,length=size(data,2),step=1/100)))) ,evts,data)
d = coeftable(m)
d.channel .= ch
cAll = append!(cAll,d)
end
return cAll

elseif example == "UnfoldLinearModelContinuousTime"
# load and generate a simulated Unfold Design
data,evts = UnfoldSim.predef_eeg(;)
data = reshape(data,1,size(data)...)
f = @formula 0~1+condition+continuous
basis = firbasis([0,0.5],100)
# generate ModelStruct
return fit(UnfoldModel,Dict(Any=>(f,basis)) ,evts,data)

elseif example == "TopoPlots.jl"
data,chanlocs = TopoPlots.example_data();
df = DataFrame(estimate=Float64[],time=Float64[],channel=Int64[],coefname=String[],topoPositions=[],se=Float64[],pval=Float64[])
pos = TopoPlots.points2mat(chanlocs)
for ch = 1:size(data,1)
for t = 1:size(data,2)
append!(df,DataFrame(estimate=data[ch,t,1],se=data[ch,t,2],pval=data[ch,t,3],time=t,channel=ch,coefname="A",topoPositions=(pos[1,ch],pos[2,ch])))


end
end
df.time = range(-0.3,0.5,step=1/500)[Int.(df.time)]
return df,chanlocs
else
error("unknown example data")
end
end
6 changes: 6 additions & 0 deletions test/test_butterfly.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
include("setup.jl")
@testset "markersize change" begin
include("example_data.jl")
data, pos = example_data("TopoPlots.jl")
plot_butterfly(data; positions=pos, extra=(markersize = 10, topoheigth=0.4, topowidth=0.4))
end

0 comments on commit 31b0f26

Please sign in to comment.