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

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

Configuration reference: GCP_1x1_N2O plugin

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

Fetch GCP N2O multi-year files bracketing the requested dates.

For each date key in input_interval, calls find_valid_file() for every sub-date to bracket the nearest available files (before and after), links all found files into target_dir, and returns deduplicated, sorted lists of files/dates per key.

Parameters:
  • ref_dir (str) – directory where the original files are found.

  • ref_file (str) – (template) name of the original files.

  • input_interval (dict) – mapping of reference dates to the list of sub-dates to simulate within each period.

  • target_dir (str) – directory where links to the original files are created.

  • tracer – the tracer Plugin; unused directly but kept for interface compatibility.

  • component – the component Plugin; unused directly but kept for interface compatibility.

  • **kwargs – unused, kept for interface compatibility.

Returns:

list_files and list_dates, keyed like input_interval, each value a deduplicated sorted list of file paths / bracketing dates found across all sub-dates of that key.

Return type:

(dict, dict)

pycif.plugins.datastreams.fluxes.GCP_1x1_N2O.get_domain.get_domain(ref_dir, ref_file, input_interval, target_dir, tracer=None)[source]#

Build the horizontal domain from a GCP N2O reference file.

Locates a reference NetCDF file (either an exact name match for ref_file in ref_dir, or the first file whose name parses against ref_file as a date format), reads its LON/LAT variables (forcing latitude into increasing order), and computes cell corners assuming a regular grid spacing (a known limitation: this is not valid for irregular grids). Builds a single-level, longitude-cyclic domain.

Parameters:
  • ref_dir (str) – directory where the original files are found.

  • ref_file (str) – (template) name of the original files.

  • input_interval (list) – unused, kept for interface compatibility.

  • target_dir (str) – unused, kept for interface compatibility.

  • tracer – unused, kept for interface compatibility.

Returns:

a single-level, longitude-cyclic domain.

Return type:

Domain

Raises:

CifError – if no reference file could be found in ref_dir.

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

Read GCP N2O fluxes for the requested dates into a pyCIF array.

tracfile may be given as a single file-name-format string (broadcast to all dates) or as a list of the same length as dates. For each date/file pair, reads the requested variable plus TIME and LAT via readnc(), computes the month index from the year encoded at the start of the file name, and extracts the corresponding time slice; latitude order is flipped if the file’s LAT is decreasing.

Parameters:
  • self – the fluxes Plugin.

  • name – the name of the component; unused directly, kept for interface compatibility.

  • tracdir – unused directly, kept for interface compatibility.

  • tracfile (str or list[str]) – file name (format) or list of file names to read from, one per date if a list.

  • varnames (str) – variable name to read from the file.

  • dates (list[datetime.datetime]) – list of dates to extract.

  • interpol_flx (bool) – unused, kept for interface compatibility.

  • tracer – unused, kept for interface compatibility.

  • model – unused, kept for interface compatibility.

  • **kwargs – unused, kept for interface compatibility.

Returns:

the flux data with dimensions (time, lev, lat, lon).

Return type:

xr.DataArray

Raises:

CifError – if tracfile is a list whose length does not match dates.

pycif.plugins.datastreams.fluxes.GCP_1x1_N2O.utils.find_valid_file(ref_dir, file_format, dd)[source]#

Find the pair of files bracketing a reference date.

Lists the files in ref_dir matching file_format, parses each file’s encoded YYYY-YYYY start/end year range from its name to enumerate the monthly (day-15) dates it covers, then returns the nearest bracketing file/date pair (one before dd, one after) among all covered dates.

Parameters:
  • ref_dir (str) – directory to search for candidate files.

  • file_format (str) – strptime-compatible file name pattern used to select candidate files.

  • dd (datetime.datetime) – reference date to bracket.

Returns:

a 2-element list of file paths [file_before, file_after] and the corresponding 2-element list of dates [date_before, date_after] bracketing dd.

Return type:

(list[str], list[datetime.datetime])

Raises:

CifError – if no file matching file_format is found in ref_dir.

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

Not implemented: writing GCP N2O fluxes is not supported.

Raises:

CifError – always.