Skip to content

Commit 3de74dc

Browse files
committed
upd gen_data: more variability across channels
1 parent d3e3b87 commit 3de74dc

File tree

3 files changed

+28
-20
lines changed

3 files changed

+28
-20
lines changed

docs/gen_data.jl

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,19 @@
11
using UnfoldSim, DataFrames, Random
22
using GeometryBasics
3-
function gen_data()
3+
function gen_data(n_channels = 64)
44
d1, evts = UnfoldSim.predef_eeg(n_repeats = 120, noiselevel = 25; return_epoched = true)
5-
dataS = permutedims(repeat(d1, 1, 1, 64), (3, 1, 2))
5+
n_timepoints = size(d1, 1)
6+
7+
# Generate distinct EEG signals per channel
8+
dataS = [
9+
d1 .+ # Keep ERP amplitude the same
10+
3 * sin.(0.1 * pi * i .+ rand() * 2π) .+ # Different slow oscillatory drift
11+
2 * sin.(0.3 * pi * i .* (1:n_timepoints)) .+ # Mid-frequency variation per channel
12+
randn(size(d1)) .* 5 .+ # Add fine-grained channel-specific noise
13+
circshift(d1, rand(-10:10)) .* 0.2 # Random small time shift for variation
14+
for i in 1:n_channels
15+
]
16+
dataS = permutedims(cat(dataS..., dims=3), (3, 1, 2))
617
dataS = dataS .+ rand(dataS)
718

819
evts = insertcols(

src/functions_formular.jl

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -55,13 +55,13 @@ function formular_widgets(variables)
5555
end
5656

5757
"""
58-
get_ERP_data(model, widget_signal, channel)
58+
get_ERP_data(model, formula_toggle, channel_chosen)
5959
Creates a dictionary with yhat values and more.\\
6060
6161
Arguments:\\
6262
- `model::UnfoldLinearModel{Float64}` - vector of key-value pairs with information about the model formula terms.\\
63-
- `widget_signal::Observable{Vector{Any}}` - a signal that emits a dictionary with the current values of the widgets.\\
64-
- `channel::Observable{Int64}` - number of selected channels.\\
63+
- `formula_toggle::Observable{Vector{Any}}` - a signal that emits a dictionary with the current values of the widgets.\\
64+
- `channel_chosen::Observable{Int64}` - number of selected channels.\\
6565
6666
Actions:\\
6767
- Compute predicted value (yhat) of the given model using `effects`.\\
@@ -70,28 +70,27 @@ Actions:\\
7070
7171
**Return Value:** `yhats_signal::Observable{Any}` containing DataFrame with yhats.
7272
"""
73-
function get_ERP_data(model, widget_signal, channel)
73+
function get_ERP_data(model, formula_toggle, channel_chosen)
74+
ERP_data = Observable{Any}(nothing; ignore_equal_values = true)
7475

75-
yhats_signal = Observable{Any}(nothing; ignore_equal_values = true)
76-
77-
onany(widget_signal, channel; update = true) do widget_values, chan
76+
onany(formula_toggle, channel_chosen; update = true) do widget_values, chan
7877
yhat_dict = Dict(
7978
k => widget_value(wv[2]) for (k, wv) in widget_values if !isempty(wv) && wv[1]
8079
)
8180
if isempty(yhat_dict)
8281
yhat_dict = Dict(:dummy => ["dummy"])
8382
end
8483
yhats = effects(yhat_dict, model)
84+
8585

8686
for (k, wv) in widget_values
8787
if isempty(wv[2]) || !wv[1]
8888
yhats[!, k] .= "typical_value"
8989
end
9090
end
91-
9291
filter!(x -> x.channel == chan, yhats)
93-
yhats_signal[] = yhats
92+
ERP_data[] = yhats
9493
end
9594

96-
return yhats_signal
95+
return ERP_data
9796
end

src/widgets_long.jl

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -85,15 +85,14 @@ Actions:\\
8585
function topoplot_widget(positions, channel_chosen; size = ())
8686
strokecolor = Observable(repeat([:red], length(to_value(positions)))) # crashing
8787
#channel_chosen = Observable(1)
88-
8988
colorrange = vcat(0, 1)
9089
colormap = vcat(Gray(0.5), Gray(1))
9190

92-
data_obs = Observable(zeros(length(to_value(positions))))
93-
data_obs.val[1] = 1
91+
marker_list = Observable(zeros(length(to_value(positions))))
92+
marker_list.val[1] = 1
9493

9594
topo_widget = eeg_topoplot(
96-
data_obs,
95+
marker_list,
9796
nothing;
9897
positions = positions,
9998
colorrange = colorrange,
@@ -108,12 +107,11 @@ function topoplot_widget(positions, channel_chosen; size = ())
108107
if event.button == Mouse.left && event.action == Mouse.press
109108
plt, p = pick(topo_widget)
110109
if isa(plt, Makie.Scatter)
111-
data_obs[] .= 0
112-
data_obs[][p] = 1
113-
notify(data_obs)
110+
marker_list[] .= 0
111+
marker_list[][p] = 1
112+
notify(marker_list)
114113
channel_chosen[] = p
115114
end
116-
117115
end
118116
end
119117
hidedecorations!(topo_widget.axis)

0 commit comments

Comments
 (0)