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_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