pycif.plugins.datastreams.fluxes.dalecbethy — API reference#
Configuration reference: dalecbethy plugin
- pycif.plugins.datastreams.fluxes.dalecbethy.fetch.fetch(ref_dir, ref_file, input_interval, target_dir, tracer=None, **kwargs)[source]#
Fetch a D&B forcing file and list the period(s) it covers.
D&B writes its whole forcing to a single NetCDF file: it is linked once into
target_dir, and, if the file has atimecoordinate (D&B’s hourly dynamic forcing, e.g.dynforcing.nc), it is read to list the hourly sub-periods overlappinginput_interval. Time-invariant static forcing files (e.g.staticforcing.nc, seesrc/ncread_forcing.f90::ncread_static_forcing) have notimecoordinate: they are instead listed as a single period covering the whole ofinput_interval.- Parameters:
ref_dir (str) – directory where the forcing file is found.
ref_file (str) – name of the forcing file.
input_interval (list) – simulation interval, as a list of the two bounding dates.
target_dir (str) – directory where a link to the forcing file is created.
tracer – the tracer Plugin, giving access to
name.**kwargs – unused, kept for interface compatibility.
- Returns:
list_filesandlist_dates, both with a single key (the first covered hour, orinput_interval’s start for static forcing), following the same{key: [...per-period...]}convention as other fluxes plugins (see e.g.pycif.plugins.datastreams.fluxes.chimere.fetch.fetch).- Return type:
(dict, dict)
- Raises:
CifError – if the forcing file is not found, or (dynamic forcing only) has no
timerecord overlappinginput_interval.
- pycif.plugins.datastreams.fluxes.dalecbethy.read.read(self, name, varnames, dates, files, interpol_flx=False, tracer=None, model=None, ddi=None, **kwargs)[source]#
Get D&B meteorological forcing values from its dynamic forcing file.
For each requested hourly period, finds the matching
timerecord in the file and extracts the row ofvar2extractfor D&B’s active sample points (tracer.domain.active, set bypycif.plugins.domains.dalecbethy.read_domain.read_grid()), so that the returned data lines up 1-to-1 withtracer.domain.zlon/zlat.D&B’s own
timerecords mark the end of each hourly period (seepycif.plugins.datastreams.fluxes.dalecbethy.fetch.fetch, which buildsperiod == [hh - 1h, hh]from eachhhrecord), so periods are matched onperiod[1], notperiod[0].- Parameters:
self – the fluxes Plugin.
name (str) – name of the component.
varnames (list[str] or str) – variable name(s) to read;
nameis used ifvarnamesis empty.dates (list) – list of the date intervals to extract.
files (list) – list of files matching
dates.interpol_flx (bool) – unused, kept for interface compatibility.
tracer – the tracer Plugin, giving access to
domain.active.model – unused, kept for interface compatibility.
ddi – unused, kept for interface compatibility.
**kwargs – unused, kept for interface compatibility.
- Returns:
the forcing data with dimensions
(time, lev, lat, lon)(levandlatof size 1).- Return type:
xr.DataArray
- Raises:
CifError – if
tracer.domainhas noactiveattribute (i.e. its grid was not read throughpycif.plugins.domains.dalecbethy), or if a requested hour cannot be found in a file.
- pycif.plugins.datastreams.fluxes.dalecbethy.write.write(self, name, flx_file, flx, mode='a', metadata=None, **kwargs)[source]#
Write D&B meteorological forcing to a native
dynforcing.ncfile.Builds/appends into the D&B-native forcing format expected by
model_sources/dalecbethy/src/ncread_forcing.f90:: ncread_dynamic_forcing:ng/timedimensions and one(ng, time)variable per meteorological component, with the exactunitsattribute the Fortran reader checks for. The mandatoryyyyymmddhhcalendar variable is not written here (it is not a per-component("meteo", <component>)mapper input): seepycif.plugins.models.dalecbethy.io.inputs.make_forcing.make_meteo(), which copies it as-is from the original forcing file.Values are scattered back from the tracer’s active sample points (
self.domain.active, a subset of the fullself.domain.nggrid cells) to their originalngrow; grid cells outsideself.domain.activeare left asNaN.- Parameters:
self – the fluxes Plugin (with a
dalecbethydomainattached).name (str or list[str]) – name(s) of the component(s) to write.
flx_file (str) – the
dynforcing.ncfile to write/append to.flx (xarray.DataArray or dict[str, xarray.DataArray]) – forcing data, with dimensions
(time, lev, lat, lon)(lev/latof size 1), as returned byread().mode (str) –
"w"to overwrite,"a"to append.metadata (dict, optional) – if given,
metadata["domain"]is used instead ofself.domain.**kwargs – unused, kept for interface compatibility.
- Raises:
CifKeyError – if no domain information can be found.
CifError – if the domain has no
active/ngsample-point selection, or a component has no known expectedunits.