spacepy.datamodel.ISTPArray

class spacepy.datamodel.ISTPArray[source]

Mixin class for array using ISTP metadata.

Array types like dmarray provide all these methods; they assume attributes of the array use the ISTP metadata standard and are unlikely to give good results if that is not the case.

Note that some operations that may seem to relate to an array (e.g. uncertainties) may require the use of other arrays in a container; these are in ISTPContainer.

Added in version 0.5.0.

__init__(*args, **kwargs)

Methods

fromQuantity(q[, copy])

Convert from Astropy Quantity

plot_as_line()

Determines if this array is better plotted as a lineplot or spectrogram.

replace_invalid()

Return data from array with invalid values replaced by nan.

toQuantity([copy])

Convert to Astropy Quantity

units([fmt])

Finds units of array.

Attributes

classmethod fromQuantity(q, copy=True)[source]

Convert from Astropy Quantity

Converts an Astropy Quantity to an ISTP array. nan are replaced with fill.

Parameters:
qQuantity

Quantity to convert

Returns:
ISTPArray

Array with attributes which can be inferred from input. This may not be fully ISTP-compliant.

Other Parameters:
copybool, default True

Copy data from the Quantity. If False, changes to the Quantity may affect this array. In some cases a copy may be made even if False.

Notes

Added in version 0.6.0.

plot_as_line()[source]

Determines if this array is better plotted as a lineplot or spectrogram.

Uses array shape and the DISPLAY_TYPE attribute to determine if should be plotted as a lineplot (potentially stacked) or spectrogram.

Returns:
bool

True if should be a lineplot, False if should be a spectrogram

Notes

Added in version 0.5.0.

replace_invalid()[source]

Return data from array with invalid values replaced by nan.

Makes a copy of the data and, for any values equal to the FILLLVAL attribute, greater than VALIDMAX, or less than VALIDMIN, replace with NaN.

Returns:
ndarray

Transformed data

See also

pycdf.istp.nanfill

an in-place variant

Notes

Added in version 0.5.0.

Comparisons with FILLVAL are done using isclose and so may replace values that are near, but not identical, to fill.

toQuantity(copy=True)[source]

Convert to Astropy Quantity

Converts this array to an Astropy Quantity. Invalid values are replaced with nan.

Returns:
Quantity

Data from this array interpreted according to its UNITS attribute.

Other Parameters:
copybool, default True

Copy data to the Quantity. If False, changes to the Quantity may affect the source array. In some cases a copy may be made even if False.

Notes

Added in version 0.6.0.

Examples

>>> import spacepy.datamodel
# https://rbsp-ect.newmexicoconsortium.org/data_pub/rbspa/ECT/level2/
>>> data = spacepy.datamodel.fromCDF(
...     'rbspa_ect-elec-L2_20140115_v2.1.0.cdf')
>>> q = data['Position'].toQuantity()
>>> q.to('m')
<Quantity [[-32833200. , -15531762. ,  -6449212. ],
           [-32903586. , -15406271. ,  -6448704.5],
           [-32967848. , -15277711. ,  -6446542.5],
           ...,
           [-20966128. ,   6941849.5,  -2896334.2],
           [-21515586. ,   6858618. ,  -3026324. ],
           [-22047328. ,   6783260.5,  -3153003.5]] m>
units(fmt='minimal')[source]

Finds units of array.

Looks up the unit attribute and performs minor cleanup (including intepreting IDL codes).

Parameters:
fmt{‘minimal’, ‘latex’, ‘astropy’, ‘raw’}

How to format the units: minimal (default) is a minimally-processed rendering, latex is in LaTeX, astropy is meant to give good results when passed to astropy.units.Unit, and raw has no processing. No checks are done on processing for AstroPy or LaTeX, and it should not be assumed they will parse.

Returns:
str

Physical units of this array. None if not present.

Notes

Added in version 0.6.0.

attrs: Mapping