spacepy.pycdf¶
Interface to the Common Data Format (CDF) library
CDF available at http://cdf.gsfc.nasa.gov/.
The interface is intended to be ‘pythonic’ rather than reproducing the
C interface. To open or close a CDF and access its variables, see the CDF
class. Accessing data within the variables is via the Var
class. The lib
object provides access to some routines
that affect the functionality of the library in general. The
const
module contains constants useful for accessing
the underlying library.
The CDF C library must be properly installed in order to use this module. Installing SpacePy from a binary installation provides this requirement.
The CDF distribution provides scripts meant to be called in a user’s
login scripts, definitions.B
for bash and definitions.C
for
C-shell derivatives. (See the installation instructions which come
with the CDF library.) These will set environment variables
specifying the location of the library; pycdf will respect these
variables if they are set. Otherwise it will search the standard
system library path and the default installation locations for the CDF
library, falling back to the version shipped with the SpacePy binary
if the library is not found.
If pycdf has trouble finding the library, try setting CDF_LIB
before importing
the module, e.g. if the library is in CDF/lib
in the user’s home directory:
>>> import os
>>> os.environ["CDF_LIB"] = "~/CDF/lib"
>>> from spacepy import pycdf
If this works, make the environment setting permanent. Note that on OSX,
using plists to set the environment may not carry over to Python terminal
sessions; use .cshrc
or .bashrc
instead.
Authors: Jon Niehof
Institution: University of New Hampshire
Contact: Jonathan.Niehof@unh.edu
For additional documentation pycdf - Python interface to CDF files
Copyright 2010-2015 Los Alamos National Security, LLC.
Submodules
Various constants defined in cdf.h and used in pycdf. |
|
Support for ISTP-compliant CDFs |
Functions
|
Concatenate data from multiple CDFs |
Classes
|
An attribute, g or z, for a CDF |
|
Object representing a list of attributes. |
|
Python object representing a CDF file. |
|
A dictionary-like copy of all data and attributes in a |
|
Abstraction of the base CDF C library and its state. |
|
A CDF variable. |
|
A list-like copy of the data and attributes in a |
|
Global Attribute for a CDF |
|
Object representing all the gAttributes in a CDF. |
|
zAttribute for zVariables within a CDF. |
|
Object representing all the zAttributes in a zVariable. |
Attributes
Exceptions
|
Raised for an error in the CDF library. |
|
Base class for errors or warnings in the CDF library. |
|
Used for a warning in the CDF library. |
Used for errors in epoch routines |
- spacepy.pycdf.concatCDF(cdfs, varnames=None, raw=False)[source]¶
Concatenate data from multiple CDFs
Reads data from all specified CDFs in order and returns as if they were from a single CDF. The assumption is that the CDFs all have the same structure (same variables, each with the same dimensions and variance.)
- Parameters:
- cdfslist of
Var
Open CDFs, will be read from in order. Must be a list (cannot be an iterable, as all files need to be open).
- varnameslist of str
Names of variables to read (default: all variables in first CDF)
- rawbool
If True, read variables as raw (don’t convert epochs, etc.) Default False.
- cdfslist of
- Returns:
SpaceData
data concatenated from each CDF, with all attributes from first. Non-record-varying data is also only from first, and record variance is only checked on the first!
Examples
Read all data from all CDFs in the current directory. Note that CDFs are closed when their variable goes out of scope.
>>> import glob >>> import spacepy.pycdf >>> data = spacepy.pycdf.concatCDF([ ... spacepy.pycdf.CDF(f) for f in glob.glob('*.cdf')])
- exception spacepy.pycdf.CDFException(status)[source]¶
Base class for errors or warnings in the CDF library.
Not normally used directly, but in subclasses
CDFError
andCDFWarning
.Error messages provided by this class are looked up from the underlying C library.
- spacepy.pycdf.lib = <spacepy.pycdf.Library object>¶
Module global library object.
Initalized at module load time so all classes have ready access to the CDF library and a common state. E.g:
>>> from spacepy import pycdf >>> pycdf.lib.version (3, 3, 0, ' ')