tsdat.utils.converters
¶
Module Contents¶
Classes¶
Base class for converting data arrays from one units to another. |
|
Default class for converting units on data arrays. This class utilizes |
|
Convert a time string to a np.datetime64, which is needed for xarray. |
|
Convert a numeric UTC timestamp to a np.datetime64, which is needed for |
-
class
tsdat.utils.converters.
Converter
(parameters={})¶ Bases:
abc.ABC
Base class for converting data arrays from one units to another. Users can extend this class if they have a special units conversion for their input data that cannot be resolved with the default converter classes.
- Parameters
parameters (dict, optional) – A dictionary of converter-specific parameters which get passed from the pipeline config file. Defaults to {}
-
abstract
run
(self, data: numpy.ndarray, in_units: str, out_units: str) → numpy.ndarray¶ Convert the input data from in_units to out_units.
- Parameters
data (np.ndarray) – Data array to be modified.
in_units (str) – Current units of the data array.
out_units (str) – Units to be converted to.
- Returns
Data array converted into the new units.
- Return type
np.ndarray
-
class
tsdat.utils.converters.
DefaultConverter
(parameters={})¶ Bases:
Converter
Default class for converting units on data arrays. This class utilizes ACT.utils.data_utils.convert_units, and should work for most variables except time (see StringTimeConverter and TimestampTimeConverter)
-
run
(self, data: numpy.ndarray, in_units: str, out_units: str) → numpy.ndarray¶ Convert the input data from in_units to out_units.
- Parameters
data (np.ndarray) – Data array to be modified.
in_units (str) – Current units of the data array.
out_units (str) – Units to be converted to.
- Returns
Data array converted into the new units.
- Return type
np.ndarray
-
-
class
tsdat.utils.converters.
StringTimeConverter
(parameters={})¶ Bases:
Converter
Convert a time string to a np.datetime64, which is needed for xarray. This class utilizes pd.to_datetime to perform the conversion.
One of the parameters should be ‘time_format’, which is the the strftime to parse time, eg “%d/%m/%Y”. Note that “%f” will parse all the way up to nanoseconds. See strftime documentation for more information on choices.
- Parameters
parameters (dict, optional) – dictionary of converter-specific parameters. Defaults to {}.
-
run
(self, data: numpy.ndarray, in_units: str, out_units: str) → numpy.ndarray¶ Convert the input data from in_units to out_units.
- Parameters
data (np.ndarray) – Data array to be modified.
in_units (str) – Current units of the data array.
out_units (str) – Units to be converted to.
- Returns
Data array converted into the new units.
- Return type
np.ndarray
-
class
tsdat.utils.converters.
TimestampTimeConverter
(parameters={})¶ Bases:
Converter
Convert a numeric UTC timestamp to a np.datetime64, which is needed for xarray. This class utilizes pd.to_datetime to perform the conversion.
One of the parameters should be ‘unit’. This parameter denotes the time unit (e.g., D,s,ms,us,ns), which is an integer or float number. The timestamp will be based off the unix epoch start.
- Parameters
parameters (dict, optional) – A dictionary of converter-specific parameters which get passed from the pipeline config file. Defaults to {}
-
run
(self, data: numpy.ndarray, in_units: str, out_units: str) → numpy.ndarray¶ Convert the input data from in_units to out_units.
- Parameters
data (np.ndarray) – Data array to be modified.
in_units (str) – Current units of the data array.
out_units (str) – Units to be converted to.
- Returns
Data array converted into the new units.
- Return type
np.ndarray