Skip to content

Conversation

@haakon-e
Copy link
Contributor

@haakon-e haakon-e commented Nov 3, 2025

This pull request adds support for gridded interpolation of AbstractDimArrays using Interpolations.jl, while ensuring that the new functionality is only available when Interpolations.jl is loaded. The main changes introduce a new extension module, user-facing API, and integration points.

New gridded interpolation support:

  • Added the DimensionalDataInterpolationsExt extension module (ext/DimensionalDataInterpolationsExt.jl) that defines a DimGriddedInterpolation type for gridded interpolation of AbstractDimArrays, a gridded_interpolate constructor, and an interpolate! method for in-place interpolation. This module also includes comprehensive documentation and a custom display method.

This PR is inspired by previous efforts and discussions to support interpolation in DimensionalData, including

I'm very open to discussing the API, bikeshed names and details, etc.
This is very much a first draft that hopefully can stimulate some discussion and feedback before I put in the additional effort to add docs, tests, and clean up the interface and edge-cases. That said, I have used a version of this for a while for an ongoing project, including a variant that works for DimStacks, but haven't gotten around to trying to get it merged into DimensionalData itself.

There's a few caveats to this draft, including:

  • in-place interpolation requires equal ordering of the dimensions of the original and target array. I can't see an obvious work-around that would
    • retain allocation-free in-place interpolation
    • keep the code simple
  • I needed to use an additional package, UnrolledUtilities, to ensure that out-of-place interpolation is type-stable. Notably, it is used to move scalar-like dimensions to refdims so that the returned DimArray only contains vector-like dimensions. Unfortunately, I think this means end-users would have to explicitly load both packages for the extension to load.
    • A workaround for this would be to add UnrolledUtilities as an ordinary dependency (it's quite light, after all and potentially useful elsewhere).

Add functions `gridded_interpolate` and `interpolate!`
in a project extension to interpolate `DimArray`s
using the `Interpolations.jl` package.

- `gridded_interpolate` creates a `DimGriddedInterpolation` object,
which can be used to interpolate the data in-place or out-of-place.
- out-of-place interpolation is supported by calling the
`DimGriddedInterpolation` object with the desired dimensions.
- in-place interpolation is supported by calling `interpolate!`
with the `DimGriddedInterpolation` object and an existing `DimArray`.
@codecov
Copy link

codecov bot commented Nov 3, 2025

Codecov Report

❌ Patch coverage is 0% with 49 lines in your changes missing coverage. Please review.
✅ Project coverage is 86.11%. Comparing base (6db30de) to head (1ead937).

Files with missing lines Patch % Lines
ext/DimensionalDataInterpolationsExt.jl 0.00% 45 Missing ⚠️
src/interpolations.jl 0.00% 4 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1126      +/-   ##
==========================================
- Coverage   86.90%   86.11%   -0.80%     
==========================================
  Files          55       57       +2     
  Lines        5338     5387      +49     
==========================================
  Hits         4639     4639              
- Misses        699      748      +49     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@rafaqz
Copy link
Owner

rafaqz commented Nov 3, 2025

Oh no... Im working on integrating DataInterpolationsND.jl here! (And working on that package quite a lot too)

Mostly because it will allow arbitrary mixed interpolation types by dimension, and will be faster and more flexible (e.g. GPU compatible) than Interpolations.jl due to KernelAbstractions.jl core, and becaise Im going to optimise the kernels pretty hard over the next week or two.

And unfortunately I also think we should go with one specific interpolations integration to minimise future maintenance.

@haakon-e
Copy link
Contributor Author

haakon-e commented Nov 3, 2025

Ah gotcha. Well in that case, please feel free to ping me once you've got a PR ready. I'd be happy to provide feedback and discuss how it could work for some use cases I would find valuable.
I agree one extension makes most sense. I'll use this for myself until we get the DataInterpolationsND-version merged!

@haakon-e haakon-e closed this Nov 3, 2025
@rafaqz
Copy link
Owner

rafaqz commented Nov 4, 2025

Think I'm back on board with using Interpolations.jl.

But I want to make this a lot more flexible and have everything by dimension. I will have a go at refactoring this PR to see how easy it is to do.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants