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

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

Configuration reference: lmdz_chemfield_reg plugin

pycif.plugins.datastreams.fields.lmdz_chemfield_reg.fetch.fetch(ref_dir: str | PathLike, ref_file: str | PathLike, input_interval: tuple[datetime, datetime], target_dir: str | PathLike, tracer: object | None = None, **kwargs) tuple[dict[datetime, list[str | PathLike]], dict[datetime, list[tuple[datetime, datetime]]]][source]#

Link monthly LMDz chemical field files and build daily sub-intervals.

Builds the list of monthly file dates spanning input_interval at tracer.file_freq, links each file into target_dir (raising if a file is missing), and for each linked file generates one daily [start, end] sub-interval per day of that month.

Parameters:
  • ref_dir – Directory where the original files are found. If both ref_dir and ref_file are falsy, nothing is fetched.

  • ref_file – Date-format pattern for the original file names.

  • input_interval – Tuple of two dates, the beginning and end of the period to fetch.

  • target_dir – Directory where links to the original files are created.

  • tracer – Tracer/component configuration; tracer.file_freq gives the frequency at which files are available.

  • **kwargs – Unused.

Returns:

A tuple (list_files, list_dates) of dictionaries keyed by monthly file date. list_dates maps each key to one (day_start, day_end) interval per day of the month; list_files maps each key to the (repeated) path of that month’s file.

Raises:

CifFileNotFoundError – If an expected monthly file does not exist.

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

Read LMDz chemical field data (regular grid) into a pyCIF DataArray.

Opens each distinct file in files once (validating that the requested variable exists), selects the day index (relative to the file’s month, computed from ddi) for each requested date, concatenates the selected time steps along time_counter, expands a missing vertical dimension (for deposition-velocity/surface-only fields), renames dimensions to pyCIF’s (time, lev, lat, lon) convention, drops non-time coordinates, and transposes accordingly.

Parameters:
  • self – The field/tracer Plugin.

  • 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 (start, end) date tuples to extract, matching files.

  • files – List of files matching dates; each distinct file is opened only once.

  • ddi – Reference date used to compute each date’s day-of-month index within its file. Mandatory.

  • **kwargs – Unused.

Returns:

A 4-dimensional (time, lev, lat, lon) array.

Return type:

xarray.DataArray

Raises:

CifValueError – If ddi is not given, or if the requested variable is not found in a file.

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

Append an LMDz chemical field (regular grid) to a NetCDF file.

Squeezes the lev dimension for single-level (surface-only) fields, builds lat/lon/vertical coordinates via self.domain.get_domain_coords(), adds a time coordinate if present in data, and appends the resulting dataset to path.

Parameters:
  • self – This plugin; self.domain supplies the coordinates.

  • name – Name of the variable to write.

  • path – Path to the NetCDF file to append to.

  • data – Data to write, as an xarray.DataArray.

  • **kwargs – Unused.

Raises:

CifTypeError – If data is not an xarray.DataArray.