JuliaArrays / AxisArrays.jl

Performant arrays where each dimension can have a named axis with values
http://JuliaArrays.github.io/AxisArrays.jl/latest/
Other
200 stars 41 forks source link

Why default tolerance at 0 in indexing on axis coordinate value? #205

Open Chiil opened 2 years ago

Chiil commented 2 years ago

I was playing around AxisArrays for the first time and did this:

using AxisArrays

x = 0:10:100 |> collect
a = AxisArray(rand(length(x)); x=x)

println(a[x=29..33])
println(a[x=30..30])
println(a[atvalue(29; atol=5)])
println(a[atvalue(29)]) # Does not work.

Would it not be more intuitive to set the default tolerance to a very large value? For my own personal use, I would use AxisArrays to find values nearest to a given coordinate in gridded data. Or did I overlook an option to set the default tolerance?

gltchr commented 2 weeks ago

I was trying out the package for a last couple of days and I feel very excited with the features it provides and thankful for the work of the developers. I was a little startled when I have encountered the same problem as described by @Chiil : I was expecting that indexing with atvalue() should yield a nearest neighbor index to the provided value. However I was getting an inconsistent error when indexing into a time-axis: certain indices would work, but others would through a BoundsError. Setting tolerance manually has fixed the issue, but seems counterintuitive considering the general aim of the package.