From 3bb186905e11e6fc81a85ca79fe74582280d6860 Mon Sep 17 00:00:00 2001 From: Vladimir Mikheev <33777074+vladdez@users.noreply.github.com> Date: Tue, 19 Sep 2023 14:12:20 +0200 Subject: [PATCH 01/12] Update plot_erp.jl --- src/plot_erp.jl | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/src/plot_erp.jl b/src/plot_erp.jl index 4685961b6..052a06881 100644 --- a/src/plot_erp.jl +++ b/src/plot_erp.jl @@ -5,22 +5,26 @@ using LinearAlgebra 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))` + ## 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 + +- `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 + ## Return Value: -f - Figure() or the inputed `f` + +- f - Figure() or the inputed `f` """ plot_erp(plotData::DataFrame; kwargs...) = plot_erp!(Figure(), plotData, ; kwargs...) @@ -28,7 +32,12 @@ plot_erp(plotData::DataFrame; kwargs...) = plot_erp!(Figure(), plotData, ; kwarg """ Plot Butterfly -see `plot_erp` +See `plot_erp` for all specifications + +## Extra Data Behavior (...;extra=(;[key]=value)): +`markersize` (Real, `10`) - change the size of the topoplot-inlay electrodes + + """ plot_butterfly(plotData::DataFrame; kwargs...) = plot_butterfly!(Figure(), plotData; kwargs...) plot_butterfly!(f::Union{GridPosition,<:Figure}, plotData::DataFrame; extra=(;), kwargs...) = plot_erp!(f, plotData, ; extra=merge((; butterfly=true), extra), kwargs...) From 72e6d4b1eba8abb5a541c4b07fa2464b29d14df6 Mon Sep 17 00:00:00 2001 From: Vladimir Mikheev Date: Wed, 20 Sep 2023 15:42:06 +0000 Subject: [PATCH 02/12] new tests, combined plot in docs --- docs/src/how_to/mult_vis_in_fig.md | 10 +-- src/plot_erp.jl | 18 ++--- test/runtests.jl | 9 ++- test/test_all.jl | 104 +++++++++++------------------ test/test_butterfly.jl | 2 +- 5 files changed, 61 insertions(+), 82 deletions(-) diff --git a/docs/src/how_to/mult_vis_in_fig.md b/docs/src/how_to/mult_vis_in_fig.md index a93e19936..2dd40939f 100644 --- a/docs/src/how_to/mult_vis_in_fig.md +++ b/docs/src/how_to/mult_vis_in_fig.md @@ -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. @@ -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; @@ -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 diff --git a/src/plot_erp.jl b/src/plot_erp.jl index 052a06881..0bf52d472 100644 --- a/src/plot_erp.jl +++ b/src/plot_erp.jl @@ -2,8 +2,8 @@ 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. @@ -11,15 +11,15 @@ Plot an ERP plot. - `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: @@ -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 """ @@ -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) diff --git a/test/runtests.jl b/test/runtests.jl index eb647a757..d7963c8f6 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -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 \ No newline at end of file diff --git a/test/test_all.jl b/test/test_all.jl index 0660eaed9..d8e728b7d 100644 --- a/test/test_all.jl +++ b/test/test_all.jl @@ -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 \ No newline at end of file diff --git a/test/test_butterfly.jl b/test/test_butterfly.jl index 26d24c757..eb5a3d085 100644 --- a/test/test_butterfly.jl +++ b/test/test_butterfly.jl @@ -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 From 28687f848c9f4f757c17e9c60eae00f696cb89e3 Mon Sep 17 00:00:00 2001 From: Vladimir Mikheev Date: Wed, 20 Sep 2023 15:51:36 +0000 Subject: [PATCH 03/12] del --- src/nb_plot_erpimage2.jl | 444 --------------------------------------- 1 file changed, 444 deletions(-) delete mode 100644 src/nb_plot_erpimage2.jl diff --git a/src/nb_plot_erpimage2.jl b/src/nb_plot_erpimage2.jl deleted file mode 100644 index 62265b92d..000000000 --- a/src/nb_plot_erpimage2.jl +++ /dev/null @@ -1,444 +0,0 @@ -### A Pluto.jl notebook ### -# v0.19.27 - -using Markdown -using InteractiveUtils - -# This Pluto notebook uses @bind for interactivity. When running this notebook outside of Pluto, the following 'mock version' of @bind gives bound variables a default value (instead of an error). -macro bind(def, element) - quote - local iv = try Base.loaded_modules[Base.PkgId(Base.UUID("6e696c72-6542-2067-7265-42206c756150"), "AbstractPlutoDingetjes")].Bonds.initial_value catch; b -> missing; end - local el = $(esc(element)) - global $(esc(def)) = Core.applicable(Base.get, el) ? Base.get(el) : iv(el) - el - end -end - -# ╔═╡ 80e36c32-187f-41ba-82eb-d84c22de6d69 -using Pkg - - -# ╔═╡ 7b3eca23-cc2a-4212-abc3-70f941afb4d4 -begin -Pkg.activate(mktempdir()) - Pkg.add(name="micromamba_jll",version="1.3") - Pkg.add(["UnfoldMakie","PyMNE","CairoMakie","Unfold","CSV","DataFrames","CoordinateTransformations","PlutoUI","StaticArrays","Statistics"]) -end - - -# ╔═╡ ea3e73be-2bb6-11ee-0b04-43b39a893537 -begin -using UnfoldMakie - using PyMNE - using CairoMakie - using Unfold - using CSV - using DataFrames - using CoordinateTransformations - using PlutoUI - using StaticArrays - using Statistics - import StatsBase.mean -end - -# ╔═╡ e0c29a25-1ccd-455b-b99b-fa93c72310d4 -using TopoPlots - -# ╔═╡ 5451c8fd-c1cf-4088-9e0b-6fed0c388bf7 -TableOfContents() - -# ╔═╡ 256e9785-9f54-4546-ac51-53c2a22e6c79 -md""" -### Load Data -""" - -# ╔═╡ ba178d91-1d03-40f1-97ea-ec03b8bd29c6 - - -# ╔═╡ c0f10639-eda1-4af5-b877-00406b066de0 -begin -evts = CSV.read("/store/data/WLFO/derivatives/preproc_agert/sub-20/eeg/sub-20_task-WLFO_events.tsv",DataFrame) - evts.latency = evts.onset .* 512 -end - -# ╔═╡ a8cf7a53-6d5e-4400-a3bd-80034a7ed5f6 -evts_fix = subset(evts,:type => x->x.=="fixation") - -# ╔═╡ 15533746-a53e-4694-b8ca-285bc20f83c5 -raw = PyMNE.io.read_raw_eeglab("/store/data/WLFO/derivatives/preproc_agert/sub-20/eeg/sub-20_task-WLFO_eeg.set") - -# ╔═╡ 67470dc9-3282-4462-a675-b00d8a9c9241 -begin -pos3= pyconvert(Array,raw._get_channel_positions()); - pos3[:,2] = -pos3[:,2] - pos3[:,1] = -pos3[:,1] -end - -# ╔═╡ b2efb84a-1f96-4671-b25e-65001cba12a2 -d,times = Unfold.epoch(pyconvert(Array,raw.get_data(units="uV")),evts_fix,(-0.1,1),512) - -# ╔═╡ df5ff6e9-505f-4a25-97aa-e19be6286c8f -md""" -## Synched ChannelImage -""" - -# ╔═╡ 1b025463-936f-432c-91a1-056d0d9b9bcd - - -# ╔═╡ 3f0fa6da-3790-4264-beba-4785eb1bb0ee -begin - function chanselectTopoplot(pos::Vector;labels=nothing,label_text=false,markersize=21,obs=nothing) - - labels = isnothing(labels) ? (1:length(pos)) : labels - - f,topoaxis,h = eeg_topoplot(zeros(length(pos)), labels; - positions=pos, - interpolation=NullInterpolator(), - enlarge=1, - label_text, - label_scatter=(markersize=markersize, color=:black) - ) - hidedecorations!(current_axis()) - hidespines!(current_axis()) - - obs = isa(obs,Observable) ? obs : Observable(1) - str = lift((obs, labels) -> "$(labels[obs])", obs, labels) - text!(topo_axis, 1, 1, text = str, align = (:center, :center)) - on(events(f).mousebutton, priority = 2) do event - if event.button == Mouse.left && event.action == Mouse.press - plt, p = pick(topo_axis) - obs[] = p - end - end - f - return obs,f - end -end - -# ╔═╡ 933f3050-4c0e-44b3-89e7-4dc59591128d -@bind chanOrder PlutoUI.Select(["chanorder","cluster","X","Y","Z"]) - -# ╔═╡ 93dc3a57-6b20-4fe8-abf8-b54ef7a8ab7e -@bind sorttime PlutoUI.Slider(0:500) - -# ╔═╡ 5c14e245-6b95-4c4d-85f6-bfbff95ca013 - let - d_m = mean(d,dims=3)[:,:,1] - series(d_m,solid_color=:black) - end - -# ╔═╡ d4c2e872-2bad-44ce-8a9a-42b549464678 - - -# ╔═╡ 8c70f1c1-313c-4b3b-b4e7-c14818ec9f57 -md""" -# ERPImage -""" - -# ╔═╡ 6d9c9e59-242e-4021-a972-db57b1b4f58b -heatmap(d[1,:,:]) # channel x time x trials - -# ╔═╡ 23f118e1-ceed-407f-9063-f0c49138077b -@bind sortby PlutoUI.Select(names(evts_fix)) - -# ╔═╡ 16369ac8-6cd4-481c-b2dc-b2d884afbfe1 -evts_fix - -# ╔═╡ cb8b03b7-6457-4fa1-ab4a-84bd1faffbf4 -coalesce.(d[1,:,:],NaN) - -# ╔═╡ d42c85dd-ecb7-4e97-87fa-7dbd1746102c -begin - - # no times + no figure? -plot_erpimage2(plotData::Matrix{<:Real}; kwargs...) = plot_erpimage2!(Figure(),plotData; kwargs...) - - # no times? -plot_erpimage2!(f::Figure,plotData::Matrix{<:Real}; kwargs...) = plot_erpimage2!(f, 1:size(plotData,1), plotData; kwargs...) - - # no figure? -plot_erpimage2(times::AbstractVector,plotData::Matrix{<:Real}; kwargs...) = plot_erpimage2!(Figure(),times, plotData; kwargs...) - -function plot_erpimage2!(f::Union{GridPosition,Figure}, times::AbstractVector,plotData::Matrix{<:Real}; sortvalues = nothing,sortix=nothing,kwargs...) - config = PlotConfig(:erpimage) - UnfoldMakie.config_kwargs!(config; kwargs...) - - - !isnothing(sortix) ? @assert(sortix isa Vector{Int}) : "" - ax = Axis(f[1:4, 1]; config.axis...) - if isnothing(sortix) - if isnothing(sortvalues) - sortix = 1:size(plotData,2) - else - sortix = sortperm(sortvalues) - - end - end - - filtered_data = UnfoldMakie.imfilter(plotData[:, sortix], UnfoldMakie.Kernel.gaussian((0, max(config.extra.erpBlur, 0)))) - - - #if config.extra.sortix - # ix = sortperm([a[1] for a in argmax(plotData, dims=1)][1, :]) # ix - trials sorted by time of maximum spike - - yvals = 1:size(filtered_data,2) - if !isnothing(sortvalues) - yvals = [minimum(sortvalues),maximum(sortvalues)] - end - - hm = heatmap!(ax,times,yvals, filtered_data; config.visual...) - - UnfoldMakie.applyLayoutSettings!(config; fig=f, hm=hm, ax=ax, plotArea=(4, 1)) - - if config.extra.meanPlot - # UserInput - subConfig = deepcopy(config) - config_kwargs!(subConfig; layout=(; - showLegend=false - ), - axis=(; - ylabel=config.colorbar.label === nothing ? "" : config.colorbar.label)) - - - #limits = (config.axis.limits[1], config.axis.limits[2], nothing, nothing))) - - axisOffset = (config.layout.showLegend && config.layout.legendPosition == :bottom) ? 1 : 0 - subAxis = Axis(f[5+axisOffset, 1]; subConfig.axis...) - - lines!(subAxis, mean(plotData, dims=2)[:, 1]) - applyLayoutSettings!(subConfig; fig=f, ax=subAxis) - end - - return f - -end -end - -# ╔═╡ eb3ed1d4-6ad7-4807-8a7a-10313b11b067 -let -f = Figure() -d_nan = coalesce.(d[100,:,:],NaN) - d_nan = d_nan .- mean(d_nan,dims=2)[:,1] - #d_nan = d_nan .+ mean(d_nan,dims=1)[:,1] -v = (;colorrange = (-10,10)) - e = (;erpBlur = 5) -@show size(d_nan) -plot_erpimage2!(f[1,1],times,d_nan,visual=v,extra=e) -plot_erpimage2!(f[1,2],times,d_nan;extra=e,sortvalues = diff(evts_fix.onset./100),visual=v) -plot_erpimage2!(f[2,1],times,d_nan;extra=e,sortvalues = evts_fix.sac_startpos_x,visual=v) -plot_erpimage2!(f[2,2],times,d_nan;extra=e,sortvalues=evts_fix.sac_amplitude,visual=v) -f -end - -# ╔═╡ 6539620f-7d85-40c4-b5f1-dda42bc9e3e9 -begin -d_nan = coalesce.(d[1,:,:],NaN) - - plot_erpimage2(times,d_nan,;sortvalues=evts_fix[:,sortby],extra=(;erpBlur=50)) - -end - -# ╔═╡ 5548c28e-f67f-4873-9f90-d91ba0aaa42b -md""" -## 3D to 2D -""" - -# ╔═╡ 776e0206-91ee-4800-83ec-8b6bdb06505a - - function cart3d_to_spherical(x,y,z) - sph = SphericalFromCartesian().(SVector.(x,y,z)) - sph = [vcat(s.r,s.θ,π/2 - s.ϕ) for s in sph] - sph = hcat(sph...)' - return sph - end - - -# ╔═╡ 03462e09-692b-47e0-96c0-bc730fcaf200 -pos3D_to_layout(pos3::AbstractMatrix;kwargs...) =pos3D_to_layout(pos3[:,1],pos3[:,2],pos3[:,3];kwargs...) - -# ╔═╡ 8513fc7f-cd5a-4ea3-b131-c1bcbcfb4878 -function pos3D_to_layout(x,y,z;sphere=[0,0,0.]) - #cart3d_to_spherical(x,y,z) - -# translate to sphere origin - x .-= sphere[1] - y .-= sphere[2] - z .-= sphere[3] - - # convert to spherical coordinates - sph = cart3d_to_spherical(x,y,z) - - # get rid of of the radius for now - pol_a = sph[:,3] - pol_b = sph[:,2] - - # use only theta & phi, convert back to cartesian coordinates - p_x = pol_a .* cos.(pol_b) - p_y = pol_a .* sin.(pol_b) - - # scale by the radius - p_x .*= sph[:,1] ./(π/2) - p_y .*= sph[:,1] ./(π/2) - - # move back by the sphere coordinates - p_x .+= sphere[1] - p_y .+= sphere[2] - - diff(m::Tuple) = [m[1],m[2]] - p_x .= p_x ./ (2* diff(extrema(p_x))[1]) - p_y .= p_y ./ (2* diff(extrema(p_y))[1]) - - p_x = p_x .+ 0.5 - p_y = p_y .+ 0.5 - return Point2f.(p_x,p_y) -end - -# ╔═╡ 461827a5-8597-4a05-9201-4cf94af01b58 -begin -pos2 = pos3D_to_layout(pos3) - -end - -# ╔═╡ 01c13032-2b18-4cc3-8e62-975448e390a1 -extrema([p[1] for p in pos2]) - -# ╔═╡ ca9835eb-0a68-461e-884f-9ca75a584d92 -begin -obs,f = chanselectTopoplot(pos2) - f -end - -# ╔═╡ 85de4fff-8eb3-4193-b11d-a545d4f60a05 -begin - global obs_pluto -on(obs) do val - global obs_pluto = val -end -end - -# ╔═╡ a91e1f64-fd06-4648-9352-4533eff5aaaa -obs_pluto - -# ╔═╡ ec1915aa-8c07-400c-ad09-2637a74aceee -begin - -f2 = Figure(resolution=(1000,500)) - d_m = mean(d,dims=3)[:,:,1] - d_m = disallowmissing(d_m) - - if chanOrder == "chanorder" - - sortix =(1:length(pos2)) - elseif chanOrder == "cluster" - sortix = sortperm(d_m[:,sorttime]) - elseif chanOrder == "X" - sortix = sortperm(pos3[:,1]) - elseif chanOrder == "Y" -sortix = sortperm(pos3[:,2]) - elseif chanOrder =="Z" - sortix = sortperm(pos3[:,3]) - end - - axzoom = (;limits=((-0.25, 1.25), (-0.25, 1.25))) - - ax,h = heatmap(f2[1,2:7],d_m[sortix,:]',colormap=Reverse("RdBu"),colorrange = [-15,15]) - Colorbar(f2[1,8],h) - vlines!(current_axis(),[sorttime]) -d_tmp = UnfoldMakie.eeg_matrix_to_dataframe(d_m,string.(1:size(d_m,1))) - d_tmp.channel = parse.(Int,d_tmp.label) - - -h = plot_topoplotseries!(f2[2,2:7],d_tmp,75;positions=pos2,visual=(;interp_resolution=(128,128),enlarge=1,label_scatter=false,contours=false),labels=nothing) - - hLeg = plot_topoplot!(f2[2,1],Float32.(1:length(pos2));positions=pos2,visual=(;interpolation=TopoPlots.NullInterpolator(),enlarge=0.9),layout=(;showLegend=false),axis=(;aspect=1,axzoom...)) - -# colgap!(h.layout.content[2].content,0) - #rowgap!(h.layout.content[2].content,1100) -rowsize!(f2.layout, 2, Relative(1/4)) - -f2 -end - -# ╔═╡ 23dca8b4-9166-41fc-bf42-9d6d57f29da6 -begin -f3 = Figure() -#GridLayout(f3[1,1]) -for (ix,chO) = enumerate(["chanorder","cluster","X","Y","Z"]) - if chO == "chanorder" - - sortix =(1:length(pos2)) - elseif chO == "cluster" - sortix = sortperm(d_m[:,100]) - elseif chO == "X" - sortix = sortperm(pos3[:,1]) - elseif chO == "Y" -sortix = sortperm(pos3[:,2]) - elseif chO =="Z" - sortix = sortperm(pos3[:,3]) - end - @show mod(ix-1,2) - @show ix - - heatmap(f3[mod(ix-1,2)+1,ix÷2],d_m[sortix,:]',axis=(;title=chO)) -end - f3 - -end - -# ╔═╡ 6f3fb600-013c-4b18-92e8-fe6c0990f0a1 -plot_topoplotseries!(Figure(),d_tmp,100;positions=pos2,visual=(;interp_resolution=(128,128),enlarge=1)) - - -# ╔═╡ 95426b22-deb7-4b58-bb43-67c368cb9ab9 -let -f = Figure() -plot_topoplot!(f[1,1],Float32.(1:length(pos2));positions=pos2,visual=(;interpolation=TopoPlots.NullInterpolator(),enlarge=0.9,markersize=20),layout=(;showLegend=false)) - plot_topoplot!(f[1,2],Float32.(zeros(length(pos2)).+0.1*rand(length(pos2)));positions=pos2,visual=(;colorrange=[-1,1],interpolation=TopoPlots.NullInterpolator(),enlarge=0.9,markersize=20),layout=(;showLegend=false)) - f -end - -# ╔═╡ 10d2ee3b-7708-4ad8-af36-6071b21e0cc9 -pos3D_to_layout(pos3) - -# ╔═╡ Cell order: -# ╠═5451c8fd-c1cf-4088-9e0b-6fed0c388bf7 -# ╠═80e36c32-187f-41ba-82eb-d84c22de6d69 -# ╠═7b3eca23-cc2a-4212-abc3-70f941afb4d4 -# ╠═ea3e73be-2bb6-11ee-0b04-43b39a893537 -# ╠═256e9785-9f54-4546-ac51-53c2a22e6c79 -# ╠═ba178d91-1d03-40f1-97ea-ec03b8bd29c6 -# ╠═c0f10639-eda1-4af5-b877-00406b066de0 -# ╠═67470dc9-3282-4462-a675-b00d8a9c9241 -# ╠═461827a5-8597-4a05-9201-4cf94af01b58 -# ╠═01c13032-2b18-4cc3-8e62-975448e390a1 -# ╠═a8cf7a53-6d5e-4400-a3bd-80034a7ed5f6 -# ╠═15533746-a53e-4694-b8ca-285bc20f83c5 -# ╠═b2efb84a-1f96-4671-b25e-65001cba12a2 -# ╠═df5ff6e9-505f-4a25-97aa-e19be6286c8f -# ╠═ca9835eb-0a68-461e-884f-9ca75a584d92 -# ╠═85de4fff-8eb3-4193-b11d-a545d4f60a05 -# ╠═a91e1f64-fd06-4648-9352-4533eff5aaaa -# ╠═1b025463-936f-432c-91a1-056d0d9b9bcd -# ╠═3f0fa6da-3790-4264-beba-4785eb1bb0ee -# ╠═933f3050-4c0e-44b3-89e7-4dc59591128d -# ╠═93dc3a57-6b20-4fe8-abf8-b54ef7a8ab7e -# ╠═5c14e245-6b95-4c4d-85f6-bfbff95ca013 -# ╠═ec1915aa-8c07-400c-ad09-2637a74aceee -# ╠═23dca8b4-9166-41fc-bf42-9d6d57f29da6 -# ╠═d4c2e872-2bad-44ce-8a9a-42b549464678 -# ╠═e0c29a25-1ccd-455b-b99b-fa93c72310d4 -# ╠═6f3fb600-013c-4b18-92e8-fe6c0990f0a1 -# ╠═10d2ee3b-7708-4ad8-af36-6071b21e0cc9 -# ╠═8c70f1c1-313c-4b3b-b4e7-c14818ec9f57 -# ╠═6d9c9e59-242e-4021-a972-db57b1b4f58b -# ╠═95426b22-deb7-4b58-bb43-67c368cb9ab9 -# ╠═eb3ed1d4-6ad7-4807-8a7a-10313b11b067 -# ╠═23f118e1-ceed-407f-9063-f0c49138077b -# ╠═6539620f-7d85-40c4-b5f1-dda42bc9e3e9 -# ╠═16369ac8-6cd4-481c-b2dc-b2d884afbfe1 -# ╠═cb8b03b7-6457-4fa1-ab4a-84bd1faffbf4 -# ╠═d42c85dd-ecb7-4e97-87fa-7dbd1746102c -# ╠═5548c28e-f67f-4873-9f90-d91ba0aaa42b -# ╠═776e0206-91ee-4800-83ec-8b6bdb06505a -# ╠═03462e09-692b-47e0-96c0-bc730fcaf200 -# ╠═8513fc7f-cd5a-4ea3-b131-c1bcbcfb4878 From 20cfa16fe4decc7f8fdf480692e799b6c256b30b Mon Sep 17 00:00:00 2001 From: Vladimir Mikheev Date: Wed, 20 Sep 2023 16:09:31 +0000 Subject: [PATCH 04/12] additional docs problems --- docs/src/literate/reference/positions.jl | 2 +- docs/src/tutorials/topoplot.md | 10 ---------- 2 files changed, 1 insertion(+), 11 deletions(-) diff --git a/docs/src/literate/reference/positions.jl b/docs/src/literate/reference/positions.jl index 78ccf2d79..6ff6a5ab4 100644 --- a/docs/src/literate/reference/positions.jl +++ b/docs/src/literate/reference/positions.jl @@ -16,7 +16,7 @@ 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) +pos = to_positions(fake_evoked) # # project from 3D electrode locations to 2D pos3d = hcat(values(pyconvert(Dict,biosemi_montage.get_positions()["ch_pos"]))...) diff --git a/docs/src/tutorials/topoplot.md b/docs/src/tutorials/topoplot.md index 2b5627fbe..9dd6de548 100644 --- a/docs/src/tutorials/topoplot.md +++ b/docs/src/tutorials/topoplot.md @@ -58,16 +58,6 @@ Note that only one of `positions` or `labels` have to be set to draw a topo plot cfgDefault = UnfoldMakie.PlotConfig() cfgDefault.mapping.y ``` -`positions` -```@example main -cfgDefault.mapping.positions #hide -``` - -`labels` -```@example main -cfgDefault.mapping.labels #hide -``` - ### label_text (boolean) Indicates whether label should drawn next to their position. From dc7fd3d81705b4fb7ed8bf8dd21c4ceafc091057 Mon Sep 17 00:00:00 2001 From: Vladimir Mikheev Date: Wed, 20 Sep 2023 16:18:27 +0000 Subject: [PATCH 05/12] little detail --- docs/make.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/make.jl b/docs/make.jl index 21222bbc0..aaaf63aa1 100644 --- a/docs/make.jl +++ b/docs/make.jl @@ -25,7 +25,7 @@ DocMeta.setdocmeta!(UnfoldMakie, :DocTestSetup, :(using UnfoldMakie); recursive= makedocs(; modules=[UnfoldMakie], - authors="Benedikt Ehinger, Daniel Baumgartner, Niklas Gärtner, Sören Döring", + authors="Benedikt Ehinger, Vladimir Mikheev, Daniel Baumgartner, Niklas Gärtner, Sören Döring", repo="https://github.com/unfoldtoolbox/UnfoldMakie.jl/blob/{commit}{path}#{line}", sitename="UnfoldMakie.jl", format=Documenter.HTML(; From fd134823462d6d8f4d831d83632a0e275a5bbd0e Mon Sep 17 00:00:00 2001 From: Vladimir Mikheev Date: Thu, 21 Sep 2023 10:31:39 +0000 Subject: [PATCH 06/12] dead links --- docs/src/how_to/show_oob_labels.md | 18 ++++++++-------- docs/src/index.md | 25 ++++++++++++----------- docs/src/tutorials/butterfly.md | 2 -- docs/src/tutorials/designmatrix.md | 2 +- docs/src/tutorials/parallelcoordinates.md | 1 - 5 files changed, 23 insertions(+), 25 deletions(-) diff --git a/docs/src/how_to/show_oob_labels.md b/docs/src/how_to/show_oob_labels.md index 1f32b1c3b..11cca1707 100644 --- a/docs/src/how_to/show_oob_labels.md +++ b/docs/src/how_to/show_oob_labels.md @@ -1,29 +1,29 @@ # [Show out of Bounds Label](@id ht_soobl) -When visualizing a designmatrix it can happen that the labels on the y-axis get cut off towards the left (especially if they are quite long). -In the following we discuss a possible quick fix for this problem. +When visualizing a design matrix, it can happen that the labels on the y-axis get cut off to the left (especially if they are quite long). +In the following, we will discuss a possible quick solution to this problem. -Here we start off with the "label-limited" timeexpanded designmatrix from the [corresponding How To section](@ref ht_gen_te_designmatrix) that details how it can be generated. +We start with the "label-limited" time-expanded designmatrix from the [corresponding Tutorial section](@ref designmatrix), which describes in detail how to generate it. ```@julia main -plot_designmatrix(designmatrix!(ufCont,evts),cDesign;setExtraValues=(xTicks=10, sortData=false)) +plot_designmatrix(designmatrix!(ufCont,evts), cDesign; setExtraValues=(xTicks=10, sortData=false)) ``` #![Label Limited Timeexpanded Designmatrix](../images/designmatrix_te_12_labels.png) -While the plot automatically sets it's height accoring to the labels, they are cut off on the left side. +While the plot automatically sets its height according to the labels, the labels are cut off on the left side. A quick fix would be to place an empty plot to the left of the designmatrix. -By creating your own figure with Makie.Figure, and then only giving a certain grid position to the designmatrix we get white space next to the plot. +By creating your own figure with Makie.Figure and then giving the designmatrix only a certain grid position, we get white space next to the plot. -The `plot!` function inside the plot config instance can take any grid position, and the figure `f` will include plot and sufficient white space next to it. +The `plot!` function inside the plot config instance can take any grid position, and the figure `f` will contain the plot and enough white space next to it. -The exact numbers in the grid position can be guessed from the ratio of the overlap, or just tried out. +The exact numbers in the grid position can be guessed from the overlap ratio, or just tried. ```@julia main f = Figure() -plot_design(f[1,2:6],designmatrix!(ufCont,evts),cDesign;setExtraValues=(xTicks=10, sortData=false)) +plot_design(f[1,2:6], designmatrix!(ufCont, evts), cDesign; setExtraValues=(xTicks=10, sortData=false)) f ``` diff --git a/docs/src/index.md b/docs/src/index.md index ec9578e84..80769e07c 100644 --- a/docs/src/index.md +++ b/docs/src/index.md @@ -5,23 +5,23 @@ This is the documentation of the UnfoldMakie module for the Julia programming la ## About -UnfoldMakie aims to allow users to generate different types of visualizations. -These include line plots, butterfly plots, designmatrices, parallel coordinates plots, ERP images and topo plots. -Building on the [Unfold](https://github.com/unfoldtoolbox/unfold.jl/) and [Makie](https://makie.juliaplots.org/stable/) Modules, it also grants users customizability through an input configuration on the plots. +UnfoldMakie aims to allow users to create different types of visualizations. +These include line plots, butterfly plots, design matrices, parallel coordinate plots, ERP images, and topo plots. +Building on the [Unfold](https://github.com/unfoldtoolbox/unfold.jl/) and [Makie](https://makie.juliaplots.org/stable/) Modules, it also allows users to customize the plots through an input configuration. -As is apparent considering the types of possible visualizations, these config options try to enable users to create plots, that are helpful in the subject area of computational EEG. -One such example is the possibility of using a topo plot as a legend for a line plot by allowing for multiple visualizations within one figure. +As can be seen from the types of visualizations possible, these configuration options try to enable the user to create plots that are helpful in the field of computational EEG. +One such example is the ability to use a topo plot as a legend for a line plot by allowing multiple visualizations within a figure. ![Coordinated Multiple Views](./images/every_plot.png) ## Structure -For easy readability, the documentation is divided into sections users can inspect depending on their query. +For ease of reading, the documentation is divided into sections that users can view based on their questions. -The `Tutorials: Setup` section contains all information to get started including [installation](@ref install_instruct) and how to aquire necessary [data](@ref test_data) for testing if the user has none. +The `Tutorials: Setup` section contains all the information needed to get started, including [installation](@ref install_instruct). -The `Tutorials: Visualizations` section summarizes all possible visualizations and how users can generate them. -It also details their unique configuration options. +The `Tutorials: Visualizations` section summarizes all possible visualizations and how users can create them. +It also describes their unique configuration options. These visualizations are: - [Designmatrices](@ref dm_vis) @@ -31,8 +31,9 @@ These visualizations are: - [Topo Plots](@ref tp_vis) - [Parallel Coordinate Plots](@ref pcp_vis) -The `Plot Configuration` all segments of the config, detailing their contained attributes. -The plot config is the prime interface allowing the user to access the different visualition options. As the options can be quite different in nature, the plot config is further split into categories. +The `Plot Configuration` shows all segments of the config, detailing the attributes they contain. +The plot config is the main interface that allows the user to access the various visualization options. Since the options can be quite different in nature, the plot config is further divided into categories. + These segments are: - [Axis Data](@ref config_axis) - [Colorbar Data](@ref config_colorbar) @@ -46,7 +47,7 @@ The `How To` section features information on how to achieve specific goals or de These segments are: - [Fix Parallel Coordinates Plot](@ref ht_fpcp) -- [Generate a Timeexpanded Designmatrix](@ref ht_gen_te_designmatrix) +- [Show Out-of-bounds Labels for Designmatrix](@ref show_oob_labels) - [Hide Axis Spines and Decorations](@ref ht_hide_deco) - [Include multiple Visualizations in one Figure](@ref ht_mvf) - [Show out of Bounds Label](@ref ht_soobl) diff --git a/docs/src/tutorials/butterfly.md b/docs/src/tutorials/butterfly.md index 7f20d5a78..367ef3ba7 100644 --- a/docs/src/tutorials/butterfly.md +++ b/docs/src/tutorials/butterfly.md @@ -14,8 +14,6 @@ using DataFrames Note that `DataFramesMeta` is also used here in order to be able to use `@subset` for testing (filtering). ## Data -In case you want to try with different data, look at the [Load Data](@ref test_data) section. - We filter the data to make it more clearly represented: ```@example main diff --git a/docs/src/tutorials/designmatrix.md b/docs/src/tutorials/designmatrix.md index d52a3001d..d0a857ea6 100644 --- a/docs/src/tutorials/designmatrix.md +++ b/docs/src/tutorials/designmatrix.md @@ -13,7 +13,7 @@ using CairoMakie ``` ## Data -In case you do not already have data, look at the [Load Data](@ref test_data) section. + ```@example main include("../../example_data.jl") uf = example_data("UnfoldLinearModel") diff --git a/docs/src/tutorials/parallelcoordinates.md b/docs/src/tutorials/parallelcoordinates.md index 83d9f6fbe..c29c4f258 100644 --- a/docs/src/tutorials/parallelcoordinates.md +++ b/docs/src/tutorials/parallelcoordinates.md @@ -11,7 +11,6 @@ using CairoMakie ``` ## Data -In case you do not already have data, look at the [Load Data](@ref test_data) section. We use the test data of `erpcore-N170.jld2`. From bc73746875631bd6e76e31d0ea31469b2a6e3416 Mon Sep 17 00:00:00 2001 From: Vladimir Mikheev Date: Thu, 21 Sep 2023 11:02:50 +0000 Subject: [PATCH 07/12] docstring warnings --- docs/src/helper.md | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 docs/src/helper.md diff --git a/docs/src/helper.md b/docs/src/helper.md new file mode 100644 index 000000000..505e03190 --- /dev/null +++ b/docs/src/helper.md @@ -0,0 +1,19 @@ +```@docs +UnfoldMakie.eeg_topoplot_series(::Tuple{DataFrame, Any}) +UnfoldMakie.to_positions(::Tuple{AbstractMatrix}) +UnfoldMakie.df_timebin(::Tuple{Any, Any}) +UnfoldMakie.plot_erp(::Tuple{DataFrame}) +UnfoldMakie.plot_circulareegtopoplot(::Tuple{DataFrame}) +UnfoldMakie.plot_designmatrix(::Tuple{Unfold.DesignMatrix}) +UnfoldMakie.cart3d_to_spherical(::Tuple{Any, Any, Any}) +UnfoldMakie.plot_topoplotseries(::Tuple{DataFrame, Real}) +UnfoldMakie.eeg_topoplot_series!(::Tuple{Any, DataFrame, Any}) +UnfoldMakie.plot_butterfly(::Tuple{DataFrame}) +UnfoldMakie.valType_to_symbol(::Tuple{Any}) +UnfoldMakie.RelativeAxis() +UnfoldMakie.config_kwargs!(::Tuple{PlotConfig}) +UnfoldMakie.eeg_matrix_to_dataframe(::Tuple{Any, Any}) +UnfoldMakie.rel_to_abs_bbox(::Tuple{Any, Any}) +UnfoldMakie.plot_parallelcoordinates(::Tuple{DataFrame, Vector{Int64}}) +UnfoldMakie.plot_topoplot(::Tuple{Union{DataFrame, Vector{Float32}}}) +``` \ No newline at end of file From 47c4b199fb998ac06fc288264096ef0be7ac4072 Mon Sep 17 00:00:00 2001 From: Vladimir Mikheev Date: Thu, 21 Sep 2023 11:17:40 +0000 Subject: [PATCH 08/12] cross-refs again --- docs/src/how_to/show_oob_labels.md | 2 +- docs/src/index.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/src/how_to/show_oob_labels.md b/docs/src/how_to/show_oob_labels.md index 11cca1707..3747bf5d9 100644 --- a/docs/src/how_to/show_oob_labels.md +++ b/docs/src/how_to/show_oob_labels.md @@ -3,7 +3,7 @@ When visualizing a design matrix, it can happen that the labels on the y-axis get cut off to the left (especially if they are quite long). In the following, we will discuss a possible quick solution to this problem. -We start with the "label-limited" time-expanded designmatrix from the [corresponding Tutorial section](@ref designmatrix), which describes in detail how to generate it. +We start with the "label-limited" time-expanded designmatrix from the [corresponding Tutorial section](@ref dm_vis), which describes in detail how to generate it. ```@julia main plot_designmatrix(designmatrix!(ufCont,evts), cDesign; setExtraValues=(xTicks=10, sortData=false)) diff --git a/docs/src/index.md b/docs/src/index.md index 80769e07c..8cbdb9c9a 100644 --- a/docs/src/index.md +++ b/docs/src/index.md @@ -47,7 +47,7 @@ The `How To` section features information on how to achieve specific goals or de These segments are: - [Fix Parallel Coordinates Plot](@ref ht_fpcp) -- [Show Out-of-bounds Labels for Designmatrix](@ref show_oob_labels) +- [Show Out-of-bounds Labels for Designmatrix](@ref ht_soobl) - [Hide Axis Spines and Decorations](@ref ht_hide_deco) - [Include multiple Visualizations in one Figure](@ref ht_mvf) - [Show out of Bounds Label](@ref ht_soobl) From 2bbc5653672d7be0d9080eb8919f2159b3bf6db2 Mon Sep 17 00:00:00 2001 From: Vladimir Mikheev Date: Thu, 21 Sep 2023 11:37:47 +0000 Subject: [PATCH 09/12] test --- docs/src/helper.md | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/docs/src/helper.md b/docs/src/helper.md index 505e03190..e7753123f 100644 --- a/docs/src/helper.md +++ b/docs/src/helper.md @@ -1,19 +1,19 @@ ```@docs -UnfoldMakie.eeg_topoplot_series(::Tuple{DataFrame, Any}) -UnfoldMakie.to_positions(::Tuple{AbstractMatrix}) -UnfoldMakie.df_timebin(::Tuple{Any, Any}) -UnfoldMakie.plot_erp(::Tuple{DataFrame}) -UnfoldMakie.plot_circulareegtopoplot(::Tuple{DataFrame}) -UnfoldMakie.plot_designmatrix(::Tuple{Unfold.DesignMatrix}) -UnfoldMakie.cart3d_to_spherical(::Tuple{Any, Any, Any}) -UnfoldMakie.plot_topoplotseries(::Tuple{DataFrame, Real}) -UnfoldMakie.eeg_topoplot_series!(::Tuple{Any, DataFrame, Any}) -UnfoldMakie.plot_butterfly(::Tuple{DataFrame}) -UnfoldMakie.valType_to_symbol(::Tuple{Any}) -UnfoldMakie.RelativeAxis() -UnfoldMakie.config_kwargs!(::Tuple{PlotConfig}) -UnfoldMakie.eeg_matrix_to_dataframe(::Tuple{Any, Any}) -UnfoldMakie.rel_to_abs_bbox(::Tuple{Any, Any}) -UnfoldMakie.plot_parallelcoordinates(::Tuple{DataFrame, Vector{Int64}}) -UnfoldMakie.plot_topoplot(::Tuple{Union{DataFrame, Vector{Float32}}}) +eeg_topoplot_series(::Tuple{DataFrame, Any}) +to_positions(::Tuple{AbstractMatrix}) +df_timebin(::Tuple{Any, Any}) +plot_erp(::Tuple{DataFrame}) +plot_circulareegtopoplot(::Tuple{DataFrame}) +plot_designmatrix(::Tuple{Unfold.DesignMatrix}) +cart3d_to_spherical(::Tuple{Any, Any, Any}) +plot_topoplotseries(::Tuple{DataFrame, Real}) +eeg_topoplot_series!(::Tuple{Any, DataFrame, Any}) +plot_butterfly(::Tuple{DataFrame}) +valType_to_symbol(::Tuple{Any}) +RelativeAxis() +config_kwargs!(::Tuple{PlotConfig}) +eeg_matrix_to_dataframe(::Tuple{Any, Any}) +rel_to_abs_bbox(::Tuple{Any, Any}) +plot_parallelcoordinates(::Tuple{DataFrame, Vector{Int64}}) +plot_topoplot(::Tuple{Union{DataFrame, Vector{Float32}}}) ``` \ No newline at end of file From fa8a8ecfec0ddf346dc38ddbe505c0829ba9b915 Mon Sep 17 00:00:00 2001 From: Vladimir Mikheev Date: Thu, 21 Sep 2023 11:53:52 +0000 Subject: [PATCH 10/12] pp_plot fixed --- docs/make.jl | 21 +++++++++------------ docs/src/tutorials/butterfly.md | 2 +- docs/src/tutorials/erpimage.md | 5 ++--- docs/src/tutorials/parallelcoordinates.md | 2 +- docs/src/tutorials/topoplot.md | 4 ++-- docs/src/tutorials/topoplotseries.md | 2 +- src/plot_parallelcoordinates.jl | 4 ++-- test/test_pp.jl | 7 +++++++ 8 files changed, 25 insertions(+), 22 deletions(-) create mode 100644 test/test_pp.jl diff --git a/docs/make.jl b/docs/make.jl index aaaf63aa1..c310c35af 100644 --- a/docs/make.jl +++ b/docs/make.jl @@ -12,15 +12,12 @@ using Literate using Glob GENERATED = joinpath(@__DIR__, "src", "literate") -for subfolder ∈ ["explanations","HowTo","tutorials","reference"] - local SOURCE_FILES = Glob.glob(subfolder*"/*.jl", GENERATED) - foreach(fn -> Literate.markdown(fn, GENERATED*"/"*subfolder), SOURCE_FILES) +for subfolder ∈ ["explanations", "HowTo", "tutorials", "reference"] + local SOURCE_FILES = Glob.glob(subfolder * "/*.jl", GENERATED) + foreach(fn -> Literate.markdown(fn, GENERATED * "/" * subfolder), SOURCE_FILES) end - - - DocMeta.setdocmeta!(UnfoldMakie, :DocTestSetup, :(using UnfoldMakie); recursive=true) makedocs(; @@ -31,19 +28,19 @@ makedocs(; format=Documenter.HTML(; prettyurls=get(ENV, "CI", "false") == "true", canonical="https://unfoldtoolbox.github.io/UnfoldMakie.jl", - assets=String[], + assets=String[] ), pages=[ "UnfoldMakie Documentation" => "index.md", "Visualizations-Types" => [ - "ERP plot" => "literate/tutorials/erp.md", + "ERP plot" => "literate/tutorials/erp.md", "Butterfly Plot" => "tutorials/butterfly.md", "Designmatrix" => "tutorials/designmatrix.md", "ERP Image" => "tutorials/erpimage.md", "Parallel Coordinates Plot" => "tutorials/parallelcoordinates.md", "Topo Plot" => "tutorials/topoplot.md", "Topo Plot Series" => "tutorials/topoplotseries.md", - "Circular TopoPlot" => "literate/tutorials/circTopo.md", + "Circular TopoPlot" => "literate/tutorials/circTopo.md", ], "Plot Configuration" => [ "Axis Data" => "config/axis_data.md", @@ -61,13 +58,13 @@ makedocs(; "Include multiple Visualizations in one Figure" => "how_to/mult_vis_in_fig.md", "Show out of Bounds Label" => "how_to/show_oob_labels.md", ], - "Reference" => [ + "Reference" => [ "Convert 3D positions / montages to 2D layouts" => "literate/reference/positions.md" ] - ], + ] ) deploydocs(; repo="github.com/unfoldtoolbox/UnfoldMakie.jl", - devbranch="main", + devbranch="main" ) diff --git a/docs/src/tutorials/butterfly.md b/docs/src/tutorials/butterfly.md index 367ef3ba7..4d55a4309 100644 --- a/docs/src/tutorials/butterfly.md +++ b/docs/src/tutorials/butterfly.md @@ -32,7 +32,7 @@ plot_butterfly(df) or if you provide the channel positions: ```@example main -plot_butterfly(df;positions=pos) +plot_butterfly(df; positions=pos) ``` ## Column Mappings for Butterfly Plots diff --git a/docs/src/tutorials/erpimage.md b/docs/src/tutorials/erpimage.md index 61a90e47e..d0a482a18 100644 --- a/docs/src/tutorials/erpimage.md +++ b/docs/src/tutorials/erpimage.md @@ -27,12 +27,11 @@ plot_erpimage(data) Since ERP images use a `Matrix` as an input, the library does not need any informations about the mapping. ## extra=(;) -- erpBlur (number,10 ) - Is a number indicating how much blur is applied to the image; using Gaussian blur of the ImageFiltering module. Negative values deactivate the blur. +- erpBlur (number, 10) - Is a number indicating how much blur is applied to the image; using Gaussian blur of the ImageFiltering module. Negative values deactivate the blur. -- sortData (boolean,false) - Indicating whether the data is sorted; using sortperm() of Base Julia +- sortData (boolean, false) - Indicating whether the data is sorted; using sortperm() of Base Julia (sortperm() computes a permutation of the array's indices that puts the array into sorted order). - - ploterp (bool, false) - Indicating whether the plot should add a line plot below the ERP image, showing the mean of the data. If limits are set in the axis values both plots will be aligned. ```@example main diff --git a/docs/src/tutorials/parallelcoordinates.md b/docs/src/tutorials/parallelcoordinates.md index c29c4f258..b77a47667 100644 --- a/docs/src/tutorials/parallelcoordinates.md +++ b/docs/src/tutorials/parallelcoordinates.md @@ -22,7 +22,7 @@ results_plot, positions = example_data(); ## Plot PCPs ```@example main -plot_parallelcoordinates(results_plot,[5,3,2]; # this selects channel 5,3 & 2 +plot_parallelcoordinates(results_plot, [5,3,2]; # this selects channel 5,3 & 2 mapping = (color = :coefname, y = :estimate)) ``` diff --git a/docs/src/tutorials/topoplot.md b/docs/src/tutorials/topoplot.md index 9dd6de548..7d03f0d21 100644 --- a/docs/src/tutorials/topoplot.md +++ b/docs/src/tutorials/topoplot.md @@ -63,12 +63,12 @@ cfgDefault.mapping.y Indicates whether label should drawn next to their position. Obviously the labels have to be provided: `plot_topoplot(...; labels=[...])` -`plot_topoplot(...;visual=(;label_text=true))` +`plot_topoplot(...;visual=(; label_text=true))` ### label_scatter (boolean) Indicates whether the dots should be drawn at the given positions. -`plot_topoplot(...;visual=(;label_scatter=true))` +`plot_topoplot(...;visual=(; label_scatter=true))` ```@example main diff --git a/docs/src/tutorials/topoplotseries.md b/docs/src/tutorials/topoplotseries.md index d925bdab3..1837724b5 100644 --- a/docs/src/tutorials/topoplotseries.md +++ b/docs/src/tutorials/topoplotseries.md @@ -32,7 +32,7 @@ plot_topoplotseries(df, Δbin; positions = positions) You can give either positions, or labels. If both are provided, positions have priority ### plot_toposeries(...;mapping=(;key=value)) -`mapping=(:y=(:estimate,:yhat,:y))` +`mapping=(:y=(:estimate, :yhat, :y))` ### visual=(;) `label_text` (boolean, false) Indicates whether label should drawn next to their position. diff --git a/src/plot_parallelcoordinates.jl b/src/plot_parallelcoordinates.jl index e693a597b..cb97b4a4c 100644 --- a/src/plot_parallelcoordinates.jl +++ b/src/plot_parallelcoordinates.jl @@ -48,7 +48,7 @@ function plot_parallelcoordinates!(f::Union{GridPosition,Figure}, plotData::Data ch_label_offset = 15 # axis for plot - ax = Axis(f; config.axis...) + ax = Axis(f[1, 1]; config.axis...) # colormap border (prevents from using outer parts of color map) bord = 0 @@ -107,7 +107,7 @@ function plot_parallelcoordinates!(f::Union{GridPosition,Figure}, plotData::Data labelfont="Arial", ticklabelfont="Arial", spinevisible=true, - labelrotation = 0.0, + labelrotation=0.0, ticklabelsize=tick_label_size, minorticks=IntervalsBetween(2), endpoints=Point2f[(x_values[i], bottom_padding), (x_values[i], y_values[i])], diff --git a/test/test_pp.jl b/test/test_pp.jl new file mode 100644 index 000000000..88bcb06ce --- /dev/null +++ b/test/test_pp.jl @@ -0,0 +1,7 @@ + +@testset "markersize change" begin + include("../docs/example_data.jl") + results_plot, positions = example_data(); + plot_parallelcoordinates(results_plot, [5,3,2]; # this selects channel 5,3 & 2 + mapping = (color = :coefname, y = :estimate)) +end From 28eafd07d2983f48a80077e6e8c4dc6b2552fcdf Mon Sep 17 00:00:00 2001 From: Vladimir Mikheev Date: Thu, 21 Sep 2023 14:18:34 +0000 Subject: [PATCH 11/12] docs errors should be resolved --- docs/nb_testAll.jl | 272 ----------------------- docs/src/config/colorbar_data.md | 2 +- docs/src/config/extra_data.md | 4 +- docs/src/config/layout_data.md | 4 +- docs/src/config/legend_data.md | 4 +- docs/src/config/mapping_data.md | 9 +- docs/src/config/visual_data.md | 2 +- docs/src/helper.md | 34 +-- docs/src/how_to/fix_pcp.md | 8 +- docs/src/how_to/hide_deco.md | 14 +- docs/src/how_to/mult_vis_in_fig.md | 13 +- docs/src/how_to/position2color.md | 11 +- docs/src/literate/reference/positions.md | 46 ++++ docs/src/literate/tutorials/circTopo.md | 18 +- docs/src/literate/tutorials/erp.md | 27 +-- docs/src/tutorials/butterfly.md | 8 +- 16 files changed, 122 insertions(+), 354 deletions(-) delete mode 100644 docs/nb_testAll.jl create mode 100644 docs/src/literate/reference/positions.md diff --git a/docs/nb_testAll.jl b/docs/nb_testAll.jl deleted file mode 100644 index ee3177ae4..000000000 --- a/docs/nb_testAll.jl +++ /dev/null @@ -1,272 +0,0 @@ -### A Pluto.jl notebook ### -# v0.19.11 - -using Markdown -using InteractiveUtils - -# ╔═╡ 4c7907ad-bc25-4188-ade7-fa69e6fc719d -# ╠═╡ show_logs = false -begin - using Pkg # cant use internal package manager because we need the topoplot version of UnfoldMakie - Pkg.activate(temp=true) - -end - -# ╔═╡ 29fca132-7f60-4caa-805f-155babb6832d -# ╠═╡ show_logs = false -# install packages -begin -Pkg.add.(["DataFramesMeta","JLD2","StatsModels","Unfold","PyMNE","CairoMakie", "CSV","DataFrames","StatsBase","FileIO","AlgebraOfGraphics","MixedModels","CategoricalArrays"]) - - - -end; - -# ╔═╡ ec872fd2-6a92-46b5-bc6e-87ba28db1b09 -# ╠═╡ show_logs = false -Pkg.develop(path="../../UnfoldMakie") - -# ╔═╡ d609f3e3-ff6a-4a96-a359-e44dba93c0e0 -using UnfoldMakie - -# ╔═╡ f3f93d30-d2b6-11ec-3ba2-898080a75c3f -begin - using Unfold - using PyMNE # MNE is a python library for EEG data analysis - using AlgebraOfGraphics # plotting Grammar of Graphics - using CSV - using DataFrames - using StatsBase # mean/std - using FileIO # loading data - using JLD2 # loading data - using StatsModels # UnfoldFit - using CairoMakie # Plotting Backend (SVGs/PNGs) - using Printf # interpolate strings - - using DataFramesMeta # @subset etc. working with DataFrames -end - -# ╔═╡ d6119836-fc49-4731-82a6-66d25963ba2c -begin # load one single-subject dataset - - # once artifacts are working, we could ship it. But for now you have to download it and - #p =joinpath(pathof(UnfoldMakie),"artifacts","sub002_ses-N170_task-N170_eeg.set") - - p = "/store/users/ehinger/projects/unfoldjl_dev/dev/UnfoldMakie/artifact/sub-002_ses-N170_task-N170_eeg.set" - raw = PyMNE.io.read_raw_eeglab(p,preload=false) -end; - -# ╔═╡ c6bb6bbb-55a4-4bfd-bb12-24307607248a -begin # load unfold-fitted dataset of all subjects - # takes ~25s to load because it is quite large :) - p_all = "/store/users/ehinger/projects/unfoldjl_dev/data/erpcore-N170.jld2" - presaved_data = load(p_all) - dat_e = presaved_data["data_e_all"].* 1e6 - evt_e = presaved_data["df_e_all"] -end; - -# ╔═╡ 434a957c-ec3f-4496-a7e6-a0ec4b431754 -# ╠═╡ show_logs = false -begin - # times vector (from-to) - times = range(-0.3, length=size(dat_e,2), step=1 ./ 128) - - # get standard errors - se_solver =(x,y)->Unfold.solver_default(x,y,stderror=true) - # define effect-coding - contrasts= Dict(:category => EffectsCoding(), :condition => EffectsCoding()) - - analysis_formula = @formula 0 ~ 1 + category * condition - - results_allSubjects = DataFrame() - - for sub ∈ unique(evt_e.subject) - - # select events of one subject - sIx = evt_e.subject .== sub - - # fit Unfold-Model - # declaring global so we can access the variable outside of this loop (local vs. global scope) - global mres = Unfold.fit(UnfoldModel, - analysis_formula, - evt_e[sIx,:], - dat_e[:,:,sIx], - times, - contrasts=contrasts, - solver=se_solver); - - # make results of one subject available - global results_onesubject = coeftable(mres) - - # concatenate results of all subjects - results_onesubject[!,:subject] .= sub - append!(results_allSubjects,results_onesubject) - - end - -end - -# ╔═╡ 9c17bcfb-9106-4b67-948c-94aa31662418 - let # We are fitting only one channel! - - using MixedModels, CategoricalArrays - lmm_formula = @formula 0 ~ 1 + category + zerocorr(1+category|subject) - evt_lmm = deepcopy(evt_e) - @transform!(evt_lmm,:subject=categorical(:subject)) - - lmm = Unfold.fit(UnfoldModel, - lmm_formula, - evt_lmm, - dat_e[1:1,:,:], - times, - contrasts=contrasts); - plot_results(coeftable(lmm)) - end - -# ╔═╡ 343f3c15-7f48-4e25-84d5-f4ef01d35db7 -md"""## Designmatrix""" - -# ╔═╡ 7cbe5fcb-4440-4a96-beca-733ddcb07861 -plot(designmatrix(mres),sort=true) - -# ╔═╡ d329586a-fd05-4729-a0c3-4700ee22a498 -md"""## Butterfly-plot?""" - -# ╔═╡ 975382de-5f24-4e9e-87f6-a7f7ba93ff8e -let # let (against begin) makes a local environment, not sharing the modifications / results wiht outside scripts. Beware of field assignments x.blub = "1,2,3" will overwrite x.blub, x = [1,2,3] will not overwrite global x, but make a copy - -results_plot = @subset(results_onesubject,:coefname .== "(Intercept)",:channel .<5) -plot_results(results_plot,color=:channel,layout=:channel) -end - -# ╔═╡ 3ba4d6bc-ffaa-456e-8d85-334d60ebbd77 -let -results_plot = @subset(results_allSubjects,:coefname .== "(Intercept)",:channel .==1) -plot_results(results_plot,color=:subject) -end - -# ╔═╡ 62632f86-5792-49c3-a229-376211deae64 -md""" -## Lineplot -ManyFactors -""" - -# ╔═╡ 41e1b735-4c19-4e6d-8681-ef0f893aec87 -let # let (against begin) makes a local environment, not sharing the modifications / results wiht outside scripts. Beware of field assignments x.blub = "1,2,3" will overwrite x.blub, x = [1,2,3] will not overwrite global x, but make a copy - -results_plot = @subset(results_onesubject,:channel .==22) -plot_results(results_plot,stderror=true) -end - -# ╔═╡ a92e775f-eede-4a0f-a404-8ed61abe6804 -md"## P-value significance" - -# ╔═╡ 5840f82c-8e0f-4bbe-8e83-6e79eae11823 -pathof(UnfoldMakie) - -# ╔═╡ c0e53025-7f23-4520-b22c-d271b8c528a9 -let -pvals = DataFrame( - from=[0.1,0.3], - to=[0.5,0.7], - coefname=["(Intercept)","category: face"] # if coefname not specified, line should be black - ) - - - #pvals = DataFrame(from=[0.1],to=[0.5]) -results_plot = @subset(results_onesubject,:channel .==22) -plot_results(results_plot,pvalue=pvals) -end - -# ╔═╡ cb396666-93d7-41e3-b958-55df52fc516e -md"""## Linear Mixed Models -The "rows" is one potential way to display multiple groups ala fixef / ranef. - -See the next example for multiple events as well -""" - -# ╔═╡ 35094a17-2be0-4d57-8846-3ed31a04e689 -md""" -## Multiple basisfunctions -It is possible to have multiple events to cut your data to - -As this is not 100% implemented for mass-univariate non-deconvolution models (i.e. you could concatenate different LMMs) I refer to this tutorial https://unfoldtoolbox.github.io/UnfoldMakie.jl/dev/plot_results/ - -But just to show what I mean, let's do a trickery doo -""" - -# ╔═╡ 3c607414-0760-48ab-961c-ab74d6df6522 -let - r1 = @subset(results_onesubject,:channel .==22) - r2 = @subset(results_onesubject,:channel .==25) - r1.basisname .= "eventA" - r2.basisname .= "eventB" - results_plot = vcat(r1,r2) - plot_results(results_plot) -end - -# ╔═╡ 98026af7-d875-43f3-a3cb-3109faef5822 -md""" -## Topoplots -""" - -# ╔═╡ 3cee30ae-cf25-4684-bd49-c64b0b96b4e6 -begin - mon = PyMNE.channels.make_standard_montage("standard_1020") - raw.set_channel_types(Dict("HEOG_left"=>"eog","HEOG_right"=>"eog","VEOG_lower"=>"eog")) - raw.set_montage(mon,match_case=false) - - pos = PyMNE.channels.make_eeg_layout(get_info(raw)).pos -end; - -# ╔═╡ 5f0f2708-f2d9-4a72-a528-185837a43e06 -let -# potentially still buggy: The sensor-positions are flipped 90° -plot_topoplot_series(@subset(results_onesubject,:coefname.=="(Intercept)",:channel .<=30),0.2,topoplotCfg=(positions=pos,)) - -end - -# ╔═╡ 6ee180df-4340-45a2-bb1e-37aad7953875 -# maybe this should be the default -# note the bad time on top :S -plot_topoplot_series(@subset(results_onesubject,:coefname.=="(Intercept)",:channel .<=30),0.2,topoplotCfg=(sensors=false,positions=pos,),mappingCfg=(col=:time,)) - -# ╔═╡ baf1fec8-fa1e-4b97-9570-c1f791f37f24 -results_onesubject - -# ╔═╡ f0f752d8-7f2d-4a49-8763-53df2cff6126 -plot_topoplot_series(@subset(results_onesubject,:channel .<=30),0.2,topoplotCfg=(sensors=false,positions=pos,),mappingCfg=(col=:time,row=:coefname)) - -# ╔═╡ 7da4df51-589a-4eb5-8f1f-f77ab65cf10a -@subset(results_onesubject,:coefname.=="(Intercept)") - -# ╔═╡ Cell order: -# ╠═4c7907ad-bc25-4188-ade7-fa69e6fc719d -# ╠═29fca132-7f60-4caa-805f-155babb6832d -# ╠═ec872fd2-6a92-46b5-bc6e-87ba28db1b09 -# ╠═d609f3e3-ff6a-4a96-a359-e44dba93c0e0 -# ╠═f3f93d30-d2b6-11ec-3ba2-898080a75c3f -# ╠═d6119836-fc49-4731-82a6-66d25963ba2c -# ╠═c6bb6bbb-55a4-4bfd-bb12-24307607248a -# ╠═434a957c-ec3f-4496-a7e6-a0ec4b431754 -# ╠═343f3c15-7f48-4e25-84d5-f4ef01d35db7 -# ╠═7cbe5fcb-4440-4a96-beca-733ddcb07861 -# ╟─d329586a-fd05-4729-a0c3-4700ee22a498 -# ╠═975382de-5f24-4e9e-87f6-a7f7ba93ff8e -# ╠═3ba4d6bc-ffaa-456e-8d85-334d60ebbd77 -# ╟─62632f86-5792-49c3-a229-376211deae64 -# ╠═41e1b735-4c19-4e6d-8681-ef0f893aec87 -# ╠═a92e775f-eede-4a0f-a404-8ed61abe6804 -# ╠═5840f82c-8e0f-4bbe-8e83-6e79eae11823 -# ╠═c0e53025-7f23-4520-b22c-d271b8c528a9 -# ╠═cb396666-93d7-41e3-b958-55df52fc516e -# ╠═9c17bcfb-9106-4b67-948c-94aa31662418 -# ╟─35094a17-2be0-4d57-8846-3ed31a04e689 -# ╠═3c607414-0760-48ab-961c-ab74d6df6522 -# ╠═98026af7-d875-43f3-a3cb-3109faef5822 -# ╠═3cee30ae-cf25-4684-bd49-c64b0b96b4e6 -# ╠═5f0f2708-f2d9-4a72-a528-185837a43e06 -# ╠═6ee180df-4340-45a2-bb1e-37aad7953875 -# ╠═baf1fec8-fa1e-4b97-9570-c1f791f37f24 -# ╠═f0f752d8-7f2d-4a49-8763-53df2cff6126 -# ╠═7da4df51-589a-4eb5-8f1f-f77ab65cf10a diff --git a/docs/src/config/colorbar_data.md b/docs/src/config/colorbar_data.md index 03a9feccf..61977390e 100644 --- a/docs/src/config/colorbar_data.md +++ b/docs/src/config/colorbar_data.md @@ -13,7 +13,7 @@ Furthermore `extra=(;categoricalColor=false)` needs to be `false`. ## Other Plots In all other Plots the `Colorbar` function of the `Makie` module is used ([documentation](https://makie.juliaplots.org/v0.17.13/examples/blocks/colorbar/index.html)). -The Colorbar will only be used when both `layoutData.showLegend` and `layoutData.useColorbar` are set `true`. +The Colorbar will only be used when both `layoutData.showLegend` and `layoutData.useColorbar` are set to `true`. ## Colorbar data default values diff --git a/docs/src/config/extra_data.md b/docs/src/config/extra_data.md index fe1fc2db5..33b44b5af 100644 --- a/docs/src/config/extra_data.md +++ b/docs/src/config/extra_data.md @@ -1,5 +1,5 @@ # [Extra Data](@id config_extra) -The extra data of the configuration consists of all config options that are unique for the visualizations. +The configuration extra data consists of all configuration options that are unique to the visualizations. -The available options for each plot are described at the end of their respective tutorial in the `Tutorials: Visualizations` section. \ No newline at end of file +The options available for each plot are described at the end of each tutorial in the `Tutorials: Visualizations` section. \ No newline at end of file diff --git a/docs/src/config/layout_data.md b/docs/src/config/layout_data.md index 643db4c6a..6812197f1 100644 --- a/docs/src/config/layout_data.md +++ b/docs/src/config/layout_data.md @@ -1,8 +1,8 @@ # [Layout Data](@id config_layout) -The layout data of the configuration consists of config options for the layout such as the legend and labels. +The layout data of the configuration consists of configuration options for the layout, such as the legend and labels. -The following layout data options exist (the default values may be different for some plots types): +The following layout data options are available (defaults may be different for some plot types): ## showLegend (boolean) Indicating whether the legend is displayed. diff --git a/docs/src/config/legend_data.md b/docs/src/config/legend_data.md index 75e4fcd5f..7b2e3251e 100644 --- a/docs/src/config/legend_data.md +++ b/docs/src/config/legend_data.md @@ -5,13 +5,13 @@ The legend data of the configuration consists of config options for the legend. ## Line Plots and Butterfly Plots For line plots the `legend!` function of the `AlgebraOfGraphics` module is used ([documentation](http://juliaplots.org/AlgebraOfGraphics.jl/stable/API/functions/#AlgebraOfGraphics.legend!)). -The `Legend` will be used automatically, when `AlgebraOfGraphics` is able to draw it. +The `Legend` is used automatically, if `AlgebraOfGraphics` is able to draw it. For this the `color` data will be used and has to be either non-numerical or `funcall(...;extra=(categoricalColor=true,)` needs to be set `true`. ## Parallel Coordinates Plots In a parallel coordinate plot the `Legend` function of the `Makie` module is used ([documentation](https://makie.juliaplots.org/v0.17.13/examples/blocks/legend/index.html)). -The Legend will only be used when `funcall(...;layout=(showLegend=true,)` is `true` and `funcall(...;layout=(useColorbar=false,)` is `false` +The legend is only used if `funcall(...;layout=(showLegend=true,)` is `true` and `funcall(...;layout=(useColorbar=false,)` is `false` ## Legend data default options diff --git a/docs/src/config/mapping_data.md b/docs/src/config/mapping_data.md index 92e19e847..f9f39e927 100644 --- a/docs/src/config/mapping_data.md +++ b/docs/src/config/mapping_data.md @@ -1,6 +1,6 @@ # [Mapping Data](@id config_mapping) -The mapping data of the configuration is used to let the plotting functions know which columns of a `DataFrame` contain which data. +The mapping data of the configuration is used to tell the plotting functions which columns of a `DataFrame` contain which data. Therefore it is only used in plots with a `DataFrame` as input. For example a Line Plot makes use of the `x` and `y` mappings. @@ -9,14 +9,15 @@ To have our Line Plot use the "estimate" column for `x` and the "time" column fo plot_erp(...;mapping=(;x=:estimate,)) ``` -Which columns are used by which plotting function can be looked up in their respective tutorials in the `Tutorials: Visualizations` section. +Which columns are used by which plotting functions can be found in the respective tutorials in the `Tutorials: Visualizations` section. ## Multiple Options -In addition to providing a single column which contains the specified data, the user can also provide a list of columns which may contain the data. + +In addition to providing a single column containing the specified data, the user can also provide a list of columns that may contain the data. ``` plot_erp(...;mapping=(;y = (:y, :yhat, :estimate))) ``` In this case the first available column will be chosen. Some configurations for certain plots already have a default column or a list of columns set. -This way the user might not need to set any mapping values themselves, in case the `DataFrame` conforms to the same standards. \ No newline at end of file +This way the user may not have to set any mapping values if the `DataFrame` meets the same standards. \ No newline at end of file diff --git a/docs/src/config/visual_data.md b/docs/src/config/visual_data.md index 2c4c85ed8..dce153a2b 100644 --- a/docs/src/config/visual_data.md +++ b/docs/src/config/visual_data.md @@ -1,6 +1,6 @@ # [Visual Data](@id config_visual) -The visual data of the configuration will be passed to the underlying plotting functions and can be used to set their specific attributes. +The visual data of the configuration is passed to the underlying plotting functions and can be used to set their specific attributes. As a consequence, the possible options are determined by the following functions: - Designmatrix, ERP Image : `heatmap` ([documentation](https://makie.juliaplots.org/v0.17.13/examples/plotting_functions/heatmap/index.html)) diff --git a/docs/src/helper.md b/docs/src/helper.md index e7753123f..0aa2d23ca 100644 --- a/docs/src/helper.md +++ b/docs/src/helper.md @@ -1,19 +1,19 @@ ```@docs -eeg_topoplot_series(::Tuple{DataFrame, Any}) -to_positions(::Tuple{AbstractMatrix}) -df_timebin(::Tuple{Any, Any}) -plot_erp(::Tuple{DataFrame}) -plot_circulareegtopoplot(::Tuple{DataFrame}) -plot_designmatrix(::Tuple{Unfold.DesignMatrix}) -cart3d_to_spherical(::Tuple{Any, Any, Any}) -plot_topoplotseries(::Tuple{DataFrame, Real}) -eeg_topoplot_series!(::Tuple{Any, DataFrame, Any}) -plot_butterfly(::Tuple{DataFrame}) -valType_to_symbol(::Tuple{Any}) -RelativeAxis() -config_kwargs!(::Tuple{PlotConfig}) -eeg_matrix_to_dataframe(::Tuple{Any, Any}) -rel_to_abs_bbox(::Tuple{Any, Any}) -plot_parallelcoordinates(::Tuple{DataFrame, Vector{Int64}}) -plot_topoplot(::Tuple{Union{DataFrame, Vector{Float32}}}) +UnfoldMakie.RelativeAxis +UnfoldMakie.eeg_topoplot_series +UnfoldMakie.eeg_topoplot_series! +UnfoldMakie.config_kwargs! +UnfoldMakie.eeg_matrix_to_dataframe +UnfoldMakie.rel_to_abs_bbox +UnfoldMakie.plot_parallelcoordinates +UnfoldMakie.plot_topoplot +UnfoldMakie.to_positions +UnfoldMakie.df_timebin +UnfoldMakie.plot_erp +UnfoldMakie.plot_circulareegtopoplot +UnfoldMakie.plot_designmatrix +UnfoldMakie.cart3d_to_spherical +UnfoldMakie.plot_topoplotseries +UnfoldMakie.plot_butterfly +UnfoldMakie.valType_to_symbol ``` \ No newline at end of file diff --git a/docs/src/how_to/fix_pcp.md b/docs/src/how_to/fix_pcp.md index 2761c1a05..84af6fe04 100644 --- a/docs/src/how_to/fix_pcp.md +++ b/docs/src/how_to/fix_pcp.md @@ -1,11 +1,11 @@ # [Fix Parallel Coordinates Plot](@id ht_fpcp) -Since Makie didn't have a native function to draw PCPs our version is somewhat experimental for broad applications. +Since Makie doesn't have a native function to draw PCPs, our version is somewhat experimental for general use. -Under certain circumstances the PCP is not properly visualized. -This leads to cut off edges of the PCP, and unused space. +Under certain circumstances the PCP is not visualized correctly. +This leads to truncated edges of the PCP and unused space. -Especially when changing the container size by customizing the figure resolution, or adding multiple plots into one figure, the PCP can have problems fitting inside. +In particular, if the container size is changed by adjusting the figure resolution, or if multiple plots are added to a figure, the PCP may not fit. ![PCP with cutoff and bad spacing](../images/broken_PCP.png) diff --git a/docs/src/how_to/hide_deco.md b/docs/src/how_to/hide_deco.md index 16d71b982..4a6421a67 100644 --- a/docs/src/how_to/hide_deco.md +++ b/docs/src/how_to/hide_deco.md @@ -1,12 +1,12 @@ # [Hide Axis Spines and Decorations](@id ht_hide_deco) -In this section we discuss how users are able to efficiently hide axis spines and decorations in their plots. +This section discusses how users can efficiently hide axis spines and decorations in their plots. -While it's possible to hide these axis decorations through setting the axis settings with `axis=(;...)`, `Makie.Axis` features multiple variables for different aspects of the plot. This means that removing all decoration is only possible by setting a lot of variables each time. +While it's possible to hide these axis decorations by setting the axis settings with `axis=(;...)`, `Makie.Axis` provides multiple variables for different aspects of the plot. This means that removing all decorations is only possible by setting many variables each time. -Makie does feature methods like `hidespines!` and `hidedecorations!`, but the user might not have easy acces to the axis their plot is drawn in. +Makie does provide methods like `hidespines` and `hidedecorations`, but the user may not have easy access to the axis their plot is drawn in. -So instead these functions can be called by setting variables with `layout = (;)`: +Instead, these functions can be called by setting variables with `layout = (;)`: ``` ... layout = ( @@ -16,11 +16,9 @@ So instead these functions can be called by setting variables with `layout = (;) ) ``` -Since these values mirror the input of the function, we can use an empty tuple to remove all decorations or spines respectively - - -And using `hidespines = (:r, :t)` results in the removal of the top and right border. +Since these values reflect the input to the function, we can use an empty tuple to remove all decorations and spines, respectively +And using `hidespines = (:r, :t)` will remove the top and right borders. For more information on the input of these functions refer to the [Makie dokumentation on Axis.](https://makie.juliaplots.org/v0.15.2/examples/layoutables/axis/#hiding_axis_spines_and_decorations) diff --git a/docs/src/how_to/mult_vis_in_fig.md b/docs/src/how_to/mult_vis_in_fig.md index 2dd40939f..c43795814 100644 --- a/docs/src/how_to/mult_vis_in_fig.md +++ b/docs/src/how_to/mult_vis_in_fig.md @@ -21,15 +21,15 @@ 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. +This section discusses how users can incorporate multiple plots into a single figure. -By using the !-version of the plotting function and putting in a grid position instead of a full figure, we can create Multiple Coordinated Views. +By using the !-version of the plotting function and inserting a grid position instead of an entire figure, we can create multiple coordinated views. -You start by creating a figure with Makie.Figure. +We start by creating a figure with Makie.Figure. `f = Figure()` -Now each plot can be added to `f` by putting in a grid position, such as `f[1,1]`. +Now any plot can be added to `f` by placing a grid position, such as `f[1,1]`. ```@example main @@ -41,10 +41,9 @@ plot_butterfly!(f[2, 1:2], d_topo; positions=positions) f ``` -By using the data from the tutorials we can create a big image with every type of plot. - -With so many plots at once it's incentivised to set a fixed resolution in your figure to order the plots evenly (Code below). +Using the data from the tutorials, we can create a large image with any type of plot. +With so many plots at once, it's tempting to set a fixed resolution in your image to order the plots evenly (code below). ```@example main diff --git a/docs/src/how_to/position2color.md b/docs/src/how_to/position2color.md index cc330e7c2..44daa3fad 100644 --- a/docs/src/how_to/position2color.md +++ b/docs/src/how_to/position2color.md @@ -6,13 +6,14 @@ In this section we discuss how users are able change the position to colorscale using UnfoldMakie using CairoMakie using DataFramesMeta +using Colors ``` By default the plot looks like this: ```@example main include("../../example_data.jl") -results,positions = example_data("TopoPlots.jl") -plot_butterfly(results;positions=positions) +results, positions = example_data("TopoPlots.jl") +plot_butterfly(results; positions=positions) ``` We can switch the colorscale of the position-map, by giving a function that maps from a `(x,y)` tuple to a color. UnfoldMakie currently provides three different ones `pos2colorRGB` (same as MNE-Python), `pos2colorHSV` (HSV colorspace), `pos2colorRomaO`. Whereas `RGB` & `HSV` have the benefits of being 2D colormaps, `Roma0` has the benefit of being perceptualy uniform. @@ -20,17 +21,17 @@ We can switch the colorscale of the position-map, by giving a function that maps ### Similar to MNE ```@example main -plot_butterfly(results;positions=positions,extra=(;topoPositionToColorFunction=pos->UnfoldMakie.posToColorRGB(pos))) +plot_butterfly(results; positions=positions, extra=(; topoPositionToColorFunction = pos -> UnfoldMakie.posToColorRGB(pos))) ``` ### HSV-Space ```@example main -plot_butterfly(results;positions=positions,extra=(;topoPositionToColorFunction=UnfoldMakie.posToColorHSV)) +plot_butterfly(results; positions=positions, extra=(; topoPositionToColorFunction=UnfoldMakie.posToColorHSV)) ``` ### Uniform Color To highlight the flexibility, we can also make all lines `gray`, or any other arbitrary color, or function of electrode-`position`. ```@example main using Colors -plot_butterfly(results;positions=positions,extra=(;topoPositionToColorFunction=x->Colors.RGB(0.5))) +plot_butterfly(results; positions=positions, extra=(; topoPositionToColorFunction = x -> Colors.RGB(0.5))) ``` \ No newline at end of file diff --git a/docs/src/literate/reference/positions.md b/docs/src/literate/reference/positions.md new file mode 100644 index 000000000..a9eb32b8f --- /dev/null +++ b/docs/src/literate/reference/positions.md @@ -0,0 +1,46 @@ +```@meta +EditURL = "positions.jl" +``` + +````@example positions +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) + +````@example positions +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 = to_positions(fake_evoked) +```` + +# project from 3D electrode locations to 2D + +````@example positions +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 page was generated using [Literate.jl](https://github.com/fredrikekre/Literate.jl).* + diff --git a/docs/src/literate/tutorials/circTopo.md b/docs/src/literate/tutorials/circTopo.md index 541b29389..69c3b3da5 100644 --- a/docs/src/literate/tutorials/circTopo.md +++ b/docs/src/literate/tutorials/circTopo.md @@ -1,33 +1,33 @@ ```@meta -EditURL = "/docs/src/literate/tutorials/circTopo.jl" +EditURL = "circTopo.jl" ``` -````@example circTopo # Circular Topoplot Arrangement - +````@example circTopo using UnfoldMakie using CairoMakie using TopoPlots # for example data using Random using DataFrames - -data,pos = TopoPlots.example_data(); - -dat = data[:, 240, 1] ```` +# Generate data Generate a Dataframe. We need to specify the TopoPlot Positions either via position, or via labels (according to TopoPlots.jl) ````@example circTopo +data,pos = TopoPlots.example_data(); +dat = data[:, 240, 1] df= DataFrame( :estimate=>eachcol(Float64.(data[:,100:40:300,1])), :circularVariable=>[0,50,80,120,180,210], :time=>100:40:300) - df = flatten(df,:estimate) +df = flatten(df,:estimate); +nothing #hide ```` -generate the plot +# Our first plot! +note how the plots are at the angles of circularVariable` ````@example circTopo plot_circulareegtopoplot(df;positions=pos,axis=(;label="Sac Incoming"),predictor=:circularVariable) diff --git a/docs/src/literate/tutorials/erp.md b/docs/src/literate/tutorials/erp.md index 6b7ae1ec4..a8ff8aa3d 100644 --- a/docs/src/literate/tutorials/erp.md +++ b/docs/src/literate/tutorials/erp.md @@ -1,10 +1,8 @@ ```@meta -EditURL = "/docs/src/literate/tutorials/erp.jl" +EditURL = "erp.jl" ``` -````@example erp -# [Line Plot Visualization](@id lp_vis) -```` +## [Line Plot Visualization](@id lp_vis) Here we discuss line plot visualization. Make sure you have looked into the [installation instructions](@ref install_instruct). @@ -22,21 +20,22 @@ using UnfoldSim using UnfoldMakie ```` -# Setup things +## Setup Let's generate some data and fit a model of a 2-level categorical and a continuous predictor with interaction. ````@example erp data,evts = UnfoldSim.predef_eeg(;noiselevel=12,return_epoched=true) data = reshape(data,(1,size(data)...)) f = @formula 0 ~ 1+condition+continuous -se_solver =(x,y)->Unfold.solver_default(x,y,stderror=true) +se_solver =(x,y)->Unfold.solver_default(x,y,stderror=true); m = fit(UnfoldModel, Dict(Any=>(f,range(0,step=1/100,length=size(data,2)))), evts, data,solver=se_solver) results = coeftable(m) -res_effects = effects(Dict(:continuous=>-5:0.5:5),m) +res_effects = effects(Dict(:continuous=>-5:0.5:5),m); +nothing #hide ```` -Plot the results +## Plot the results ````@example erp plot_erp(results; extra=(:stderror=>true,)) @@ -52,9 +51,7 @@ There are multiple default values, that are checked in that order if they exist :y Default is `(:y, :estimate, :yhat)`. :color Default is `(:color, :coefname)`. -````@example erp # Configuration for Line Plots -```` ## extra `plot_erp(...;extra=(;=,...)`. @@ -72,21 +69,18 @@ plot_erp(res_effects; categoricalColor=false, categoricalGroup=true), legend = (;nbanks=2), - layout = (;legendPosition=:bottom)) + layout = (;legendPosition=:right)) ```` In the following we will use this "pretty" line plot as a basis for looking into configuration options. -````@example erp -### pvalue (array) -```` +## pvalue (array) !!! important this is currently broken! Is an array of p-values. If array not empty, plot shows colored lines under the plot representing the p-values. Default is `[]` (an empty array). - Shown below is an example in which `pvalue` are given: pvals = DataFrame( @@ -98,12 +92,11 @@ pvals = DataFrame( ```` plot_erp(results;extra= (;:pvalue=>pvals)) - ### stderror (boolean) Indicating whether the plot should show a colored band showing lower and higher estimates based on the stderror. Default is `false`. -#previously we showed `:stderror`- but low/high is possible as well` +previously we showed `:stderror`- but low/high is possible as well` ````@example erp results.se_low = results.estimate .- 0.5 diff --git a/docs/src/tutorials/butterfly.md b/docs/src/tutorials/butterfly.md index 4d55a4309..3b7c19e76 100644 --- a/docs/src/tutorials/butterfly.md +++ b/docs/src/tutorials/butterfly.md @@ -37,11 +37,12 @@ plot_butterfly(df; positions=pos) ## Column Mappings for Butterfly Plots -Since butterfly plots use a `DataFrame` as an input, the library needs to know the names of the columns used for plotting. You can set these mapping values by `plot_butterfly(...; mapping=(;:x=:time,))`, that is, providing a `NamedTuple` (note the `;` just after the opening-brackets +Since butterfly plots use a `DataFrame` as input, the library needs to know the names of the columns used for plotting. You can set these mapping values by calling `plot_butterfly(...; mapping=(;:x=:time,))`, that is, by specifying a `NamedTuple` (note the `;` right after the opening parentheses). -For more information about mapping values look into the [Mapping Data](@ref config_mapping) section of the documentation. +For more information on mapping values, see the [Mapping Data](@ref config_mapping) section of the documentation. + +While there are several default values that will be checked in that order if they exist in the `DataFrame`, a custom name may need to be chosen: -While there are multiple default values, that are checked in that order if they exist in the `DataFrame`, a custom name might need to be choosen for: ### x Default is `(:x, :time)`. @@ -57,6 +58,7 @@ Default is `(:labels, :label, :topoLabels, :sensor, :nothing)` Here we look into possible options for configuring the butterfly plot visualization using `(...;extra=(=,...)`. This is the list of unique configuration (extraData): + - topoLegend (boolean) ### topoLegend (boolean) From 39f43d58c4926b20b35f3f82e861c469654bf648 Mon Sep 17 00:00:00 2001 From: Vladimir Mikheev <33777074+vladdez@users.noreply.github.com> Date: Thu, 21 Sep 2023 16:43:08 +0200 Subject: [PATCH 12/12] Update hide_deco.md --- docs/src/how_to/hide_deco.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/src/how_to/hide_deco.md b/docs/src/how_to/hide_deco.md index 4a6421a67..97973016e 100644 --- a/docs/src/how_to/hide_deco.md +++ b/docs/src/how_to/hide_deco.md @@ -4,7 +4,7 @@ This section discusses how users can efficiently hide axis spines and decoration While it's possible to hide these axis decorations by setting the axis settings with `axis=(;...)`, `Makie.Axis` provides multiple variables for different aspects of the plot. This means that removing all decorations is only possible by setting many variables each time. -Makie does provide methods like `hidespines` and `hidedecorations`, but the user may not have easy access to the axis their plot is drawn in. +Makie does provide methods like `hidespines!` and `hidedecorations!`, but the user may not have easy access to the axis their plot is drawn in. Instead, these functions can be called by setting variables with `layout = (;)`: