From edb6a5b618a91e1e5bbe9c17244da26ac791aeb4 Mon Sep 17 00:00:00 2001 From: Vladimir Mikheev Date: Wed, 15 Nov 2023 16:05:58 +0000 Subject: [PATCH] plot_erpimage + bug in erp_plot detected --- docs/src/tutorials/erpimage.md | 8 +++---- src/docstringtemplate.jl | 2 +- src/plot_erpimage.jl | 41 +++++++++++++++++----------------- test/test_all.jl | 9 ++++---- test/test_erpimage.jl | 8 +++---- 5 files changed, 33 insertions(+), 35 deletions(-) diff --git a/docs/src/tutorials/erpimage.md b/docs/src/tutorials/erpimage.md index 6f7e034ad..7ddf5f70a 100644 --- a/docs/src/tutorials/erpimage.md +++ b/docs/src/tutorials/erpimage.md @@ -26,16 +26,16 @@ plot_erpimage(data) Since ERP images use a `Matrix` as an input, the library does not need any informations about the mapping. -- 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. -- sortvalues - Indicating whether the data is sorted; using sortperm() of Base Julia +- sortvalues - 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). -- meanPlot (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. +- meanplot (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 plot_erpimage(data; - meanPlot = true, + meanplot = true, colorbar = (label = "Voltage [µV]",), visual = (colormap = :viridis, colorrange = (-40, 40))) diff --git a/src/docstringtemplate.jl b/src/docstringtemplate.jl index 62999f799..921713b49 100644 --- a/src/docstringtemplate.jl +++ b/src/docstringtemplate.jl @@ -36,7 +36,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=(showLegend=true,legendPosition=:right))`. Multiple defaults will be cycled until match. + `type=(; key=value,...))` - for example `plot_x(..., layout=(showLegend=true, legendPosition=:right))`. Multiple defaults will be cycled until match. $(out) """ diff --git a/src/plot_erpimage.jl b/src/plot_erpimage.jl index dcfca82c8..fa4bb3495 100644 --- a/src/plot_erpimage.jl +++ b/src/plot_erpimage.jl @@ -8,16 +8,15 @@ Plot an ERP image. ## Arguments: - `f::Union{GridPosition, GridLayout, Figure}`: Figure or GridPosition that the plot should be drawn into -- `plotData::Matrix{Float64}`: Data for the plot visualization +- `plot::Matrix{Float64}`: Data for the plot visualization ## Keyword Arguments -`erpBlur` (Number, `10`) - Number indicating how much blur is applied to the image; using Gaussian blur of the ImageFiltering module. +- `erpblur` (Number, `10`) - Number indicating how much blur is applied to the image; using Gaussian blur of the ImageFiltering module. Non-Positive values deactivate the blur. - -`sortvalues` (bool, `false`) - parameter over which plot will be sorted. Using sortperm() of Base Julia -(sortperm() computes a permutation of the array's indices that puts the array into sorted order). - -`meanPlot`: (bool, `false`) - Indicating whether the plot should add a line plot below the ERP image, showing the mean of the data. +- `sortix` (): . +- `sortvalues` (bool, `false`) - parameter over which plot will be sorted. Using sortperm() of Base Julia. + - sortperm() computes a permutation of the array's indices that puts the array into sorted order. +- `meanplot`: (bool, `false`) - Indicating whether the plot should add a line plot below the ERP image, showing the mean of the data. $(_docstring(:erpimage)) @@ -26,26 +25,26 @@ The input `f` """ # no times + no figure? -plot_erpimage(plotData::Matrix{<:Real}; kwargs...) = - plot_erpimage!(Figure(), plotData; kwargs...) +plot_erpimage(plot::Matrix{<:Real}; kwargs...) = + plot_erpimage!(Figure(), plot; kwargs...) # no times? -plot_erpimage!(f::Union{GridPosition,GridLayout,Figure}, plotData::Matrix{<:Real}; kwargs...) = - plot_erpimage!(f, 1:size(plotData, 1), plotData; kwargs...) +plot_erpimage!(f::Union{GridPosition,GridLayout,Figure}, plot::Matrix{<:Real}; kwargs...) = + plot_erpimage!(f, 1:size(plot, 1), plot; kwargs...) # no figure? -plot_erpimage(times::AbstractVector, plotData::Matrix{<:Real}; kwargs...) = - plot_erpimage!(Figure(), times, plotData; kwargs...) +plot_erpimage(times::AbstractVector, plot::Matrix{<:Real}; kwargs...) = + plot_erpimage!(Figure(), times, plot; kwargs...) function plot_erpimage!( f::Union{GridPosition,GridLayout,Figure}, times::AbstractVector, - plotData::Matrix{<:Real}; + plot::Matrix{<:Real}; sortvalues = nothing, sortix = nothing, - meanPlot = false, - erpBlur = 10, + meanplot = false, + erpblur = 10, kwargs..., ) config = PlotConfig(:erpimage) @@ -56,7 +55,7 @@ function plot_erpimage!( ax = Axis(f[1:4, 1]; config.axis...) if isnothing(sortix) if isnothing(sortvalues) - sortix = 1:size(plotData, 2) + sortix = 1:size(plot, 2) else sortix = sortperm(sortvalues) @@ -64,8 +63,8 @@ function plot_erpimage!( end filtered_data = UnfoldMakie.imfilter( - plotData[:, sortix], - UnfoldMakie.Kernel.gaussian((0, max(erpBlur, 0))), + plot[:, sortix], + UnfoldMakie.Kernel.gaussian((0, max(erpblur, 0))), ) yvals = 1:size(filtered_data, 2) @@ -77,7 +76,7 @@ function plot_erpimage!( UnfoldMakie.applyLayoutSettings!(config; fig = f, hm = hm, ax = ax, plotArea = (4, 1)) - if meanPlot + if meanplot # UserInput subConfig = deepcopy(config) config_kwargs!( @@ -92,7 +91,7 @@ function plot_erpimage!( (config.layout.showLegend && config.layout.legendPosition == :bottom) ? 1 : 0 subAxis = Axis(f[5+axisOffset, 1]; subConfig.axis...) - lines!(subAxis, mean(plotData, dims = 2)[:, 1]) + lines!(subAxis, mean(plot, dims = 2)[:, 1]) applyLayoutSettings!(subConfig; fig = f, ax = subAxis) end diff --git a/test/test_all.jl b/test/test_all.jl index dea892b61..d87c87623 100644 --- a/test/test_all.jl +++ b/test/test_all.jl @@ -125,12 +125,11 @@ end coefname=["(Intercept)", "category: face"] ) plot_erp!(f[2, 1:2], results, - categoricalColor=false, - categoricalGroup=false, + categorical_color=false, + categorical_group=false, pvalue=pvals, stderror=true) - plot_designmatrix!(f[2, 3], designmatrix(uf)) plot_topoplot!(f[3, 1], data[:, 150, 1]; positions=positions) @@ -138,7 +137,7 @@ end res_effects = effects(Dict(:continuous => -5:0.5:5), uf_deconv) - plot_erp!(f[2, 4:5], res_effects; categoricalColor=false, categoricalGroup=true, + plot_erp!(f[2, 4:5], res_effects; categorical_color=false, categorical_group=true, mapping=(; y=:yhat, color=:continuous, group=:continuous), legend=(; nbanks=2), layout=(; showLegend=true, legendPosition=:right)) @@ -147,7 +146,7 @@ end 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, predictorBounds=[-0.3, 0.5]) + positions=positions, predictor=:time, predictor_bounds=[-0.3, 0.5]) f #save("test.png", f) diff --git a/test/test_erpimage.jl b/test/test_erpimage.jl index fda7b0e6b..3c209fc6f 100644 --- a/test/test_erpimage.jl +++ b/test/test_erpimage.jl @@ -6,18 +6,18 @@ end @testset "with mean erp plot" begin data, evts = UnfoldSim.predef_eeg(; noiselevel = 10, return_epoched = true) - plot_erpimage(data; meanPlot = true) + plot_erpimage(data; meanplot = true) end -@testset "changing erpBlur to zero" begin +@testset "changing erpblur to zero" begin data, evts = UnfoldSim.predef_eeg(; noiselevel = 10, return_epoched = true) - plot_erpimage(data; meanPlot = true, erpBlur = 0) + plot_erpimage(data; meanplot = true, erpblur = 0) end @testset "GridPosition" begin f = Figure() data, evts = UnfoldSim.predef_eeg(; noiselevel = 10, return_epoched = true) - plot_erpimage!(f[1, 1], data; meanPlot = true) + plot_erpimage!(f[1, 1], data; meanplot = true) #save("erpimage.eps", f) end