anu_ctlab_io.netcdf

Read and write data from/to the ANU CTLab netcdf data format.

This is an optional extra module, and must be explicitly installed to be used (e.g., pip install anu_ctlab_io[netcdf]).

Package Contents

anu_ctlab_io.netcdf.dataset_to_netcdf(dataset, path, datatype=None, dataset_id=None, max_file_size_mb=500.0, compression_level=0, history=None, **extra_attrs)

Write a Dataset to netcdf format.

Parameters:
  • dataset (anu_ctlab_io._dataset.Dataset) – The Dataset to write.

  • path (pathlib.Path | str) – Path to write the netcdf file or directory (if splitting).

  • datatype (anu_ctlab_io._datatype.DataType | str | None) – Data type identifier. Inferred from dataset if None.

  • dataset_id (str | None) – Unique dataset identifier. Auto-generated if not provided.

  • max_file_size_mb (float | None) – Max file size in MB. Data exceeding this is split into multiple files along z-axis. Default 500MB. Set to None for single file.

  • compression_level (int) – NetCDF compression level (0-9). Default 0 (no compression).

  • history (anu_ctlab_io._parse_history.History | None) – History entries to add. Keys are identifiers, values are strings or parsed history dicts. If None, uses dataset’s history attribute.

  • extra_attrs (Any) – Additional global attributes to include.

Return type:

None

anu_ctlab_io.netcdf.dataset_from_netcdf(path, *, parse_history=True, **kwargs)

Loads a Dataset from the path to a netcdf.

This method is used by Dataset.from_path, by preference call that constructor directly.

Parameters:
  • Path – The path to the netcdf or directory of split netcdf blocks to be loaded.

  • parse_history (bool) – Whether to parse the history of the netcdf file. Defaults to True, but disableable because the parser is currently not guaranteed to succeed.

  • kwargs (Any) – Currently this method consumes no kwargs, but will pass provided kwargs to Xarray.open_mfdataset.

  • path (pathlib.Path)

Raises:

lark.exceptions.UnexpectedInput – Raised if parse_history=True and the parser fails to parse the specific history provided.

Return type:

anu_ctlab_io._dataset.Dataset