Skip to content

Commit

Permalink
Merge pull request #53 from s-ccs/tests
Browse files Browse the repository at this point in the history
Tests
  • Loading branch information
vladdez authored Dec 4, 2024
2 parents 8062603 + 0831291 commit 19d771c
Show file tree
Hide file tree
Showing 22 changed files with 413 additions and 344 deletions.
33 changes: 20 additions & 13 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,21 +36,28 @@ UnfoldSim = "ed8ae6d2-84d3-44c6-ab46-0baf21700804"
WGLMakie = "276b4fcb-3e11-5398-bf8b-a0c2d153d008"

[compat]
WGLMakie = "0.10"
ProgressBars = "1"
BenchmarkTools = "1"
CairoMakie = "0.12"
CSV = "0.10"
ComputationalResources = "0.3"
DataFrames = "1"
Distributions = "0.25"
Revise = "3"
Observables = "0.5"
DSP = "0.7"
FileIO = "1"
HDF5 = "0.17"
Statistics = "1"
DataFrames = "1"
ComputationalResources = "0.3"
ImageFiltering = "0.7"
BenchmarkTools = "1"
CSV = "0.10"
Images = "0.26"
JLD2 = "0.5"
JuliaFormatter = "1"
Makie = "0.21, 0.22"
Observables = "0.5"
ProgressBars = "1"
Revise = "3"
Statistics = "1"
StatsBase = "0.34"
Unfold = "0.7"
DSP = "0.7"
JuliaFormatter = "2"
Makie = "0.21"
TopoPlots = "0.2"
Unfold = "0.7"
UnfoldMakie = "0.5"
UnfoldSim = "0.3"
WGLMakie = "0.10"

Binary file added data/channel_123.jld2
Binary file not shown.
Binary file added data/channels_1_123.jld2
Binary file not shown.
Binary file added data/erps_fix_32.jld2
Binary file not shown.
9 changes: 9 additions & 0 deletions docs/Project.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
[deps]
AlgebraOfGraphics = "cbdf2221-f076-402e-a563-3d30da359d67"
CSV = "336ed68f-0bac-5ca0-87d4-7b16caf5d00b"
CairoMakie = "13f3f980-e62b-5c42-98c6-ff1f3baf88f0"
ColorSchemes = "35d6a980-a343-548e-a6ea-1d62b119f2f4"
Colors = "5ae59095-9a9b-59fe-a467-6f913c188581"
Expand All @@ -8,7 +9,10 @@ DataFrames = "a93c6f00-e57d-5684-b7b6-d8193f3e46c0"
DataFramesMeta = "1313f7d8-7da2-5740-9ea0-a2ca25f37964"
DocStringExtensions = "ffbed154-4ef7-542d-bbb7-c09d3a79fcae"
Documenter = "e30172f5-a6a5-5a46-863b-614d45cd2de4"
DocumenterTools = "35a29f4d-8980-5a13-9543-d66fff28ecb8"
ERPgnostics = "b811cc8a-7213-4a66-9205-28465b3b3ba1"
Glob = "c27321d9-0574-5035-807b-f59d2c89b15c"
JLD2 = "033835bb-8acc-5ee8-8aae-3f567f8a3819"
Literate = "98b081ad-f1c9-55d3-8b20-4c87d4299306"
MakieThemes = "e296ed71-da82-5faf-88ab-0034a9761098"
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
Expand All @@ -18,3 +22,8 @@ TopoPlots = "2bdbdf9c-dbd8-403f-947b-1a4e0dd41a7a"
Unfold = "181c99d8-e21b-4ff3-b70b-c233eddec679"
UnfoldMakie = "69a5ce3b-64fb-4f22-ae69-36dd4416af2a"
UnfoldSim = "ed8ae6d2-84d3-44c6-ab46-0baf21700804"

[compat]
DSP = "0.7"
JLD2 = "0.5"
TopoPlots = "0.2"
40 changes: 40 additions & 0 deletions docs/example_data.jl
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
26 changes: 26 additions & 0 deletions docs/literate/intro/gnostics.jl
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 removed docs/literate/intro/test.jl
Empty file.
35 changes: 35 additions & 0 deletions docs/literate/intro/toposeries.jl
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)),
)
4 changes: 3 additions & 1 deletion docs/make.jl
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@ makedocs(;
assets = String[],
),
pages = [
"ERPgnostics Documentation" => "index.md",
"ERPgnostics highlights" => "index.md",
"Plotting" => "generated/intro/toposeries.md",
"Diagnostics" => "generated/intro/gnostics.md",
"API / DocStrings" => "api.md",
],
)
Expand Down
8 changes: 0 additions & 8 deletions docs/src/generated/intro/test.md

This file was deleted.

14 changes: 9 additions & 5 deletions src/ERPgnostics.jl
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ using Statistics, StatsBase, Distributions
using HDF5, FileIO
using Printf
using Images
using TopoPlots
using TopoPlots
using ImageFiltering
using ComputationalResources
using Observables
Expand All @@ -22,18 +22,22 @@ using ProgressBars

include("interactive_heatmap.jl")
include("interactive_topoplots.jl")
include("pattern_detection_mean_filter.jl")
include("pattern_detection_probability.jl")
include("pattern_detection.jl")
include("pattern_simulation.jl")
include("filters.jl")

export inter_toposeries # or better toposeries_inter
export inter_toposeries_image

export inter_heatmap
export inter_heatmap_image

export mult_chan_pattern_detector_probability
export mult_chan_pattern_detector_probability_meanfilter

export simulate_6patterns

export pattern_detector
export complex_pattern_detector

export slow_filter
export mean_filter
end
47 changes: 47 additions & 0 deletions src/filters.jl
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
8 changes: 4 additions & 4 deletions src/interactive_heatmap.jl
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ function inter_heatmap(pattern_detection_values::DataFrame)
if event.button == Mouse.left && event.action == Mouse.press
plot, _ = pick(ax.scene)
a = DataInspector(plot)
pos = Makie.position_on_plot(plot, -1, apply_transform = false)[Vec(1, 2)]
b = Makie._pixelated_getindex(plot[1][], plot[2][], plot[3][], pos, true)
pos = WGLMakie.position_on_plot(plot, -1, apply_transform = false)[Vec(1, 2)]
b = WGLMakie._pixelated_getindex(plot[1][], plot[2][], plot[3][], pos, true)
chan_i[], var_i[] = b[1], b[2]
end
end
Expand Down Expand Up @@ -118,8 +118,8 @@ function inter_heatmap_image(
on(events(f).mousebutton, priority = 1) do event
if event.button == Mouse.left && event.action == Mouse.press
plot, _ = pick(ax.scene)
pos = Makie.position_on_plot(plot, -1, apply_transform = false)[Vec(1, 2)]
b = Makie._pixelated_getindex(plot[1][], plot[2][], plot[3][], pos, true)
pos = WGLMakie.position_on_plot(plot, -1, apply_transform = false)[Vec(1, 2)]
b = WGLMakie._pixelated_getindex(plot[1][], plot[2][], plot[3][], pos, true)
chan_i[], var_i[] = b[1], b[2]
#a = DataInspector(plot)
end
Expand Down
Loading

0 comments on commit 19d771c

Please sign in to comment.