Interpolate

class sofia_redux.toolkit.interpolate.interpolate.Interpolate(*args, method=None, cval=nan, cubic=None, ignorenans=True, error=None, mode='constant')[source]

Bases: object

Fast interpolation on a regular grid

Much like scipy.interpolate.RegularGridInterpolator except better. Allows for cubic interpolation, omission of grid coordinates, and NaN handling.

Parameters:
argsarray_like or tuple of array_like

Either a single array whose coordinates will be determined by the features, or arrays of independent values followed by the dependent values.

methodstr, optional

One of {‘linear’, ‘cubic’, ‘nearest’}

cubicfloat, optional

Defines the value of “a” below for the fast approximation of the bicubic interpolator. a = -0.5 produces third order convergence with respect to the sampling interval. The convolution weights are defined as:

w(x) = (a+2)|x|^3 - (a+3)|x|^2 + 1 for |x|<=1,

       a|x|^3 - 5a|x|^2 + 8a|x| - 4a for 1<|x|<2,

       0 otherwise

If method is None, setting cubic to a float will result in cubic interpolation using the above weightings in each dimension. The default value for cubic is -0.5.

modestr, optional

One of {‘nearest’, ‘reflect’, ‘mirror’, ‘wrap’, ‘constant’} which determines how edge conditions are handled when the interpolation kernel overlaps a border. Valid values and behaviours are as follows:

  • ‘nearest’ (a a a a | a b c d | d d d d): The input is extended by replicating the last pixel

  • ‘reflect’ (d c b a | a b c d | d c b a): The input is extended by reflecting about the edge of the last pixel.

  • ‘mirror’ (d c b | a b c d | c b a): The input is extended by reflecting about the center of last pixel.

  • ‘wrap’ (a b c d | a b c d | a b c d): The input is extended by wrapping around the opposite edge.

  • constant (k k k k | a b c d | k k k k):

    The input is extended by filling all values beyond the edge with the same constant value defined by the cval parameter.

cvalfloat, optional

The value used to fill values when mode is ‘constant’.

ignorenansbool, optional

If True, NaNs will be ignored in all calculations where possible.

Methods Summary

__call__(*args[, method, cubic, mode])

Interpolation at coordinates.

cubic_weights(distances[, a])

parse_arguments(*args[, error])

Parse initialization arguments.

set_values(values)

Reset the interpolation values only.

set_values_and_error(values[, error])

Set new interpolating values and error.

Methods Documentation

__call__(*args, method=None, cubic=None, mode=None)[source]

Interpolation at coordinates.

Parameters:
argsarray_like or tuple of array_like

The coordinates to sample the gridded data at. The order of features follow the ‘xy’ rather than ‘ij’ convention. For example, arguments for two-dimensional data should be supplied in the order (x, y).

methodstr

The method of interpolation to perform. One of {‘linear’, ‘cubic’, ‘nearest’}.

static cubic_weights(distances, a=-0.5)[source]
parse_arguments(*args, error=None)[source]

Parse initialization arguments.

Parameters:
argsarray_like or tuple of array_like

Either a single array whose coordinates will be determined by the features, or arrays of independent values followed by the dependent values.

errornumpy.ndarray, optional

The associated error values for the data.

Returns:
None
set_values(values)[source]

Reset the interpolation values only.

Parameters:
valuesnumpy.ndarray, optional

The new values to set. Must be the same shape as the interpolation grid.

Returns:
None
set_values_and_error(values, error=None)[source]

Set new interpolating values and error.

Parameters:
valuesnumpy.ndarray (int or float)

The new values to set. Must be the same shape as the interpolation grid.

errornumpy.ndarray (int or float), optional

Optional error values to set.

Returns:
None