Skip to content

Commit

Permalink
Merge pull request #292 from unfoldtoolbox/uncertain
Browse files Browse the repository at this point in the history
Horizontal colorbars and other topoplot issues
- `Cite this repository` is updated for a JOOS paper
- issue #288 fixed
- adding horizontal colorbars
- using `LinRange` for ticks in ERPimage
- #251 fixed
  • Loading branch information
vladdez authored Jan 13, 2025
2 parents ceae175 + 4281364 commit 4d08c03
Show file tree
Hide file tree
Showing 9 changed files with 101 additions and 40 deletions.
37 changes: 22 additions & 15 deletions CITATION.cff
Original file line number Diff line number Diff line change
@@ -1,24 +1,31 @@
# This CITATION.cff file was generated with cffinit.
# Visit https://bit.ly/cffinit to generate yours today!

cff-version: 1.2.1
title: 'UnfoldMakie.jl: EEG/ERP visualization package'
message: 'If you use this page, please cite it as below.'
type: software
journal: 'Journal of Open Source Software'
volume : 10
number: 105
pages: 7560
cff-version: 1.2.0
message: "If you use this software, please cite it as below."
authors:
- given-names: Vladimir
family-names: Mikheev
orcid: 'https://orcid.org/0000-0002-4738-6655'
- given-names: Benedikt
family-names: Ehinger
orcid: 'https://orcid.org/0000-0002-6276-3332'
identifiers:
- type: doi
value: https://doi.org/10.21105/joss.07560
repository-code: 'https://github.com/unfoldtoolbox/UnfoldMakie.jl'
title: 'UnfoldMakie.jl: EEG/ERP visualization package'
version: 0.5.10
doi: 10.21105/joss.07560
date-released: '2025-01-10'
url: 'https://github.com/unfoldtoolbox/UnfoldMakie.jl'
preferred-citation:
type: article
authors:
- given-names: Vladimir
family-names: Mikheev
orcid: 'https://orcid.org/0000-0002-4738-6655'
- given-names: Benedikt
family-names: Ehinger
orcid: 'https://orcid.org/0000-0002-6276-3332'
doi: 10.21105/joss.07560
journal: 'Journal of Open Source Software'
month: 1
title: 'UnfoldMakie.jl: EEG/ERP visualization package'
volume : 10
number: 105
pages: 7560
year: 2025
1 change: 1 addition & 0 deletions docs/literate/intro/speed.jl
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ end
# ![](topoplot_animation_UM.gif)

