pycif.plugins.datastreams.fields.lmdz_chemfield — API reference#
Configuration reference: lmdz_chemfield plugin
- pycif.plugins.datastreams.fields.lmdz_chemfield.fetch.fetch(ref_dir, ref_file, input_interval, target_dir, tracer=None, **kwargs)[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 existing file intotarget_dir, 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.
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 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.
- pycif.plugins.datastreams.fields.lmdz_chemfield.read.read(self, name, varnames, dates, files, interpol_flx=False, comp_type=None, ddi=None, **kwargs)[source]#
Read LMDz chemical field data and load it into a pyCIF DataArray.
Opens each distinct file in
filesonce, selects the day index (relative to the file’s month, computed fromddi) for each requested date, concatenates the selected time steps alongtime_counter, renames dimensions to pyCIF’s(time, lev, lat, lon)convention, drops non-time coordinates, and duplicates the first longitude column to close LMDZ’s cyclic grid.- 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 date entries to extract, matching
files.files – List of files matching
dates; each distinct file is opened only once.interpol_flx – Unused.
comp_type – Unused.
ddi – Reference date used to compute each date’s day-of-month index within its file.
**kwargs – Unused.
- Returns:
A 4-dimensional
(time, lev, lat, lon)array.- Return type:
xarray.DataArray
- pycif.plugins.datastreams.fields.lmdz_chemfield.write.write(self, name, path, data, metadata=None, **kwargs) None[source]#
Write an LMDz chemical field to a Fortran binary or NetCDF file.
The output format is selected from
path’s extension:.binwrites a Fortran binary file from aDatasetwithfwdandtl(forward and tangent-linear) variables, transposed and dumped vianumpy.ndarray.tofile;.ncwrites (or appends to) a NetCDF file, dropping the cyclic-closure longitude, buildinglat/loncoordinates (and bounds) frommetadata['domain']if given, and renaming dimensions to LMDZ’stime_counter/presnivsconvention.- Parameters:
self – This plugin;
self.pluginis used for error messages.name – Name of the variable to write (used only for
.ncoutput).path – Path to the file to write; its extension (
.binor.nc) selects the output format.data – Data to write: an
xarray.Datasetwithfwd/tlvariables for.binoutput, or anxarray.DataArrayfor.ncoutput.metadata – Optional dict with a
"domain"entry, used to build thelat/loncoordinates when writing NetCDF.**kwargs – Unused.
- Raises:
CifTypeError – If
datais not of the type expected for the target extension.CifKeyError – If writing
.binanddatalacks afwdortlvariable.CifValueError – If
path’s extension is neither.binnor.nc.