-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #53 from s-ccs/tests
Tests
- Loading branch information
Showing
22 changed files
with
413 additions
and
344 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
using UnfoldSim | ||
using TopoPlots | ||
using Unfold | ||
using Random | ||
using CSV | ||
|
||
""" | ||
example_data(String) | ||
Creates example data. Currently, 1 dataset is available. | ||
Datasets: | ||
- `pattern_detection_values` (default) - Dataframe with 2 fields:\\ | ||
sorting conditions, estimate (pattern detection values).\\ | ||
**Return Value:** `DataFrame`. | ||
""" | ||
function example_data(example = "pattern_detection_values"; mode = 1) | ||
if mode == 1 | ||
datapath = dirname(dirname(Base.current_project())) * "/data/evts_d.csv" | ||
else | ||
datapath = dirname(Base.current_project()) * "/data/evts_d.csv" | ||
end | ||
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 | ||
return pattern_detection_values | ||
else | ||
error("unknown example data") | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
using CairoMakie | ||
using DataFrames | ||
using UnfoldMakie | ||
using JLD2 | ||
using ERPgnostics | ||
CairoMakie.activate!() | ||
|
||
# Data input | ||
path = dirname(dirname(Base.current_project())) | ||
include(path * "/docs/example_data.jl") | ||
evts = DataFrame(CSV.File(path * "/data/events.csv")) | ||
positions_128 = JLD2.load_object(path * "/data/positions_128.jld2") | ||
erps_fix_32 = JLD2.load_object(path * "/data/erps_fix_32.jld2") | ||
pattern_detection_values_32 = example_data("pattern_detection_values_32"); | ||
desired_conditions = ["duration", "fix_avgpos_x", "fix_avgpos_y", "fix_avgpupilsize"] | ||
|
||
# Plotting | ||
|
||
inter_toposeries_image( | ||
filter(row -> row.condition in desired_conditions, pattern_detection_values_32), | ||
evts, | ||
erps_fix_32, | ||
1:151; | ||
positions = positions_128[1:32], | ||
figure_configs = (; size = (1500, 700)), | ||
) |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
# # Interactive topoplots | ||
|
||
# These topoplots series are different: instead fo voltage they represent pattern detection value (here - entropy) for different sorting variables. | ||
|
||
# By clicking on the markers you can see the channel name and sorted variabel in title. | ||
|
||
using CairoMakie | ||
using DataFrames | ||
using UnfoldMakie | ||
using JLD2 | ||
using ERPgnostics | ||
CairoMakie.activate!() | ||
|
||
# Data input | ||
path = dirname(dirname(Base.current_project())) | ||
include(path * "/docs/example_data.jl") | ||
|
||
positions_128 = JLD2.load_object(path * "/data/positions_128.jld2") | ||
pattern_detection_values = example_data(); | ||
|
||
# Interactive topoplot series with one row | ||
|
||
desired_conditions = ["duration", "fix_avgpos_x", "fix_avgpos_y", "fix_avgpupilsize"] | ||
inter_toposeries( | ||
filter(row -> row.condition in desired_conditions, pattern_detection_values); | ||
positions = positions_128, | ||
) | ||
|
||
# Interactive topoplot series with multiple rows | ||
inter_toposeries( | ||
pattern_detection_values; | ||
positions = positions_128, | ||
toposeries_configs = (; nrows = 4), | ||
figure_configs = (; size = (1500, 1200)), | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
|
||
function slow_filter(data_init) | ||
return UnfoldMakie.imfilter(data_init, UnfoldMakie.Kernel.gaussian((0, max(50, 0)))) | ||
end | ||
|
||
function fast_filter!(dat_filtered, kernel, dat) # broken | ||
#r = Images.ImageFiltering.ComputationalResources.CPU1(Images.ImageFiltering.FIR()) | ||
DSP.filt!(dat_filtered, kernel[1].data.parent, dat) | ||
return dat_filtered | ||
end | ||
|
||
function mean_filter(dat; output_dim = 20) | ||
mean_filter!(similar(dat, output_dim, size(dat, 2)), dat) | ||
end | ||
|
||
function mean_filter!(dat_filtered, dat) | ||
n_out = size(dat_filtered, 1) | ||
dat_nrows = size(dat, 1) | ||
bins = Int.(round.(collect(range(1, stop = dat_nrows, length = n_out + 1)))) | ||
bins[1] = 1 | ||
bins[end] = dat_nrows | ||
for b = 1:length(bins)-1 | ||
bin_start = bins[b] | ||
bin_stop = bins[b+1] | ||
dat_filtered[b, :] .= mean(@view(dat[bin_start:bin_stop, :]), dims = 1)[1, :] | ||
end | ||
return dat_filtered | ||
end | ||
|
||
#= | ||
function range_mean(dat_filt) | ||
a = extrema(dat_filt, dims = 2) | ||
b = last.(a) .- first.(a) | ||
return mean(b) | ||
end =# | ||
|
||
entropy_robust(img::AbstractArray; kind = :shannon, nbins = 256) = | ||
entropy_robust(Images.ImageQualityIndexes._log(kind), img; nbins = nbins) | ||
function entropy_robust(logᵦ::Log, img; nbins = 256) where {Log<:Function} | ||
img_trimmed = collect(trim(img[:], prop = 0.1)) | ||
_, counts = Images.ImageContrastAdjustment.build_histogram(img_trimmed, nbins) | ||
n = length(img) | ||
_zero = zero(first(counts) / n) | ||
-sum(counts) do c | ||
c > 0 ? c / n * logᵦ(c / n) : _zero | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.