ndarray_linear_interpolation#

regridding.ndarray_linear_interpolation(a, indices, axis=None, axis_indices=None)[source]#

Interpolate a numpy.ndarray onto a new grid.

Similar to scipy.ndimage.map_coordinates(), but allows for interpolation along only some of the axes of a.

Parameters:
  • a (ndarray) – The input array to be interpolated. Should have at least as many axes as len(indices)

  • indices (tuple[ndarray, ...]) – The new indices where a will be evaluated. The number of indices, len(indices) should be equal to the number of interpolation axes, len(axis)

  • axis (None | int | tuple[int, ...]) – The axes of a to interpolate. If None, interpolate over all the axes of a.

  • axis_indices (None | int | tuple[int, ...]) – The axes of indices that are complementary to the axes in axis. If None, all axes of indices are complementary to the axes in axis.

Return type:

The interpolated array

Examples

import numpy as np
import matplotlib.pyplot as plt
import regridding

x = np.arange(5)
y = np.arange(6)

Interpolate a 1D array

a = x * x

x_new = np.linspace(0, x.size - 1, num=20)
a_new = regridding.ndarray_linear_interpolation(a, indices=(x_new, ))

plt.figure(figsize=(6, 3));
plt.scatter(x, a, s=100, label="original", zorder=1);
plt.scatter(x_new, a_new, label="interpolated", zorder=0);
plt.legend();
../_images/regridding.ndarray_linear_interpolation_1_0.png