RegularGrid

Module for higher order interpolation on regular grids

RegularGrid

Multidimensional interpolator on regular grids.

RegularGrid.get_grid_axes

Calculates the grid axes from a meshed grid and re-orders the values so they fit on a mesh generated with numpy.meshgrid(ax1, ax2, …, axn, indexing=”ij”)

RegularGrid.fit

Construct the interpolator given points and values.

RegularGrid.predict

Evaluate interpolator at given new_point, can be multiple points.

class RegularGrid[source]

Bases: ezyrb.approximation.approximation.Approximation

Multidimensional interpolator on regular grids. See also scipy’s RegularGridInterpolator for information on kwargs.

Parameters
  • points (array_like) – the coordinates of the points on a regular grid.

  • values (array_like) – The (vector-) data on the regular grid in n dimensions.

Example
>>> import ezyrb
>>> import numpy as np
>>> def f(x, y, z):
...     return 2 * x**3 + 3 * y**2 - z
>>> x = np.linspace(1, 4, 11)
>>> y = np.linspace(4, 7, 22)
>>> z = np.linspace(7, 9, 33)
>>> xg, yg, zg = np.meshgrid(x, y, z, indexing='ij')
>>> points = np.c_[xg.ravel(), yg.ravel(), zg.ravel()]
>>> data_mode_x = f(xg, yg, zg).reshape(-1, 1)
# lets assume we have 2 modes, i.e. a rank 2 model
>>> data = np.concatenate((data_mode_x, data_mode_x/10), axis=1)
>>> rgi = ezyrb.RegularGrid()
>>> rgi.fit(points, data, method="linear")
>>> pts = np.array([[2.1, 6.2, 8.3],
...                 [3.3, 5.2, 7.1],
...                 [1., 4., 7.],
...                 [4., 7., 9.]])
>>> rgi.predict(pts)
array([[125.80469388,  12.58046939],
       [146.30069388,  14.63006939],
       [ 43.        ,   4.3       ],
       [266.        ,  26.6       ]])
>>> f(pts[:, 0], pts[:, 1], pts[:, 2])
array([125.542, 145.894,  43.   , 266.   ])
>>> f(pts[:, 0], pts[:, 1], pts[:, 2])/10
array([12.5542, 14.5894,  4.3   , 26.6   ])
_abc_impl = <_abc_data object>
fit(points, values, **kwargs)[source]

Construct the interpolator given points and values. Assumes that the points are on a regular grid, fails when not. see scipy.interpolate.RegularGridInterpolator

Parameters
  • points (array_like) – the coordinates of the points.

  • values (array_like) – the values in the points.

get_grid_axes(pts_scrmbld, vals_scrmbld)[source]

Calculates the grid axes from a meshed grid and re-orders the values so they fit on a mesh generated with numpy.meshgrid(ax1, ax2, …, axn, indexing=”ij”)

Parameters
  • pts_scrmbld (array_like) – the coordinates of the points.

  • vals_scrmbld (array_like) – the (vector-)values in the points.

Returns

The grid axes given as a tuple of ndarray, with shapes (m1, ), …, (mn, ) and values mapped on the ordered grid.

Return type

(list, numpy.ndarray)

predict(new_point)[source]

Evaluate interpolator at given new_point, can be multiple points.

Parameters

new_point (array_like) – the coordinates of the given point(s).

Returns

the interpolated values.

Return type

numpy.ndarray