pycif.plugins.datastreams.fields.lmdz_inicond_reg — API reference

pycif.plugins.datastreams.fields.lmdz_inicond_reg — API reference#

Configuration reference: lmdz_inicond_reg plugin

pycif.plugins.datastreams.fields.lmdz_inicond_reg.fetch.fetch(ref_dir: str, ref_file: str, input_interval: tuple[datetime, datetime], target_dir: str, **kwargs) tuple[dict[datetime, list[str]], dict[datetime, list[tuple[datetime, datetime]]]][source]#

Link the single LMDz inicond file for the simulation start date.

Parameters:
  • ref_dir (str) – Path to the data. If both ref_dir and ref_file are falsy, nothing is fetched.

  • ref_file (str) – File name format of the data.

  • input_interval (list[datetime.datetime]) – Date range; only the start date is used.

  • target_dir (str) – Where to link the data.

  • **kwargs – Unused.

Returns:

tuple of single-entry dictionaries keyed

by the simulation start date, describing the linked file and the (single-point) date interval it covers.

Return type:

(list_files, list_dates)

Raises:

CifFileNotFoundError – If the original inicond file does not exist.

pycif.plugins.datastreams.fields.lmdz_inicond_reg.read.read(self, name: str, varnames: str, dates: list[tuple[datetime, datetime]], files: list[str], tracer: object | None = None, **kwargs) DataArray[source]#

Read a mixing-ratio initial condition (regular grid) into a pyCIF DataArray.

For backward compatibility with older LMDZ files, strips a leading singleton time dimension if present, and drops a trailing duplicated (cyclic-closure) longitude column if the longitude size is self.domain.nlon + 1. The resulting shape is validated against self.domain.

Parameters:
  • self – The field/tracer Plugin; self.domain gives the expected (nlev, nlat, nlon) shape.

  • name – Name of the component; used as fallback variable name.

  • varnames – Name of the variable to read; if empty, name is used instead.

  • dates – List of date entries; only the first date is used as the output time coordinate.

  • files – List with a single inicond file path.

  • tracer – Unused.

  • **kwargs – Unused.

Returns:

A 4-dimensional (time, lev, lat, lon) array with a single time step.

Return type:

xarray.DataArray

Raises:

CifValueError – If more than one file is given, or if the data shape (after backward-compatibility adjustments) does not match self.domain.

pycif.plugins.datastreams.fields.lmdz_inicond_reg.write.write(self, name: str, path: str | PathLike, data: DataArray, metadata: dict[str, Any] | None = None, **kwargs)[source]#

Append a mixing-ratio initial condition (regular grid) to a NetCDF file.

Squeezes the singleton time dimension, builds coordinates via self.domain.get_domain_coords(), and appends the resulting dataset to path.

Parameters:
  • self (object) – this plugin; self.domain supplies the coordinates.

  • name (str) – variable name to write.

  • path (str) – path to the target file to write.

  • data (xarray.DataArray) – data to write, with a singleton time dimension.

  • metadata – Unused.

  • **kwargs – Unused.

Raises:

CifTypeError – If data is not an xarray.DataArray.