Skip to content

Commit

Permalink
new tests, combined plot in docs
Browse files Browse the repository at this point in the history
  • Loading branch information
vladdez committed Sep 20, 2023
1 parent 3bb1869 commit 72e6d4b
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 82 deletions.
10 changes: 3 additions & 7 deletions docs/src/how_to/mult_vis_in_fig.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ uf = example_data("UnfoldLinearModel")
results = coeftable(uf)
uf_5chan = example_data("UnfoldLinearModelMultiChannel")
d_singletrial, _ = UnfoldSim.predef_eeg(; return_epoched=true)
times = -0.099609375:0.001953125:1.0
nothing #hide
```
In this section we discuss how users are able to include multiple visualizations in a single figure.
Expand Down Expand Up @@ -66,12 +67,9 @@ plot_erp!(f[2, 1:2], results, extra=(;
plot_designmatrix!(f[2, 3], designmatrix(uf))
#plot_designmatrix!(f[2,4], designmatrix(uf_deconv);visual=(;colormap=:inferno))
plot_topoplot!(f[3, 1], collect(1:64); positions=positions, visual=(; colormap=:viridis))
plot_topoplotseries!(f[4, 1:3], d_topo, 0.1; positions=positions, mapping=(; label=:channel))
res_effects = effects(Dict(:continuous => -5:0.5:5), uf_deconv)
plot_erp!(f[2, 4:5], res_effects;
Expand All @@ -82,12 +80,10 @@ plot_erp!(f[2, 4:5], res_effects;
legend=(; nbanks=2),
layout=(; legendPosition=:right))
plot_parallelcoordinates!(f[3, 2:3], uf_5chan, [1, 2, 3, 4, 5]; mapping=(; color=:coefname), layout=(; legendPosition=:bottom))
plot_erpimage!(f[1, 4:5], d_singletrial)
plot_circulareegtopoplot!(f[3:4, 4:5], d_topo[in.(d_topo.time, Ref(-0.3:0.1:0.5)), :];
plot_erpimage!(f[1, 4:5], times, d_singletrial)
plot_circulareegtopoplot!(f[3:4, 4:5], d_topo[in.(d_topo.time, Ref(-0.3:0.1:0.5)), :];
positions=positions, predictor=:time, extra=(; predictorBounds=[-0.3, 0.5]))
f
Expand Down
18 changes: 10 additions & 8 deletions src/plot_erp.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,24 @@ using DataFrames
using TopoPlots
using LinearAlgebra
"""
function plot_erp!(f::Union{GridPosition, Figure}, plotData::DataFrame;kwargs...)
function plot_erp(plotData::DataFrame, ;kwargs...)
function plot_erp!(f::Union{GridPosition, Figure}, plotData::DataFrame; kwargs...)
function plot_erp(plotData::DataFrame; kwargs...)
Plot an ERP plot.
## Arguments:
- `f::Union{GridPosition, Figure}`: Figure or GridPosition that the plot should be drawn into
- `plotData::DataFrame`: Data for the line plot visualization.
- `kwargs...`: Additional styling behavior. Often used: `plot_erp(df;mapping=(;color=:coefname,col=:conditionA))`
- `kwargs...`: Additional styling behavior. Often used: `plot_erp(df; mapping=(; color=:coefname, col=:conditionA))`
## Extra Data Behavior (...;extra=(;[key]=value)):
## Extra Data Behavior (...; extra = (; [key]=value)):
- `categoricalColor` (bool, `true`) - Indicates whether the column referenced in mapping.color should be used nonnumerically.
- `categoricalGroup` (bool, `true`) - Indicates whether the column referenced in mapping.group should be used nonnumerically.
- `topoLegend` (bool, `false`) - Indicating whether a topo plot is used as a legend.
- `stderror` (bool, `false`) - Indicating whether the plot should show a colored band showing lower and higher estimates based on the stderror.
- `pvalue` (Array, `[]`) - example: `DataFrame(from=[0.1,0.3],to=[0.5,0.7],coefname=["(Intercept)","condition: face"])` - if coefname not specified, the lines will be black
- `pvalue` (Array, `[]`) - example: `DataFrame(from=[0.1,0.3], to=[0.5,0.7], coefname=["(Intercept)", "condition:face"])` - if coefname not specified, the lines will be black
## Return Value:
Expand All @@ -34,8 +34,10 @@ Plot Butterfly
See `plot_erp` for all specifications
## Extra Data Behavior (...;extra=(;[key]=value)):
`markersize` (Real, `10`) - change the size of the topoplot-inlay electrodes
## Extra Data Behavior (...; extra=(; [key]=value)):
`markersize` (Real, `10`) - change the size of the markers, topoplot-inlay electrodes
`topowidth` (Real, `0.25`) - change the size of the inlay topoplot width
`topoheigth` (Real, `0.25`) - change the size of the inlay topoplot height
"""
Expand Down Expand Up @@ -145,7 +147,7 @@ function plot_erp!(f::Union{GridPosition,Figure}, plotData::DataFrame; positions
end
# no extra legend
mainAxis = Axis(f_grid; config.axis...)
hidedecorations!(mainAxis, label = false, ticks = false, ticklabels = false)
hidedecorations!(mainAxis, label=false, ticks=false, ticklabels=false)

if isnothing(colors)
drawing = draw!(mainAxis, plotEquation)
Expand Down
9 changes: 8 additions & 1 deletion test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,14 @@ end
include("test_erpimage.jl")
end


@testset "UnfoldMakie.jl" begin
include("test_topoplot.jl")
end

@testset "UnfoldMakie.jl" begin
include("test_butterfly.jl")
end

@testset "UnfoldMakie.jl" begin
include("test_all.jl")
end
104 changes: 39 additions & 65 deletions test/test_all.jl
Original file line number Diff line number Diff line change
@@ -1,80 +1,54 @@
### A Pluto.jl notebook ###
# v0.19.11
@testset "testing combined figure" begin
include("../docs/example_data.jl")
d_topo, positions = example_data("TopoPlots.jl")
uf_deconv = example_data("UnfoldLinearModelContinuousTime")
uf = example_data("UnfoldLinearModel")
results = coeftable(uf)
uf_5chan = example_data("UnfoldLinearModelMultiChannel")
d_singletrial, _ = UnfoldSim.predef_eeg(; return_epoched=true)

using Markdown
using InteractiveUtils
f = Figure(resolution=(2000, 2000))

# ╔═╡ a979aa82-4b9d-11ed-1469-978ebad92bc3
begin
using Pkg
Pkg.activate("..")
end
plot_butterfly!(f[1, 1:3], d_topo; positions=positions)

# ╔═╡ c2e68f1d-23a6-4d8a-bcf2-9ba1620869cf
using Revise
pvals = DataFrame(
from=[0.1, 0.15],
to=[0.2, 0.5],
# if coefname not specified, line should be black
coefname=["(Intercept)", "category: face"]
)
plot_erp!(f[2, 1:2], results, extra=(;
categoricalColor=false,
categoricalGroup=false,
pvalue=pvals,
stderror=true))

# ╔═╡ cd201ca2-6256-48af-8184-8744ab24028f
using UnfoldMakie

# ╔═╡ 87c04057-55cd-4772-918f-9e29ec12e6ea
using CairoMakie
plot_designmatrix!(f[2, 3], designmatrix(uf))

# ╔═╡ 6219f1b9-1e5b-4e07-81c9-867022baa554
using TopoPlots
plot_topoplot!(f[3, 1], collect(1:64); positions=positions, visual=(; colormap=:viridis))
plot_topoplotseries!(f[4, 1:3], d_topo, 0.1; positions=positions, mapping=(; label=:channel))

# ╔═╡ 16636c28-95e4-4e8e-aa8d-6a0807f15a74
using Unfold

# ╔═╡ ea4472d4-d6f4-4270-9483-405d27f09be3
using DataFrames
res_effects = effects(Dict(:continuous => -5:0.5:5), uf_deconv)

# ╔═╡ d6afa7aa-eb8a-4a85-b378-37c01408756d
data,chanlocs = TopoPlots.example_data();
plot_erp!(f[2, 4:5], res_effects;
mapping=(; y=:yhat, color=:continuous, group=:continuous),
extra=(; showLegend=true,
categoricalColor=false,
categoricalGroup=true),
legend=(; nbanks=2),
layout=(; legendPosition=:right))

# ╔═╡ b1a9cd37-f22e-471c-bd7f-c0e508d26adc
begin
df = DataFrame(estimate=Float64[],time=[],channel=[],coefname=[],topoPositions=[],se=[])
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,1],time=t,channel=ch,coefname="A",topoPositions=(pos[1,ch],pos[2,ch])))


end
end
dftmp = deepcopy(df)
dftmp.estimate .= 0.5 .* dftmp.estimate .+ 0.1.*rand(nrow(df)) .- 0.05
dftmp.coefname .= "B"
df = vcat(df,dftmp)
end

# ╔═╡ 5fb731af-d004-4e01-a459-b8ccc5362613
UnfoldMakie.plot_butterfly(df[df.coefname .=="A",:];setExtraValues=(:topoLegend=>true,),setMappingValues=(:category=>:coefname,))#,topoPositions=chanlocs))

# ╔═╡ 3f25224f-e2a2-4df3-9ee5-94c7e5b3760b
UnfoldMakie.plot_erp(df[df.channel .==32,:])
plot_parallelcoordinates!(f[3, 2:3], uf_5chan, [1, 2, 3, 4, 5]; mapping=(; color=:coefname), layout=(; legendPosition=:bottom))

# ╔═╡ 01457325-fde5-4c61-95c7-9467175ef4a7
times = -0.099609375:0.001953125:1.0
plot_erpimage!(f[1, 4:5], times, d_singletrial)

plot_circulareegtopoplot!(f[3:4, 4:5], d_topo[in.(d_topo.time, Ref(-0.3:0.1:0.5)), :];
positions=positions, predictor=:time, extra=(; predictorBounds=[-0.3, 0.5]))

# ╔═╡ 4182b4dc-f6bb-4de2-883e-9db5c5e592b8
UnfoldMakie.plot_topo(df[(df.time .==230) .&&(df.coefname.=="A"),:])

# ╔═╡ 3f7decce-5f15-4298-a304-f42967cb0f9b
UnfoldMakie.plot_paraCoord(df,collect(20:30),setMappingValues=(:category=>:coefname,))

# ╔═╡ Cell order:
# ╠═a979aa82-4b9d-11ed-1469-978ebad92bc3
# ╠═cd201ca2-6256-48af-8184-8744ab24028f
# ╠═87c04057-55cd-4772-918f-9e29ec12e6ea
# ╠═6219f1b9-1e5b-4e07-81c9-867022baa554
# ╠═d6afa7aa-eb8a-4a85-b378-37c01408756d
# ╠═16636c28-95e4-4e8e-aa8d-6a0807f15a74
# ╠═ea4472d4-d6f4-4270-9483-405d27f09be3
# ╠═b1a9cd37-f22e-471c-bd7f-c0e508d26adc
# ╠═5fb731af-d004-4e01-a459-b8ccc5362613
# ╠═3f25224f-e2a2-4df3-9ee5-94c7e5b3760b
# ╠═01457325-fde5-4c61-95c7-9467175ef4a7
# ╠═4182b4dc-f6bb-4de2-883e-9db5c5e592b8
# ╠═3f7decce-5f15-4298-a304-f42967cb0f9b
# ╠═c2e68f1d-23a6-4d8a-bcf2-9ba1620869cf
f
end
2 changes: 1 addition & 1 deletion test/test_butterfly.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

@testset "markersize change" begin
include("example_data.jl")
include("../docs/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 72e6d4b

Please sign in to comment.