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

argument names review #105

Merged
merged 18 commits into from
Nov 16, 2023
146 changes: 91 additions & 55 deletions docs/example_data.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7,60 +7,96 @@ type ==
"TopoPlots.jl"(default) Returns tidy DataFrame with two conditions, 64 channels and 800ms of data. This is an average over many subjects.
"""

function example_data(example="TopoPlots.jl")
function example_data(example = "TopoPlots.jl")

if example == "UnfoldLinearModel"
# load and generate a simulated Unfold Design
data,evts = UnfoldSim.predef_eeg(;noiselevel=10,return_epoched=true)
data = reshape(data,1,size(data)...)
f = @formula 0~1+condition+continuous
# generate ModelStruct
se_solver =(x,y)->Unfold.solver_default(x,y,stderror=true)
return fit(UnfoldModel,(Dict(Any=>(f,range(0,length=size(data,2),step=1/100)))) ,evts,data;solver=se_solver)
elseif example == "UnfoldLinearModelMultiChannel"
# load and generate a simulated Unfold Design
cAll = DataFrame()
sfreq = 100
for ch = 1:5
data,evts = UnfoldSim.predef_eeg(;p1 = (p100(;sfreq=sfreq), @formula(0~1),[5],Dict()),

n1 = (n170(;sfreq=sfreq), @formula(0~1+condition),[5,-ch*0.5],Dict()),
p3 = (p300(;sfreq=sfreq), @formula(0~1+continuous),[ch,1],Dict()),
return_epoched=true)
data = reshape(data,1,size(data)...)
f = @formula 0~1+condition+continuous
# generate ModelStruct

m= fit(UnfoldModel,(Dict(Any=>(f,range(0,length=size(data,2),step=1/100)))) ,evts,data)
d = coeftable(m)
d.channel .= ch
cAll = append!(cAll,d)
end
return cAll
if example == "UnfoldLinearModel"
# load and generate a simulated Unfold Design
data, evts = UnfoldSim.predef_eeg(; noiselevel = 10, return_epoched = true)
data = reshape(data, 1, size(data)...)
f = @formula 0 ~ 1 + condition + continuous
# generate ModelStruct
se_solver = (x, y) -> Unfold.solver_default(x, y, stderror = true)
return fit(
UnfoldModel,
(Dict(Any => (f, range(0, length = size(data, 2), step = 1 / 100)))),
evts,
data;
solver = se_solver,
)
elseif example == "UnfoldLinearModelMultiChannel"
# load and generate a simulated Unfold Design
cAll = DataFrame()
sfreq = 100
for ch = 1:5
data, evts = UnfoldSim.predef_eeg(;
p1 = (p100(; sfreq = sfreq), @formula(0 ~ 1), [5], Dict()),
n1 = (
n170(; sfreq = sfreq),
@formula(0 ~ 1 + condition),
[5, -ch * 0.5],
Dict(),
),
p3 = (p300(; sfreq = sfreq), @formula(0 ~ 1 + continuous), [ch, 1], Dict()),
return_epoched = true,
)
data = reshape(data, 1, size(data)...)
f = @formula 0 ~ 1 + condition + continuous
# generate ModelStruct

elseif example == "UnfoldLinearModelContinuousTime"
# load and generate a simulated Unfold Design
data,evts = UnfoldSim.predef_eeg(;)
data = reshape(data,1,size(data)...)
f = @formula 0~1+condition+continuous
basis = firbasis([0,0.5],100)
# generate ModelStruct
return fit(UnfoldModel,Dict(Any=>(f,basis)) ,evts,data)

elseif example == "TopoPlots.jl"
data,chanlocs = TopoPlots.example_data();
df = DataFrame(estimate=Float64[],time=Float64[],channel=Int64[],coefname=String[],topoPositions=[],se=Float64[],pval=Float64[])
pos = TopoPlots.points2mat(chanlocs)
for ch = 1:size(data,1)
for t = 1:size(data,2)
append!(df,DataFrame(estimate=data[ch,t,1],se=data[ch,t,2],pval=data[ch,t,3],time=t,channel=ch,coefname="A",topoPositions=(pos[1,ch],pos[2,ch])))


end
end
df.time = range(-0.3,0.5,step=1/500)[Int.(df.time)]
return df,chanlocs
else
error("unknown example data")
end
end
m = fit(
UnfoldModel,
(Dict(Any => (f, range(0, length = size(data, 2), step = 1 / 100)))),
evts,
data,
)
d = coeftable(m)
d.channel .= ch
cAll = append!(cAll, d)
end
return cAll

elseif example == "UnfoldLinearModelContinuousTime"
# load and generate a simulated Unfold Design
data, evts = UnfoldSim.predef_eeg(;)
data = reshape(data, 1, size(data)...)
f = @formula 0 ~ 1 + condition + continuous
basis = firbasis([0, 0.5], 100)
# generate ModelStruct
return fit(UnfoldModel, Dict(Any => (f, basis)), evts, data)

elseif example == "TopoPlots.jl"
data, chanlocs = TopoPlots.example_data()
df = DataFrame(
estimate = Float64[],
time = Float64[],
channel = Int64[],
coefname = String[],
topo_positions = [],
se = Float64[],
pval = Float64[],
)
pos = TopoPlots.points2mat(chanlocs)
for ch = 1:size(data, 1)
for t = 1:size(data, 2)
append!(
df,
DataFrame(
estimate = data[ch, t, 1],
se = data[ch, t, 2],
pval = data[ch, t, 3],
time = t,
channel = ch,
coefname = "A",
topo_positions = (pos[1, ch], pos[2, ch]),
),
)


end
end
df.time = range(-0.3, 0.5, step = 1 / 500)[Int.(df.time)]
return df, chanlocs
else
error("unknown example data")
end
end
10 changes: 5 additions & 5 deletions docs/literate/tutorials/circTopo.jl
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,18 @@ data, pos = TopoPlots.example_data();
dat = data[:, 240, 1]
df = DataFrame(
:estimate => eachcol(Float64.(data[:, 100:40:300, 1])),
:circularVariable => [0, 50, 80, 120, 180, 210],
:circular_variable => [0, 50, 80, 120, 180, 210],
:time => 100:40:300,
)
df = flatten(df, :estimate);

# # Our first plot!
# note how the plots are at the angles of circularVariable`
# note how the plots are at the angles of circular_variable`
plot_circulareegtopoplot(
df;
positions = pos,
axis = (; label = "Sac Incoming"),
predictor = :circularVariable,
axis = (; label = "Incoming saccade"),
predictor = :circular_variable,
)


Expand All @@ -37,6 +37,6 @@ plot_circulareegtopoplot(
positions = pos,
axis = (; label = "Time?!"),
predictor = :time,
predictorBounds = [80, 320],
predictor_bounds = [80, 320],
)

25 changes: 12 additions & 13 deletions docs/literate/tutorials/erp.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# ## [Line Plot Visualization](@id lp_vis)

# Here we discuss line plot visualization.
# Here we discuss ERP plot visualization.
# Make sure you have looked into the [installation instructions](@ref install_instruct).

# ## Include used Modules
Expand All @@ -15,7 +15,7 @@ using UnfoldSim
using UnfoldMakie

# ## Setup
# Let's generate some data and fit a model of a 2-level categorical and a continuous predictor with interaction.
# Let's generate some data. We'll fit a model with a 2 level categorical predictor and a continuous predictor with interaction.
data, evts = UnfoldSim.predef_eeg(; noiselevel = 12, return_epoched = true)
data = reshape(data, (1, size(data)...))
f = @formula 0 ~ 1 + condition + continuous
Expand All @@ -40,7 +40,7 @@ plot_erp(results; :stderror => true,)
# `plot_erp` use a `DataFrame` as an input, the library needs to know the names of the columns used for plotting.

# There are multiple default values, that are checked in that order if they exist in the `DataFrame`, a custom name can be chosen using
# `plot_erp(...;mapping=(; :y=:myEstimate)`
# `plot_erp(...; mapping=(; :y=:my_estimate)`

# :x Default is `(:x, :time)`.
# :y Default is `(:y, :estimate, :yhat)`.
Expand All @@ -50,24 +50,23 @@ plot_erp(results; :stderror => true,)

# ## key values
# `plot_erp(...; <name>=<value>,...)`.
# - categoricalColor (boolean, true) - in case of numeric `:color` column, is color a continuous or categorical variable?
# - categoricalGroup (boolean, true) - in case of numeric `:group` column, treat `:group` as categorical variable by default
# - stderror (boolean, false) - add an error-ribbon based on the `:stderror` column
# - pvalue (see below)
# - categorical_color (boolean, true) - in case of numeric `:color` column, treat `:color` as continuous or categorical variable.
# - categorical_group (boolean, true) - in case of numeric `:group` column, treat `:group` as categorical variable by default.
# - `topolegend` (bool, `false`): add an inlay topoplot with corresponding electrodes.
# - `stderror` (bool, `false`): add an error ribbon, with lower and upper limits based on the `:stderror` column.
# - `pvalue` (Array, `[]`): show a pvalue (see below).

# Using some general configurations we can pretty up the default visualization. Here we use the following configuration:

plot_erp(
res_effects;
mapping = (; y = :yhat, color = :continuous, group = :continuous),
legend = (; nbanks = 2),
layout = (; showLegend = true, legendPosition = :right),
categoricalColor = false, categoricalGroup = true,
layout = (; showLegend = true, legend_position = :right),
categorical_color = false, categorical_group = true,
)




# In the following we will use this "pretty" line plot as a basis for looking into configuration options.

# ## pvalue (array)
Expand All @@ -77,11 +76,11 @@ plot_erp(
#
# Is an array of p-values. If array not empty, plot shows colored lines under the plot representing the p-values.
# Default is `[]` (an empty array).
# Shown below is an example in which `pvalue` are given:
# Below is an example in which `pvalue` are given:
# pvals = DataFrame(
# from=[0.1,0.3],
# to=[0.5,0.7],
# coefname=["(Intercept)","condition: face"] # if coefname not specified, line should be black
# coefname=["(Intercept)", "condition: face"] # if coefname not specified, line should be black
# )
#
# plot_erp(results; :pvalue=>pvals)
Expand Down
31 changes: 13 additions & 18 deletions docs/make.jl
Original file line number Diff line number Diff line change
Expand Up @@ -22,20 +22,20 @@ for subfolder ∈ ["explanations", "HowTo", "tutorials", "reference"]

end

DocMeta.setdocmeta!(UnfoldMakie, :DocTestSetup, :(using UnfoldMakie); recursive=true)
DocMeta.setdocmeta!(UnfoldMakie, :DocTestSetup, :(using UnfoldMakie); recursive = true)

makedocs(;
modules=[UnfoldMakie],
authors="Benedikt Ehinger, Vladimir Mikheev, Daniel Baumgartner, Niklas Gärtner, Sören Döring",
repo="https://github.com/unfoldtoolbox/UnfoldMakie.jl/blob/{commit}{path}#{line}",
sitename="UnfoldMakie.jl",
warnonly = :cross_references,
format=Documenter.HTML(;
prettyurls=get(ENV, "CI", "false") == "true",
canonical="https://unfoldtoolbox.github.io/UnfoldMakie.jl",
assets=String[]
modules = [UnfoldMakie],
authors = "Benedikt Ehinger, Vladimir Mikheev, Daniel Baumgartner, Niklas Gärtner, Sören Döring",
repo = "https://github.com/unfoldtoolbox/UnfoldMakie.jl/blob/{commit}{path}#{line}",
sitename = "UnfoldMakie.jl",
warnonly = :cross_references,
format = Documenter.HTML(;
prettyurls = get(ENV, "CI", "false") == "true",
canonical = "https://unfoldtoolbox.github.io/UnfoldMakie.jl",
assets = String[],
),
pages=[
pages = [
"UnfoldMakie Documentation" => "index.md",
"Visualizations-Types" => [
"ERP plot" => "generated/tutorials/erp.md",
Expand All @@ -55,16 +55,11 @@ makedocs(;
"Show out of Bounds Label" => "how_to/show_oob_labels.md",
],
"Reference" => [
"Convert 3D positions / montages to 2D layouts" => "generated/reference/positions.md"

"Convert 3D positions / montages to 2D layouts" => "generated/reference/positions.md",
],
"API" => "api.md",
"Utilities" => "helper.md",
],

)

deploydocs(;
repo="github.com/unfoldtoolbox/UnfoldMakie.jl",
devbranch="main"
)
deploydocs(; repo = "github.com/unfoldtoolbox/UnfoldMakie.jl", devbranch = "main")
8 changes: 6 additions & 2 deletions docs/run_liveserver.jl
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
using LiveServer
servedocs(skip_dir=joinpath("src","generated"),literate_dir=joinpath("literate"),literate=joinpath("literate"),foldername=".")

servedocs(
skip_dir = joinpath("src", "generated"),
literate_dir = joinpath("literate"),
literate = joinpath("literate"),
foldername = ".",
)
15 changes: 8 additions & 7 deletions docs/src/how_to/mult_vis_in_fig.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ This section discusses how users can incorporate multiple plots into a single fi

By using the !-version of the plotting function and inserting a grid position instead of an entire figure, we can create multiple coordinated views.

We start by creating a figure with Makie.Figure.
We will start by creating a figure with Makie.Figure.

`f = Figure()`

Expand Down Expand Up @@ -60,8 +60,8 @@ pvals = DataFrame(
coefname=["(Intercept)", "category: face"]
)
plot_erp!(f[2, 1:2], results,
categoricalColor=false,
categoricalGroup=false,
categorical_color=false,
categorical_group=false,
pvalue=pvals,
stderror=true)

Expand All @@ -73,16 +73,17 @@ plot_topoplotseries!(f[4, 1:3], d_topo, 0.1; positions=positions, mapping=(; lab

res_effects = effects(Dict(:continuous => -5:0.5:5), uf_deconv)

plot_erp!(f[2, 4:5], res_effects; categoricalColor=false, categoricalGroup=true,
plot_erp!(f[2, 4:5], res_effects; categorical_color=false, categorical_group=true,
mapping=(; y=:yhat, color=:continuous, group=:continuous),
legend=(; nbanks=2),
layout=(; showLegend=true, legendPosition=:right))
layout=(; show_legend=true, legend_position=:right))

plot_parallelcoordinates!(f[3, 2:3], uf_5chan, [1, 2, 3, 4, 5]; mapping=(; color=:coefname), layout=(; legendPosition=:bottom))
plot_parallelcoordinates!(f[3, 2:3], uf_5chan, [1, 2, 3, 4, 5]; mapping=(; color=:coefname),
layout=(; legend_position=:bottom))

plot_erpimage!(f[1, 4:5], times, d_singletrial)
plot_circulareegtopoplot!(f[3:4, 4:5], d_topo[in.(d_topo.time, Ref(-0.3:0.1:0.5)), :];
positions=positions, predictor=:time, predictorBounds=[-0.3, 0.5])
positions=positions, predictor=:time, predictor_bounds=[-0.3, 0.5])

f
```
Expand Down
11 changes: 7 additions & 4 deletions docs/src/how_to/position2color.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,20 @@ We can switch the colorscale of the position-map, by giving a function that maps

### Similar to MNE
```@example main
plot_butterfly(results; positions=positions, extra=(; topoPositionToColorFunction = pos -> UnfoldMakie.posToColorRGB(pos)))
plot_butterfly(results;
positions=positions,
topopositions_to_color = pos -> UnfoldMakie.posToColorRGB(pos)
)
```

### HSV-Space
```@example main
plot_butterfly(results; positions=positions, extra=(; topoPositionToColorFunction=UnfoldMakie.posToColorHSV))
plot_butterfly(results; positions=positions, topopositions_to_color=UnfoldMakie.posToColorHSV)
```

### Uniform Color
To highlight the flexibility, we can also make all lines `gray`, or any other arbitrary color, or function of electrode-`position`.

```@example main
using Colors
plot_butterfly(results; positions=positions, extra=(; topoPositionToColorFunction = x -> Colors.RGB(0.5)))
plot_butterfly(results; positions=positions, topopositions_to_color = x -> Colors.RGB(0.5))
```
Loading
Loading