Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Configs #56

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,9 @@ jobs:
- run: |
julia --project=docs -e '
using Documenter: DocMeta, doctest
using UnfoldMakie
DocMeta.setdocmeta!(UnfoldMakie, :DocTestSetup, :(using UnfoldMakie); recursive=true)
doctest(UnfoldMakie)'
using ERPgnostics
DocMeta.setdocmeta!(ERPgnostics, :DocTestSetup, :(using ERPgnostics); recursive=true)
doctest(ERPgnostics)'
- run: julia --project=docs docs/make.jl
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Expand Down
1 change: 1 addition & 0 deletions src/ERPgnostics.jl
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ using WGLMakie
using Revise
using ProgressBars

include("configs.jl")
include("interactive_heatmap.jl")
include("interactive_topoplots.jl")
include("pattern_detection.jl")
Expand Down
44 changes: 44 additions & 0 deletions src/configs.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@

"""
supportive_defaults(cfg_symb::Symbol)

Default configurations for the supporting axis. Similar to PlotConfig, but these configurations are not shared by all plots.\\
Such supporting axes allow users to flexibly see defaults in docstrings and manipulate them using corresponding axes.

For developers: to make them updateable in the function, use `update_axis`.
**Return value:** `NamedTuple`.
"""
function supportive_defaults(cfg_symb::Symbol)
# plot_splines
if cfg_symb == :toposeries_default
return (;
nrows = 1,
col_labels = true,
mapping = (; col = :condition),
axis = (; xlabel = "Conditions", xlabelvisible = false),
visual = (
label_scatter = (markersize = 10, strokewidth = 2),
contours = (; levels = 0),
colormap = Reverse(:RdGy_4),
),
colorbar = (;
label = "Pattern detection function value",
colorrange = (0, 1),
height = 300,
),
layout = (; use_colorbar = true),
)
elseif cfg_symb == :erpimage_defaults
return (; show_sortval = true, meanplot = true, axis = (; title = "ERP image"))
end
end

"""
update_axis(support_axis::NamedTuple; kwargs...)
Update values of `NamedTuple{key = value}`.\\
Used for supportive axes to make users be able to flexibly change them.
"""
function update_axis(support_axis::NamedTuple; kwargs...)
support_axis = (; support_axis..., kwargs...)
return support_axis
end
54 changes: 32 additions & 22 deletions src/interactive_topoplots.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,13 @@ Plot interactive topoplot series.

- `pattern_detection_values::DataFrame`\\
DataFrame with columns condition and estimate. Each condition is resposible for a topoplot. Estimates will be projected across channels.
- `figure_configs::NamedTuple = (;)`\\
Here you can flexibly change configurations of the Figure axis.\\
To see all options just type `?Figure` in REPL.\\
- `toposeries_configs::NamedTuple = (;)`\\
Here you can flexibly change configurations of the topoplot series.\\
To see all options just type `?plot_topoplotseries` in REPL.\\
Defaults: $(supportive_defaults(:toposeries_default))
- `kwargs...`\\
Additional styling behavior. \\

Expand All @@ -20,7 +27,7 @@ function inter_toposeries(
pattern_detection_values::DataFrame;
positions::Vector{Point{2,Float64}} = positions_128,
figure_configs = (; size = (1500, 400)),
toposeries_configs = (; nrows = 1,),
toposeries_configs = (;),
)

names = unique(pattern_detection_values.condition)
Expand Down Expand Up @@ -51,15 +58,14 @@ function inter_toposeries(
end
hidespines!(ax)
hidedecorations!(ax)

toposeries_configs =
update_axis(supportive_defaults(:toposeries_default); toposeries_configs...)
plot_topoplotseries!( # make configurable
f[1, 1],
pattern_detection_values;
mapping = (; col = :condition),
positions = positions,
nrows = nrows,
interactive_scatter = obs_tuple,
visual = (label_scatter = (markersize = 10, strokewidth = 2),),
layout = (; use_colorbar = true),
toposeries_configs...,
)

Expand All @@ -84,6 +90,17 @@ ERP image will have trials on y-axis and time on x-axis
3-dimensional Array of voltages of Event-related potentials. Dimensions: channels, time of recording, trials.
- `timing::?`\\
Timing of recording. Should be similar to y-value of erps.
- `figure_configs::NamedTuple = (;)`\\
Here you can flexibly change configurations of the Figure axis.\\
To see all options just type `?Figure` in REPL.\\
- `toposeries_configs::NamedTuple = (;)`\\
Here you can flexibly change configurations of the topoplot series.\\
To see all options just type `?plot_topoplotseries` in REPL.\\
Defaults: $(supportive_defaults(:toposeries_default))
- `erpimage_configs::NamedTuple = (;)`\\
Here you can flexibly change configurations of the ERP image plot.\\
To see all options just type `?plot_erpimage` in REPL.\\
Defaults: $(supportive_defaults(:erpimage_defaults))
- `kwargs...`\\
Additional styling behavior. \\

Expand All @@ -98,8 +115,10 @@ function inter_toposeries_image(
events,
erps, #::Array{Float64,3},
timing;
figure_configs = (; size = (1500, 400)),
positions = positions_128,
figure_configs = (; size = (1500, 400)),
toposeries_configs = (;),
erpimage_configs = (;),
)

cond_names = unique(pattern_detection_values.condition)
Expand All @@ -116,24 +135,17 @@ function inter_toposeries_image(
hidespines!(ax)
hidedecorations!(ax)

toposeries_configs =
update_axis(supportive_defaults(:toposeries_default); toposeries_configs...)
erpimage_configs =
update_axis(supportive_defaults(:erpimage_defaults); erpimage_configs...)

plot_topoplotseries!(
f[1, 1:5],
pattern_detection_values;
positions = positions,
col_labels = true,
mapping = (; col = :condition),
axis = (; xlabel = "Conditions", xlabelvisible = false),
visual = (
label_scatter = (markersize = 10, strokewidth = 2),
contours = (; levels = 0),
colormap = Reverse(:RdGy_4),
),
interactive_scatter = obs_tuple,
colorbar = (;
label = "Pattern detection function value",
colorrange = (0, 1),
height = 300,
),
toposeries_configs...,
)

single_channel_erpimage = @lift(erps[$obs_tuple[3], :, :])
Expand All @@ -145,10 +157,8 @@ function inter_toposeries_image(
timing,
single_channel_erpimage;
sortvalues = sortval,
show_sortval = true,
meanplot = true,
sortval_xlabel = str2,
axis = (; title = "ERP image"),
erpimage_configs...,
)

#= on(events(f).mousebutton, priority = 1) do event
Expand Down
14 changes: 13 additions & 1 deletion test/interactive_topoplots_test.jl
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,25 @@ desired_conditions = ["duration", "fix_avgpos_x", "fix_avgpos_y", "fix_avgpupils
)
end

@testset "inter_toposeries" begin
@testset "inter_toposeries_image" begin
inter_toposeries_image(
filter(row -> row.condition in desired_conditions, pattern_detection_values_32),
evts,
erps_fix_32,
1:151;
positions = positions_128[1:32],
figure_configs = (; size = (1500, 700)),
)
end

@testset "inter_toposeries_image: toposeries_config" begin
inter_toposeries_image(
filter(row -> row.condition in desired_conditions, pattern_detection_values_32),
evts,
erps_fix_32,
1:151;
positions = positions_128[1:32],
figure_configs = (; size = (1500, 700)),
toposeries_configs = (; colorbar = (; label = "test")),
)
end
Loading