Skip to content

Commit e79330d

Browse files
authored
Merge pull request #56 from s-ccs/tests
Configs and bumps
2 parents 19d771c + 2e8a79f commit e79330d

11 files changed

+121
-49
lines changed

.github/workflows/CI.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,9 @@ jobs:
5555
- run: |
5656
julia --project=docs -e '
5757
using Documenter: DocMeta, doctest
58-
using UnfoldMakie
59-
DocMeta.setdocmeta!(UnfoldMakie, :DocTestSetup, :(using UnfoldMakie); recursive=true)
60-
doctest(UnfoldMakie)'
58+
using ERPgnostics
59+
DocMeta.setdocmeta!(ERPgnostics, :DocTestSetup, :(using ERPgnostics); recursive=true)
60+
doctest(ERPgnostics)'
6161
- run: julia --project=docs docs/make.jl
6262
env:
6363
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
runner.jl
2+
test/drafts (to be ignored).jl
3+
Manifest.toml

Project.toml

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,12 @@ WGLMakie = "276b4fcb-3e11-5398-bf8b-a0c2d153d008"
3737

3838
[compat]
3939
BenchmarkTools = "1"
40-
CairoMakie = "0.12"
4140
CSV = "0.10"
41+
CairoMakie = "0.12, 0.13"
4242
ComputationalResources = "0.3"
43+
DSP = "0.7, 0.8"
4344
DataFrames = "1"
4445
Distributions = "0.25"
45-
DSP = "0.7"
4646
FileIO = "1"
4747
HDF5 = "0.17"
4848
ImageFiltering = "0.7"
@@ -56,8 +56,7 @@ Revise = "3"
5656
Statistics = "1"
5757
StatsBase = "0.34"
5858
TopoPlots = "0.2"
59-
Unfold = "0.7"
59+
Unfold = "0.8"
6060
UnfoldMakie = "0.5"
6161
UnfoldSim = "0.3"
62-
WGLMakie = "0.10"
63-
62+
WGLMakie = "0.10, 0.11"

docs/example_data.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,14 @@ function example_data(example = "pattern_detection_values"; mode = 1)
2222
else
2323
datapath = dirname(Base.current_project()) * "/data/evts_d.csv"
2424
end
25+
evts_d = CSV.read(datapath, DataFrame)
26+
evts_d.channel = 1:nrow(evts_d)
2527
if example == "pattern_detection_values"
26-
evts_d = CSV.read(datapath, DataFrame)
2728
pattern_detection_values = stack(evts_d)
2829
rename!(pattern_detection_values, :variable => :condition, :value => :estimate)
2930
evts_d = nothing
3031
return pattern_detection_values
3132
elseif example == "pattern_detection_values_32"
32-
evts_d = CSV.read(datapath, DataFrame)
3333
pattern_detection_values = stack(evts_d[1:32, :])
3434
rename!(pattern_detection_values, :variable => :condition, :value => :estimate)
3535
evts_d = nothing

src/ERPgnostics.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ using WGLMakie
2020
using Revise
2121
using ProgressBars
2222

23+
include("configs.jl")
2324
include("interactive_heatmap.jl")
2425
include("interactive_topoplots.jl")
2526
include("pattern_detection.jl")

src/configs.jl

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
2+
"""
3+
supportive_defaults(cfg_symb::Symbol)
4+
5+
Default configurations for the supporting axis. Similar to PlotConfig, but these configurations are not shared by all plots.\\
6+
Such supporting axes allow users to flexibly see defaults in docstrings and manipulate them using corresponding axes.
7+
8+
For developers: to make them updateable in the function, use `update_axis`.\\
9+
**Return value:** `NamedTuple`.
10+
"""
11+
function supportive_defaults(cfg_symb::Symbol)
12+
# plot_splines
13+
if cfg_symb == :toposeries_default
14+
return (;
15+
nrows = 1,
16+
mapping = (; col = :condition),
17+
axis = (; xlabel = "Conditions", xlabelvisible = false),
18+
visual = (
19+
label_scatter = (markersize = 10, strokewidth = 2),
20+
contours = (; levels = 0),
21+
colormap = Reverse(:RdGy_4),
22+
),
23+
colorbar = (; label = "Pattern detection function value", height = 300),
24+
layout = (; use_colorbar = true),
25+
)
26+
elseif cfg_symb == :erpimage_defaults
27+
return (; show_sortval = true, meanplot = true, axis = (; title = "ERP image"))
28+
end
29+
end
30+
31+
"""
32+
update_axis(support_axis::NamedTuple; kwargs...)
33+
Update values of `NamedTuple{key = value}`.\\
34+
Used for supportive axes to make users be able to flexibly change them.
35+
"""
36+
function update_axis(support_axis::NamedTuple; kwargs...)
37+
support_axis = (; support_axis..., kwargs...)
38+
return support_axis
39+
end

src/interactive_topoplots.jl

