I am playing around with AxisArrays, as it seems like a great package for adding axis with geographical locations to gridded data. What I would like is to let AxisArray give me the value of the nearest location, without having to specify the tolerance each time. Is it somehow possible?
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.
I think it is because the default tolerance seems to be zero. I would prefer the default tolerance to be very large. I would like to use it for gridded data and get the nearest value to an arbitrary coordinate.
Also, note that just having the tolerance be very large wouldn’t do what you want - it doesn’t get the nearest index to what we specify, it seems to be getting the smallest index within the tolerance:
Is there a way to return a default value such as NaN or 0 instead of throwing a BoundsError when there is no value within array a in the vicinity of a given index along x? Similar to the behvaiour of DefaultDict and DefaultOrderedDict · DataStructures.jl