-
Notifications
You must be signed in to change notification settings - Fork 9
Weak extensions #253
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
Draft
vladdez
wants to merge
26
commits into
main
Choose a base branch
from
weak_extensions
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Weak extensions #253
Changes from all commits
Commits
Show all changes
26 commits
Select commit
Hold shift + click to select a range
5bc8512
upd Project
vladdez 5787cd7
introducing benchmarking
vladdez fc6131f
bug
vladdez 512b251
issue 245
vladdez 59c8e24
benchmarktools
vladdez 4457a40
small edits
vladdez 56e0fdc
new supportive axis topo_interpolate for plot_topoplot
vladdez 10507f1
with other interpolation
vladdez 5050062
make possible to change interpolation in topoplotseries
vladdez 8d1549d
bug
vladdez 752593d
color and colormap in visiula for plot_erp
vladdez d2d1753
same
vladdez 01811d8
Update src/plot_erp.jl
vladdez 245a7c8
Contribute
vladdez 77129fe
topo_attributes for plot_butterfly enabled, reorganising eeg_series
vladdez db95394
bug
vladdez fa5672d
Update test/test_topoplot.jl
vladdez 21ce0e7
Update src/plot_topoplot.jl
vladdez 1cef44c
clean Project
vladdez aaa4f2d
small changes after comments
vladdez 43781d2
details after comments
vladdez 7ec46dd
get read of Unfold extension
vladdez ba5598c
MATLAB benchmarking
vladdez b0cb1aa
image
vladdez 6e5b7b2
bug
vladdez a721dc0
first
vladdez File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,38 @@ | ||
# Contribution guide | ||
Contributions are very welcome. These could be typos, bug reports, feature requests, speed optimization, better code, and better documentation. | ||
You are very welcome to raise issues and start pull requests. | ||
|
||
## Issues | ||
If you notice any bugs, such as crashing code, incorrect results or speed issues, please raise a GitHub issue. | ||
|
||
Before filing an issue please | ||
- check that there are no similar existing issues already | ||
- check that your versions are up to date | ||
|
||
If you want to report a bug, include your version and system information, as well as stack traces with all relevant information. | ||
If possible, condense your bug into the shortest example possible that the maintainers can replicate, a so called "minimal working example" or MWE. | ||
|
||
If you want to suggest a new feature, for example functionality that other plotting packages offer already, include supplementary material such as example images if possible, so it's clear what you are asking for. | ||
|
||
## Code contributions (Pull requests) | ||
When opening a pull request, please add a short but meaningful description of the changes/features you implemented. Moreover, please add tests (where appropriate) to ensure that your code is working as expected. | ||
|
||
For each feature you want to contribute, please file a separate PR to keep the complexity down and time to merge short. | ||
Add PRs in draft mode if you want to discuss your approach first. | ||
|
||
|
||
## Adding documentation | ||
1. We recommend to write a Literate.jl document and place it in `docs/literate/FOLDER/FILENAME.jl` with `FOLDER` being `HowTo`, `Explanations`, `Tutorials` or `Intro` ([recommended reading on the 4 categories](https://documentation.divio.com/)). | ||
2. Literate.jl converts the `.jl` file to a `.md` automatically and places it in `docs/src/generated/FOLDER/FILENAME.md`. | ||
3. Edit [make.jl](https://github.com/unfoldtoolbox/Unfold.jl/blob/main/docs/make.jl) with a reference to `docs/src/generated/FOLDER/FILENAME.md`. | ||
|
||
## Formatting (Beware of reviewdog :dog:) | ||
We use the [julia-format](https://github.com/julia-actions/julia-format) Github action to ensure that the code follows the formatting rules defined by [JuliaFormatter.jl](https://github.com/domluna/JuliaFormatter.jl). | ||
When opening a pull request [reviewdog](https://github.com/reviewdog/reviewdog) will automatically make formatting suggestions for your code. | ||
|
||
## Seeking Help | ||
|
||
If you get stuck, here are some options to seek help: | ||
|
||
- Use the REPL `?` help mode. | ||
- Check the Documentation. |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,77 @@ | ||
# Speed measurement | ||
using UnfoldMakie | ||
using TopoPlots | ||
using PyMNE | ||
using PythonPlot | ||
using BenchmarkTools | ||
|
||
# Data input | ||
dat, positions = TopoPlots.example_data() | ||
df = UnfoldMakie.eeg_array_to_dataframe(dat[:, :, 1], string.(1:length(positions))); | ||
|
||
# # Topoplots | ||
|
||
# UnfoldMakie.jl | ||
@benchmark plot_topoplot(dat[:, 320, 1]; positions = positions) | ||
|
||
# UnfoldMakie.jl with DelaunayMesh | ||
@benchmark plot_topoplot( | ||
dat[:, 320, 1]; | ||
positions = positions, | ||
topo_interpolation = (; interpolation = DelaunayMesh()), | ||
) | ||
|
||
# MNE | ||
posmat = collect(reduce(hcat, [[p[1], p[2]] for p in positions])') | ||
pypos = Py(posmat).to_numpy() | ||
pydat = Py(dat[:, 320, 1]) | ||
|
||
@benchmark begin | ||
f = PythonPlot.figure() | ||
PyMNE.viz.plot_topomap( | ||
pydat, | ||
pypos, | ||
sphere = 1.1, | ||
extrapolate = "box", | ||
cmap = "RdBu_r", | ||
sensors = false, | ||
contours = 6, | ||
) | ||
f.show() | ||
end | ||
|
||
# # Topoplot series | ||
# UnfoldMakie.jl | ||
@benchmark begin | ||
plot_topoplotseries( | ||
df; | ||
bin_num = 20, | ||
positions = positions, | ||
axis = (; xlabel = "Time windows [s]"), | ||
) | ||
end | ||
|
||
# UnfoldMakie.jl with DelaunayMesh | ||
@benchmark begin | ||
plot_topoplotseries( | ||
df; | ||
bin_num = 50, | ||
positions = positions, | ||
topo_attributes = (; interpolation = DelaunayMesh()), | ||
) | ||
end | ||
|
||
# MNE | ||
easycap_montage = PyMNE.channels.make_standard_montage("standard_1020") | ||
ch_names = pyconvert(Vector{String}, easycap_montage.ch_names)[1:64] | ||
info = PyMNE.create_info(PyList(ch_names), ch_types = "eeg", sfreq = 1) | ||
info.set_montage(easycap_montage) | ||
simulated_epochs = PyMNE.EvokedArray(Py(dat[:, :, 1]), info) | ||
|
||
@benchmark simulated_epochs.plot_topomap(1:50) | ||
|
||
# MATLAB | ||
|
||
# ```@raw html | ||
# <img src="../../../assets/MATLAB_benchmarking.png" align="middle"/> | ||
# ``` | ||
This file contains hidden or 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 hidden or 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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains hidden or 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,28 @@ | ||
module UnfoldMakieUnfoldExt | ||
|
||
using Unfold | ||
using UnfoldMakie | ||
using GridLayoutBase | ||
using Makie | ||
|
||
# Unfold Backward Compatability. AbstractDesignMatrix was introduced only in v0.7 | ||
if isdefined(Unfold, :AbstractDesignMatrix) | ||
# nothing to do for AbstractDesignMatrix, already imprted | ||
# backward compatible accessor | ||
#const drop_missing_epochs = Unfold.drop_missing_epochs | ||
#const modelmatrices = Unfold.modelmatrices | ||
else | ||
const AbstractDesignMatrix = Unfold.DesignMatrix | ||
#const drop_missing_epochs = Unfold.dropMissingEpochs | ||
#const modelmatrices = Unfold.get_Xs | ||
end | ||
|
||
import UnfoldMakie.supportive_defaults | ||
import UnfoldMakie._docstring | ||
include("plot_splines.jl") | ||
include("plot_designmatrix.jl") | ||
|
||
|
||
|
||
|
||
end |
This file contains hidden or 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,144 @@ | ||
""" | ||
plot_designmatrix!(f::Union{GridPosition, GridLayout, Figure}, data::Unfold.DesignMatrix; kwargs...) | ||
plot_designmatrix(data::Unfold.DesignMatrix; kwargs...) | ||
|
||
|
||
Plot a designmatrix. | ||
## Arguments | ||
- `f::Union{GridPosition, GridLayout, Figure}`\\ | ||
`Figure`, `GridLayout`, or `GridPosition` to draw the plot. | ||
- `data::Unfold.DesignMatrix`\\ | ||
Data for the plot visualization. | ||
|
||
## Keyword arguments (kwargs) | ||
- `standardize_data::Bool = true`\\ | ||
Indicates whether the data is standardized by pointwise division of the data with its sampled standard deviation. | ||
- `sort_data::Bool = true`\\ | ||
Indicates whether the data is sorted. It uses `sortslices()` of Base Julia. | ||
- `xticks::Num = nothing`\\ | ||
Returns the number of labels on the x axis. | ||
- `xticks` = 0: no labels are placed. | ||
- `xticks` = 1: first possible label is placed. | ||
- `xticks` = 2: first and last possible labels are placed. | ||
- 2 < `xticks` < `number of labels`: equally distribute the labels. | ||
- `xticks` ≥ `number of labels`: all labels are placed. | ||
|
||
$(_docstring(:designmat)) | ||
|
||
**Return Value:** `Figure` displaying the Design matrix. | ||
""" | ||
UnfoldMakie.plot_designmatrix( | ||
data::Union{<:Vector{<:AbstractDesignMatrix},<:AbstractDesignMatrix}; | ||
kwargs..., | ||
) = UnfoldMakie.plot_designmatrix!(Figure(), data; kwargs...) | ||
|
||
function UnfoldMakie.plot_designmatrix!(f, data::Vector{<:AbstractDesignMatrix}; kwargs...) | ||
if length(data) > 1 | ||
@warn "multiple $(length(data)) designmatrices found, plotting the first one" | ||
end | ||
UnfoldMakie.plot_designmatrix!(f, data[1]; kwargs...) | ||
end | ||
function UnfoldMakie.plot_designmatrix!( | ||
f::Union{GridPosition,GridLayout,Figure}, | ||
data::AbstractDesignMatrix; | ||
xticks = nothing, | ||
sort_data = false, | ||
standardize_data = false, | ||
kwargs..., | ||
) | ||
config = PlotConfig(:designmat) | ||
UnfoldMakie.config_kwargs!(config; kwargs...) | ||
designmat = modelmatrix(data) | ||
if standardize_data | ||
designmat = designmat ./ std(designmat, dims = 1) | ||
designmat[isinf.(designmat)] .= 1.0 | ||
end | ||
|
||
if isa(designmat, Unfold.SparseMatrixCSC) | ||
if sort_data | ||
@warn "Sorting does not make sense for time-expanded designmatrices. sort_data has been set to `false`" | ||
sort_data = false | ||
end | ||
designmat = Matrix(designmat[end÷2-2000:end÷2+2000, :]) # needs a size(designmat) of at least 4000 x Any | ||
end | ||
|
||
if sort_data | ||
designmat = Base.sortslices(designmat, dims = 1) | ||
end | ||
labels0 = replace.(Unfold.get_coefnames(data), r"\s*:" => ":") | ||
|
||
if length(split(labels0[1], ": ")) > 1 | ||
labels = map(x -> join(split(x, ": ")[3]), labels0) | ||
labels_top1 = Unfold.extract_coef_info(Unfold.get_coefnames(data), 2) | ||
unique_names = String[] | ||
labels_top2 = String[""] | ||
for el in labels_top1 | ||
if !in(el, unique_names) | ||
push!(unique_names, el) | ||
push!(labels_top2, el) | ||
else | ||
push!(labels_top2, "") | ||
end | ||
end | ||
end | ||
lLength = length(labels0) | ||
# only change xticks if we want less then all | ||
if (xticks !== nothing && xticks < lLength) | ||
@assert(xticks >= 0, "xticks shouldn't be negative") | ||
# sections between xticks | ||
section_size = (lLength - 2) / (xticks - 1) | ||
new_labels = [] | ||
|
||
# first tick. Empty if 0 ticks | ||
if xticks >= 1 | ||
push!(new_labels, labels0[1]) | ||
else | ||
push!(new_labels, "") | ||
end | ||
|
||
# fill in ticks in the middle | ||
for i = 1:(lLength-2) | ||
# checks if we're at the end of a section, but NO tick on the very last section | ||
if i % section_size < 1 && i < ((xticks - 1) * section_size) | ||
push!(new_labels, labels0[i+1]) | ||
else | ||
push!(new_labels, "") | ||
end | ||
end | ||
|
||
# last tick at the end | ||
if xticks >= 2 | ||
push!(new_labels, labels0[lLength-1]) | ||
else | ||
push!(new_labels, "") | ||
end | ||
|
||
labels0 = new_labels | ||
end | ||
if length(split(labels0[1], ": ")) > 1 | ||
ax2 = Axis( | ||
f[1, 1], | ||
xticklabelcolor = :red, | ||
xaxisposition = :top; | ||
xticks = (1:length(labels_top2), labels_top2), | ||
) | ||
hidespines!(ax2) | ||
hidexdecorations!(ax2, ticklabels = false, ticks = false) | ||
hm = heatmap!(ax2, designmat'; config.visual...) | ||
else | ||
labels = labels0 | ||
end | ||
|
||
# plot Designmatrix | ||
config.axis = merge(config.axis, (; xticks = (1:length(labels), labels))) | ||
ax = Axis(f[1, 1]; config.axis...) | ||
hm = heatmap!(ax, designmat'; config.visual...) | ||
|
||
if isa(designmat, SparseMatrixCSC) | ||
ax.yreversed = true | ||
end | ||
|
||
apply_layout_settings!(config; fig = f, hm = hm) | ||
|
||
return f | ||
end |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.