Skip to content

Commit

Permalink
Merge pull request #56 from s-ccs/tests
Browse files Browse the repository at this point in the history
Configs and bumps
  • Loading branch information
vladdez authored Feb 11, 2025
2 parents 19d771c + 2e8a79f commit e79330d
Show file tree
Hide file tree
Showing 11 changed files with 121 additions and 49 deletions.
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
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
runner.jl
test/drafts (to be ignored).jl
Manifest.toml
9 changes: 4 additions & 5 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,12 @@ WGLMakie = "276b4fcb-3e11-5398-bf8b-a0c2d153d008"

[compat]
BenchmarkTools = "1"
CairoMakie = "0.12"
CSV = "0.10"
CairoMakie = "0.12, 0.13"
ComputationalResources = "0.3"
DSP = "0.7, 0.8"
DataFrames = "1"
Distributions = "0.25"
DSP = "0.7"
FileIO = "1"
HDF5 = "0.17"
ImageFiltering = "0.7"
Expand All @@ -56,8 +56,7 @@ Revise = "3"
Statistics = "1"
StatsBase = "0.34"
TopoPlots = "0.2"
Unfold = "0.7"
Unfold = "0.8"
UnfoldMakie = "0.5"
UnfoldSim = "0.3"
WGLMakie = "0.10"

WGLMakie = "0.10, 0.11"
4 changes: 2 additions & 2 deletions docs/example_data.jl
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,14 @@ function example_data(example = "pattern_detection_values"; mode = 1)
else
datapath = dirname(Base.current_project()) * "/data/evts_d.csv"
end
evts_d = CSV.read(datapath, DataFrame)
evts_d.channel = 1:nrow(evts_d)
if example == "pattern_detection_values"
evts_d = CSV.read(datapath, DataFrame)
pattern_detection_values = stack(evts_d)
rename!(pattern_detection_values, :variable => :condition, :value => :estimate)
evts_d = nothing
return pattern_detection_values
elseif example == "pattern_detection_values_32"
evts_d = CSV.read(datapath, DataFrame)
pattern_detection_values = stack(evts_d[1:32, :])
rename!(pattern_detection_values, :variable => :condition, :value => :estimate)
evts_d = nothing
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
39 changes: 39 additions & 0 deletions src/configs.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@

"""
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,
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", 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
55 changes: 33 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,18 @@ 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),
),
positions = positions,
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 +158,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
18 changes: 9 additions & 9 deletions src/pattern_detection.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,23 @@ For instance, single EEG channel (sensor) with trials over time.\\
Method:\\
- Filter dataset for smearing.\\
- Use pattern detection function.\\
- In "plot" mode returns an ERP image with a value of pattern detection. Otherwise - only value.
- In `mode = "plot"` returns an ERP image with a value of pattern detection. Otherwise - only value.
## Arguments
- erp_data::Matrix{Float64}`\\
- `erp_data::Matrix{Float64}`\\
3-dimensional array of voltages of event-related potentials. Dimensions: channels, recording time, trials.
- detector::Function`\\
- `detector::Function`\\
Function used for pattern detection.\\
For example, `Images.entropy` from `Images.jl`.
- filter::Function`\\
- `filter::Function`\\
Function used for smearing.\\
## Keyword arguments (kwargs)
- mode::String = "plot"` \\
- `mode::String = "plot"` \\
Plot an ERP image with the pattern detection value.
**Return Value:** (Figure with) pattern detection value.
**Return Value:** (`Figure` with) pattern detection value.
"""
function pattern_detector(
erp_data::Matrix{Float64},
Expand Down Expand Up @@ -64,17 +64,17 @@ Mode of permuted means:\\
- `erp_data::Array{Float64, 3}`\\
3-dimensional Array of voltages of Event-related potentials. Dimensions: time of recording, trials, channels.
- detector::Function`\\
- `detector::Function`\\
Function used for pattern detection.\\
For example, `Images.entropy` from `Images.jl`.
- filter::Function`\\
- `filter::Function`\\
Function used for smearing.\\- `kwargs...`\\
Additional styling behavior. \\
## Keyword arguments (kwargs)
- `n_permutations::Number = 10` \\
Number fo permutations. Useful for mode "permuted_means" where it defines number of random permutations before averaging.
- mode::String = "basic"` \\
- `mode::String = "basic"` \\
With the "permuted_means" mode, results are given as the absolute value between the detector result over the given data set and the randomly permuted data set.
**Return Value:** DataFrame with pattern detection values. Dimensions: experimental events, channels.
Expand Down
2 changes: 1 addition & 1 deletion src/pattern_simulation.jl
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ Columns in resulting sim\\_6patterns Data Frame to simulate this patterns: Δlat
- `σ::Float = 3.2`\\
Controls standart deviation.
**Return Value:** sim\\_6patterns::Matrix{Float64} with voltages and sim_evts::DataFrame with events.
**Return Value:** `sim\\_6patterns::Matrix{Float64}` with voltages and `sim_evts::DataFrame` with events.
"""
function simulate_6patterns= 3.2, σ = 0.5; tmp = nothing)
design = SingleSubjectDesign(;
Expand Down
6 changes: 3 additions & 3 deletions test/interactive_heatmap_test.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ begin
pattern_detection_values = CSV.read("../data/evts_d.csv", DataFrame)
end

@testset "inter_heatmap" begin
@testset "interactive heatmap" begin
inter_heatmap(pattern_detection_values)
end

Expand All @@ -12,7 +12,7 @@ end
erps_fix = read(fid["data"]["data_fixations.hdf5"])
close(fid)
@testset "inter_heatmap_image" begin
@testset "interactive heatmap image" begin
inter_heatmap_image(pattern_detection_values, events, erps_fix)
end
=#
=#
27 changes: 23 additions & 4 deletions test/interactive_topoplots_test.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,38 @@ pattern_detection_values_32 = example_data("pattern_detection_values_32"; mode =
desired_conditions = ["duration", "fix_avgpos_x", "fix_avgpos_y", "fix_avgpupilsize"]

@testset "inter_toposeries" begin
inter_toposeries(
filter(row -> row.condition in desired_conditions, pattern_detection_values);
filtered_data = filter(row -> row.condition in desired_conditions, pattern_detection_values)
plot_topoplotseries(
filtered_data;
nrows = 2,
positions = positions_128,
mapping = (; col = :condition),
)
end

@testset "inter_toposeries_image" begin
filtered_data = filter(row -> row.condition in desired_conditions, pattern_detection_values_32)

inter_toposeries_image(
filtered_data,
evts,
erps_fix_32,
1:151;
positions = positions_128[1:32],
figure_configs = (; size = (1500, 700)),
)
end

@testset "inter_toposeries" begin
@testset "inter_toposeries_image: toposeries_config" begin
filtered_data = filter(row -> row.condition in desired_conditions, pattern_detection_values_32)

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

0 comments on commit e79330d

Please sign in to comment.