map_coordinates

sofia_redux.toolkit.image.utilities.map_coordinates(data, coordinates, order=3, mode='constant', cval=nan, output=None, clip=True, threshold=0.5)[source]

A drop in replacement for ndimage.map_coordinates().

This function has been modified to handle NaN cval values with the ‘constant’ mode. The original method results in inconsistent results and occasionally fills the output with all NaN values.

The array of coordinates is used to find, for each point in the output, the corresponding coordinates in the input. The value of the input at those coordinates is determined by spline interpolation of the requested order.

The shape of the output is derived from that of the coordinate array by dropping the first axis. The values of the array along the first axis are the coordinates in the input array at which the output value is found.

Parameters:
datanumpy.ndarray

The data array to map with n_dimensions dimensions with a size of N.

coordinatesnumpy.ndarray

The coordinates at which data is evaluated. Must be of shape (n_dimensions, N) or (n_dimensions, shape,) where product(shape) = N. Dimensions are ordered using the Numpy (y, x) convention.

orderint, optional

The order of the spline interpolation. Must be in the range 0-5.

modestr, optional

Can take values of {‘constant’, ‘edge’, ‘symmetric’, ‘reflect’, ‘wrap’} for which points outside the boundaries of the input are filled according to the given mode. Modes match the behaviour of np.pad().

cvalfloat, optional

Used in conjunction with mode ‘constant’, the value outside the image boundaries.

outputnumpy.ndarray, optional

The output array to fill with the results. Should generally be the same shape as data.

clipbool, optional

Whether to clip the output to the range of values of the input image. This is enabled by default, since higher order interpolation may produce values outside the given input range.

thresholdfloat, optional

Used in conjunction with cval`=NaN and `mode`='constant'.  Should generally take values in the range -1 to 1 with a default of 0.5. This is used to better apply NaN `cval boundaries as expected. Points inside the boundaries are mapped to 1, and values outside are mapped to -1. Points which map to values >= threshold are considered valid, while others will be set to NaN in the output.

Returns:
mapped_coordinatesnumpy.ndarray

The result of transforming the data. The shape of the output is derived from that of coordinates by dropping the first axis, or via output.