nantrim

sofia_redux.toolkit.utilities.func.nantrim(xin, flag=0, trim=False, bounds=False)[source]

Derive a mask to trim NaNs from an array

Parameters:
xinarray_like of float (shape)

The n-D array to be trimmed

flagint, optional

0 -> trailing NaNs are removed 1 -> leading NaNs are removed 2 -> leading and trailing NaNs are removed 3 -> all NaNs are removed

trimbool, optional

If True, apply the mask and return the trimmed array. Note that if flag == 3, the returned array will be flattened. Overidden by bounds.

boundsbool, optional

If True, return the start and end index points for each dimension of xin. The output array shape will be (2, ndim) where result[0, 1] would give the start index of the second dimension and result[1, 1] would give the end index of the second dimension. Note that end points give the indices one would supply to slices, i.e. an endpoint of 10 would mean indices < 10 are valid, but one should trim indices >= 10. Bounds overrides trim

Returns:
numpy.ndarray

A bool array (shape) where True indicates an element to keep, and False indicates a value to remove. If trim is set to True then the output will be a copy of the trimmed array.