YAXArrays.jl
YAXArrays.jl copied to clipboard
yaxconvert alters the dim names
why the change from D1, D2 here to Dim{:D1}, Dim{:D2} when converting a dimarray to a yaxarray?
julia> using DimensionalData, YAXArrays, YAXArrayBase
julia> DimensionalData.@dim D1
julia> DimensionalData.@dim D2
julia> dd = rand(D1(["a","b"]), D2(["x","y"]), metadata = Dict{String, Any}())
2×2 DimArray{Float64,2} with dimensions:
D1 Categorical{String} String["a", "b"] ForwardOrdered,
D2 Categorical{String} String["x", "y"] ForwardOrdered
"x" "y"
"a" 0.790863 0.345696
"b" 0.490964 0.814311
julia> ddyax = yaxconvert(YAXArray, dd)
2×2 YAXArray{Float64,2} with dimensions:
Dim{:D1} Categorical{String} String["a", "b"] ForwardOrdered,
Dim{:D2} Categorical{String} String["x", "y"] ForwardOrdered
Total size: 32.0 bytes
same thing happens in the other direction, yax to dd:
julia> yax = YAXArray((D1(["a","b"]), D2(["x","y"])), rand(2,2))
2×2 YAXArray{Float64,2} with dimensions:
D1 Categorical{String} String["a", "b"] ForwardOrdered,
D2 Categorical{String} String["x", "y"] ForwardOrdered
Total size: 32.0 bytes
julia> yaxdd = yaxconvert(DimArray, yax)
2×2 DimArray{Float64,2} with dimensions:
Dim{:D1} Categorical{String} String["a", "b"] ForwardOrdered,
Dim{:D2} Categorical{String} String["x", "y"] ForwardOrdered
"x" "y"
"a" 0.27363 0.455353
"b" 0.446381 0.709265
there is a workaround, but why doesn't yaxconvert operate like this?
julia> hack = DimArray(yax.data, dims(yax))
2×2 DimArray{Float64,2} with dimensions:
D1 Categorical{String} String["a", "b"] ForwardOrdered,
D2 Categorical{String} String["x", "y"] ForwardOrdered
"x" "y"
"a" 0.27363 0.455353
"b" 0.446381 0.709265
i ask because indexing with D1 is more succinct and easier to read and type than Dim{:D1}.
most likely is because currently there is not a @dim definition as in DimensionalData.@dim D1 . I agree that is annoying, suggestions [PRs] are welcome.
The construction of the DimArray or Yaxarray in yaxcreate in YAXArrayBase is using the Dim Constructor explicitely. There might be a smarter way to get the Dimension from a dimension name.