pycif.plugins.datastreams.fluxes.dalecbethy — API reference

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 a time coordinate (D&B’s hourly dynamic forcing, e.g. dynforcing.nc), it is read to list the hourly sub-periods overlapping input_interval. Time-invariant static forcing files (e.g. staticforcing.nc, see src/ncread_forcing.f90::ncread_static_forcing) have no time coordinate: they are instead listed as a single period covering the whole of input_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_files and list_dates, both with a single key (the first covered hour, or input_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 time record overlapping input_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 time record in the file and extracts the row of var2extract for D&B’s active sample points (tracer.domain.active, set by pycif.plugins.domains.dalecbethy.read_domain.read_grid()), so that the returned data lines up 1-to-1 with tracer.domain.zlon/zlat.

D&B’s own time records mark the end of each hourly period (see pycif.plugins.datastreams.fluxes.dalecbethy.fetch.fetch, which builds period == [hh - 1h, hh] from each hh record), so periods are matched on period[1], not period[0].

Parameters:
  • self – the fluxes Plugin.

  • name (str) – name of the component.

  • varnames (list[str] or str) – variable name(s) to read; name is used if varnames is 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) (lev and lat of size 1).

Return type:

xr.DataArray

Raises:

CifError – if tracer.domain has no active attribute (i.e. its grid was not read through pycif.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.nc file.

Builds/appends into the D&B-native forcing format expected by model_sources/dalecbethy/src/ncread_forcing.f90:: ncread_dynamic_forcing: ng/time dimensions and one (ng, time) variable per meteorological component, with the exact units attribute the Fortran reader checks for. The mandatory yyyymmddhh calendar variable is not written here (it is not a per-component ("meteo", <component>) mapper input): see pycif.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 full self.domain.ng grid cells) to their original ng row; grid cells outside self.domain.active are left as NaN.

Parameters:
  • self – the fluxes Plugin (with a dalecbethy domain attached).

  • name (str or list[str]) – name(s) of the component(s) to write.

  • flx_file (str) – the dynforcing.nc file to write/append to.

  • flx (xarray.DataArray or dict[str, xarray.DataArray]) – forcing data, with dimensions (time, lev, lat, lon) (lev/lat of size 1), as returned by read().

  • mode (str) – "w" to overwrite, "a" to append.

  • metadata (dict, optional) – if given, metadata["domain"] is used instead of self.domain.

  • **kwargs – unused, kept for interface compatibility.

Raises:
  • CifKeyError – if no domain information can be found.

  • CifError – if the domain has no active/ng sample-point selection, or a component has no known expected units.