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

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

Configuration reference: lmdz_chemfield plugin

pycif.plugins.datastreams.fields.lmdz_chemfield.fetch.fetch(ref_dir, ref_file, input_interval, target_dir, tracer=None, **kwargs)[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 existing file into target_dir, 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.

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

  • input_interval – List 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.

pycif.plugins.datastreams.fields.lmdz_chemfield.read.read(self, name, varnames, dates, files, interpol_flx=False, comp_type=None, ddi=None, **kwargs)[source]#

Read LMDz chemical field data and load it into a pyCIF DataArray.

Opens each distinct file in files once, 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, renames dimensions to pyCIF’s (time, lev, lat, lon) convention, drops non-time coordinates, and duplicates the first longitude column to close LMDZ’s cyclic grid.

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 date entries to extract, matching files.

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

  • interpol_flx – Unused.

  • comp_type – Unused.

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

  • **kwargs – Unused.

Returns:

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

Return type:

xarray.DataArray

pycif.plugins.datastreams.fields.lmdz_chemfield.write.write(self, name, path, data, metadata=None, **kwargs) None[source]#

Write an LMDz chemical field to a Fortran binary or NetCDF file.

The output format is selected from path’s extension: .bin writes a Fortran binary file from a Dataset with fwd and tl (forward and tangent-linear) variables, transposed and dumped via numpy.ndarray.tofile; .nc writes (or appends to) a NetCDF file, dropping the cyclic-closure longitude, building lat/lon coordinates (and bounds) from metadata['domain'] if given, and renaming dimensions to LMDZ’s time_counter/presnivs convention.

Parameters:
  • self – This plugin; self.plugin is used for error messages.

  • name – Name of the variable to write (used only for .nc output).

  • path – Path to the file to write; its extension (.bin or .nc) selects the output format.

  • data – Data to write: an xarray.Dataset with fwd/tl variables for .bin output, or an xarray.DataArray for .nc output.

  • metadata – Optional dict with a "domain" entry, used to build the lat/lon coordinates when writing NetCDF.

  • **kwargs – Unused.

Raises:
  • CifTypeError – If data is not of the type expected for the target extension.

  • CifKeyError – If writing .bin and data lacks a fwd or tl variable.

  • CifValueError – If path’s extension is neither .bin nor .nc.