Skip to content

Instantly share code, notes, and snippets.

@denis-bz
Last active August 29, 2015 14:17
Show Gist options
  • Save denis-bz/da098bd8baee7f339e68 to your computer and use it in GitHub Desktop.
Save denis-bz/da098bd8baee7f339e68 to your computer and use it in GitHub Desktop.
Interpolation between order 1 (bilinear, trilinear ...) and order 0 (nearest corner) on a box grid

Mixed order interpolation

Interpolating e.g. wind or water temperature on a box grid in d dimensions usually looks at (order+1)^d neighbors of each point. Order 1, bilinear trilinear ... looks at all 2^d corners of the box around each data point; 2^d grows pretty fast. Order 0, though, looks at only 1 the nearest corner, so is blocky, discontinuous at box edges.

What's in between ? A simple method is

  • linear interpolate in one coordinate, e.g. that nearest the middle of the box
  • order 0, nearest corner, for the rest.

For example, if 0 <= x_0 <= x_1 ... <= x_mid <= 1/2 in the unit cube, linear-interpolate

(1 - x_mid) * f( 0 0 ... 0 )  + x_mid * f( 0 0 ... 1 )

Other mixed-orders are obvious. In particular, one can find the nearest few corners of a cube in R^d quickly, and mix order-1 "few", order-0 the rest.

In practice, data in >= 5d is usually scattered, not on a box grid. And for box grids in 5d, Intergrid or scipy RegularGridInterpolator should be plenty fast.

Comments welcome, test cases most welcome.

cheers
-- denis-bz-py \at t-online \dot de

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