DimensionalData.jl
DimensionalData.jl copied to clipboard
Makie is unable to plot a DimArray when a dimension is constructed from another DimArray
See below MWE
How are you saving to disk?
OK... I found the problem... da2 had a dimension built from a DimArray... I wonder if there is an issue here as a DimArray should behave as an AbstractArray. Here's the MWE:
This plots just fine:
julia> date = [DateTime("1985-03-13T00:00:00"), DateTime("1985-04-12T00:00:00"), DateTime("1985-05-12T00:00:00"), DateTime("1985-06-11T00:00:00")]
4-element Vector{DateTime}:
1985-03-13T00:00:00
1985-04-12T00:00:00
1985-05-12T00:00:00
1985-06-11T00:00:00
julia> ddate = Dim{:date}(date)
date [DateTime("1985-03-13T00:00:00"), …, DateTime("1985-06-11T00:00:00")]
julia> data = rand(length(ddate))
4-element Vector{Float64}:
0.2693751970756716
0.6519072128117327
0.9912748870960395
0.4505443280597703
julia> da1 = DimArray(data, ddate)
┌ 4-element DimArray{Float64, 1} ┐
├────────────────────────────────┴─────────────────────────────────────────────────────────────────────────────────────────── dims ┐
↓ date Sampled{DateTime} [DateTime("1985-03-13T00:00:00"), …, DateTime("1985-06-11T00:00:00")] ForwardOrdered Irregular Points
└──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘
1985-03-13T00:00:00 0.269375
1985-04-12T00:00:00 0.651907
1985-05-12T00:00:00 0.991275
This throws an error when the dimension is constructed from a DimArray:
julia> date = [DateTime("1985-03-13T00:00:00"), DateTime("1985-04-12T00:00:00"), DateTime("1985-05-12T00:00:00"), DateTime("1985-06-11T00:00:00")]
4-element Vector{DateTime}:
1985-03-13T00:00:00
1985-04-12T00:00:00
1985-05-12T00:00:00
1985-06-11T00:00:00
julia> date2 = DimArray(date, ddate)
┌ 4-element DimArray{DateTime, 1} ┐
├─────────────────────────────────┴────────────────────────────────────────────────────────────────────────────────────────── dims ┐
↓ date Sampled{DateTime} [DateTime("1985-03-13T00:00:00"), …, DateTime("1985-06-11T00:00:00")] ForwardOrdered Irregular Points
└──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘
1985-03-13T00:00:00 1985-03-13T00:00:00
1985-04-12T00:00:00 1985-04-12T00:00:00
1985-05-12T00:00:00 1985-05-12T00:00:00
1985-06-11T00:00:00 1985-06-11T00:00:00
julia> ddate2 = Dim{:date}(date2)
date [DateTime("1985-03-13T00:00:00"), …, DateTime("1985-06-11T00:00:00")]
julia> da2 = DimArray(data, ddate2)
┌ 4-element DimArray{Float64, 1} ┐
├────────────────────────────────┴─────────────────────────────────────────────────────────────────────────────────────────── dims ┐
↓ date Sampled{DateTime} [DateTime("1985-03-13T00:00:00"), …, DateTime("1985-06-11T00:00:00")] ForwardOrdered Irregular Points
└──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘
1985-03-13T00:00:00 0.269375
1985-04-12T00:00:00 0.651907
1985-05-12T00:00:00 0.991275
1985-06-11T00:00:00 0.450544
julia> lines(da2)
ERROR: ArgumentError: Conversion failed for Lines (With conversion trait PointBased()) with args: Tuple{Vector{Int64}, Vector{Point{2, Float64}}} .
Lines requires to convert to argument types Tuple{AbstractVector{<:Union{Point2, Point3}}}, which convert_arguments didn't succeed in.
To fix this overload convert_arguments(P, args...) for Lines or PointBased() and return an object of type Tuple{AbstractVector{<:Union{Point2, Point3}}}.`
Stacktrace:
[1] conversion_pipeline(P::Type{…}, used_attrs::Tuple{}, args::Tuple{…}, args_obs::Tuple{…}, user_attributes::Dict{…}, deregister::Vector{…}, recursion::Int64)
@ Makie ~/.julia/packages/Makie/8h0bl/src/interfaces.jl:241
[2] conversion_pipeline(P::Type{…}, used_attrs::Tuple{}, args::Tuple{…}, args_obs::Tuple{…}, user_attributes::Dict{…}, deregister::Vector{…}, recursion::Int64)
@ Makie ~/.julia/packages/Makie/8h0bl/src/interfaces.jl:234
[3] conversion_pipeline(P::Type{…}, used_attrs::Tuple{}, args::Tuple{…}, args_obs::Tuple{…}, user_attributes::Dict{…}, deregister::Vector{…})
@ Makie ~/.julia/packages/Makie/8h0bl/src/interfaces.jl:214
[4] (Lines)(user_args::Tuple{DimVector{…}, Vector{…}}, user_attributes::Dict{Symbol, Any})
@ Makie ~/.julia/packages/Makie/8h0bl/src/interfaces.jl:272
[5] _create_plot(::Function, ::Dict{…}, ::DimVector{…}, ::Vararg{…})
@ Makie ~/.julia/packages/Makie/8h0bl/src/figureplotting.jl:316
[6] #lines#60
@ ~/.julia/packages/MakieCore/hXATT/src/recipes.jl:436 [inlined]
[7] lines(A::DimVector{…}; axislegendkw::@NamedTuple{}, axislegend::@NamedTuple{}, axis::@NamedTuple{}, attributes::@Kwargs{})
@ DimensionalDataMakie ~/.julia/packages/DimensionalData/5jhQ2/ext/DimensionalDataMakie.jl:78
[8] lines(A::DimVector{…})
@ DimensionalDataMakie ~/.julia/packages/DimensionalData/5jhQ2/ext/DimensionalDataMakie.jl:74
[9] top-level scope
@ REPL[79]:1
Some type information was truncated. Use `show(err)` to see complete types.
Note that the display() of da1 and da2 are identical
Aha interesting! Yes it probably hits a second expansion somehow.
But presumably dims should be treated as strictly normal base arrays. Maybe we need to check if they are dimarrays and extract .data?
Yeah probably we should do a convert(Array, parent(lookup)) rather than just parent(lookup) so that there are no further expansions.