readers
Classes#
CSVReader #
Bases: DataReader
Uses pandas and xarray functions to read a csv file and extract its contents into an
xarray Dataset object. Two parameters are supported: read_csv_kwargs
and
from_dataframe_kwargs
, whose contents are passed as keyword arguments to
pandas.read_csv()
and xarray.Dataset.from_dataframe()
respectively.
NetCDFReader #
Bases: DataReader
Thin wrapper around xarray's open_dataset()
function, with optional parameters
used as keyword arguments in the function call.
ParquetReader #
Bases: DataReader
Uses pandas and xarray functions to read a parquet file and extract its contents
into an xarray Dataset object. Two parameters are supported: read_parquet_kwargs
and from_dataframe_kwargs
, whose contents are passed as keyword arguments to
pandas.read_parquet()
and xarray.Dataset.from_dataframe()
respectively.
TarReader #
Bases: ArchiveReader
DataReader for reading from a tarred archive. Writing to this format is not supported.
This class requires a that readers be specified in the parameters section of the
storage configuration file. The structure of the
readers section should mirror the
structure of its parent `readers section. To illustrate, consider the following
configuration block:
readers:
.*:
tar:
file_pattern: .*\.tar
classname: tsdat.io.readers.TarReader
parameters:
# Parameters to specify how the TarReader should read/unpack the archive.
# Parameters here are passed to the Python open() method as kwargs. The
# default value is shown below.
open_tar_kwargs:
mode: "rb"
# Parameters here are passed to tarfile.open() as kwargs. Useful for
# specifying the system encoding or compression algorithm to use for
# unpacking the archive. These are optional.
read_tar_kwargs:
mode: "r:gz"
# The readers section tells the TarReader which DataReaders should be
# used to handle the unpacked files.
readers:
.*\.csv:
classname: tsdat.io.readers.CSVReader
parameters: # Parameters specific to tsdat.io.readers.CSVReader
read_csv_kwargs:
sep: '\t'
# Pattern(s) used to exclude certain files in the archive from being handled.
# This parameter is optional, and the default value is shown below:
exclude: ['.*\_\_MACOSX/.*', '.*\.DS_Store']
Source code in tsdat/io/base.py
Attributes#
Classes#
Functions#
read #
Extracts the file into memory and uses registered DataReaders
to read each relevant
extracted file into its own xarray Dataset object. Returns a mapping like
{filename: xr.Dataset}.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
file |
Union[str, BytesIO]
|
The file to read in. Can be provided as a filepath or |
required |
name |
str
|
A label used to help trace the origin of the data read-in. |
required |
Returns:
Type | Description |
---|---|
Dict[str, Dataset]
|
Dict[str, xr.Dataset]: A mapping of {label: xr.Dataset}. |
Source code in tsdat/io/readers.py
ZarrReader #
ZipReader #
Bases: ArchiveReader
DataReader for reading from a zipped archive. Writing to this format is not supported.
This class requires a that readers be specified in the parameters section of the
storage configuration file. The structure of the
readers section should mirror the
structure of its parent `readers section. To illustrate, consider the following
configuration block:
readers:
.*:
zip:
file_pattern: .*\.zip
classname: tsdat.io.readers.ZipReader
parameters:
# Parameters to specify how the ZipReader should read/unpack the archive.
# Parameters here are passed to the Python open() method as kwargs. The
# default value is shown below.
open_zip_kwargs:
mode: "rb"
# Parameters here are passed to zipfile.ZipFile.open() as kwargs. Useful
# for specifying the system encoding or compression algorithm to use for
# unpacking the archive. These are optional.
read_zip_kwargs:
mode: "r"
# The readers section tells the ZipReaders which DataReaders should be
# used to read the unpacked files.
readers:
.*\.csv:
classname: tsdat.io.readers.CSVReader
parameters: # Parameters specific to tsdat.io.readers.CsvReader
read_csv_kwargs:
sep: '\t'
# Pattern(s) used to exclude certain files in the archive from being handled.
# This parameter is optional, and the default value is shown below:
exclude: ['.*\_\_MACOSX/.*', '.*\.DS_Store']
Source code in tsdat/io/base.py
Attributes#
Classes#
Functions#
read #
Extracts the file into memory and uses registered DataReaders
to read each relevant
extracted file into its own xarray Dataset object. Returns a mapping like
{filename: xr.Dataset}.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
input_key |
Union[str, BytesIO]
|
The file to read in. Can be provided as a filepath or |
required |
name |
str
|
A label used to help trace the origin of the data read-in. |
required |
Returns:
Type | Description |
---|---|
Dict[str, Dataset]
|
Dict[str, xr.Dataset]: A mapping of {label: xr.Dataset}. |