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

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

Configuration reference: oldlmdz_photochem plugin

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

Fetch legacy LMDZ4 photolysis-rate files and their sub-intervals.

For each date in date_interval (stepped at tracer.file_freq), links the corresponding file into target_dir if it exists, and reads its time_counter dimension to build one 24h sub-interval per time step found in the file.

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

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

  • date_interval – list of two dates, the beginning and end of the simulation.

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

  • tracer – the fields Plugin, giving access to file_freq.

Returns:

for each date, the file path repeated once per time

step found in that file.

list_dates: for each date, the list of 24h [start, end]

sub-intervals covered by that file’s time steps.

Return type:

list_files

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

Build the legacy LMDZ4 72x96x19 Domain from a reference J-rate 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.

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_photochem.read.read(self, name, tracdir, tracfile, varnames, dates, interpol_j=False, comp_type=None, model=None, **kwargs)[source]#

Get photolysis kinetic constants from pre-computed Js 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.

Parameters:
  • self – the photochem Plugin

  • name – the name of the component

  • tracdir – kinetic directory and file format

  • tracfile – kinetic directory and file format

  • varnames – unused, accepted for interface compatibility (Js are resolved from the chemical scheme, not from the yaml file)

  • dates – list of dates to extract

  • interpol_j (bool) – unused, accepted for interface compatibility

  • 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_photochem.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.