Skip to content

Commit

Permalink
Merge branch 'master' into yg/better-interpolation
Browse files Browse the repository at this point in the history
  • Loading branch information
palday authored Jul 28, 2022
2 parents d693d6b + b2f8b98 commit 39b4f91
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 1 deletion.
1 change: 1 addition & 0 deletions docs/src/general.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ The recipe supports different interpolation methods, namely:
```@docs
TopoPlots.ClaughTochter
TopoPlots.SplineInterpolator
TopoPlots.NullInterpolator
```
One can define your own interpolation by subtyping:

Expand Down
4 changes: 3 additions & 1 deletion src/core-recipe.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
sensors = true,
interpolation = ClaughTochter(),
bounding_geometry = Circle,
markersize = 5,
padding = 0.1,
pad_value = 0.0,
resolution = (512, 512),
Expand All @@ -27,6 +28,7 @@ Creates an irregular interpolation for each `data[i]` point at `positions[i]`.
* `labels::Vector{<:String}` = nothing: names for each data point
* `interpolation::Interpolator = ClaughTochter()`: Applicable interpolators are $(join(subtypes(TopoPlots.Interpolator), ", "))
* `bounding_geometry = Circle`: the geometry added to the points, to create a smooth boundary. Can be `Rect` or `Circle`.
* `markersize = 5`: size of the points defined by positions
* `padding = 0.1`: padding applied to `bounding_geometry`
* `pad_value = 0.0`: data value filled in for each added position from `bounding_geometry`
* `resolution = (512, 512)`: resolution of the interpolation
Expand Down Expand Up @@ -124,7 +126,7 @@ function Makie.plot!(p::TopoPlot)
contour!(p, xg, yg, data; attributes...)
end
label_scatter = to_value(p.label_scatter)
attributes = @plot_or_defaults label_scatter Attributes(markersize=5, color=p.data, colormap=p.colormap, colorrange=p.colorrange, strokecolor=:black, strokewidth=1)
attributes = @plot_or_defaults label_scatter Attributes(markersize=p.markersize, color=p.data, colormap=p.colormap, colorrange=p.colorrange, strokecolor=:black, strokewidth=1)
if !isnothing(attributes)
scatter!(p, p.positions; attributes...)
end
Expand Down
17 changes: 17 additions & 0 deletions src/interpolators.jl
Original file line number Diff line number Diff line change
Expand Up @@ -101,3 +101,20 @@ end
# # the xg' * ones is a shorthand for np.meshgrid
# return xg, yg, interp.set_locations( ones(length(xg))' .* yg, xg' .* ones(length(yg)))()
# end


"""
NullInterpolator()
Interpolator that returns "0", which is useful to display only the electrode locations + labels
"""
struct NullInterpolator <: TopoPlots.Interpolator

end

function (ni::NullInterpolator)(
xrange::LinRange, yrange::LinRange,
positions::AbstractVector{<: Point{2}}, data::AbstractVector{<:Number})

return zeros(length(xrange),length(yrange))
end
6 changes: 6 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ begin
@test_figure("all-interpolations", f)
end

begin # empty eeg topoplot
f, ax, pl = TopoPlots.eeg_topoplot(1:length(TopoPlots.CHANNELS_10_20),TopoPlots.CHANNELS_10_20; interpolation=TopoPlots.NullInterpolator(),)
@test_figure("nullInterpolator", f)
end

# begin
# f = Figure(resolution=(1000, 1000))
# s = Slider(f[:, 1], range=1:size(data, 2), startvalue=351)
Expand Down Expand Up @@ -72,3 +77,4 @@ begin
f, ax, pl = eeg_topoplot(data[:, 340, 1]; positions=positions)
@test_figure("eeg-topoplot3", f)
end

0 comments on commit 39b4f91

Please sign in to comment.