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

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

Configuration reference: oldlmdz_prescrconcs plugin

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

Fetch legacy LMDZ4 prescribed-concentration files.

input_interval is a mapping of key dates to lists of sub-dates; for each sub-date, calls find_valid_file() to locate the two straddling files, links them into target_dir, and deduplicates the resulting file/date pairs.

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

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

  • input_interval – mapping of key dates to the list of sub-dates covered under each key.

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

  • tracer – unused, accepted for interface compatibility.

Returns:

for each key date, the deduplicated array of file

paths matching list_dates.

list_dates: for each key date, the deduplicated, sorted array of

dates found by find_valid_file().

Return type:

list_files

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

Build the legacy LMDZ4 72x96x19 Domain from a reference concentration file.

Looks for a reference NetCDF file in ref_dir, either an exact match for ref_file or the first file whose name matches ref_file used as a date-format pattern, reads lat/lon (flipping latitude to increasing order if needed), computes grid-cell corners manually (with an ad hoc pole adjustment), and hardcodes the 19-level hybrid-sigma coefficients (sigma_a/ sigma_b) when the file’s presnivs dimension has size 19, since they are not available in the input files.

Warning

If presnivs size differs from 19, sigma_a/sigma_b are never assigned in this function, which raises an unbound-variable error rather than a domain-specific one.

Parameters:
  • ref_dir – directory to search for a reference file.

  • ref_file – exact file name, or a date-format pattern used to match one of the files in ref_dir.

  • input_interval – unused, accepted for interface compatibility.

  • target_dir – unused, accepted for interface compatibility.

  • tracer – unused, accepted for interface compatibility.

Returns:

the legacy LMDZ4 grid domain.

Return type:

Domain

Raises:

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

pycif.plugins.datastreams.fields.oldlmdz_prescrconcs.read.read(self, name, tracdir, tracfile, varnames, dates, comp_type=None, model=None, **kwargs)[source]#

Get prescribed concentrations from pre-computed fields and load them into a pyCIF variable.

Reconstructs the in-file timestamps manually from time_counter (expressed in seconds since the first day of the month), because the 360-day calendar used in these files is not handled by xarray’s decode_times, then selects the matching time index; the result is flipped along latitude if the file’s latitude axis is decreasing. Unlike photolysis rates, the concentration variable name is taken directly from varnames rather than resolved via the chemical scheme.

Parameters:
  • self – the prescribed concentrations Plugin

  • name – the name of the component

  • tracdir – raw data directory and file format

  • tracfile – raw data directory and file format

  • varnames – name of the concentration variable to read from the file

  • dates – list of dates to extract

  • comp_type – unused, accepted for interface compatibility

  • model – unused, accepted for interface compatibility

Returns:

xarray.DataArray with dims (time, lev, lat, lon).

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

Find the two files/dates straddling date dd in ref_dir.

Lists files in ref_dir matching file_format for the same year/month as dd (plus the previous month if dd falls on hour 0), expands each matching file into the list of hourly dates it covers, then returns the closest file/date at or before dd and the closest at or after dd.

Parameters:
  • ref_dir – directory to search for files.

  • file_format – date-format pattern used to parse file names and match them against dd.

  • dd – the date to find files around.

Returns:

A tuple ([file_ref1, file_ref2], [date_ref1, date_ref2]) with the file paths and dates immediately before and after (or equal to) dd.

Raises:

CifError – if no file in ref_dir matches file_format.