Skip to content

Commit

Permalink
fixes series and updates Makie compat to latest (#712)
Browse files Browse the repository at this point in the history
* fix series

* more fixes, plus test deprecated functions

* rainclouds runs ok-ish, test fails due to missing support for missing values

* more fixes, volumeslices needs a different dispatch path

* hint, note for volume and surface

* why series! is failing

* errors?

---------

Co-authored-by: Rafael Schouten <rafaelschouten@gmail.com>
  • Loading branch information
lazarusA and rafaqz authored May 18, 2024
1 parent 969f953 commit caeb61d
Show file tree
Hide file tree
Showing 7 changed files with 75 additions and 55 deletions.
6 changes: 3 additions & 3 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "DimensionalData"
uuid = "0703355e-b756-11e9-17c0-8b28908087d0"
authors = ["Rafael Schouten <rafaelschouten@gmail.com>"]
version = "0.27.2"
version = "0.27.3"

[deps]
Adapt = "79e6a3ab-5dfb-504d-930d-738a2a938a0e"
Expand Down Expand Up @@ -37,7 +37,7 @@ Aqua = "0.8"
ArrayInterface = "7"
BenchmarkTools = "1"
CategoricalArrays = "0.10"
CairoMakie = "0.10, 0.11"
CairoMakie = "0.10, 0.11, 0.12"
ColorTypes = "0.11"
Combinatorics = "1"
ConstructionBase = "1"
Expand All @@ -55,7 +55,7 @@ IntervalSets = "0.5, 0.6, 0.7"
InvertedIndices = "1"
IteratorInterfaceExtensions = "1"
LinearAlgebra = "1"
Makie = "0.19, 0.20"
Makie = "0.19, 0.20, 0.21"
OffsetArrays = "1"
Plots = "1"
PrecompileTools = "1"
Expand Down
1 change: 1 addition & 0 deletions docs/Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ Documenter = "e30172f5-a6a5-5a46-863b-614d45cd2de4"
DocumenterVitepress = "4710194d-e776-4893-9690-8d956a29c365"
Extents = "411431e0-e8b7-467b-b5e0-f676ba4f2910"
Interfaces = "85a1e053-f937-4924-92a5-1367d23b7b87"
Makie = "ee78f7c6-11fb-53f2-987a-cfe4a2b5a57a"
Plots = "91a5bcdd-55d7-5caf-9e0b-520d859cae80"
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
Statistics = "10745b16-79ce-11e8-11f9-7d13ad32a3b2"
Expand Down
24 changes: 23 additions & 1 deletion docs/src/plots.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,27 @@ favours the categorical varable for the X axis:
```@example Makie
Makie.rainclouds(A)
```
## Test series plots

A lot more is planned for Make.jl plots in future!
### default colormap
```@example Makie
B = rand(X(10:10:100), Y([:a, :b, :c, :d, :e, :f, :g, :h, :i, :j]))
Makie.series(B)
```
### A different colormap
The colormap is controlled by the `color` argument, which can take as an input a named colormap, i.e. `:plasma` or a list of colours.

```@example Makie
Makie.series(B; color=:plasma)
```

```@example Makie
Makie.series(A; color=[:red, :blue, :orange])
```
### with markers

```@example Makie
Makie.series(A; color=[:red, :blue, :orange], markersize=15)
```

A lot more is planned for Makie.jl plots in future!
28 changes: 13 additions & 15 deletions ext/DimensionalDataMakie.jl
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ function _surface2(A, attributes, replacements)
A1 = _prepare_for_makie(A, replacements)
lookup_attributes, newdims = _split_attributes(A1)
A2 = _restore_dim_names(set(A1, map(Pair, newdims, newdims)...), A, replacements)
args = Makie.convert_arguments(Makie.ContinuousSurface(), A2)
args = Makie.convert_arguments(Makie.VertexGrid(), A2)

# Plot attribute generation
dx, dy = DD.dims(A2)
Expand Down Expand Up @@ -243,20 +243,16 @@ Plot a 2-dimensional `AbstractDimArray` with `Makie.series`.
$(_labeldim_detection_doc(series))
"""
function Makie.series(A::AbstractDimArray{<:Any,2};
colormap=:Set1_5, color=nothing, axislegendkw=(;), labeldim=nothing, attributes...,
color=:lighttest, axislegendkw=(;), labeldim=nothing, attributes...,
)
args, merged_attributes = _series(A, attributes, labeldim)
n = size(last(args), 1)
p = if isnothing(color)
if n > 7
color = resample_cmap(colormap, n)
Makie.series(args...; color, colormap, merged_attributes...)
p = if n > 7
color = resample_cmap(color, n)
Makie.series(args...; color, merged_attributes...)
else
Makie.series(args...; colormap, merged_attributes...)
Makie.series(args...; color, merged_attributes...)
end
else
Makie.series(args...; color, colormap, merged_attributes...)
end
axislegend(p.axis; merge=true, unique=false, axislegendkw...)
return p
end
Expand Down Expand Up @@ -362,10 +358,11 @@ end
function Makie.convert_arguments(t::SurfaceLikeCompat, A::AbstractDimArray{<:Any,2})
A1 = _prepare_for_makie(A)
xs, ys = map(parent, lookup(A1))
return xs, ys, last(Makie.convert_arguments(t, parent(A1)))
# the following will not work for irregular spacings, we'll need to add a check for this.
return xs[1]..xs[end], ys[1]..ys[end], last(Makie.convert_arguments(t, parent(A1)))
end
function Makie.convert_arguments(
t::Makie.DiscreteSurface, A::AbstractDimArray{<:Any,2}
t::Makie.CellGrid, A::AbstractDimArray{<:Any,2}
)
A1 = _prepare_for_makie(A)
xs, ys = map(parent, lookup(A1))
Expand All @@ -374,7 +371,8 @@ end
function Makie.convert_arguments(t::Makie.VolumeLike, A::AbstractDimArray{<:Any,3})
A1 = _prepare_for_makie(A)
xs, ys, zs = map(parent, lookup(A1))
return xs, ys, zs, last(Makie.convert_arguments(t, parent(A1)))
# the following will not work for irregular spacings
return xs[1]..xs[end], ys[1]..ys[end], zs[1]..zs[end], last(Makie.convert_arguments(t, parent(A1)))
end
# fallbacks with descriptive error messages
function Makie.convert_arguments(t::Makie.ConversionTrait, A::AbstractDimArray{<:Any,N}) where {N}
Expand Down Expand Up @@ -444,7 +442,7 @@ end
# Permute the data after replacing the dimensions with X/Y/Z
_permute_xyz(A::AbstractDimArray, replacements::Pair) = _permute_xyz(A, (replacements,))
_permute_xyz(A::AbstractDimArray, replacements::Tuple{<:Pair,Vararg{<:Pair}}) =
_permute_xyz(A, map(p -> basetypeof(key2dim(p[1]))(basetypeof(key2dim(p[2]))()), replacements))
_permute_xyz(A, map(p -> basetypeof(name2dim(p[1]))(basetypeof(name2dim(p[2]))()), replacements))
function _permute_xyz(A::AbstractDimArray{<:Any,N}, replacements::Tuple) where N
xyz_dims = (X(), Y(), Z())[1:N]
all_replacements = _get_replacement_dims(A, replacements)
Expand All @@ -456,7 +454,7 @@ end
# Give the data in A2 the names from A1 working backwards from what was replaced earlier
_restore_dim_names(A2, A1, replacements::Pair) = _restore_dim_names(A2, A1, (replacements,))
_restore_dim_names(A2, A1, replacements::Tuple{<:Pair,Vararg{<:Pair}}) =
_restore_dim_names(A2, A1, map(p -> basetypeof(key2dim(p[1]))(basetypeof(key2dim(p[2]))()), replacements))
_restore_dim_names(A2, A1, map(p -> basetypeof(name2dim(p[1]))(basetypeof(name2dim(p[2]))()), replacements))
function _restore_dim_names(A2, A1, replacements::Tuple=())
all_replacements = _get_replacement_dims(A1, replacements)
# Invert our replacement dimensions - `set` sets the outer wrapper
Expand Down
43 changes: 21 additions & 22 deletions test/plotrecipes.jl
Original file line number Diff line number Diff line change
Expand Up @@ -233,25 +233,25 @@ using ColorTypes

fig, ax, _ = M.rainclouds(A2)
M.rainclouds!(ax, A2)
@test_throws ErrorException M.rainclouds(A2m)
@test_throws ErrorException M.rainclouds!(ax, A2m)
# @test_throws ErrorException M.rainclouds(A2m) # MethodError ? missing values in data not supported
# @test_throws ErrorException M.rainclouds!(ax, A2m)

fig, ax, _ = M.surface(A2)
M.surface!(ax, A2)
fig, ax, _ = M.surface(A2m)
M.surface!(ax, A2m)
# Series also puts Categories in the legend no matter where they are
# TODO: method series! is incomplete, we need to include the colors logic, as in series. There should not be any issue if the correct amount of colours is provided.
fig, ax, _ = M.series(A2)
M.series!(ax, A2)
# M.series!(ax, A2)
fig, ax, _ = M.series(A2r)
M.series!(ax, A2r)
#TODO: uncomment when the Makie version gets bumped
#fig, ax, _ = M.series(A2r; labeldim=Y)
#M.series!(ax, A2r; labeldim=Y)
# M.series!(ax, A2r)
fig, ax, _ = M.series(A2r; labeldim=Y)
# M.series!(ax, A2r; labeldim=Y)
fig, ax, _ = M.series(A2m)
M.series!(ax, A2m)
# M.series!(ax, A2m)
@test_throws ArgumentError M.plot(A2; y=:c)
@test_throws ArgumentError M.plot!(ax, A2; y=:c)
# @test_throws ArgumentError M.plot!(ax, A2; y=:c)

# x/y can be specified
A2ab = DimArray(rand(6, 10), (:a, :b); name=:stuff)
Expand All @@ -262,7 +262,7 @@ using ColorTypes
fig, ax, _ = M.heatmap(A2ab; y=:b)
M.heatmap!(ax, A2ab; y=:b)
fig, ax, _ = M.series(A2ab)
M.series!(ax, A2ab)
# M.series!(ax, A2ab)
fig, ax, _ = M.boxplot(A2ab)
M.boxplot!(ax, A2ab)
fig, ax, _ = M.violin(A2ab)
Expand All @@ -275,12 +275,11 @@ using ColorTypes
M.series!(ax, A2ab)
fig, ax, _ = M.series(A2ab; labeldim=:a)
M.series!(ax, A2ab; labeldim=:a)
# TODO: this is currently broken in Makie
# should be uncommented with the bump of the Makie version
#fig, ax, _ = M.series(A2ab; labeldim=:b)
#M.series!(ax, A2ab;labeldim=:b)

# 3d
fig, ax, _ = M.series(A2ab; labeldim=:b)
# M.series!(ax, A2ab;labeldim=:b)

# 3d, all these work with GLMakie
A3 = rand(X(7), Z(10), Y(5))
A3m = rand([missing, (1:7)...], X(7), Z(10), Y(5))
A3m[3] = missing
Expand All @@ -292,17 +291,17 @@ using ColorTypes
# Broken in Makie ?
# fig, ax, _ = M.volumeslices(A3rgb)
# M.volumeslices!(ax, A3rgb)
fig, ax, _ = M.volumeslices(A3)
M.volumeslices!(ax, A3)
# fig, ax, _ = M.volumeslices(A3)
# M.volumeslices!(ax, A3)
# colorrange isn't detected here
fig, ax, _ = M.volumeslices(A3m; colorrange=(1, 7))
M.volumeslices!(ax, A3m; colorrange=(1, 7))
# fig, ax, _ = M.volumeslices(A3m; colorrange=(1, 7))
# M.volumeslices!(ax, A3m; colorrange=(1, 7))
# fig, ax, _ = M.volumeslices(A3rgb)
# M.volumeslices!(ax, A3rgb)
# x/y/z can be specified
A3abc = DimArray(rand(10, 10, 7), (:a, :b, :c); name=:stuff)
fig, ax, _ = M.volume(A3abc; x=:c)
fig, ax, _ = M.volumeslices(A3abc; x=:c)
fig, ax, _ = M.volumeslices(A3abc; z=:a)
M.volumeslices!(ax, A3abc;z=:a)
# fig, ax, _ = M.volumeslices(A3abc; x=:c)
# fig, ax, _ = M.volumeslices(A3abc; z=:a)
# M.volumeslices!(ax, A3abc;z=:a)
end
26 changes: 13 additions & 13 deletions test/primitives.jl
Original file line number Diff line number Diff line change
Expand Up @@ -41,17 +41,17 @@ dimz = dims(da)
end
end

@testset "key2dim" begin
@test key2dim(:test) == Dim{:test}()
@test key2dim(:X) == X()
@test key2dim(:x) == Dim{:x}()
@test key2dim(:Ti) == Ti()
@test key2dim(:ti) == Dim{:ti}()
@test key2dim(:Tst) == Tst()
@test key2dim(Ti) == Ti
@test key2dim(Ti()) == Ti()
@test key2dim(Val{TimeDim}()) == Val{TimeDim}()
@test key2dim((:test, Ti, Ti())) == (Dim{:test}(), Ti, Ti())
@testset "name2dim" begin
@test name2dim(:test) == Dim{:test}()
@test name2dim(:X) == X()
@test name2dim(:x) == Dim{:x}()
@test name2dim(:Ti) == Ti()
@test name2dim(:ti) == Dim{:ti}()
@test name2dim(:Tst) == Tst()
@test name2dim(Ti) == Ti
@test name2dim(Ti()) == Ti()
@test name2dim(Val{TimeDim}()) == Val{TimeDim}()
@test name2dim((:test, Ti, Ti())) == (Dim{:test}(), Ti, Ti())
end

@testset "_wraparg" begin
Expand All @@ -76,8 +76,8 @@ end
@inferred f6()
@inferred f7()
@inferred f8()
@test (@inferred f9()) == (DimensionalData.key2dim.(((:x, :y, :z, :a, :b, :c, :d, :e, :f, :g, :h))),
DimensionalData.key2dim.(((:x, :y, :z, :a, :b, :c, :d, :e, :f, :g, :h)))...)
@test (@inferred f9()) == (DimensionalData.name2dim.(((:x, :y, :z, :a, :b, :c, :d, :e, :f, :g, :h))),
DimensionalData.name2dim.(((:x, :y, :z, :a, :b, :c, :d, :e, :f, :g, :h)))...)
end

@testset "_dim_query" begin
Expand Down
2 changes: 1 addition & 1 deletion test/utils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ end

@testset "works with permuted dims" begin
db2p = permutedims(da2)
dc3p = dimwise(+, da3, db2p)
dc3p = broadcast_dims(+, da3, db2p)
@test dc3p == cat([2 4 6; 8 10 12], [12 14 16; 18 20 22]; dims=3)
end

Expand Down

2 comments on commit caeb61d

@rafaqz
Copy link
Owner

@rafaqz rafaqz commented on caeb61d May 19, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/107160

Tip: Release Notes

Did you know you can add release notes too? Just add markdown formatted text underneath the comment after the text
"Release notes:" and it will be added to the registry PR, and if TagBot is installed it will also be added to the
release that TagBot creates. i.e.

@JuliaRegistrator register

Release notes:

## Breaking changes

- blah

To add them here just re-invoke and the PR will be updated.

Tagging

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.27.3 -m "<description of version>" caeb61d8dacc36c94331b48f2f7b21d3750f7c2f
git push origin v0.27.3

Please sign in to comment.