Skip to content

data_reader

Classes:

Name Description
DataReader

Base class for reading data from an input source.

Classes#

DataReader #

Bases: ParameterizedClass, ABC

Base class for reading data from an input source.

Methods:

Name Description
read

Functions#

read abstractmethod #
read(
    input_key: str,
) -> Union[xr.Dataset, Dict[str, xr.Dataset]]

Reads data given an input key.

Uses the input key to open a resource and load data as a xr.Dataset object or as a mapping of strings to xr.Dataset objects.

In most cases DataReaders will only need to return a single xr.Dataset, but occasionally some types of inputs necessitate that the data loaded from the input_key be returned as a mapping. For example, if the input_key is a path to a zip file containing multiple disparate datasets, then returning a mapping is appropriate.

Parameters:

Name Type Description Default
input_key str

An input key matching the DataReader's regex pattern that should be used to load data.

required

Returns:

Type Description
Union[Dataset, Dict[str, Dataset]]

Union[xr.Dataset, Dict[str, xr.Dataset]]: The raw data extracted from the provided input key.


Source code in tsdat/io/base/data_reader.py
@abstractmethod
def read(
    self,
    input_key: str,
) -> Union[xr.Dataset, Dict[str, xr.Dataset]]:
    """-----------------------------------------------------------------------------
    Reads data given an input key.

    Uses the input key to open a resource and load data as a xr.Dataset object or as
    a mapping of strings to xr.Dataset objects.

    In most cases DataReaders will only need to return a single xr.Dataset, but
    occasionally some types of inputs necessitate that the data loaded from the
    input_key be returned as a mapping. For example, if the input_key is a path to a
    zip file containing multiple disparate datasets, then returning a mapping is
    appropriate.

    Args:
        input_key (str): An input key matching the DataReader's regex pattern that
            should be used to load data.

    Returns:
        Union[xr.Dataset, Dict[str, xr.Dataset]]: The raw data extracted from the
            provided input key.

    -----------------------------------------------------------------------------"""
    ...