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

add Interpolations.jl extension

Open rafaqz opened this issue 1 year ago • 8 comments

This is an idea for adding an Interpolations.jl extension.

It turns out there isn't a clean way to extend Interpolations.jl methods like interpolate or scale because really on a DimArray you would always want both and have the information for both already in one object.

So the idea here (and what i personally need the most) is to define an interpolation method that lets you interpolate from one AbstractDimArray to another in a single command.

We have most of the information we need to choose the interpolation method - users can specify e.g. Cubic or Linear if they really want to. But BSpline/Gridded we know from Regular / Irregular etc.

We may also want to provide an interpolator object that can interpolate points.

I'll probably leave this here for a while until its clearer what the best strategy is, but comments are welcome.

rafaqz avatar Dec 27 '23 00:12 rafaqz

Closes #420

@DanDeepPhase we can implement this pretty easily now. But if you have any comments on syntax or how this should work that would help. See the new tests added here for an example.

rafaqz avatar Jan 30 '24 23:01 rafaqz

Any particular reason this was closed?

asinghvi17 avatar Jun 24 '24 11:06 asinghvi17

In favour of

https://github.com/rafaqz/DimensionalData.jl/pull/609

Which needs tests, and I forgot about. And I'm not really sure on the best syntax. Feedback appreciated.

rafaqz avatar Jun 24 '24 11:06 rafaqz

Did #609 get merged here? I don't see the log

asinghvi17 avatar Jun 24 '24 17:06 asinghvi17

It got merged to the branch yes, but the PR seems dead there's no reopen button

Maybe that's just a phone app thing idk

rafaqz avatar Jun 24 '24 20:06 rafaqz

I guess the PR had to be reopened for the log to refresh...

asinghvi17 avatar Jun 24 '24 20:06 asinghvi17

Glad to find this PR. It seems the PR as-is returns an array upon interpolation

To add on to how cool this would be, here's a hacked up version that for DimVectors (but probably easy to generalize) would return a DimVector after interpolation:

function Interpolations.linear_interpolation(A::AbstractDimVector; kw...)
    function itp(pts...)
        itp = linear_interpolation(DimensionalData.index(dims(A)), A; kw...)
        valtuple = lookup(pts, dims(A))
        intp = itp(valtuple...)
        DimVector(intp, pts)
    end	
end

example:

da = cumsum(rand(X(0:0.1:1)))
itpp = linear_interpolation(da)
da_itp = itpp(X(0:0.01:1))

# plotting
f,a,s = scatter(da_itp, markersize=4, label = "new pts")
scatter!(a, da, label = "old pts")
axislegend()
f
image

haakon-e avatar Aug 26 '24 00:08 haakon-e

It's just a little tricky getting the syntax right, if you want to take over find shing the PR that would help it along

rafaqz avatar Aug 26 '24 08:08 rafaqz