writers

Data export functionality for AMOC datasets.

Data writing utilities for AMOCatlas.

This module provides functions for writing and exporting AMOCatlas datasets to various formats, with special handling for NetCDF export, attribute sanitization, and datetime encoding. Includes functions to save datasets with proper compression and metadata formatting.

amocatlas.writers.save_AC1_dataset(ds: Dataset, data_dir: str | Path) Path[source]

Save AC1 dataset to netCDF using the OceanSITES ‘id’ attribute.

Parameters:
  • ds (xarray.Dataset) – Dataset with AC1-compliant global attributes including ‘id’.

  • data_dir (str or pathlib.Path) – Directory to save the netCDF file.

Returns:

Full path to the saved NetCDF file.

Return type:

Path

Raises:

ValueError – If ‘id’ global attribute is not found.

amocatlas.writers.save_dataset(ds: Dataset, output_file: str = '../test.nc') bool[source]

Attempts to save the dataset to a NetCDF file. If a TypeError occurs due to invalid attribute values, it converts the invalid attributes to strings and retries the save operation.

Parameters:
  • ds (xarray.Dataset) – The dataset to be saved.

  • output_file (str, optional) – The path to the output NetCDF file. Defaults to ‘../test.nc’.

Returns:

True if the dataset was saved successfully, False otherwise.

Return type:

bool

Notes

This function is based on a workaround for issues with saving datasets containing attributes of unsupported types. See: https://github.com/pydata/xarray/issues/3743