# MNE with .gif
# Note that due to some bugs in (probably) `CondaPkg` topoplot is blac and white.
@benchmark begin
fig, anim = simulated_epochs.animate_topomap(
times = Py(timestamps),
Expand Down
10 changes: 10 additions & 0 deletions docs/literate/tutorials/topoplot.jl
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,16 @@ end
# # Highlighting channels
plot_topoplot(dat[:, 50, 1]; positions, high_chan = [1, 2])


# # Horizontal colorbars
# Just switch `colorbar.vertical` to `false`
plot_topoplot(
dat[:, 50, 1];
positions,
axis = (; xlabel = "50 ms"),
colorbar = (; vertical = false, width = 180, label = "Voltage estimate"),
)

# # Configurations of Topoplot

# ```@docs
Expand Down
2 changes: 1 addition & 1 deletion src/eeg_series.jl
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ The function takes the `combinefun = mean` over the `:time` column of `data`.
- `topo_attributes::NamedTuple = (;)`\\
Here you can flexibly change configurations of the topoplot interoplation.\\
To see all options just type `?Topoplot.topoplot` in REPL.\\
Defaults: $(supportive_defaults(:topo_default_attributes)).
Defaults: $(replace(string(supportive_defaults(:topo_default_attributes; docstring = true)), "_" => "\\_")).
- `positions::Vector{Point{2, Float32}}`\\
Channel positions. The list of x and y positions for all unique electrodes.
Expand Down
22 changes: 10 additions & 12 deletions src/plot_erpimage.jl
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Plot an ERP image.
`Figure`, `GridLayout`, or `GridPosition` to draw the plot.
- `data::Union{DataFrame, Vector{Float32}}`\\
Data for the plot visualization.
## Keyword arguments (kwargs)
- `erpblur::Number = 10`\\
Number indicating how much blur is applied to the image. \\
Expand Down Expand Up @@ -93,13 +93,8 @@ function plot_erpimage!(
!isnothing(to_value(sortindex)) ? @assert(to_value(sortindex) isa Vector{Int}) : ""
ax = Axis(ga[1:4, 1:4]; config.axis...)

ax.yticks = [
1,
size(to_value(data), 2) ÷ 4,
size(to_value(data), 2) ÷ 2,
size(to_value(data), 2) - (size(to_value(data), 2) ÷ 4),
size(to_value(data), 2),
]
ax.yticks = LinRange(1, size(to_value(data), 2), 5)

ax.yticklabelsvisible = true
sortindex = sortindex_management(sortindex, sortvalues, data)
filtered_data = @lift(
Expand Down Expand Up @@ -138,10 +133,14 @@ function ei_meanplot(ax, data, config, f, ga, times, meanplot_axis)

trace = @lift(mean($data, dims = 2)[:, 1])
meanplot_axis = update_axis(supportive_defaults(:meanplot_default); meanplot_axis...)
xticks = @lift(round.(LinRange(minimum($times), maximum($times), 5), digits = 2))
yticks = @lift(round.(LinRange(minimum($trace), maximum($trace), 5), digits = 1))

axbottom = Axis(
ga[5, 1:4];
ylabel = config.colorbar.label === nothing ? "" : config.colorbar.label,
xticks = xticks,
yticks = yticks,
limits = @lift((
minimum($times),
maximum($times),
Expand Down Expand Up @@ -172,10 +171,9 @@ function ei_sortvalue(sortvalues, f, ax, hm, config, sortval_xlabel, sortplot_ax
axleft = Axis(
gb[1:4, 1:5];
xlabel = sortval_xlabel,
xticks = @lift([
round(minimum($sortvalues), digits = 2),
round(maximum($sortvalues), digits = 2),
]),
xticks = @lift(
round.(LinRange(minimum($sortvalues), maximum($sortvalues), 2), digits = 2)
),
limits = @lift((
minimum($sortvalues) - (maximum($sortvalues) / 100 * 3),
maximum($sortvalues) + (maximum($sortvalues) / 100 * 3),
Expand Down
26 changes: 18 additions & 8 deletions src/plot_topoplot.jl
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ Plot a topoplot.
- `topo_attributes::NamedTuple = (;)`\\
Here you can flexibly change configurations of the topoplot interoplation.\\
To see all options just type `?Topoplot.topoplot` in REPL.\\
Defaults: $(supportive_defaults(:topo_default_attributes))
Defaults: $(replace(string(supportive_defaults(:topo_default_attributes; docstring = true)), "_" => "\\_"))
$(_docstring(:topoplot))
**Return Value:** `Figure` displaying the Topoplot.
Expand Down Expand Up @@ -56,7 +56,7 @@ function plot_topoplot!(
config = PlotConfig(:topoplot)
config_kwargs!(config; kwargs...) # potentially should be combined

outer_axis = Axis(f[1, 1]; config.axis...)
outer_axis = Axis(f[1:4, 1:2]; config.axis...)
hidespines!(outer_axis)
hidedecorations!(outer_axis, label = false)

Expand All @@ -72,7 +72,8 @@ function plot_topoplot!(
topo_attributes =
update_axis(supportive_defaults(:topo_default_attributes); topo_attributes...)
topo_axis = update_axis(supportive_defaults(:topo_default_single); topo_axis...)
inner_axis = Axis(f[1, 1]; topo_axis...)
inner_axis = Axis(f[1:4, 1:2]; topo_axis...)

if isa(high_chan, Int) || isa(high_chan, Vector{Int64})
x = zeros(length(positions))
isa(high_chan, Int) ? x[high_chan] = 1 : x[high_chan] .= 1
Expand Down Expand Up @@ -100,18 +101,27 @@ function plot_topoplot!(
)
end


if config.layout.use_colorbar == true
Colorbar(f[:, 2]; colormap = config.visual.colormap, config.colorbar...)
end
clims = @lift (min($data...), max($data...))
if clims[][1] clims[][2]
@warn """The min and max of the value represented by the color are the same, it seems that the data values are identical.
We disable the color bar in this figure.
Note: The identical min and max may cause an interpolation error when plotting the topoplot."""
config_kwargs!(config, layout = (; use_colorbar = false))
else
config_kwargs!(config, colorbar = (; limits = clims))
ticks = LinRange(clims[][1], clims[][2], 5)
rounded_ticks = round.(ticks, digits = 2) # Round to 2 decimal places
config_kwargs!(
config,
colorbar = (; ticks = (ticks, string.(rounded_ticks)), limits = clims),
)
end
if config.layout.use_colorbar == true
if config.colorbar.vertical == true
Colorbar(f[1:4, 2]; colormap = config.visual.colormap, config.colorbar...)
else
config_kwargs!(config, colorbar = (; labelrotation = 2π, flipaxis = false))
Colorbar(f[5, 1:2]; colormap = config.visual.colormap, config.colorbar...)
end
end
apply_layout_settings!(config; fig = f)
return f
Expand Down
2 changes: 1 addition & 1 deletion src/plot_topoplotseries.jl
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ Multiple miniature topoplots in regular distances.
- `topo_attributes::NamedTuple = (;)`\\
Here you can flexibly change configurations of the topoplot interoplation.\\
To see all options just type `?Topoplot.topoplot` in REPL.\\
Defaults: $(supportive_defaults(:topo_default_attributes))
Defaults: $(replace(string(supportive_defaults(:topo_default_attributes; docstring = true)), "_" => "\\_"))
$(_docstring(:topoplotseries))
Expand Down
10 changes: 7 additions & 3 deletions src/supportive_defaults.jl
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Such supporting axes allow users to flexibly see defaults in docstrings and mani
For developers: to make them updateable in the function, use `update_axis`.
**Return value:** `NamedTuple`.
"""
function supportive_defaults(cfg_symb::Symbol)
function supportive_defaults(cfg_symb::Symbol; docstring = false)
# plot_splines
if cfg_symb == :spline_default
return (;
Expand Down Expand Up @@ -62,10 +62,14 @@ function supportive_defaults(cfg_symb::Symbol)
height = Relative(1),
halign = 0.05,
valign = 0.95,
aspect = 1,
aspect = DataAspect(),
)
elseif cfg_symb == :topo_default_attributes
return (; interp_resolution = (128, 128), interpolation = CloughTocher())
if docstring == false
return (; interp_resolution = (128, 128), interpolation = CloughTocher())
else
return string("interp_resolution = (128, 128), interpolation = CloughTocher()")
end
# plot_topoplotseries
elseif cfg_symb == :topo_default_series
return (;
Expand Down
31 changes: 31 additions & 0 deletions test/test_topoplot.jl
Original file line number Diff line number Diff line change
Expand Up @@ -104,3 +104,34 @@ end
dat_obs[] = dat[:, 30, 1]
plot_topoplot(dat_obs; positions = positions)
end


@testset "topoplot: horizontal colorbar" begin
plot_topoplot(
dat[:, 50, 1];
positions,
colorbar = (; vertical = false, width = 180, label = "Voltage estimate"),
axis = (; xlabel = "50 ms"),
)
end

@testset "topoplot: std errors" begin
f = Figure()
plot_topoplot!(
f[:, 1],
dat[:, 50, 1];
positions,
colorbar = (; vertical = false, width = 180, label = "Voltage estimate"),
axis = (; xlabel = "50 ms"),
)
plot_topoplot!(
f[:, 2],
dat[:, 50, 2];
positions,
colorbar = (; vertical = false, width = 180, label = "Voltage uncertainty"),
axis = (; xlabel = "50 ms"),
visual = (; colormap = :viridis),
)
colgap!(f.layout, 0)
f
end

0 comments on commit 4d08c03

Please sign in to comment.