pds4_tools.reader.data module

Classes

PDS_array(data[, meta_data, masked])

A factory and helper class to work with PDS_ndarray and PDS_marray.

PDS_ndarray(data[, meta_data])

PDS ndarray, enabling some record array functionality and having a meta_data attribute.

PDS_marray(data[, meta_data])

PDS masked array, enabling some record array functionality and having a meta_data attribute.

Details

class PDS_array(data, meta_data=None, masked=None, **options)[source]

Bases: object

A factory and helper class to work with PDS_ndarray and PDS_marray.

Intended such that PDS_ndarray and PDS_marray never need to be separately imported or called, and rather that all initialization and type checking should go through this helper class.

classmethod get_array(masked)[source]

Obtain a PDS array type.

Parameters
maskedbool

If True, a PDS array class subclassing np.ma.MaskedArray is returned. Otherwise a PDS array class subclassing the regular np.ndarray is returned.

Returns
PDS_ndarray or PDS_marray

A PDS array class. See masked.

static get_ndarray()[source]
Returns
PDS_ndarray

A PDS array class based on np.ndarray.

static get_marray()[source]
Returns
PDS_marray

A PDS array class based on np.ma.MaskedArray.

classmethod isinstance(input)[source]
Parameters
inputany
Returns
bool

True if input is an instance of PDS_ndarray or PDS_marray. False otherwise.

class PDS_ndarray(data, meta_data=None, **options)[source]

Bases: numpy.ndarray

PDS ndarray, enabling some record array functionality and having a meta_data attribute.

Subclasses ndarrays such that we can provide meta data for an individual array or table field.

Inherits all Attributes from np.ndarray.

Parameters
dataarray_like

Data for the array.

meta_dataMeta_ArrayStructure or Meta_Field, optional

Meta-data for the array.

optionsdict, optional

NumPy keywords to pass to the np.ndarray initializer.

Attributes
meta_dataMeta_ArrayStructure, Meta_Field or None

Meta-data for the array. Defaults to None if no meta-data was given on initialization or has been set.

copy(order='C')[source]

Copy the array.

Parameters
order{‘C’, ‘F’, ‘A’, ‘K’}, optional

Controls the memory layout of the copy. ‘C’ means C-order, ‘F’ means F-order, ‘A’ means ‘F’ if a is Fortran contiguous, ‘C’ otherwise. ‘K’ means match the layout of a as closely as possible.

Returns
PDS_ndarray

An array with both the data and meta data copied.

field(key, val=None)[source]

Get or set data for a single field.

Parameters
keyint or str

Key to select the field on. Either the name of the field, or its index.

valany, optional

If given, sets the field specified by key to have value of val.

Returns
any or None

A view of the selected field, if val is None. Otherwise returns None.

set_field(data, meta_data, name=None)[source]

Set data and meta data for a single field.

Parameters
dataany

Data to set for the field.

meta_dataMeta_Field

Meta data to set for the field. If name is None, then the field name to set data for will be pulled from this attribute.

namestr, optional

The name of the field to set data for.

Returns
None
class PDS_marray(data, meta_data=None, **options)[source]

Bases: numpy.ma.core.MaskedArray, pds4_tools.reader.data.PDS_ndarray

PDS masked array, enabling some record array functionality and having a meta_data attribute.

Subclasses np.ma.MaskedArray such that we can provide meta data for an individual array or table field.

Inherits all Attributes from np.ma.MaskedArray.

Parameters
dataarray_like

Data for the array.

meta_dataMeta_ArrayStructure or Meta_Field, optional

Meta-data for the array.

optionsdict, optional

NumPy keywords to pass to the np.ndarray initializer.

Attributes
meta_dataMeta_ArrayStructure, Meta_Field or None

Meta-data for the array. Defaults to None if no meta-data was given on initialization or has been set.

view(dtype=None, type=None, fill_value=None)[source]

Return a view of the PDS_marray data.

Subclassed to fix a NumPy bug that breaks setting fill_value when subselecting a field from a structured array.

filled(fill_value=None)[source]

Return a copy of self, with masked values filled with a given value.

Parameters
fill_valuescalar, optional

The value to use for invalid entries. If None, the fill_value attribute of the array is used instead. Defaults to None.

Returns
PDS_ndarray

A copy of self with invalid entries replaced by fill_value.

compressed()[source]

Return a copy of all the non-masked data as a 1-D array.

Returns
PDS_ndarray

A new array holding the non-masked data is returned.

copy(order='C')[source]

Copy the array.

Parameters
order{‘C’, ‘F’, ‘A’, ‘K’}, optional

Controls the memory layout of the copy. ‘C’ means C-order, ‘F’ means F-order, ‘A’ means ‘F’ if a is Fortran contiguous, ‘C’ otherwise. ‘K’ means match the layout of a as closely as possible.

Returns
PDS_marray

An array with both the data and meta data copied.

property fill_value

The filling value of the masked array is a scalar. When setting, None will set to a default based on the data type.

Examples

>>> for dt in [np.int32, np.int64, np.float64, np.complex128]:
...     np.ma.array([0, 1], dtype=dt).get_fill_value()
...
999999
999999
1e+20
(1e+20+0j)
>>> x = np.ma.array([0, 1.], fill_value=-np.inf)
>>> x.fill_value
-inf
>>> x.fill_value = np.pi
>>> x.fill_value
3.1415926535897931 # may vary

Reset to default:

>>> x.fill_value = None
>>> x.fill_value
1e+20
set_fill_value(value=None)[source]

Set the filling value.

Parameters
valuescalar, optional

A value used to fill the invalid entries of the masked array.

Returns
None
set_field(data, meta_data, name=None)[source]

Set data and meta data for a single field.

Parameters
dataany

Data to set for the field.

meta_dataMeta_Field

Meta data to set for the field. If name is None, then the field name to set data for will be pulled from this attribute.

namestr, optional

The name of the field to set data for.

Returns
None