Gradient of 2D splines on irregular grid


I’m looking to (1) interpolate data where the x-axis is a log-spaced grid, the y-axis is a regular spaced grid and there is an array A(x,y) recording the function values in each point; and (2) take the gradient of the resulting interpolated function.

I’ve been looking at different packages, e.g. Dierckx and Interpolations. But Dierckx doesn’t support gradients above 1 dimension and Interpolations only support linear interpolations for irregular grids, and hence the derivatives will not be well-defined.

Is there a different package that will let me do the above?

Thanks alot.

You could use a (smoothing) interpolation on a sufficiently fine numerical grid (e.g. GitHub - gher-uliege/DIVAnd.jl: DIVAnd performs an n-dimensional variational analysis of arbitrarily located observations) and then just perform a simple finite difference on this high-resolution grid.


In other words, x = \exp(z) where z = \log(x) is on a regularly spaced grid? So then you can use a method for a regular grid in z,y to interpolate the function B(z,y), from which you can compute A(x,y) = B(e^z, y) and hence \nabla A = ((1/x) \partial B/\partial z, \partial B/\partial y).

Alternatively, whenever your data is on a product of two grids, even if the grids are irregular, you can do a sequence of two 1d interpolations

  1. for each x value construct an interpolant in the y coordinate.
  2. you now have a sequence of interpolation coefficients c (at each x) — interpolate these in the x grid to get an interpolated coefficient c(x).
  3. for any arbitrary (x,y), first interpolate the coefficients c(x) at this x, then use those interpolated coefficients to evaluate at y.