Compute a grid-to-grid linear or nearest interpolation given.
(from_shape, to_shape, trans, order=1, inuse=None)
| 2416 | |
| 2417 | |
| 2418 | def _grid_interp(from_shape, to_shape, trans, order=1, inuse=None): |
| 2419 | """Compute a grid-to-grid linear or nearest interpolation given.""" |
| 2420 | from_shape = np.array(from_shape, int) |
| 2421 | to_shape = np.array(to_shape, int) |
| 2422 | trans = np.array(trans, np.float64) # to -> from |
| 2423 | assert trans.shape == (4, 4) and np.array_equal(trans[3], [0, 0, 0, 1]) |
| 2424 | assert from_shape.shape == to_shape.shape == (3,) |
| 2425 | shape = (np.prod(to_shape), np.prod(from_shape)) |
| 2426 | if inuse is None: |
| 2427 | inuse = np.ones(shape[1], bool) |
| 2428 | assert inuse.dtype == np.dtype(bool) |
| 2429 | assert inuse.shape == (shape[1],) |
| 2430 | data, indices, indptr = _grid_interp_jit(from_shape, to_shape, trans, order, inuse) |
| 2431 | data = np.concatenate(data) |
| 2432 | indices = np.concatenate(indices) |
| 2433 | indptr = np.cumsum(indptr) |
| 2434 | interp = csr_array((data, indices, indptr), shape=shape) |
| 2435 | return interp |
| 2436 | |
| 2437 | |
| 2438 | # This is all set up to do jit, but it's actually slower! |