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

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

Configuration reference: VPRM_nc plugin

pycif.plugins.datastreams.fluxes.VPRM_nc.fetch.fetch(ref_dir, ref_file, input_interval, target_dir, tracer=None, **kwargs)[source]#

Fetch VPRM flux files and build hourly date intervals covering the simulation window.

Iterates hourly over input_interval; for each hour, uses find_valid_file to locate the nearest available (forecast-style) file bracketing it, considering the current directory as well as the previous/next hour’s directory when close to a boundary, and links the nearest file into target_dir if it exists.

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

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

  • input_interval (list[datetime.datetime]) – [date_i, date_f] simulation interval to cover.

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

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

Returns:

(list_files, list_dates), each keyed by the hourly date, mapping to the list of resolved file paths and a single-element list with the [start, end] one-hour date interval.

Return type:

tuple[dict, dict]

pycif.plugins.datastreams.fluxes.VPRM_nc.get_domain.get_domain(ref_dir, ref_file, input_interval, target_dir, tracer=None)[source]#

Build the VPRM domain from a reference data file and the corners file.

Locates a reference data file (by exact name match, or by pattern-matching ref_file against filenames in ref_dir) to read the lon/lat cell centers and their min/max extents. Reads the XLONG_C/XLAT_C corner arrays from the separate tracer.corners_file. Initializes a dummy/std domain via Setup using the centers’ extent and shape, then overwrites its zlon/zlat/zlonc/zlatc attributes with the arrays read from file.

Parameters:
  • ref_dir (str) – Directory containing the reference data and corners files.

  • ref_file (str) – Filename (or strftime pattern) of the reference data file.

  • input_interval (list) – Unused directly, kept for interface consistency.

  • target_dir (str) – Unused directly, kept for interface consistency.

  • tracer – The flux tracer plugin, providing corners_file.

Returns:

a surface-only Domain built from the reference and corners files.

Return type:

Domain

Raises:

CifError – If no matching reference data file is found.

pycif.plugins.datastreams.fluxes.VPRM_nc.read.read(self, name, varnames, dates, files, interpol_flx=False, comp_type=None, tracer=None, **kwargs)[source]#

Get fluxes from VPRM files and load them into a pyCIF variable.

For each date/file pair, opens the file and reads the field at the hour-of-day index matching the requested date (each file is expected to hold 24 hourly time steps for one day).

Parameters:
  • name (str) – Unused directly, kept for interface consistency with other flux plugins.

  • varnames (str) – Name of the variable to read in the file.

  • dates (list) – list of [start, end] date intervals to extract; only the start of each interval is used to select the hour of day.

  • files (list) – list of files matching dates (each a single-element list, per fetch’s output).

  • interpol_flx (bool) – Unused, kept for interface consistency.

  • comp_type – Unused, kept for interface consistency.

  • tracer – Unused directly, kept for interface consistency.

Returns:

the flux data with dimensions

(time, lev, lat, lon).

Return type:

xr.DataArray

pycif.plugins.datastreams.fluxes.VPRM_nc.utils.find_valid_file(ref_dir, file_format, dd, ref_dir_next, ref_dir_previous=False)[source]#

Find the nearest available files bracketing a given date.

Lists candidate files in ref_dir matching file_format, extending the search to ref_dir_next/ref_dir_previous when dd is close to a month boundary (within 3 hours), sorts them by parsed date, and returns the file/date pair nearest to dd on-or-before and on-or-after it.

Parameters:
  • ref_dir (str) – Directory to search for candidate files.

  • file_format (str) – strftime-style filename pattern used both to match files and parse their embedded date.

  • dd (datetime.datetime) – Reference date to bracket.

  • ref_dir_next (str) – Directory for the following month, searched in addition to ref_dir when dd is near a month boundary.

  • ref_dir_previous (str or bool) – Directory for the previous month, searched in addition to ref_dir when dd is near a month boundary; False to skip.

Returns:

([file1, file2], [dd1, dd2]), the paths and adjusted dates of the nearest file on-or-before and on-or-after dd.

Return type:

tuple[list[str], list[datetime.datetime]]

Raises:

CifError – If no candidate files are found at all.

pycif.plugins.datastreams.fluxes.VPRM_nc.write.write(self, name, flx_file, flx, mode='a', **kwargs)[source]#

Not implemented; always raises, since writing VPRM fluxes is not supported.