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

pycif.plugins.datastreams.fluxes.lmdz_netcdf_ico — API reference#

Configuration reference: lmdz_netcdf_ico plugin

pycif.plugins.datastreams.fluxes.lmdz_netcdf_ico.fetch.get_period_times(ds: Dataset, var_freq: str | None = None)[source]#

Convert a dataset’s time coordinate to validity period start/end times.

Converts the time coordinate values to Pandas periods (inferring the frequency automatically, or using var_freq if given), then returns the start and end timestamp of each period.

Parameters:
  • ds (Dataset) – Dataset holding a time coordinate.

  • var_freq (str, optional) – Time frequency of the data (a Pandas offset alias, without a 'S'/start anchor), passed to pandas.DatetimeIndex.to_period. Inferred automatically if not given.

Returns:

(period_start, period_end), arrays of datetime.datetime marking the start and end of each period.

Return type:

tuple[numpy.ndarray, numpy.ndarray]

Raises:

ValueError – If var_freq ends with the 'S' anchor, or if the time coordinate cannot be parsed/converted to periods.

pycif.plugins.datastreams.fluxes.lmdz_netcdf_ico.fetch.fetch(ref_dir: str, ref_file: str, input_interval: tuple[datetime, datetime], target_dir: str, tracer: object | None = None, **kwargs: Any) tuple[dict[datetime, list[str]], dict[datetime, list[tuple[datetime, datetime]]]][source]#

Fetch LMDZ DYNAMICO NetCDF flux files and derive the validity time intervals they cover.

Builds the list of candidate file dates from tracer.file_freq, links each matching file into target_dir, and computes the period start/end times of every time record in the file via get_period_times (falling back to file_freq as the period frequency for files with a single timestamp).

Parameters:
  • ref_dir (str) – Directory containing the reference input files.

  • ref_file (str) – Filename pattern of the input files (a strftime format string).

  • input_interval (tuple[datetime, datetime]) – (date_i, date_f) simulation sub-period to cover.

  • target_dir (str) – Directory where the resolved files are linked.

  • tracer – The flux tracer plugin, providing file_freq and, optionally, var_freq.

Returns:

(list_files, list_dates), each keyed by the requested sub-period date, mapping to the list of resolved file paths and the list of (start, end) date-interval pairs found in those files. Both are empty if neither ref_dir nor ref_file is given.

Return type:

tuple[dict, dict]

Raises:

FileNotFoundError – If a resolved file does not exist on disk.

pycif.plugins.datastreams.fluxes.lmdz_netcdf_ico.read.read(self, name: str, varnames: str, dates: list[tuple[datetime, datetime]], files: list[str], tracer: object | None = None, **kwargs: Any) DataArray[source]#

Read LMDZ DYNAMICO NetCDF flux files into a pyCIF variable.

For each requested date/file pair, opens the file (only when the file path changes) and selects the exact requested time slice; the native cell dimension is renamed to lon and dummy lev/lat dimensions are added to match pyCIF’s convention.

Parameters:
  • self – The flux tracer plugin instance.

  • name (str) – name of the component

  • varnames (str) – original name of the variable to read; name is used if varnames is empty

  • dates (list[tuple[datetime, datetime]]) – list of (start, end) date intervals to extract

  • files (list[str]) – list of files matching dates

  • tracer – Unused directly, kept for interface consistency with other flux plugins.

Returns:

the flux data with dimensions (time, lev, lat, lon).

Return type:

DataArray

Raises:

ValueError – If a requested time slice yields zero or multiple matches in a file.

pycif.plugins.datastreams.fluxes.lmdz_netcdf_ico.write.write(self, name: str, path: str | PathLike, data: DataArray, metadata: dict[str, Any] | None = None, **kwargs) None[source]#

Write prescribed species fluxes to an LMDZ DYNAMICO NetCDF file.

Builds coordinates from self.domain.get_domain_coords() (plus a time coordinate, if present in data), squeezes the lat and lev dimensions of data, renames the lon dimension to cell to match the DYNAMICO convention, and appends the result to path.

Parameters:
  • self – this plugin

  • name (str) – name of the flux variable to write

  • path (str) – path to the file to write (or append to)

  • data (xarray.DataArray) – Data to write

  • metadata (dict, optional) – Unused, kept for interface consistency with other flux plugins.

Raises:

TypeError – If data is not an xarray.DataArray.