Lines changed: 33 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,13 @@ Plot interactive topoplot series.
77
88
- `pattern_detection_values::DataFrame`\\
99
DataFrame with columns condition and estimate. Each condition is resposible for a topoplot. Estimates will be projected across channels.
10+
- `figure_configs::NamedTuple = (;)`\\
11+
Here you can flexibly change configurations of the Figure axis.\\
12+
To see all options just type `?Figure` in REPL.\\
13+
- `toposeries_configs::NamedTuple = (;)`\\
14+
Here you can flexibly change configurations of the topoplot series.\\
15+
To see all options just type `?plot_topoplotseries` in REPL.\\
16+
Defaults: $(supportive_defaults(:toposeries_default))
1017
- `kwargs...`\\
1118
Additional styling behavior. \\
1219
@@ -20,7 +27,7 @@ function inter_toposeries(
2027
pattern_detection_values::DataFrame;
2128
positions::Vector{Point{2,Float64}} = positions_128,
2229
figure_configs = (; size = (1500, 400)),
23-
toposeries_configs = (; nrows = 1,),
30+
toposeries_configs = (;),
2431
)
2532

2633
names = unique(pattern_detection_values.condition)
@@ -51,15 +58,14 @@ function inter_toposeries(
5158
end
5259
hidespines!(ax)
5360
hidedecorations!(ax)
61+
62+
toposeries_configs =
63+
update_axis(supportive_defaults(:toposeries_default); toposeries_configs...)
5464
plot_topoplotseries!( # make configurable
5565
f[1, 1],
5666
pattern_detection_values;
57-
mapping = (; col = :condition),
5867
positions = positions,
59-
nrows = nrows,
6068
interactive_scatter = obs_tuple,
61-
visual = (label_scatter = (markersize = 10, strokewidth = 2),),
62-
layout = (; use_colorbar = true),
6369
toposeries_configs...,
6470
)
6571

@@ -84,6 +90,17 @@ ERP image will have trials on y-axis and time on x-axis
8490
3-dimensional Array of voltages of Event-related potentials. Dimensions: channels, time of recording, trials.
8591
- `timing::?`\\
8692
Timing of recording. Should be similar to y-value of erps.
93+
- `figure_configs::NamedTuple = (;)`\\
94+
Here you can flexibly change configurations of the Figure axis.\\
95+
To see all options just type `?Figure` in REPL.\\
96+
- `toposeries_configs::NamedTuple = (;)`\\
97+
Here you can flexibly change configurations of the topoplot series.\\
98+
To see all options just type `?plot_topoplotseries` in REPL.\\
99+
Defaults: $(supportive_defaults(:toposeries_default))
100+
- `erpimage_configs::NamedTuple = (;)`\\
101+
Here you can flexibly change configurations of the ERP image plot.\\
102+
To see all options just type `?plot_erpimage` in REPL.\\
103+
Defaults: $(supportive_defaults(:erpimage_defaults))
87104
- `kwargs...`\\
88105
Additional styling behavior. \\
89106
@@ -98,8 +115,10 @@ function inter_toposeries_image(
98115
events,
99116
erps, #::Array{Float64,3},
100117
timing;
101-
figure_configs = (; size = (1500, 400)),
102118
positions = positions_128,
119+
figure_configs = (; size = (1500, 400)),
120+
toposeries_configs = (;),
121+
erpimage_configs = (;),
103122
)
104123

105124
cond_names = unique(pattern_detection_values.condition)
@@ -116,24 +135,18 @@ function inter_toposeries_image(
116135
hidespines!(ax)
117136
hidedecorations!(ax)
118137

138+
toposeries_configs =
139+
update_axis(supportive_defaults(:toposeries_default); toposeries_configs...)
140+
erpimage_configs =
141+
update_axis(supportive_defaults(:erpimage_defaults); erpimage_configs...)
142+
119143
plot_topoplotseries!(
120144
f[1, 1:5],
121145
pattern_detection_values;
122-
positions = positions,
123-
col_labels = true,
124146
mapping = (; col = :condition),
125-
axis = (; xlabel = "Conditions", xlabelvisible = false),
126-
visual = (
127-
label_scatter = (markersize = 10, strokewidth = 2),
128-
contours = (; levels = 0),
129-
colormap = Reverse(:RdGy_4),
130-
),
147+
positions = positions,
131148
interactive_scatter = obs_tuple,
132-
colorbar = (;
133-
label = "Pattern detection function value",
134-
colorrange = (0, 1),
135-
height = 300,
136-
),
149+
toposeries_configs...,
137150
)
138151

139152
single_channel_erpimage = @lift(erps[$obs_tuple[3], :, :])
@@ -145,10 +158,8 @@ function inter_toposeries_image(
145158
timing,
146159
single_channel_erpimage;
147160
sortvalues = sortval,
148-
show_sortval = true,
149-
meanplot = true,
150161
sortval_xlabel = str2,
151-
axis = (; title = "ERP image"),
162+
erpimage_configs...,
152163
)
153164

154165
#= on(events(f).mousebutton, priority = 1) do event

src/pattern_detection.jl

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,23 +7,23 @@ For instance, single EEG channel (sensor) with trials over time.\\
77
Method:\\
88
- Filter dataset for smearing.\\
99
- Use pattern detection function.\\
10-
- In "plot" mode returns an ERP image with a value of pattern detection. Otherwise - only value.
10+
- In `mode = "plot"` returns an ERP image with a value of pattern detection. Otherwise - only value.
1111
1212
## Arguments
1313
14-
- erp_data::Matrix{Float64}`\\
14+
- `erp_data::Matrix{Float64}`\\
1515
3-dimensional array of voltages of event-related potentials. Dimensions: channels, recording time, trials.
16-
- detector::Function`\\
16+
- `detector::Function`\\
1717
Function used for pattern detection.\\
1818
For example, `Images.entropy` from `Images.jl`.
19-
- filter::Function`\\
19+
- `filter::Function`\\
2020
Function used for smearing.\\
2121
2222
## Keyword arguments (kwargs)
23-
- mode::String = "plot"` \\
23+
- `mode::String = "plot"` \\
2424
Plot an ERP image with the pattern detection value.
2525
26-
**Return Value:** (Figure with) pattern detection value.
26+
**Return Value:** (`Figure` with) pattern detection value.
2727
"""
2828
function pattern_detector(
2929
erp_data::Matrix{Float64},
@@ -64,17 +64,17 @@ Mode of permuted means:\\
6464
6565
- `erp_data::Array{Float64, 3}`\\
6666
3-dimensional Array of voltages of Event-related potentials. Dimensions: time of recording, trials, channels.
67-
- detector::Function`\\
67+
- `detector::Function`\\
6868
Function used for pattern detection.\\
6969
For example, `Images.entropy` from `Images.jl`.
70-
- filter::Function`\\
70+
- `filter::Function`\\
7171
Function used for smearing.\\- `kwargs...`\\
7272
Additional styling behavior. \\
7373
7474
## Keyword arguments (kwargs)
7575
- `n_permutations::Number = 10` \\
7676
Number fo permutations. Useful for mode "permuted_means" where it defines number of random permutations before averaging.
77-
- mode::String = "basic"` \\
77+
- `mode::String = "basic"` \\
7878
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.
7979
8080
**Return Value:** DataFrame with pattern detection values. Dimensions: experimental events, channels.

src/pattern_simulation.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ Columns in resulting sim\\_6patterns Data Frame to simulate this patterns: Δlat
130130
- `σ::Float = 3.2`\\
131131
Controls standart deviation.
132132
133-
**Return Value:** sim\\_6patterns::Matrix{Float64} with voltages and sim_evts::DataFrame with events.
133+
**Return Value:** `sim\\_6patterns::Matrix{Float64}` with voltages and `sim_evts::DataFrame` with events.
134134
"""
135135
function simulate_6patterns= 3.2, σ = 0.5; tmp = nothing)
136136
design = SingleSubjectDesign(;

test/interactive_heatmap_test.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ begin
33
pattern_detection_values = CSV.read("../data/evts_d.csv", DataFrame)
44
end
55

6-
@testset "inter_heatmap" begin
6+
@testset "interactive heatmap" begin
77
inter_heatmap(pattern_detection_values)
88
end
99

@@ -12,7 +12,7 @@ end
1212
erps_fix = read(fid["data"]["data_fixations.hdf5"])
1313
close(fid)
1414
15-
@testset "inter_heatmap_image" begin
15+
@testset "interactive heatmap image" begin
1616
inter_heatmap_image(pattern_detection_values, events, erps_fix)
1717
end
18-
=#
18+
=#

test/interactive_topoplots_test.jl

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,38 @@ pattern_detection_values_32 = example_data("pattern_detection_values_32"; mode =
77
desired_conditions = ["duration", "fix_avgpos_x", "fix_avgpos_y", "fix_avgpupilsize"]
88

99
@testset "inter_toposeries" begin
10-
inter_toposeries(
11-
filter(row -> row.condition in desired_conditions, pattern_detection_values);
10+
filtered_data = filter(row -> row.condition in desired_conditions, pattern_detection_values)
11+
plot_topoplotseries(
12+
filtered_data;
13+
nrows = 2,
1214
positions = positions_128,
15+
mapping = (; col = :condition),
16+
)
17+
end
18+
19+
@testset "inter_toposeries_image" begin
20+
filtered_data = filter(row -> row.condition in desired_conditions, pattern_detection_values_32)
21+
22+
inter_toposeries_image(
23+
filtered_data,
24+
evts,
25+
erps_fix_32,
26+
1:151;
27+
positions = positions_128[1:32],
28+
figure_configs = (; size = (1500, 700)),
1329
)
1430
end
1531

16-
@testset "inter_toposeries" begin
32+
@testset "inter_toposeries_image: toposeries_config" begin
33+
filtered_data = filter(row -> row.condition in desired_conditions, pattern_detection_values_32)
34+
1735
inter_toposeries_image(
18-
filter(row -> row.condition in desired_conditions, pattern_detection_values_32),
36+
filtered_data,
1937
evts,
2038
erps_fix_32,
2139
1:151;
2240
positions = positions_128[1:32],
2341
figure_configs = (; size = (1500, 700)),
42+
toposeries_configs = (; colorbar = (; label = "test")),
2443
)
2544
end

0 commit comments

Comments
 (0)