diff --git a/docs/example_data.jl b/docs/example_data.jl index 92106a3e1..020593727 100644 --- a/docs/example_data.jl +++ b/docs/example_data.jl @@ -96,6 +96,14 @@ function example_data(example = "TopoPlots.jl") end df.time = range(-0.3, 0.5, step = 1 / 500)[Int.(df.time)] return df, chanlocs + elseif example == "sort_data" + dat, evts = + UnfoldSim.predef_eeg(; onset = LogNormalOnset(μ = 3.5, σ = 0.4), noiselevel = 5) + dat_e, times = Unfold.epoch(dat, evts, [-0.1, 1], 100) + evts, dat_e = Unfold.dropMissingEpochs(evts, dat_e) + evts.Δlatency = diff(vcat(evts.latency, 0)) *-1 + dat_e = dat_e[1, :, :] + return dat_e, evts, times else error("unknown example data") end diff --git a/docs/src/how_to/mult_vis_in_fig.md b/docs/src/how_to/mult_vis_in_fig.md index 1df4c4f51..35f9bc6f8 100644 --- a/docs/src/how_to/mult_vis_in_fig.md +++ b/docs/src/how_to/mult_vis_in_fig.md @@ -17,9 +17,8 @@ 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) -times = -0.099609375:0.001953125:1.0 data, positions = TopoPlots.example_data() +dat_e, evts, times = example_data("sort_data") nothing #hide ``` This section discusses how users can incorporate multiple plots into a single figure. @@ -81,7 +80,7 @@ plot_erp!(f[2, 4:5], res_effects; categorical_color=false, categorical_group=tru plot_parallelcoordinates!(f[3, 2:3], uf_5chan, [1, 2, 3, 4, 5]; mapping=(; color=:coefname), layout=(; legend_position=:bottom)) -plot_erpimage!(f[1, 4:5], times, d_singletrial) +plot_erpimage!(f[1, 4:5], times, dat_e; sortvalues=evts.Δlatency) plot_circulareegtopoplot!(f[3:4, 4:5], d_topo[in.(d_topo.time, Ref(-0.3:0.1:0.5)), :]; positions=positions, predictor=:time, predictor_bounds=[-0.3, 0.5]) diff --git a/docs/src/tutorials/erpimage.md b/docs/src/tutorials/erpimage.md index 18dcb15da..94ecc9bb3 100644 --- a/docs/src/tutorials/erpimage.md +++ b/docs/src/tutorials/erpimage.md @@ -51,7 +51,7 @@ First, generate a data. Second, specify the necessary sorting parameter. ) dat_e, times = Unfold.epoch(dat, evts, [-0.1,1], 100) evts, dat_e = Unfold.dropMissingEpochs(evts, dat_e) - evts.Δlatency = diff(vcat(evts.latency, 0)) + evts.Δlatency = diff(vcat(evts.latency, 0)) *-1 dat_e = dat_e[1,:,:] plot_erpimage(times, dat_e; sortvalues=evts.Δlatency) diff --git a/src/UnfoldMakie.jl b/src/UnfoldMakie.jl index e742859f4..2bf17072e 100644 --- a/src/UnfoldMakie.jl +++ b/src/UnfoldMakie.jl @@ -43,6 +43,7 @@ include("plot_erpimage.jl") include("plot_parallelcoordinates.jl") include("plot_circulareegtopoplot.jl") include("plot_erpgrid.jl") +include("plot_channelimage.jl") include("layout_helper.jl") include("eeg_positions.jl") @@ -71,6 +72,8 @@ export plot_topoplotseries export plot_topoplotseries! export plot_erpgrid export plot_erpgrid! +export plot_channelimage +export plot_channelimage! export to_positions export nonnumeric # reexport from AoG diff --git a/src/docstringtemplate.jl b/src/docstringtemplate.jl index aea66ab9d..f37d4a84e 100644 --- a/src/docstringtemplate.jl +++ b/src/docstringtemplate.jl @@ -1,6 +1,6 @@ -function _docstring(cfgsymb::Symbol) +function _docstring(cfg_symb::Symbol) #pad = maximum(length(string(f)) for f in fieldnames(T)) - cfg = PlotConfig(cfgsymb) + cfg = PlotConfig(cfg_symb) fn = fieldnames(PlotConfig) out = "" @@ -8,6 +8,7 @@ function _docstring(cfgsymb::Symbol) :erp =>`Makie.lines`, :butterfly =>`Makie.lines`, :paracoord =>`Makie.lines`, + :erpgrid =>`Makie.lines`, :designmat => `Makie.heatmap`, :erpimage => `Makie.heatmap`, :channelimage => `Makie.heatmap`, @@ -15,17 +16,17 @@ function _docstring(cfgsymb::Symbol) :topoplot => `Topoplot.eeg_topoplot`, :topoplotseries => `Topoplot.eeg_topoplot` ) - cbarstring = (cfgsymb == :erp || cfgsymb == :butterfly) ? "[`AlgebraOfGraphics.colobar!`](@ref)" : "[`Makie.Colorbar`](@ref)" + cbarstring = (cfg_symb == :erp || cfg_symb == :butterfly) ? "[`AlgebraOfGraphics.colobar!`](@ref)" : "[`Makie.Colorbar`](@ref)" link = Dict( :figure => "use `kwargs...` of [`Makie.Figure`](@ref)", :axis => "use `kwargs...` of [`Makie.Axis`](@ref)", :legend => "use `kwargs...` of [`Makie.Legend`](@ref)", :colorbar => "use `kwargs...` of $cbarstring", - :visual => "use `kwargs...` of [`$(visuallink[cfgsymb])`](@ref)", + :visual => "use `kwargs...` of [`$(visuallink[cfg_symb])`](@ref)", ) for k = 1:length(fn) - namedtpl = Base.getfield(cfg,fn[k]) + namedtpl = Base.getfield(cfg, fn[k]) addlink = "" try addlink = "- *"*link[fn[k]]*"*" @@ -36,7 +37,7 @@ function _docstring(cfgsymb::Symbol) return """## Shared plot configuration options The shared plot options can be used as follows: - `type=(; key=value,...))` - for example `plot_x(..., layout=(show_legend=true, legend_position=:right))`. + `type = (; key=value, ...))` - for example `plot_x(..., layout = (show_legend=true, legend_position=:right))`. Multiple defaults will be cycled until match. $(out) diff --git a/src/plot_channelimage.jl b/src/plot_channelimage.jl new file mode 100644 index 000000000..4fc7b91b3 --- /dev/null +++ b/src/plot_channelimage.jl @@ -0,0 +1,60 @@ +""" + plot_channelimage!(f::Union{GridPosition, GridLayout, Figure}, data::Matrix{<:Real}, position::Vector{Point{2,Float32}}, ch_names::Vector{String}; kwargs...) + plot_channelimage(data::Matrix{<:Real}, position::Vector{Point{2,Float32}}, ch_names::Vector{String}; kwargs...) + +Channel image + +## Arguments: + +- `f::Union{GridPosition, GridLayout, Figure}`: Figure, GridLayout or GridPosition that the plot should be drawn into. +- `data::DataFrame`: DataFrame with data. +- `position` (Vector{Point{2,Float32}}): a vector with EEG layout coordinates. +- `ch_names` (Vector{String}): vector with channel names. + +$(_docstring(:channelimage)) + +## Return Value: +A figure displaying channel image + +""" + +plot_channelimage(data::Matrix{<:Real}, position::Vector{Point{2,Float32}}, ch_names::Vector{String}; kwargs...) = + plot_channelimage!(Figure(), data, position, ch_names; kwargs...) + +function plot_channelimage!( + f::Union{GridPosition,GridLayout,Figure}, + data::Matrix{<:Real}, + position::Vector{Point{2,Float32}}, + ch_names::Vector{String}; + kwargs..., +) + config = PlotConfig(:channelimage) + config_kwargs!(config; kwargs...) + + + x = [i[1] for i in position] + y = [i[2] for i in position] + + x = round.(x; digits = 2) + y = Integer.(round.((y .- mean(y)) * 20)) * -1 + x = Integer.(round.((x .- mean(x)) * 20)) + d = zip(x, y, ch_names, 1:20) + a = sort!(DataFrame(d), [:2, :1], rev = [true, false]) + b = a[!, :4] + c = a[!, :3] + c = [string(x) for x in c] + + ix = range(-0.3, 1.2, length = size(data, 2)) + iy = 1:20 + iz = mean(data, dims = 3)[b, :, 1]' + + gin = f[1, 1] = GridLayout() + ax = Axis(gin[1, 1], xlabel = config.axis.xlabel, ylabel = config.axis.ylabel) + hm = Makie.heatmap!(ix, iy, iz, colormap = config.visual.colormap) + ax.yticks = iy + ax.ytickformat = xc -> c + ax.yticklabelsize = config.axis.yticklabelsize + + Makie.Colorbar(gin[1, 2], hm, label = config.colorbar.label, labelrotation = config.colorbar.labelrotation) + return f +end diff --git a/src/plot_circulareegtopoplot.jl b/src/plot_circulareegtopoplot.jl index 2a303e552..019d4d87f 100644 --- a/src/plot_circulareegtopoplot.jl +++ b/src/plot_circulareegtopoplot.jl @@ -1,6 +1,7 @@ """ - plot_circulareegtopoplot(data::DataFrame; kwargs...) plot_circulareegtopoplot!(f, data::DataFrame; kwargs...) + plot_circulareegtopoplot(data::DataFrame; kwargs...) + Plot a circular EEG topoplot. ## Arguments: diff --git a/src/plot_erpgrid.jl b/src/plot_erpgrid.jl index 06abdf879..4af354e4f 100644 --- a/src/plot_erpgrid.jl +++ b/src/plot_erpgrid.jl @@ -12,8 +12,9 @@ Plot an ERP image. - `drawlabels` (bool, `false`): draw channels labels over each waveform. - `times`: (Vector, `1:size(data, 2)`): vector of size(). + ## Return Value: -The input `f` +The figure displaying ERP grid """ # no figure? diff --git a/src/plot_erpimage.jl b/src/plot_erpimage.jl index bd1a9de3b..2f7e99ae5 100644 --- a/src/plot_erpimage.jl +++ b/src/plot_erpimage.jl @@ -25,8 +25,7 @@ The input `f` """ # no times + no figure? -plot_erpimage(plot::Matrix{<:Real}; kwargs...) = - plot_erpimage!(Figure(), plot; kwargs...) +plot_erpimage(plot::Matrix{<:Real}; kwargs...) = plot_erpimage!(Figure(), plot; kwargs...) # no times? plot_erpimage!(f::Union{GridPosition,GridLayout,Figure}, plot::Matrix{<:Real}; kwargs...) = diff --git a/src/plot_topoplot.jl b/src/plot_topoplot.jl index 166925157..c2f36fbd9 100644 --- a/src/plot_topoplot.jl +++ b/src/plot_topoplot.jl @@ -1,6 +1,6 @@ """ plot_topoplot!(f::Union{GridPosition, GridLayout, Figure}, data, ; positions=nothing, labels=nothing,kwargs...) - plot_topoplot(data,; positions=nothing, labels=nothing, kwargs...) + plot_topoplot(data; positions=nothing, labels=nothing, kwargs...) Plot a topo plot. ## Arguments: diff --git a/src/plot_topoplotseries.jl b/src/plot_topoplotseries.jl index f920e093d..f8a862419 100644 --- a/src/plot_topoplotseries.jl +++ b/src/plot_topoplotseries.jl @@ -1,5 +1,5 @@ """ - plot_topoplotseries!(f::Union{GridPosition, GridLayout, Figure}, data::DataFrame, Δbin::Real; kwargs...) + plot_topoplotseries(f::Union{GridPosition, GridLayout, Figure}, data::DataFrame, Δbin::Real; kwargs...) plot_topoplotseries!(data::DataFrame, Δbin::Real; kwargs...) Multiple miniature topoplots in regular distances @@ -77,7 +77,6 @@ function plot_topoplotseries!( f[1, end+1], colormap = d.colormap, colorrange = d.colorrange, - height = config.colorbar.height, flipaxis = config.colorbar.flipaxis, labelrotation = config.colorbar.labelrotation , label = config.colorbar.label, @@ -89,7 +88,6 @@ function plot_topoplotseries!( f[:, :][1, length(axlist)+1], colormap = d.colormap, colorrange = d.colorrange, - height = config.colorbar.height, flipaxis = config.colorbar.flipaxis, labelrotation = config.colorbar.labelrotation , label = config.colorbar.label, @@ -98,4 +96,4 @@ function plot_topoplotseries!( end return f -end +end \ No newline at end of file diff --git a/src/plotconfig.jl b/src/plotconfig.jl index 2f0decd99..4421e66a2 100644 --- a/src/plotconfig.jl +++ b/src/plotconfig.jl @@ -51,28 +51,31 @@ function PlotConfig()# defaults tellheight = false, ), ) - end - """ Takes a kwargs named tuple of Key => NamedTuple and merges the fields with the defaults """ function config_kwargs!(cfg::PlotConfig; kwargs...) - is_namedtuple = [isa(t,NamedTuple) for t in values(kwargs)] + is_namedtuple = [isa(t, NamedTuple) for t in values(kwargs)] @debug is_namedtuple - @assert(all(is_namedtuple), - """ Keyword argument specification (kwargs...) Specified config groups must be NamedTuples', but $(keys(kwargs)[.!is_namedtuple]) was not. - Maybe you forgot the semicolon (;) at the beginning of your specification? Compare these strings: - - plot_example(...; layout = (; use_colorbar=true)) - - plot_example(...; layout = (use_colorbar=true)) - - The first is correct and creates a NamedTuple as required. The second is wrong and its call is ignored.""") - list = fieldnames(PlotConfig)#[:layout,:visual,:mapping,:legend,:colorbar,:axis] + @assert( + all(is_namedtuple), + """ Keyword argument specification (kwargs...) Specified config groups must be NamedTuples', but $(keys(kwargs)[.!is_namedtuple]) was not. + Maybe you forgot the semicolon (;) at the beginning of your specification? Compare these strings: + + plot_example(...; layout = (; use_colorbar=true)) + + plot_example(...; layout = (use_colorbar=true)) + + The first is correct and creates a NamedTuple as required. The second is wrong and its call is ignored.""" + ) + list = fieldnames(PlotConfig) #[:layout, :visual, :mapping, :legend, :colorbar, :axis] keyList = collect(keys(kwargs)) - :extra ∈ keyList ? @warn("Extra is deprecated in 0.4 and extra-keyword args have to be used directly as key-word arguments") : "" + :extra ∈ keyList ? + @warn( + "Extra is deprecated in 0.4 and extra-keyword args have to be used directly as key-word arguments" + ) : "" applyTo = keyList[in.(keyList, Ref(list))] for k ∈ applyTo setfield!(cfg, k, merge(getfield(cfg, k), kwargs[k])) @@ -105,13 +108,7 @@ end function PlotConfig(T::Val{:topoarray}) cfg = PlotConfig(:erp) - config_kwargs!( - cfg; - layout = (;), - colorbar = (;), - mapping = (;), - axis = (;), - ) + config_kwargs!(cfg; layout = (;), colorbar = (;), mapping = (;), axis = (;)) return cfg end @@ -151,12 +148,7 @@ function PlotConfig(T::Val{:topoplotseries}) config_kwargs!( cfg, layout = (use_colorbar = true,), - colorbar = (; - height = 300, # why even should i made it manually? - flipaxis = true, - labelrotation = 4.7, - label = "Voltage [µV]" - ), + colorbar = (; flipaxis = true, labelrotation = -π / 2, label = "Voltage [µV]"), visual = (; label_text = false # true doesnt work again ), @@ -196,12 +188,23 @@ function PlotConfig(T::Val{:erp}) config_kwargs!( cfg; mapping = (; color = (:color, :coefname, nothing)), - layout = (; show_legend = true, hidespines = (:r, :t)), + layout = (; show_legend = true, hidespines = (:r, :t)), legend = (; framevisible = false), ) return cfg end +function PlotConfig(T::Val{:channelimage}) + cfg = PlotConfig() + config_kwargs!( + cfg; + #layout = (; use_colorbar = true), + colorbar = (; label = "Voltage [µV]", labelrotation = 4.7), + axis = (xlabel = "Time [s]", ylabel = "Channels", yticklabelsize = 14), + visual = (; colormap = Reverse("RdBu")), #cork + ) + return cfg +end function PlotConfig(T::Val{:erpimage}) cfg = PlotConfig() config_kwargs!( diff --git a/test/runtests.jl b/test/runtests.jl index e85af7104..069c96c84 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -15,10 +15,14 @@ end include("test_butterfly.jl") end -@testset "ERP Image" begin +@testset "ERP image" begin include("test_erpimage.jl") end +@testset "Channel image" begin + include("test_channelimage.jl") +end + @testset "Topoplot" begin include("test_topoplot.jl") end diff --git a/test/test_channelimage.jl b/test/test_channelimage.jl new file mode 100644 index 000000000..ed808411c --- /dev/null +++ b/test/test_channelimage.jl @@ -0,0 +1,17 @@ +data, pos = TopoPlots.example_data() +data = data[:, :, 1] +pos = pos[1:30] +raw_ch_names = ["FP1", "F3", "F7", "FC3", "C3", "C5", "P3", "P7", "P9", "PO7", +"PO3", "O1", "Oz", "Pz", "CPz", "FP2", "Fz", "F4", "F8", "FC4", "FCz", "Cz", +"C4", "C6", "P4", "P8", "P10", "PO8", "PO4", "O2"] + +@testset "channel image basic" begin + plot_channelimage(data, pos, raw_ch_names; ) + +end + +@testset "channel image with Figure" begin + f = Figure() + plot_channelimage!(f, data, pos, raw_ch_names; ) + +end diff --git a/test/test_complexplots.jl b/test/test_complexplots.jl index b570e0d14..3a9f4edae 100644 --- a/test/test_complexplots.jl +++ b/test/test_complexplots.jl @@ -1,14 +1,13 @@ @testset "8 plots" begin f = Figure(resolution=(1200, 1400)) - ga = f[1, 1] = GridLayout() - gc = f[2, 1] = GridLayout() - ge = f[3, 1] = GridLayout() - gg = f[4, 1] = GridLayout() - geh = f[1:4, 2] = GridLayout() - gb = geh[1, 1] = GridLayout() - gd = geh[2, 1] = GridLayout() - gf = geh[3, 1] = GridLayout() - gh = geh[4, 1] = GridLayout() + ga = f[1, 1] + gc = f[2, 1] + ge = f[3, 1] + gg = f[4, 1] + gb = f[1, 2] + gd = f[2, 2] + gf = f[3, 2] + gh = f[4, 2] include("../docs/example_data.jl") d_topo, pos = example_data("TopoPlots.jl") @@ -20,6 +19,9 @@ times = -0.099609375:0.001953125:1.0 data, positions = TopoPlots.example_data() df = UnfoldMakie.eeg_matrix_to_dataframe(data[:,:,1], string.(1:length(positions))); + raw_ch_names = ["FP1", "F3", "F7", "FC3", "C3", "C5", "P3", "P7", "P9", "PO7", +"PO3", "O1", "Oz", "Pz", "CPz", "FP2", "Fz", "F4", "F8", "FC4", "FCz", "Cz", +"C4", "C6", "P4", "P8", "P10", "PO8", "PO4", "O2"] data_erp, evts = UnfoldSim.predef_eeg(; noiselevel = 12, return_epoched = true) data_erp = reshape(data_erp, (1, size(data_erp)...)) @@ -41,7 +43,14 @@ plot_topoplotseries!(gd, df, 80; positions=positions, visual=(label_scatter=false,), layout = (; use_colorbar=true)) plot_erpgrid!(ge, data[:, :, 1], positions) - plot_erpimage!(gf, times, d_singletrial) + + dat, evts = UnfoldSim.predef_eeg(;onset=LogNormalOnset(μ=3.5, σ=0.4), noiselevel = 5) + dat_e, times = Unfold.epoch(dat,evts, [-0.1,1], 100) + evts, dat_e = Unfold.dropMissingEpochs(evts, dat_e) + evts.Δlatency = diff(vcat(evts.latency, 0)) *-1 + dat_e = dat_e[1,:,:] + plot_erpimage!(gf, times, dat_e; sortvalues=evts.Δlatency) + plot_channelimage!(gg, data[:, :, 1], positions[1:30], raw_ch_names; ) plot_parallelcoordinates!(gh, uf_5chan, [1, 2, 3, 4, 5]; mapping=(; color=:coefname), layout=(; legend_position=:bottom), legend=(; tellwidth =false)) @@ -55,7 +64,6 @@ f end - @testset "8 plots with a Figure" begin f = Figure(resolution=(1200, 1400)) diff --git a/test/test_erp.jl b/test/test_erp.jl index f7549c9ee..42ba53bfc 100644 --- a/test/test_erp.jl +++ b/test/test_erp.jl @@ -1,16 +1,6 @@ +include("../docs/example_data.jl") @testset "basic with results" begin - 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) - - m = fit( - UnfoldModel, - Dict(Any => (f, range(0, step = 1 / 100, length = size(data, 2)))), - evts, - data, - solver = se_solver, - ) + m = example_data("UnfoldLinearModel") results = coeftable(m) res_effects = effects(Dict(:continuous => -5:0.5:5), m) @@ -20,18 +10,7 @@ end @testset "basic with res_effects without colorbar" begin - 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) - - m = fit( - UnfoldModel, - Dict(Any => (f, range(0, step = 1 / 100, length = size(data, 2)))), - evts, - data, - solver = se_solver, - ) + m = example_data("UnfoldLinearModel") results = coeftable(m) res_effects = effects(Dict(:continuous => -5:0.5:5), m) @@ -47,18 +26,7 @@ end end @testset "basic with res_effects" begin - 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) - - m = fit( - UnfoldModel, - Dict(Any => (f, range(0, step = 1 / 100, length = size(data, 2)))), - evts, - data, - solver = se_solver, - ) + m = example_data("UnfoldLinearModel") results = coeftable(m) res_effects = effects(Dict(:continuous => -5:0.5:5), m) @@ -99,17 +67,7 @@ end @testset "erp plot with error bands" begin - data_erp, evts = UnfoldSim.predef_eeg(; noiselevel = 12, return_epoched = true) - data_erp = reshape(data_erp, (1, size(data_erp)...)) - f = @formula 0 ~ 1 + condition + continuous - 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_erp, 2)))), - evts, - data_erp, - solver = se_solver, - ) + m = example_data("UnfoldLinearModel") results = coeftable(m) res_effects = effects(Dict(:continuous => -5:0.5:5), m); @@ -120,17 +78,7 @@ end f = Figure(resolution=(1200, 1400)) ga = f[1, 1] = GridLayout() - data_erp, evts = UnfoldSim.predef_eeg(; noiselevel = 12, return_epoched = true) - data_erp = reshape(data_erp, (1, size(data_erp)...)) - form = @formula 0 ~ 1 + condition + continuous - se_solver = (x, y) -> Unfold.solver_default(x, y, stderror = true); - m = fit( - UnfoldModel, - Dict(Any => (form, range(0, step = 1 / 100, length = size(data_erp, 2)))), - evts, - data_erp, - solver = se_solver, - ) + m = example_data("UnfoldLinearModel") results = coeftable(m) res_effects = effects(Dict(:continuous => -5:0.5:5), m); @@ -143,17 +91,7 @@ end f = Figure(resolution=(1200, 1400)) ga = f[1, 1] = GridLayout() - data_erp, evts = UnfoldSim.predef_eeg(; noiselevel = 12, return_epoched = true) - data_erp = reshape(data_erp, (1, size(data_erp)...)) - form = @formula 0 ~ 1 + condition + continuous - se_solver = (x, y) -> Unfold.solver_default(x, y, stderror = true); - m = fit( - UnfoldModel, - Dict(Any => (form, range(0, step = 1 / 100, length = size(data_erp, 2)))), - evts, - data_erp, - solver = se_solver, - ) + m = example_data("UnfoldLinearModel") results = coeftable(m) res_effects = effects(Dict(:continuous => -5:0.5:5), m); diff --git a/test/test_erpimage.jl b/test/test_erpimage.jl index 3c209fc6f..cacbfa100 100644 --- a/test/test_erpimage.jl +++ b/test/test_erpimage.jl @@ -21,29 +21,8 @@ end #save("erpimage.eps", f) end - -#= @testset "testing better sorting" begin - - using PyMNE - using Unfold - using CSV - - - evts = CSV.read("/store/data/WLFO/derivatives/preproc_agert/sub-20/eeg/sub-20_task-WLFO_events.tsv", DataFrame) - evts.latency = evts.onset .* 512 - evts_fix = subset(evts, :type => x -> x .== "fixation") - raw = PyMNE.io.read_raw_eeglab("/store/data/WLFO/derivatives/preproc_agert/sub-20/eeg/sub-20_task-WLFO_eeg.set") - d, times = Unfold.epoch(pyconvert(Array, raw.get_data(units="uV")), evts_fix, (-0.1, 1), 512) - coalesce.(d[1, :, :], NaN) - f = Figure() - d_nan = coalesce.(d[1, :, :], NaN) - v = (; colorrange=(-10, 10)) - @show size(d_nan) - plot_erpimage!(f[1, 1], times, d_nan, visual=v) - plot_erpimage!(f[1, 2], times, d_nan; sortvalues=diff(evts_fix.onset ./ 100), visual=v) - plot_erpimage!(f[2, 1], times, d_nan; sortvalues=evts_fix.sac_startpos_x, visual=v) - plot_erpimage!(f[2, 2], times, d_nan; sortvalues=evts_fix.sac_amplitude, visual=v) - f + include("../docs/example_data.jl") + dat_e, evts, times = example_data("sort_data") + plot_erpimage(times, dat_e; sortvalues = evts.Δlatency) end -=#