pycif.plugins.datastreams.fields.chimere_icbc — API reference#
Configuration reference: chimere_icbc plugin
- pycif.plugins.datastreams.fields.chimere_icbc.fetch.fetch(ref_dir, ref_file, input_interval, target_dir, tracer=None, component=None)[source]#
Link CHIMERE INI_CONCS/BOUN_CONCS files and build the date/file maps.
For
component.orig_name == "inicond", links the single initial condition file matching the start ofinput_interval. Otherwise (lateral/top boundary conditions), iterates over dates spaced bytracer.file_freqacrossinput_interval, links each existingBOUN_CONCS-style file found, and builds hourly sub-intervals covering the period spanned by each file.- Parameters:
ref_dir – Directory where the original files are found.
ref_file – Date-format pattern for the original file names.
input_interval – List of two dates, the beginning and end of the period to fetch.
target_dir – Directory where links to the original files are created.
tracer – Tracer/component configuration;
tracer.file_freqgives the frequency at which BOUN_CONCS files are available.component – Component being fetched;
component.orig_nameis used to distinguish initial conditions from boundary conditions.
- Returns:
A tuple
(list_files, list_dates). For initial conditions, both dictionaries have a single key (the start date). For boundary conditions, each key is a file date mapping to the list of hourly files/sub-intervals covered by that file.
- pycif.plugins.datastreams.fields.chimere_icbc.read.read(self, name, varnames, dates, files, interpol_flx=False, comp_type=None, ddi=None, **kwargs)[source]#
Read CHIMERE INI_CONCS/BOUN_CONCS data and load it into a pyCIF DataArray.
For
comp_type == "inicond", reads the variable from the singleINI_CONCS-style file infiles. For"latcond"/"topcond", reads thelat_conc/top_concvariable from eachBOUN_CONCSfile in turn, looks up the matching species and date index (falling back to an index derived fromddiif the exact date string is not found), and fills the corresponding slice with zeros if the species is absent from the file.- Parameters:
self – The field/tracer Plugin.
name – Name of the component (used as fallback variable name).
varnames – Name of the variable/species to read; if empty,
nameis used instead.dates – List of dates to extract, matching
files.files – List of files matching
dates.interpol_flx – Unused.
comp_type – Type of boundary condition to read:
"inicond","latcond"or"topcond".ddi – Reference date used to compute a fallback time index when the exact date string cannot be found in a
BOUN_CONCSfile.**kwargs – Unused.
- Returns:
A 4-dimensional
(time, lev, lat, lon)array.- Return type:
xarray.DataArray
- Raises:
CifError – If
comp_typeisNone, unrecognized, or ifddiis needed but not given while a date cannot be matched exactly.
- pycif.plugins.datastreams.fields.chimere_icbc.write.write(self, name, lbc_file, data, mode='a', metadata=None, comp_type=None, **kwargs)[source]#
Write data to CHIMERE INI_CONCS or BOUN_CONCS compatible files.
Resolves the domain (from
self.domainormetadata["domain"]) and thecomp_type(from the argument, orself.comp_type), then dispatches towrite_iniconcs()forcomp_type == "inicond"(choosing ppb or molecules/cm3 units depending on the magnitude of the data) or towrite_bounconcs()otherwise.- Parameters:
self – The field/tracer Plugin.
name – Name (or list of names) of the species/component to write.
lbc_file – Path to the output NetCDF file.
data – Data to write, either a single array-like or a dict mapping species names to their data.
mode – NetCDF write mode,
"a"to append (falls back to"w"if the file does not yet exist) or"w"to overwrite.metadata – Optional dict with a
"domain"entry, used whenself.domainis not available.comp_type – Type of conditions to write:
"inicond","latcond"or"topcond". Falls back toself.comp_typeif not given.**kwargs – Unused.
- Raises:
CifAttributeError – If no domain information can be found.
CifError – If
comp_typecannot be determined.
- pycif.plugins.datastreams.fields.chimere_icbc.write.write_iniconcs(name, lbc_file, data, lon, lat, mode='a', units_in='ppb')[source]#
Create or update a CHIMERE
INI_CONCS.nc-style file.Validates that
datahas a horizontal shape matchinglon, then either appends the new species to an existing file (updating thespecies/Timescharacter arrays and rewriting the file) or creates the file from scratch with thelon/lat/Times/speciesvariables plus one data variable per species.- Parameters:
name – Name, or list of names, of the species being written.
lbc_file – Path to the output
INI_CONCS-style NetCDF file.data – Data to write, either a single array-like (if
nameis a single string) or a dict mapping species names to their time-indexed data.lon – 2D array of grid-cell center longitudes.
lat – 2D array of grid-cell center latitudes.
mode – NetCDF write mode,
"a"to append or"w"to overwrite.units_in – Units attribute to attach to the written data variables.
- Raises:
CifError – If the data has the shape of boundary conditions instead of initial conditions, or has an incorrect horizontal shape.
- pycif.plugins.datastreams.fields.chimere_icbc.write.write_bounconcs(name, lbc_file, data, lon, lat, lon_side, lat_side, nlev, mode='a', comp_type=None)[source]#
Create or update a CHIMERE
BOUN_CONCS.nc-style file.Either appends new species (or overwrites existing species’ slices) of the
lat_conc/top_concarrays in an existing file, or creates the file from scratch withlon/lat/Times/speciesvariables plus thelat_conc/top_concdata arrays (the array not being written,top_concforcomp_type == "latcond"or vice versa, is filled with zeros).- Parameters:
name – Name, or list of names, of the species being written.
lbc_file – Path to the output
BOUN_CONCS-style NetCDF file.data – Dict mapping species names to their time-indexed data (or a single array-like if
nameis a single string).lon – 2D array of grid-cell center longitudes.
lat – 2D array of grid-cell center latitudes.
lon_side – Array of perimeter-cell longitudes (lateral boundary).
lat_side – Array of perimeter-cell latitudes (lateral boundary).
nlev – Number of vertical levels.
mode – NetCDF write mode,
"a"to append or"w"to overwrite.comp_type –
"latcond"to write thelat_concarray, or"topcond"to write thetop_concarray.