JuliaDataCubes / YAXArrays.jl

Yet Another XArray-like Julia package
https://juliadatacubes.github.io/YAXArrays.jl/
Other
101 stars 17 forks source link

batch extraction with site as first entry in the table fails #207

Closed felixcremer closed 1 year ago

felixcremer commented 1 year ago

I am currently trying to get a test case for #194 and I run into the following error, when I use a list of named tuples where the site is the first entry:

    lons = range(30,35,length=10)
    lats = range(50,55,step=0.5)
    times = Date(2000,1,1):Month(1):Date(2000,12,31)

    data = rand(length(lons),length(lats), length(times));

    c = YAXArray([RangeAxis("longitude",lons),RangeAxis("latitude",lats),RangeAxis("time",times)],data)
    c_perm = permutedims(c,(3,2,1))

julia>     r = c[sites_first]
ERROR: MethodError: no method matching -(::String, ::Float64)
Closest candidates are:
  -(::T, ::T) where T<:Union{Float16, Float32, Float64} at float.jl:384
  -(::ChainRulesCore.AbstractThunk, ::Any) at ~/.julia/packages/ChainRulesCore/C73ay/src/tangent_types/thunks.jl:34
  -(::ForwardDiff.Dual{Tx}, ::AbstractFloat) where Tx at ~/.julia/packages/ForwardDiff/pDtsf/src/dual.jl:144
  ...
Stacktrace:
  [1] axVal2Index(a::RangeAxis{Float64, :longitude, StepRangeLen{Float64, Base.TwicePrecision{Float64}, Base.TwicePrecision{Float64}, Int64}}, v::String; fuzzy::Bool)
    @ YAXArrays.Cubes.Axes ~/.julia/dev/YAXArrays/src/Cubes/Axes.jl:202
  [2] axVal2Index(a::RangeAxis{Float64, :longitude, StepRangeLen{Float64, Base.TwicePrecision{Float64}, Base.TwicePrecision{Float64}, Int64}}, v::String)
    @ YAXArrays.Cubes.Axes ~/.julia/dev/YAXArrays/src/Cubes/Axes.jl:201
  [3] (::YAXArrays.Cubes.var"#153#160"{RangeAxis{Float64, :longitude, StepRangeLen{Float64, Base.TwicePrecision{Float64}, Base.TwicePrecision{Float64}, Int64}}})(val::String)
    @ YAXArrays.Cubes ~/.julia/dev/YAXArrays/src/Cubes/Cubes.jl:228
  [4] iterate
    @ ./generator.jl:47 [inlined]
  [5] _collect
    @ ./array.jl:807 [inlined]
  [6] collect_similar(cont::Vector{String}, itr::Base.Generator{Vector{String}, YAXArrays.Cubes.var"#153#160"{RangeAxis{Float64, :longitude, StepRangeLen{Float64, Base.TwicePrecision{Float64}, Base.TwicePrecision{Float64}, Int64}}}})
    @ Base ./array.jl:716
  [7] map(f::Function, A::Vector{String})
    @ Base ./abstractarray.jl:2933
  [8] #152
    @ ~/.julia/dev/YAXArrays/src/Cubes/Cubes.jl:258 [inlined]
  [9] #4
    @ ./generator.jl:36 [inlined]
 [10] iterate
    @ ./generator.jl:47 [inlined]
 [11] collect(itr::Base.Generator{Base.Iterators.Zip{Tuple{Tuple{Int64, Int64}, NamedTuple{(:site, :lon), Tuple{Vector{String}, Vector{Float64}}}}}, Base.var"#4#5"{YAXArrays.Cubes.var"#152#159"{YAXArray{Float64, 3, Array{Float64, 3}, Vector{RangeAxis}}}}})
    @ Base ./array.jl:787
 [12] map(::Function, ::Tuple{Int64, Int64}, ::NamedTuple{(:site, :lon), Tuple{Vector{String}, Vector{Float64}}})
    @ Base ./abstractarray.jl:3055
 [13] batchextract(x::YAXArray{Float64, 3, Array{Float64, 3}, Vector{RangeAxis}}, i::Vector{NamedTuple{(:site, :lon, :lat), Tuple{String, Float64, Float64}}})
    @ YAXArrays.Cubes ~/.julia/dev/YAXArrays/src/Cubes/Cubes.jl:256
 [14] getindex(x::YAXArray{Float64, 3, Array{Float64, 3}, Vector{RangeAxis}}, i::Vector{NamedTuple{(:site, :lon, :lat), Tuple{String, Float64, Float64}}})
    @ YAXArrays.Cubes ~/.julia/dev/YAXArrays/src/Cubes/Cubes.jl:223
 [15] top-level scope
    @ REPL[132]:1
felixcremer commented 1 year ago

This is an actual duplicate of #194.