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)
- 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.
- 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.
- 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.
- varget(variable=None, epoch=None, starttime=None, endtime=None, startrec=0, endrec=None)[source][source]
Returns the variable data.
- Parameters:
variable (str) – Variable name to fetch.
startrec (int) – Index of the first record to get.
endrec (int) – Index of the last record to get. All records from startrec to endrec inclusive are fetched.
epoch (str | None)
starttime (int | int64 | float | float64 | complex | complex128 | List[int] | List[int64] | List[float] | List[float64] | List[complex] | List[complex128] | ndarray[Any, dtype[_ScalarType_co]] | None)
endtime (int | int64 | float | float64 | complex | complex128 | List[int] | List[int64] | List[float] | List[float64] | List[complex] | List[complex128] | ndarray[Any, dtype[_ScalarType_co]] | None)
- Return type:
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.
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.