numpyExt module

Extensions to NumPy used by several programs.

Module author: Michael S. Chapman <chapmami@ohsu.edu>

Module author: Brynmor K. Chapman

Authors:

Michael S. Chapman <chapmami@ohsu.edu>,

Oregon Health & Science University

Version:

0.5, March 23, 2016

Changed in version 04/25/13.

Changed in version 0.5.0: (5/1/15) ReStructured Text documentation

class numpyExt.Flagged

Bases: numpy.ma.core.MaskedArray, object

Array with elements designated to be used (or skipped).

Subclass of NumPy.MaskedArray with extensions to support assignment, selection and iteration over elements designated as used (or masked). Note: use is an added antonym for mask, i.e. its complement.

The most succinct way to (in)activate elements in an existing instance f, is with the assignments: f[slice] = f.inactive eg. f[:3] = f.inactive, and: f[slice] = f.data[slice]. These are variants of the recommendations for MaskedArray (masking with special assignment to numpy.ma.masked), noting an important difference. In a masked array, the presumption is that masked elements are invalid data and can be reactivated by assignment to any valid value. In Flagged, there is no such presumption, and previously inactivated elements may be needed again, so the activating assignment should always assign to the corresponding element(s) of the data attribute.

Warning

an assignment to an inactive element makes it active, eg. instance[i] = 2, activates element i! To avoid this, assign instance.data[i].

inactive = masked
iteritems()

Index and value for each used element.

Returns:(index, value).
Return type:tuple(int, float)
set_unused_values(values)

Set only used elements to value(s).

Parameters:values – sequence or single value to broadcast.
Returns:self with reassigned elements.
Return type:Masked
set_used_values(values)

Set only used elements to value(s).

Parameters:values – sequence or single value to broadcast.
Returns:self with reassigned elements.
Return type:Masked
skip

Logical array denoting unused elements (ndarray(dtype=bool)).

skipped

Indices of unused elements (ndarray, or tuple of ndarray for multidimensional).

use

Logical array denoting used elements (ndarray(dtype=bool)).

used

Indices of used elements (ndarray, or tuple of ndarray for multidimensional).

value

View of used data, containing only elements in use (ndarray(ndim=1).

numpyExt.testFlagged()