pycif.plugins.datastreams.fluxes.lmdz_sflx — API reference

pycif.plugins.datastreams.fluxes.lmdz_sflx — API reference#

Configuration reference: lmdz_sflx plugin

pycif.plugins.datastreams.fluxes.lmdz_sflx.fetch.fetch(ref_dir, ref_file, date_interval, target_dir, tracer=None, **kwargs)[source]#

Fetch LMDZ sflx flux files and rebuild the tracer’s domain as a single-level surface variant.

Expands date_interval to cover full years, lists candidate files at tracer.file_freq, and for each existing file reads and rounds its time values (detecting a monthly resolution and normalizing to month starts if so), shifts years to align a fixed reference file with the requested year, and links the file into target_dir. Also rebuilds tracer.domain as a copy of the model’s domain restricted to a single (surface) vertical level.

Parameters:
  • ref_dir (str) – Directory containing the reference input files.

  • ref_file (str) – Filename pattern of the input files (a strftime format string).

  • date_interval (list[datetime.datetime]) – [date_i, date_f] simulation interval to cover.

  • target_dir (str) – Directory where the resolved files are linked.

  • tracer – The flux tracer plugin, providing file_freq and domain (the model’s domain, used as a template for the rebuilt single-level domain).

Returns:

(list_files, list_dates), each keyed by the candidate file date, mapping to the list of resolved file paths and the list of [start, end] date-interval pairs found in those files.

Return type:

tuple[dict, dict]

pycif.plugins.datastreams.fluxes.lmdz_sflx.read.read(self, name, varnames, dates, files, interpol_flx=False, tracer=None, model=None, **kwargs)[source]#

Read LMDZ sflx flux files and unflatten the vector grid into a pyCIF variable.

For each date/file pair, rounds and normalizes the file’s time values as in fetch, shifts years if the file is a fixed reference, finds the exact matching time index, and reshapes the flat vector flux back into a 2D (lat, lon) field: pole values (first/last vector entries) are replicated across all longitudes, and a wrap-around longitude column is appended to close the grid.

Parameters:
  • self – the model Plugin, providing domain (for nlon/nlat).

  • name – the name of the component

  • varnames – name of the variable to read in the file

  • dates – list of [start, end] date intervals to extract; only the start of each interval is used to match a time index.

  • files – list of files matching dates

  • interpol_flx (bool) – Not currently applied (temporal interpolation logic is present but commented out); kept for interface consistency with other flux plugins.

  • tracer – Unused directly, kept for interface consistency.

  • model – Unused directly, kept for interface consistency.

Returns:

the flux data with dimensions

(time, lev, lat, lon).

Return type:

xr.DataArray

pycif.plugins.datastreams.fluxes.lmdz_sflx.write.write(self, name, flx_file, flx, mode='a', metadata=None, **kwargs)[source]#

Write a single-level flux DataArray to an LMDZ sflx compatible NetCDF file.

Flattens the gridded (lat, lon) flux into the LMDZ vector convention: North/South pole rows are averaged zonally into single values, the remaining rows are flattened row-major (dropping the wrap-around longitude at the date line), and pole values are placed at the start/end of the resulting vector dimension.

Parameters:
  • self (Fluxes) – the Fluxes plugin

  • name (str) – name of the flux variable to write

  • flx_file (str) – the file where to write fluxes

  • flx (xarray.DataArray) – fluxes data to write, with a single vertical level

  • mode (str) – Unused, kept for interface consistency; the file is always (over)written.

  • metadata (dict) – Must contain a 'domain' key with the Domain object used to derive latitude ordering and grid size.

Raises:

CifError – If metadata (or its 'domain' key) is missing, or if flx has more than one vertical level.