DimensionalData.jl icon indicating copy to clipboard operation
DimensionalData.jl copied to clipboard

Interpolate

Open DanDeepPhase opened this issue 3 years ago • 8 comments

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()

DanDeepPhase avatar Nov 17 '22 17:11 DanDeepPhase

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 avatar Nov 17 '22 19:11 rafaqz

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.

rafaqz avatar Jan 16 '23 13:01 rafaqz