CDFepoch
- class cdflib.epochs.CDFepoch[source][source]
Bases:
object
Convert between CDF-based epochs, np.datetime64, and Unix time.
- There are three (3) epoch data types in CDF:
1. CDF_EPOCH is milliseconds since Year 0 represented as a single double (float in Python), 2. CDF_EPOCH16 is picoseconds since Year 0 represented as 2-doubles (complex in Python), and 3. CDF_TIME_TT2000 (TT2000 as short) is nanoseconds since J2000 with leap seconds, represented by an 8-byte integer (int in Python).
In Numpy, they are np.float64, np.complex128 and np.int64, respectively. All these epoch values can come from from CDF.varget function.
Example
>>> import cdflib # Convert to an epoch >>> epoch = cdflib.cdfepoch.compute_epoch([2017,1,1,1,1,1,111]) # Convert from an epoch >>> time = cdflib.cdfepoch.to_datetime(epoch) # Or pass epochs via CDF.varget.
Attributes Summary
Methods Summary
breakdown
(epochs)breakdown_epoch
(epochs)Calculate date and time from epochs
breakdown_epoch16
(epochs)Calculate date and time from epochs
breakdown_tt2000
(tt2000)Breaks down the epoch(s) into UTC components.
compute
(datetimes)Computes the provided date/time components into CDF epoch value(s).
compute_epoch
(dates)compute_epoch16
(datetimes)compute_tt2000
(datetimes)encode
(epochs[, iso_8601])Converts one or more epochs into UTC strings.
encode_epoch
(epochs[, iso_8601])encode_epoch16
(epochs[, iso_8601])encode_tt2000
(tt2000[, iso_8601])epochrange_epoch
(epochs[, starttime, endtime])epochrange_epoch16
(epochs[, starttime, endtime])epochrange_tt2000
(epochs[, starttime, endtime])findepochrange
(epochs[, starttime, endtime])Finds the record range within the start and end time from values of a CDF epoch data type.
parse
(value)Parses the provided date/time string(s) into CDF epoch value(s).
timestamp_to_cdfepoch
(unixtime_data)Converts a unix timestamp to CDF_EPOCH, the number of milliseconds since the year 0.
timestamp_to_cdfepoch16
(unixtime_data)Converts a unix timestamp to CDF_EPOCH16
timestamp_to_tt2000
(unixtime_data)Converts a unix timestamp to CDF_TIME_TT2000
to_datetime
(cdf_time)Converts CDF epoch argument to numpy.datetime64.
unixtime
(cdf_time)Converts CDF epoch argument into seconds after 1970-01-01.
Attributes Documentation
- LTS = [[1960, 1, 1, 1.417818, 37300.0, 0.001296], [1961, 1, 1, 1.422818, 37300.0, 0.001296], [1961, 8, 1, 1.372818, 37300.0, 0.001296], [1962, 1, 1, 1.845858, 37665.0, 0.0011232], [1963, 11, 1, 1.945858, 37665.0, 0.0011232], [1964, 1, 1, 3.24013, 38761.0, 0.001296], [1964, 4, 1, 3.34013, 38761.0, 0.001296], [1964, 9, 1, 3.44013, 38761.0, 0.001296], [1965, 1, 1, 3.54013, 38761.0, 0.001296], [1965, 3, 1, 3.64013, 38761.0, 0.001296], [1965, 7, 1, 3.74013, 38761.0, 0.001296], [1965, 9, 1, 3.84013, 38761.0, 0.001296], [1966, 1, 1, 4.31317, 39126.0, 0.002592], [1968, 2, 1, 4.21317, 39126.0, 0.002592], [1972, 1, 1, 10.0, 0.0, 0.0], [1972, 7, 1, 11.0, 0.0, 0.0], [1973, 1, 1, 12.0, 0.0, 0.0], [1974, 1, 1, 13.0, 0.0, 0.0], [1975, 1, 1, 14.0, 0.0, 0.0], [1976, 1, 1, 15.0, 0.0, 0.0], [1977, 1, 1, 16.0, 0.0, 0.0], [1978, 1, 1, 17.0, 0.0, 0.0], [1979, 1, 1, 18.0, 0.0, 0.0], [1980, 1, 1, 19.0, 0.0, 0.0], [1981, 7, 1, 20.0, 0.0, 0.0], [1982, 7, 1, 21.0, 0.0, 0.0], [1983, 7, 1, 22.0, 0.0, 0.0], [1985, 7, 1, 23.0, 0.0, 0.0], [1988, 1, 1, 24.0, 0.0, 0.0], [1990, 1, 1, 25.0, 0.0, 0.0], [1991, 1, 1, 26.0, 0.0, 0.0], [1992, 7, 1, 27.0, 0.0, 0.0], [1993, 7, 1, 28.0, 0.0, 0.0], [1994, 7, 1, 29.0, 0.0, 0.0], [1996, 1, 1, 30.0, 0.0, 0.0], [1997, 7, 1, 31.0, 0.0, 0.0], [1999, 1, 1, 32.0, 0.0, 0.0], [2006, 1, 1, 33.0, 0.0, 0.0], [2009, 1, 1, 34.0, 0.0, 0.0], [2012, 7, 1, 35.0, 0.0, 0.0], [2015, 7, 1, 36.0, 0.0, 0.0], [2017, 1, 1, 37.0, 0.0, 0.0]][source]
- lsfile = <_io.TextIOWrapper name='/home/docs/checkouts/readthedocs.org/user_builds/cdflib/envs/latest/lib/python3.9/site-packages/cdflib/CDFLeapSeconds.txt' mode='r' encoding='UTF-8'>[source]
- month_Token = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'][source]
Methods Documentation
- static breakdown_epoch(epochs)[source][source]
Calculate date and time from epochs
- Parameters:
epochs (int, float, or array-like) – Single, list, tuple, or np.array of epoch values
- Returns:
components – List or array of date and time values. The last axis contains (in order): year, month, day, hour, minute, second, and millisecond
- Return type:
Notes
If a bad epoch (-1.0e31) is supplied, a fill date of 9999-12-31 23:59:59 and 999 ms is returned.
- static breakdown_epoch16(epochs)[source][source]
Calculate date and time from epochs
- Parameters:
epochs (array-like) – Single, list, tuple, or np.array of epoch values
- Returns:
components – List or array of date and time values. The last axis contains (in order): year, month, day, hour, minute, second, millisecond, microsecond, nanosecond, and picosecond
- Return type:
ndarray
Notes
If a bad epoch (-1.0e31 for the real and imaginary components) is supplied, a fill date of 9999-12-31 23:59:59 and 999 ms, 999 us, 999 ns, and 999 ps is returned
- static breakdown_tt2000(tt2000)[source][source]
Breaks down the epoch(s) into UTC components.
Calculate date and time from cdf_time_tt2000 integers
- Parameters:
- Returns:
components – List or array of date and time values. The last axis contains (in order): year, month, day, hour, minute, second, millisecond, microsecond, and nanosecond
- Return type:
ndarray
Notes
If a bad epoch is supplied, a fill date of 9999-12-31 23:59:59 and 999 ms, 999 us, and 999 ns is returned.
- static compute(datetimes)[source][source]
Computes the provided date/time components into CDF epoch value(s).
- For CDF_EPOCH:
For computing into CDF_EPOCH value, each date/time elements should have exactly seven (7) components, as year, month, day, hour, minute, second and millisecond, in a list. For example: [[2017,1,1,1,1,1,111],[2017,2,2,2,2,2,222]] Or, call function compute_epoch directly, instead, with at least three (3) first (up to seven) components. The last component, if not the 7th, can be a float that can have a fraction of the unit.
- For CDF_EPOCH16:
They should have exactly ten (10) components, as year, month, day, hour, minute, second, millisecond, microsecond, nanosecond and picosecond, in a list. For example: [[2017,1,1,1,1,1,123,456,789,999],[2017,2,2,2,2,2,987,654,321,999]] Or, call function compute_epoch directly, instead, with at least three (3) first (up to ten) components. The last component, if not the 10th, can be a float that can have a fraction of the unit.
- For TT2000:
Each TT2000 typed date/time should have exactly nine (9) components, as year, month, day, hour, minute, second, millisecond, microsecond, and nanosecond, in a list. For example: [[2017,1,1,1,1,1,123,456,789],[2017,2,2,2,2,2,987,654,321]] Or, call function compute_tt2000 directly, instead, with at least three (3) first (up to nine) components. The last component, if not the 9th, can be a float that can have a fraction of the unit.
- static encode(epochs, iso_8601=True)[source][source]
Converts one or more epochs into UTC strings. The input epoch format is deduced from the argument type.
- Parameters:
epochs (int, float, list, complex) – One or more ECD epochs in one of three formats: 1. CDF_EPOCH: The input should be either a float or list of floats (in numpy, a np.float64 or a np.ndarray of np.float64) 2. CDF_EPOCH16: The input should be either a complex or list of complex(in numpy, a np.complex128 or a np.ndarray of np.complex128) 3. TT2000: The input should be either a int or list of ints (in numpy, a np.int64 or a np.ndarray of np.int64)
iso_8601 (bool) – The return time format. If ISO 8601 is True, the format is, for example, 2008-02-02T06:08:10.10.012014016, otherwise the format is 02-Feb-2008 06:08:10.012.014.016.
- Return type:
- static epochrange_epoch(epochs, starttime=None, endtime=None)[source][source]
- Parameters:
epochs (int | int64 | float | float64 | complex | complex128 | List[int] | List[int64] | List[float] | List[float64] | List[complex] | List[complex128] | ndarray[Any, dtype[_ScalarType_co]])
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:
- static epochrange_epoch16(epochs, starttime=None, endtime=None)[source][source]
- Parameters:
epochs (complex | complex128 | List[complex] | ndarray[Any, dtype[complex128]])
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:
ndarray | None
- static epochrange_tt2000(epochs, starttime=None, endtime=None)[source][source]
- Parameters:
epochs (int | int64 | List[int] | ndarray[Any, dtype[int64]])
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:
- static findepochrange(epochs, starttime=None, endtime=None)[source][source]
Finds the record range within the start and end time from values of a CDF epoch data type. It returns a list of record numbers. If the start time is not provided, then it is assumed to be the minimum possible value. If the end time is not provided, then the maximum possible value is assumed. The epoch is assumed to be in the chronological order. The start and end times should have the proper number of date/time components, corresponding to the epoch’s data type.
The start/end times should be in either be in epoch units, or in the list format described in “compute_epoch/epoch16/tt2000” section.
- Parameters:
epochs (str | List[float] | List[int] | List[complex] | Tuple[float, ...] | Tuple[int, ...] | Tuple[complex, ...] | ndarray)
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:
- static parse(value)[source][source]
Parses the provided date/time string(s) into CDF epoch value(s).
- For CDF_EPOCH:
The string has to be in the form of ‘dd-mmm-yyyy hh:mm:ss.xxx’ or ‘yyyy-mm-ddThh:mm:ss.xxx’ (in iso_8601). The string is the output from encode function.
- For CDF_EPOCH16:
The string has to be in the form of ‘dd-mmm-yyyy hh:mm:ss.mmm.uuu.nnn.ppp’ or ‘yyyy-mm-ddThh:mm:ss.mmmuuunnnppp’ (in iso_8601). The string is the output from encode function.
- For TT2000:
The string has to be in the form of ‘dd-mmm-yyyy hh:mm:ss.mmm.uuu.nnn’ or ‘yyyy-mm-ddThh:mm:ss.mmmuuunnn’ (in iso_8601). The string is the output from encode function.
- static timestamp_to_cdfepoch(unixtime_data)[source][source]
Converts a unix timestamp to CDF_EPOCH, the number of milliseconds since the year 0.
- static timestamp_to_cdfepoch16(unixtime_data)[source][source]
Converts a unix timestamp to CDF_EPOCH16
- static timestamp_to_tt2000(unixtime_data)[source][source]
Converts a unix timestamp to CDF_TIME_TT2000
- classmethod to_datetime(cdf_time)[source][source]
Converts CDF epoch argument to numpy.datetime64.
- Parameters:
cdf_time (int | int64 | float | float64 | complex | complex128 | List[int] | List[int64] | List[float] | List[float64] | List[complex] | List[complex128] | ndarray[Any, dtype[_ScalarType_co]]) – NumPy scalar/arrays to convert. np.int64 will be converted to cdf_tt2000, np.complex128 will be converted to cdf_epoch16, and floats will be converted to cdf_epoch.
- Return type:
Notes
Because of datetime64 limitations, CDF_EPOCH16 precision is only kept to the nearest nanosecond.