tsdat.io.converters

Classes

NearestNeighbor

Maps data onto the specified coordinate grid using nearest-neighbor.

StringToDatetime

Converts date strings into datetime64 data.

UnitsConverter

Converts the units of a retrieved variable to specified output units.

class tsdat.io.converters.NearestNeighbor[source]

Bases: tsdat.io.base.DataConverter

Maps data onto the specified coordinate grid using nearest-neighbor.

coord :str = time[source]

The coordinate axis this converter should be applied on. Defaults to ‘time’.

Class Methods

convert

Runs the data converter on the retrieved data.

Method Descriptions

convert(self, data: xarray.DataArray, variable_name: str, dataset_config: tsdat.config.dataset.DatasetConfig, retrieved_dataset: tsdat.io.base.RetrievedDataset, **kwargs: Any) Optional[xarray.DataArray][source]

Runs the data converter on the retrieved data.

Parameters
  • data (xr.DataArray) – The retrieved DataArray to convert.

  • retrieved_dataset (RetrievedDataset) – The retrieved dataset containing data to convert.

  • dataset_config (DatasetConfig) – The output dataset configuration.

  • variable_name (str) – The name of the variable to convert.

Returns

Optional[xr.DataArray]

The converted DataArray for the specified variable,

or None if the conversion was done in-place.

class tsdat.io.converters.StringToDatetime[source]

Bases: tsdat.io.base.DataConverter

Converts date strings into datetime64 data.

Allows parameters to specify the string format of the input data, as well as the timezone the input data are reported in. If the input timezone is not UTC, the data are converted to UTC time.

Parameters
  • format (Optional[str]) – The format of the string data. See strftime.org for more information on what components can be used. If None (the default), then pandas will try to interpret the format and convert it automatically. This can be unsafe but is not explicitly prohibited, so a warning is issued if format is not set explicitly.

  • timezone (Optional[str]) – The timezone of the input data. If not specified it is assumed to be UTC.

  • to_datetime_kwargs (Dict[str, Any]) – A set of keyword arguments passed to the pandas.to_datetime() function as keyword arguments. Note that ‘format’ is already included as a keyword argument. Defaults to {}.

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

convert

Runs the data converter on the retrieved data.

warn_if_no_format_set

Method Descriptions

convert(self, data: xarray.DataArray, variable_name: str, dataset_config: tsdat.config.dataset.DatasetConfig, retrieved_dataset: tsdat.io.base.RetrievedDataset, **kwargs: Any) Optional[xarray.DataArray][source]

Runs the data converter on the retrieved data.

Parameters
  • data (xr.DataArray) – The retrieved DataArray to convert.

  • retrieved_dataset (RetrievedDataset) – The retrieved dataset containing data to convert.

  • dataset_config (DatasetConfig) – The output dataset configuration.

  • variable_name (str) – The name of the variable to convert.

Returns

Optional[xr.DataArray]

The converted DataArray for the specified variable,

or None if the conversion was done in-place.

classmethod warn_if_no_format_set(cls, format: Optional[str]) Optional[str][source]
class tsdat.io.converters.UnitsConverter[source]

Bases: tsdat.io.base.DataConverter

Converts the units of a retrieved variable to specified output units.

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. The output units are specified by the output dataset configuration.

Parameters

input_units (Optional[str]) – The units that the retrieved data comes in.

input_units :Optional[str][source]

The units of the input data.

Class Methods

convert

Runs the data converter on the retrieved data.

Method Descriptions

convert(self, data: xarray.DataArray, variable_name: str, dataset_config: tsdat.config.dataset.DatasetConfig, retrieved_dataset: tsdat.io.base.RetrievedDataset, **kwargs: Any) Optional[xarray.DataArray][source]

Runs the data converter on the retrieved data.

Parameters
  • data (xr.DataArray) – The retrieved DataArray to convert.

  • retrieved_dataset (RetrievedDataset) – The retrieved dataset containing data to convert.

  • dataset_config (DatasetConfig) – The output dataset configuration.

  • variable_name (str) – The name of the variable to convert.

Returns

Optional[xr.DataArray]

The converted DataArray for the specified variable,

or None if the conversion was done in-place.