tsdat.io.converters
¶
Classes¶
Converts date strings into datetime64 data, accounting for the input format and |
|
Converts the units of a retrieved variable to the units specified by the variable’s |
-
class
tsdat.io.converters.
StringToDatetime
[source]¶ Bases:
tsdat.io.base.DataConverter
Converts date strings into datetime64 data, accounting for the input format and timezone.
- Parameters
format (Optional[str]) – The format of the string data. See strftime.org for more
on what components can be used. If None (information) –
try to interpret the format and convert it automatically. This can be unsafe (will) –
is not explicitly prohibited (but) –
a warning is issued if format is not set (so) –
explicitly. –
timezone (Optional[str]) – The timezone of the input data. If not specified it is
to be UTC. (assumed) –
to_datetime_kwargs (Dict[str, Any]) – A set of keyword arguments passed to the
function as keyword arguments. Note that 'format' is (pandas.to_datetime()) –
included as a keyword argument. Defaults to {}. (already) –
-
format
:Optional[str][source]¶ %S’ for date strings such as ‘2022-04-13 23:59:00’), or None (the default) to have pandas guess the format automatically.
- Type
The date format the string is using (e.g., ‘%Y-%m-%d %H
- Type
%M
-
timezone
:Optional[str][source]¶ The timezone of the data to convert. If provided, this converter will apply the appropriate offset to convert data from the specified timezone to UTC. The timezone of the output data is assumed to always be UTC.
-
to_datetime_kwargs
:Dict[str, Any][source]¶ Any parameters set here will be passed to pd.to_datetime as keyword arguments.
Class Methods
Runs the data converter on the provided (retrieved) dataset.
Method Descriptions
-
convert
(self, dataset: xarray.Dataset, dataset_config: tsdat.config.dataset.DatasetConfig, variable_name: str, **kwargs: Any) → xarray.Dataset[source]¶ Runs the data converter on the provided (retrieved) dataset.
- Parameters
dataset (xr.Dataset) – The dataset to convert.
dataset_config (DatasetConfig) – The dataset configuration.
variable_name (str) – The name of the variable to convert.
- Returns
The converted dataset.
- Return type
xr.Dataset
-
class
tsdat.io.converters.
UnitsConverter
[source]¶ Bases:
tsdat.io.base.DataConverter
Converts the units of a retrieved variable to the units specified by the variable’s specification in the DatasetConfig.
If the ‘input_units’ property is set then that string is used to determine the input input units, otherwise the converter will attempt to look up and use the ‘units’ attribute on the specified variable in the dataset provided to the convert method. If the input units cannot be set then a warning is issued and the original dataset is returned.
- Parameters
input_units (Optional[str]) – The units that the retrieved data comes in.
Class Methods
Runs the data converter on the provided (retrieved) dataset.
Method Descriptions
-
convert
(self, dataset: xarray.Dataset, dataset_config: tsdat.config.dataset.DatasetConfig, variable_name: str, **kwargs: Any) → xarray.Dataset[source]¶ Runs the data converter on the provided (retrieved) dataset.
- Parameters
dataset (xr.Dataset) – The dataset to convert.
dataset_config (DatasetConfig) – The dataset configuration.
variable_name (str) – The name of the variable to convert.
- Returns
The converted dataset.
- Return type
xr.Dataset