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 singlewrfinput-style file for the start date. Forcomponent.orig_name == "latcond", links thewrfbdyfile and parses itsTimesvariable 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_nameselects 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]](forinicond).
- Return type:
list_files
- Raises:
CifValueError – if
component.orig_nameis neither"inicond"nor"latcond", or if thewrfbdyfile 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 thewrfbdyfile: 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_BTxxtrend variables. The four boundary-side variables (_BXS/_BXE/_BYS/_BYE) are then read and assembled into a single perimeter dimension matchingself.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 extractfiles – list with the single
wrfbdy/wrfinputfile pathinterpol_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), wherelonspans the domain perimeter.- Raises:
CifError – if
comp_typeisNoneor 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
fileoutis a symlink, to avoid overwriting an original reference file. Forcomp_type == "inicond", reshapesicbcand writes it directly into thevarname(orself.forced_varnameif set andvarnameis not found) NetCDF variable. Forcomp_type == "latcond", matches the timestamps carried byicbcto those already in the file, redistributes the perimeter data inicbcback 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)(forlatcond,lonspans the domain perimeter) to writecomp_type –
'inicond'or'latcond'; defaults toself.comp_typeif not givenmetadata – mapping possibly containing
"domain", used as a fallback ifself.domainis not set (latcondonly)
- Raises:
CifValueError – if
fileoutis 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
varnamecannot be found in theinicondfile andself.forced_varnameis not set.CifAttributeError – if neither
self.domainnormetadatais available forlatcond.