spacepy.pycdf.istp¶
Support for ISTP-compliant CDFs
The ISTP metadata standard specifies the interpretation of the attributes in a CDF to describe relationships between the variables and their physical interpretation.
This module supports that subset of CDFs.
Authors: Jon Niehof
Additional Contributors: Lorna Ellis, Asher Merrill
Institution: University of New Hampshire
Contact: Jonathan.Niehof@unh.edu
Functions
|
Set ISTP-compliant FILLVAL on a variable |
|
Set ISTP-compliant FORMAT on a variable |
|
Set fill values to NaN |
Classes
ISTP compliance checks for a CDF file. |
|
|
Collective handling of ISTP-compliant variable and its dependencies. |
ISTP compliance checks for a single variable. |
- spacepy.pycdf.istp.fillval(v, ret=False)[source]¶
Set ISTP-compliant FILLVAL on a variable
Sets or returns a CDF variable’s FILLVAL attribute to the value required by ISTP (based on variable type).
- Parameters:
- v
Var
CDF variable to update
- v
- Returns:
- various
If
ret
is True, returns the correct value for variable type (which may be of various Python types). Otherwise sets the value and returnsNone
.
- Other Parameters:
- retboolean
If True, return the value instead of setting it (Default False, set).
Examples
>>> import spacepy.pycdf >>> import spacepy.pycdf.istp >>> f = spacepy.pycdf.CDF('foo.cdf', create=True) >>> v = f.new('Var', data=[1, 2, 3]) >>> spacepy.pycdf.istp.fillval(v) >>> v.attrs['FILLVAL'] -128
- spacepy.pycdf.istp.format(v, use_scaleminmax=False, dryrun=False)[source]¶
Set ISTP-compliant FORMAT on a variable
Sets a CDF variable’s FORMAT attribute, which provides a Fortran-like format string that should be useable for printing any valid value in the variable. Sets according to the VALIDMIN/VALIDMAX attributes (or, optionally, SCALEMIN/SCALEMAX) if present, otherwise uses the full range of the type.
- Parameters:
- v
Var
Variable to update
- use_scaleminmaxbool, optional
Use SCALEMIN/MAX instead of VALIDMIN/MAX (default False). Note: istpchecks may complain about result.
- dryrunbool, optional
Print the decided format to stdout instead of modifying the CDF (for use in command-line debugging) (default False).
- v
Examples
>>> import spacepy.pycdf >>> import spacepy.pycdf.istp >>> f = spacepy.pycdf.CDF('foo.cdf', create=True) >>> v = f.new('Var', data=[1, 2, 3]) >>> spacepy.pycdf.istp.format(v) >>> v.attrs['FORMAT'] 'I4'
- spacepy.pycdf.istp.nanfill(v)[source]¶
Set fill values to NaN
Finds all values which are equal to
FILLVAL
, greater thanVALIDMAX
, or less thanVALIDMIN
, and replace withNaN
(not-a-number). This is an update-in-place operation; does not return a copy.Assumes a single value for
VALIDMIN
,VALIDMAX
,FILLVAL
(although if the attribute is not present, will simply assume no restriction.)Only applicable to floating-point types. Best applied to a
VarCopy
ordmarray
rather thanVar
. Updating a variable in a CDF requires one write per changed value, and also will result in a CDF that is no longer ISTP compliant.Because of floating-point comparison, the matching to
FILLVAL
may fail.Examples
>>> import spacepy.pycdf >>> import spacepy.pycdf.istp >>> f = spacepy.pycdf.CDF('foo.cdf', create=True) >>> v = f.new('Var', data=[1, 2, 3, -1e31]) >>> spacepy.pycdf.istp.fillval(v) >>> data = v.copy() >>> data VarCopy([1., 2., 3., -1.e31], dtype=float32) >>> spacepy.pycdf.istp.nanfill(data) >>> data VarCopy([1., 2., 3., nan], dtype=float32)