pycif.plugins.datastreams.fields.lmdz_chemfield_reg — API reference#
Configuration reference: lmdz_chemfield_reg plugin
- pycif.plugins.datastreams.fields.lmdz_chemfield_reg.fetch.fetch(ref_dir: str | PathLike, ref_file: str | PathLike, input_interval: tuple[datetime, datetime], target_dir: str | PathLike, tracer: object | None = None, **kwargs) tuple[dict[datetime, list[str | PathLike]], dict[datetime, list[tuple[datetime, datetime]]]][source]#
Link monthly LMDz chemical field files and build daily sub-intervals.
Builds the list of monthly file dates spanning
input_intervalattracer.file_freq, links each file intotarget_dir(raising if a file is missing), and for each linked file generates one daily[start, end]sub-interval per day of that month.- Parameters:
ref_dir – Directory where the original files are found. If both
ref_dirandref_fileare falsy, nothing is fetched.ref_file – Date-format pattern for the original file names.
input_interval – Tuple 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 files are available.**kwargs – Unused.
- Returns:
A tuple
(list_files, list_dates)of dictionaries keyed by monthly file date.list_datesmaps each key to one(day_start, day_end)interval per day of the month;list_filesmaps each key to the (repeated) path of that month’s file.- Raises:
CifFileNotFoundError – If an expected monthly file does not exist.
- pycif.plugins.datastreams.fields.lmdz_chemfield_reg.read.read(self, name: str, varnames: str, dates: list[tuple[datetime, datetime]], files: list[str | PathLike], ddi: datetime | None = None, **kwargs)[source]#
Read LMDz chemical field data (regular grid) into a pyCIF DataArray.
Opens each distinct file in
filesonce (validating that the requested variable exists), selects the day index (relative to the file’s month, computed fromddi) for each requested date, concatenates the selected time steps alongtime_counter, expands a missing vertical dimension (for deposition-velocity/surface-only fields), renames dimensions to pyCIF’s(time, lev, lat, lon)convention, drops non-time coordinates, and transposes accordingly.- Parameters:
self – The field/tracer Plugin.
name – Name of the component; used as fallback variable name.
varnames – Name of the variable to read; if empty,
nameis used instead.dates – List of
(start, end)date tuples to extract, matchingfiles.files – List of files matching
dates; each distinct file is opened only once.ddi – Reference date used to compute each date’s day-of-month index within its file. Mandatory.
**kwargs – Unused.
- Returns:
A 4-dimensional
(time, lev, lat, lon)array.- Return type:
xarray.DataArray
- Raises:
CifValueError – If
ddiis not given, or if the requested variable is not found in a file.
- pycif.plugins.datastreams.fields.lmdz_chemfield_reg.write.write(self, name: str, path: str | PathLike, data: DataArray, **kwargs) None[source]#
Append an LMDz chemical field (regular grid) to a NetCDF file.
Squeezes the
levdimension for single-level (surface-only) fields, buildslat/lon/vertical coordinates viaself.domain.get_domain_coords(), adds atimecoordinate if present indata, and appends the resulting dataset topath.- Parameters:
self – This plugin;
self.domainsupplies the coordinates.name – Name of the variable to write.
path – Path to the NetCDF file to append to.
data – Data to write, as an
xarray.DataArray.**kwargs – Unused.
- Raises:
CifTypeError – If
datais not anxarray.DataArray.