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

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

Configuration reference: wrfchem_icbc plugin

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

Fetch the WRF-Chem initial or lateral boundary condition file.

For component.orig_name == "inicond", links the single wrfinput-style file for the start date. For component.orig_name == "latcond", links the wrfbdy file and parses its Times variable to build the sequence of boundary intervals, extrapolating one extra timestep past the last one found in the file (using the last inter-timestep spacing).

Parameters:
  • ref_dir – directory where the original file is found.

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

  • input_interval – list of two dates; only the start date is used.

  • target_dir – directory where the link to the original file is created.

  • tracer – unused, accepted for interface compatibility.

  • component – the component Plugin; component.orig_name selects between "inicond" and "latcond" handling.

Returns:

single-entry dict mapping the start date to a

one-element list with the file path.

list_dates: single-entry dict mapping the start date to the list

of boundary intervals (for latcond) or [[start date, start date]] (for inicond).

Return type:

list_files

Raises:

CifValueError – if component.orig_name is neither "inicond" nor "latcond", or if the wrfbdy file has fewer than two timestamps.

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

Get initial and boundary conditions from pre-computed WRF-Chem files and load them into a pyCIF variable.

Reading initial conditions (comp_type="inicond") is not implemented yet and always raises. Reading lateral conditions (comp_type="latcond") compares the requested timestamps to those found in the wrfbdy file: either they match exactly, or exactly one extra timestamp is requested beyond the file’s last one, in which case its value is extrapolated from the _BTxx trend variables. The four boundary-side variables (_BXS/_BXE/_BYS/_BYE) are then read and assembled into a single perimeter dimension matching self.domain.zlon_side.

Parameters:
  • self – the wrfchem_icbc plugin

  • name – the name of the component

  • varnames – unused, accepted for interface compatibility

  • dates – list of [start, end] date pairs to extract

  • files – list with the single wrfbdy/wrfinput file path

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

  • comp_type'inicond' or 'latcond'

  • ddi – unused, accepted for interface compatibility

Returns:

xarray.DataArray with dims (time, lev, lat, lon), where lon spans the domain perimeter.

Raises:
  • CifError – if comp_type is None or not recognized.

  • CifNotImplementedError – if comp_type == "inicond".

  • CifValueError – if more than one file is given for latcond, or if the file’s timestamps don’t match the expected pattern.

pycif.plugins.datastreams.fields.wrfchem_icbc.write.write(self, varname, fileout, icbc, comp_type=None, metadata=None, **kwargs)[source]#

Write initial or lateral boundary condition values into a WRF-Chem file.

Refuses to write if fileout is a symlink, to avoid overwriting an original reference file. For comp_type == "inicond", reshapes icbc and writes it directly into the varname (or self.forced_varname if set and varname is not found) NetCDF variable. For comp_type == "latcond", matches the timestamps carried by icbc to those already in the file, redistributes the perimeter data in icbc back into the four boundary-side arrays (_BXS/_BXE/_BYS/_BYE), computes the corresponding trend arrays (_BTxx) from the time differences, and writes both the boundary and trend arrays back into the file.

Parameters:
  • self – the wrfchem_icbc plugin

  • varname – name of the species variable to write

  • fileout – path of the WRF-Chem file to write into (must not be a symlink)

  • icbc – xarray.DataArray with dims (time, lev, lat, lon) (for latcond, lon spans the domain perimeter) to write

  • comp_type'inicond' or 'latcond'; defaults to self.comp_type if not given

  • metadata – mapping possibly containing "domain", used as a fallback if self.domain is not set (latcond only)

Raises:
  • CifValueError – if fileout is a symlink, or if the requested timestamps cannot be matched to those in the file (or if the per-timestep time differences are not constant).

  • CifError – if varname cannot be found in the inicond file and self.forced_varname is not set.

  • CifAttributeError – if neither self.domain nor metadata is available for latcond.