rafaqz / DimensionalData.jl

Named dimensions and indexing for julia arrays and other data
https://rafaqz.github.io/DimensionalData.jl/stable/
MIT License
279 stars 41 forks source link

Interpolate #420

Open DanDeepPhase opened 1 year ago

DanDeepPhase commented 1 year ago

Any interest in supporting interpolation along the axes?

I was able to hack it in my code with something like:

using Interpolations, DimensionalData
import Interpolations.interpolate

interpolate(da::DimArray) = interpolate(Array.(dims(da)), da, Gridded(Linear())) 

xs = ys = 1:10
zs = [rand() for x in xs, y in ys]
M = DimArray(zs, (Y(ys),X(xs)))

itp = interpolate(M)
itp[3.3, 5.1]
[itp[y,x] for y in 3.1:0.35:7.2, x in 2:4] 

I saw you use something in rasters for re-gridding, which i think this approach is best suited for. some tweaks would be needed to get reverse ordered vectors working.

There may be a more intrusive / better way to do this by extending or creating a variant of At()

rafaqz commented 1 year ago

Rasters users gdalwarp because it handles projections and has a lot of options. But native interpolation is better eventually.

Unfortunately Interpolations.jl is a very heavy dependency, and this package is a dep of other packages so we have to keep things lean.

DimensionalDataInterpolations.jl could be useful.

rafaqz commented 1 year ago

Revisiting this: with Julia 1.9 and this PR https://github.com/JuliaLang/julia/pull/47695 we can add a weak dependency on Interpolations.jl.

If you want to make a PR that extends Intpolations.jl methods to work on AbstractDimArray in a weak dependency in this package, that would be a very useful addition.

Edit: also note that with Regular sampling you do not need to use Gridded interpolation - but you do if any LookupArray for the axes has Irregular sampling. We can really customize the interpolation method to match the traits of the LookupArray.