CDF Reader Class

class cdflib.cdfread.CDF(path, validate=False, string_encoding='ascii', s3_read_method=1)[source][source]

Read a CDF file into the CDF object. This object contains methods to load the cdf file information, variable names, and values.

Example

>>> import cdflib
>>> cdf_file = cdflib.CDF('/path/to/cdf_file.cdf')
>>> cdf_file.cdf_info()
>>> x = cdf_file.varget("NameOfVariable", startrec=0, endrec=150)
Parameters:
  • path (str | Path) –

  • validate (bool) –

  • string_encoding (str) –

  • s3_read_method (int) –

attget(attribute, entry=None)[source][source]

Returns the value of the attribute at the entry number provided.

A variable name can be used instead of its corresponding entry number.

Parameters:
  • attribute (str, int) – Attribute name or number to get.

  • entry (int, optional) –

Return type:

AttData

attinq(attribute)[source][source]

Get attribute information.

Parameters:

attribute (str, int) – Attribute to get information for.

Return type:

ADRInfo

cdf_info()[source][source]

Returns basic CDF information.

Return type:

CDFInfo

globalattsget()[source][source]

Gets all global attributes.

This function returns all of the global attribute entries, in a dictionary (in the form of 'attribute': {entry: value} pairs) from a CDF.

Return type:

Dict[str, List[str | ndarray]]

varattsget(variable)[source][source]

Gets all variable attributes.

Unlike attget, which returns a single attribute entry value, this function returns all of the variable attribute entries, in a dictionary (in the form of ‘attribute’: value pair) for a variable.

Parameters:

variable (str | int) –

Return type:

Dict[str, None | str | ndarray]

varget(variable=None, epoch=None, starttime=None, endtime=None, startrec=0, endrec=None)[source][source]

Returns the variable data.

Parameters:
Return type:

str | ndarray

Notes

Variable can be entered either a name or a variable number. By default, it returns a ‘numpy.ndarray’ or ‘list’ class object, depending on the data type, with the variable data and its specification.

By default, the full variable data is returned. To acquire only a portion of the data for a record-varying variable, either the time or record (0-based) range can be specified. ‘epoch’ can be used to specify which time variable this variable depends on and is to be searched for the time range. For the ISTP-compliant CDFs, the time variable will come from the attribute ‘DEPEND_0’ from this variable. The function will automatically search for it thus no need to specify ‘epoch’. If either the start or end time is not specified, the possible minimum or maximum value for the specific epoch data type is assumed. If either the start or end record is not specified, the range starts at 0 or/and ends at the last of the written data.

The start (and end) time should be presented in a list as: [year month day hour minute second millisec] for CDF_EPOCH [year month day hour minute second millisec microsec nanosec picosec] for CDF_EPOCH16 [year month day hour minute second millisec microsec nanosec] for CDF_TIME_TT2000 If not enough time components are presented, only the last item can have the floating portion for the sub-time components.

Note: CDF’s CDF_EPOCH16 data type uses 2 8-byte doubles for each data value. In Python, each value is presented as a complex or numpy.complex128.

varinq(variable)[source][source]

Get basic variable information.

Return type:

VDRInfo

Parameters:

variable (str) –

vdr_info(variable)[source][source]
Parameters:

variable (str | int) –

Return type:

VDR

Sample Usage

To begin accessing the data within a CDF file, first create a new CDF class. This can be done with the following commands

>>> import cdflib
>>> cdf_file = cdflib.CDF('/path/to/cdf_file.cdf')

Then, you can call various functions on the variable.

For example:

>>> x = cdf_file.varget("NameOfVariable", startrec = 0, endrec = 150)

This command will return all data inside of the variable Variable1, from records 0 to 150.