tsdat.io.writers

Classes

CSVWriter

Converts a xr.Dataset object to a pandas DataFrame and saves the result to a csv

NetCDFWriter

Thin wrapper around xarray's Dataset.to_netcdf() function for saving a dataset to a

ParquetWriter

Writes the dataset to a parquet file.

SplitNetCDFWriter

Wrapper around xarray's Dataset.to_netcdf() function for saving a dataset to a

ZarrWriter

Writes the dataset to a basic zarr archive.

class tsdat.io.writers.CSVWriter[source]

Bases: tsdat.io.base.FileWriter

Converts a xr.Dataset object to a pandas DataFrame and saves the result to a csv file using pd.DataFrame.to_csv(). Properties under the to_csv_kwargs parameter are passed to pd.DataFrame.to_csv() as keyword arguments.

class Parameters[source]

Bases: pydantic.BaseModel

dim_order: List[str] | None[source]
to_csv_kwargs: Dict[str, Any][source]
file_extension: str = 'csv'[source]
parameters: CSVWriter.Parameters[source]

Class Methods

write

Writes the dataset to the provided filepath.

Method Descriptions

write(dataset: xarray.Dataset, filepath: pathlib.Path | None = None, **kwargs: Any) None[source]

Writes the dataset to the provided filepath.

This method is typically called by the tsdat storage API, which will be responsible for providing the filepath, including the file extension.

Parameters:
  • dataset (xr.Dataset) – The dataset to save.

  • filepath (Optional[Path]) – The path to the file to save.

class tsdat.io.writers.NetCDFWriter[source]

Bases: tsdat.io.base.FileWriter

Thin wrapper around xarray’s Dataset.to_netcdf() function for saving a dataset to a netCDF file. Properties under the to_netcdf_kwargs parameter will be passed to Dataset.to_netcdf() as keyword arguments.

File compression is used by default to save disk space. To disable compression set the compression_level parameter to 0.

class Parameters[source]

Bases: pydantic.BaseModel

compression_engine: str = 'zlib'[source]

The compression engine to use.

compression_level: int = 1[source]

The level of compression to use (0-9). Set to 0 to not use compression.

to_netcdf_kwargs: Dict[str, Any][source]

Keyword arguments passed directly to xr.Dataset.to_netcdf().

file_extension: str = 'nc'[source]
parameters: NetCDFWriter.Parameters[source]

Class Methods

write

Writes the dataset to the provided filepath.

Method Descriptions

write(dataset: xarray.Dataset, filepath: pathlib.Path | None = None, **kwargs: Any) None[source]

Writes the dataset to the provided filepath.

This method is typically called by the tsdat storage API, which will be responsible for providing the filepath, including the file extension.

Parameters:
  • dataset (xr.Dataset) – The dataset to save.

  • filepath (Optional[Path]) – The path to the file to save.

class tsdat.io.writers.ParquetWriter[source]

Bases: tsdat.io.base.FileWriter

Writes the dataset to a parquet file.

Converts a xr.Dataset object to a pandas DataFrame and saves the result to a parquet file using pd.DataFrame.to_parquet(). Properties under the to_parquet_kwargs parameter are passed to pd.DataFrame.to_parquet() as keyword arguments.

class Parameters[source]

Bases: pydantic.BaseModel

dim_order: List[str] | None[source]
to_parquet_kwargs: Dict[str, Any][source]
file_extension: str = 'parquet'[source]
parameters: ParquetWriter.Parameters[source]

Class Methods

write

Writes the dataset to the provided filepath.

Method Descriptions

write(dataset: xarray.Dataset, filepath: pathlib.Path | None = None, **kwargs: Any) None[source]

Writes the dataset to the provided filepath.

This method is typically called by the tsdat storage API, which will be responsible for providing the filepath, including the file extension.

Parameters:
  • dataset (xr.Dataset) – The dataset to save.

  • filepath (Optional[Path]) – The path to the file to save.

class tsdat.io.writers.SplitNetCDFWriter[source]

Bases: NetCDFWriter

Wrapper around xarray’s Dataset.to_netcdf() function for saving a dataset to a netCDF file based on a particular time interval, and is an extension of the NetCDFWriter. Files are split (sliced) via a time interval specified in two parts, time_interval a literal value, and a time_unit character (year: “Y”, month: “M”, day: “D”, hour: “h”, minute: “m”, second: “s”).

Properties under the to_netcdf_kwargs parameter will be passed to Dataset.to_netcdf() as keyword arguments. File compression is used by default to save disk space. To disable compression set the compression_level parameter to 0.

class Parameters[source]

Bases: NetCDFWriter

time_interval: int = 1[source]

Time interval value.

time_unit: str = 'D'[source]

Time interval unit.

file_extension: str = 'nc'[source]
parameters: SplitNetCDFWriter.Parameters[source]

Class Methods

write

Writes the dataset to the provided filepath.

Method Descriptions

write(dataset: xarray.Dataset, filepath: pathlib.Path | None = None, **kwargs: Any) None[source]

Writes the dataset to the provided filepath.

This method is typically called by the tsdat storage API, which will be responsible for providing the filepath, including the file extension.

Parameters:
  • dataset (xr.Dataset) – The dataset to save.

  • filepath (Optional[Path]) – The path to the file to save.

class tsdat.io.writers.ZarrWriter[source]

Bases: tsdat.io.base.FileWriter

Writes the dataset to a basic zarr archive.

Advanced features such as specifying the chunk size or writing the zarr archive in AWS S3 will be implemented later.

class Parameters[source]

Bases: pydantic.BaseModel

to_zarr_kwargs: Dict[str, Any][source]
file_extension: str = 'zarr'[source]
parameters: ZarrWriter.Parameters[source]

Class Methods

write

Writes the dataset to the provided filepath.

Method Descriptions

write(dataset: xarray.Dataset, filepath: pathlib.Path | None = None, **kwargs: Any) None[source]

Writes the dataset to the provided filepath.

This method is typically called by the tsdat storage API, which will be responsible for providing the filepath, including the file extension.

Parameters:
  • dataset (xr.Dataset) – The dataset to save.

  • filepath (Optional[Path]) – The path to the file to save.