Skip to content

Commit

Permalink
explaining text
Browse files Browse the repository at this point in the history
  • Loading branch information
vladdez committed Jan 20, 2025
1 parent c37ed6a commit 81496e9
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 8 deletions.
14 changes: 10 additions & 4 deletions docs/example_data.jl
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,11 @@ function example_data(example = "TopoPlots.jl")
generate_events(design)

time1 = vcat(rand(time_padding), component) # 500 msec = randiom 100 msec and 400 msec of n400
c = UnfoldSim.LinearModelComponent(; basis = time1, formula = @formula(0 ~ 1), β = [1])
c = UnfoldSim.LinearModelComponent(;
basis = time1,
formula = @formula(0 ~ 1),
β = [1],
)

hart = headmodel(type = "hartmut") # 227 electrodes
less_hart = magnitude(hart)[:, 1] # extract 1 lead field and 64 electrodes
Expand All @@ -207,16 +211,18 @@ function example_data(example = "TopoPlots.jl")
# Create the DataFrame
df = DataFrame(
:estimate => dat[:],
:channel => repeat(1:size(dat, 1), outer = Int(length(dat[:]) / size(dat, 1))),
:channel =>
repeat(1:size(dat, 1), outer = Int(length(dat[:]) / size(dat, 1))),
:time => repeat(1:size(dat, 2), outer = Int(length(dat[:]) / size(dat, 2))),
:trial => repeat(1:size(dat, 3), outer = Int(length(dat[:]) / size(dat, 3))),
:trial =>
repeat(1:size(dat, 3), outer = Int(length(dat[:]) / size(dat, 3))),
)

# chosing positions
pos3d = hart.electrodes["pos"]
pos2d = to_positions(pos3d')
pos2d = [Point2f(p[1] + 0.5, p[2] + 0.5) for p in pos2d]
return df, pos2d
return df, pos2d
elseif example == "raw_ch_names"
return [
"FP1",
Expand Down
18 changes: 14 additions & 4 deletions docs/literate/how_to/uncertain_topo.jl
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# ```@raw html
# <details>
# <summary>Click to expand</summary>
# ```
using Unfold
using UnfoldMakie
using UnfoldSim
Expand All @@ -7,11 +11,20 @@ using TopoPlots
using Statistics
using Random

# ```@raw html
# </details >
# ```
# Representing uncertainty is one of the most difficult tasks in visualization. It is especially difficult for heatmaps and topoplots.
# Here we will present new ways to show uncertainty for topoplots series.

# Data input
include("../../../example_data.jl")
dat, positions = TopoPlots.example_data()
df = UnfoldMakie.eeg_array_to_dataframe(dat[:, :, 1], string.(1:length(positions)));
df_uncert = UnfoldMakie.eeg_array_to_dataframe(dat[:, :, 2], string.(1:length(positions)));

# Generate data with 227 channels, 50 trials, 500 mseconds for bootstrapping
df_toposeries, pos_toposeries = data, pos = example_data("bootstrap_toposeries");
nothing #hide

# # Uncertainty via additional row
Expand Down Expand Up @@ -50,15 +63,12 @@ function bootstrap_toposeries(df)
df1.estimate = tmp
return df1
end

# Generate data with 227 channels, 50 trials, 500 mseconds
# ```@raw html
# </details >
# ```

# To show uncertainty of estimate we will compute 10 different means of bootsrtaped data.
# More detailed: 1) create N boostrapped datasets by random sampling with replacement across trials; 2) compute their means; 3) do toposeries animation iterating across these means.
df_toposeries, pos_toposeries = data, pos = example_data("bootstrap_toposeries")
dat_obs = Observable(df_toposeries)
f = Figure()
plot_topoplotseries!(
Expand All @@ -74,6 +84,6 @@ record(f, "bootstrap_toposeries.gif"; framerate = 10000) do io
dat_obs[] = bootstrap_toposeries(df_toposeries)
recordframe!(io)
end
end
end;

# ![](bootstrap_toposeries.gif)

0 comments on commit 81496e9

Please sign in to comment.