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

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

Configuration reference: CAMSREG_nc plugin

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

Fetch TNO/CAMS-REG forecast-style files covering the simulation interval.

Iterates daily over input_interval; for each day, brackets the nearest valid file within a 3-hour window in the current (and, at month boundaries, adjacent) directory using find_valid_file(), links the found file into target_dir, and builds hourly date sub-intervals for that day.

Parameters:
  • ref_dir (str) – directory where the original files are found.

  • ref_file (str) – (template) name of the original files.

  • input_interval (list) – simulation interval, as a list of the two bounding dates.

  • target_dir (str) – directory where links to the original files are created.

  • tracer – the tracer Plugin, corresponding to the paragraph datavect/components/fluxes/parameters/my_species in the configuration yaml.

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

Returns:

list_files and list_dates.

list_files: for each date that begins a period, a list containing

the names of the files that are available for the dates within this period.

list_dates: for each date that begins a period, a list containing

the date intervals matching the files listed in list_files.

Return type:

(dict, dict)

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

Build the horizontal (and, for point sources, vertical) domain.

Dispatches to get_area_domain() for the default gridded area-source mode, or to get_point_domain() when tracer.point_sources is set.

Parameters:
  • ref_dir (str) – directory where the original files are found.

  • ref_file (str) – (template) name of the original files.

  • input_interval (list) – simulation interval, as a list of the two bounding dates.

  • target_dir (str) – directory where links to the original files are created.

  • tracer – the tracer Plugin, corresponding to the paragraph datavect/components/fluxes/parameters/my_species in the configuration yaml.

Returns:

a domain class object, gridded (area mode) or unstructured (point-source mode).

Return type:

Domain

pycif.plugins.datastreams.fluxes.CAMSREG_nc.get_domain.get_area_domain(tracer)[source]#

Build a regular gridded domain from a TNO/CAMS-REG reference file.

Reads longitude/latitude and their _bounds variables from the first fetched input file to build the grid centers and corners, with a single dummy vertical level (surface only).

Parameters:

tracer – the tracer Plugin holding the list of fetched input files (tracer.input_files).

Returns:

a gridded, single-level domain.

Return type:

Domain

Raises:

CifError – if no reference file could be found among the fetched input files.

pycif.plugins.datastreams.fluxes.CAMSREG_nc.get_domain.get_point_domain(tracer)[source]#

Build an unstructured point-source domain from TNO/CAMS-REG files.

Reads the TNO vertical height-distribution profile CSV to determine the vertical levels, then loops over all fetched input files to extract non-zero point-source emission locations (filtered by emission category and source type), building an unstructured domain where each point is associated with the file it came from (value_file).

Parameters:

tracer – the tracer Plugin, giving access to dir_profiles, cat_select, and the fetched input_dates/input_files.

Returns:

an unstructured domain with one horizontal “cell” per point source and nlev vertical height bins.

Return type:

Domain

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

Get GNFR-profiled TNO/CAMS-REG fluxes and load them into a pyCIF array.

Loads the GNFR month-in-year, day-in-week and hour-in-day time-profile CSVs (and the height-distribution profile if tracer.point_sources is set) from tracer.dir_profiles. For each requested date/file, loops over the emission categories present in the file, matches each to its GNFR temporal profile (falling back to tracer.default_profil if a category has no matching profile), applies the month/weekday/hour (and height, for point sources) scaling coefficients to the raw category emission, and accumulates the result — either scattered onto point-source grid cells, or onto gridded area cells normalized by cell area (to kg/m2/h-equivalent units, converted from /km2).

Parameters:
  • name (str) – name of the component.

  • varnames (list[str] or str) – variable name(s) to read from the file.

  • dates (list) – list of the date intervals to extract.

  • files (list) – list of files matching dates.

  • interpol_flx (bool) – unused, kept for interface compatibility.

  • comp_type – unused, kept for interface compatibility.

  • tracer – the tracer Plugin, giving access to dir_profiles, point_sources, cat_select and default_profil.

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

Returns:

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

Return type:

xr.DataArray

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

Find the pair of files bracketing a reference date.

Lists the files in ref_dir (and, when dd falls near a month boundary, in ref_dir_next/ref_dir_previous) that match file_format, parses their date from the file name, sorts them, and returns the nearest available file/date before dd and the nearest one after dd (used to bracket forecast-style files).

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

  • file_format (str) – strptime/strftime-compatible file name pattern used both to parse each candidate file’s date and to derive dd’s canonical file name.

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

  • ref_dir_next (str) – adjacent directory to also search when dd is close to the end of its month.

  • ref_dir_previous (str or bool) – adjacent directory to also search when dd is close to the start of its month; False to skip this lookup.

Returns:

a 2-element list of file paths [file_before, file_after] and the corresponding 2-element list of dates [date_before, date_after] bracketing dd.

Return type:

(list[str], list[datetime.datetime])

Raises:

CifError – if no file matching file_format is found in ref_dir (and adjacent directories, if searched).

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

Not implemented: writing TNO/CAMS-REG fluxes is not supported.

Raises:

CifError – always.