pycif.plugins.datastreams.fluxes.wrfchem — API reference#
Configuration reference: wrfchem plugin
- pycif.plugins.datastreams.fluxes.wrfchem.fetch.fetch(ref_dir, ref_file, input_interval, target_dir, tracer=None, **kwargs)[source]#
Links flux files to target_dir, returns file list
Inputs:#
ref_dir: directory where the original files are found (yml: dir) ref_file: (template) name of the original files (yml: file) input_interval: list of the periods to simulate, each item is the list
of the dates of the period # FR: I think now it’s just start and end date to
simulate (2021-09-20)
target_dir: directory where the links to the orginal files are created
Ouputs:#
- list_files: for each date that begins a period, an array containing
the names of the files that are available for the dates within this period
- list_dates: for each date that begins a period, an array containing
the names of the dates mathcin the files listed in list_files
VERSION HISTORY (before incremental git commit messages) 2021-09-22 freum Reverted 2021-09-21 to one item per file 2021-09-21 freum Changed list_dates to one item per subsimu
start. Left the original lines in there but commented.
- 2021-09-20 freum After talking to Antoine, copied first part of
chimere’s fetch instead, then adapted ctdas’ observationoperator_wrfchem.py into it
- 2021-08-20 freum Original from flux_template_plugin, raising
NotImplementedError at beginning
- pycif.plugins.datastreams.fluxes.wrfchem.get_domain.get_domain(ref_dir, ref_file, input_interval, target_dir, tracer=None)[source]#
Not used; always raises immediately.
The wrfchem flux plugin’s domain is instead provided by a separate
wrfchemdomain plugin (see this plugin’srequirements). The code below the raise is unreachable leftover template code (never executed) and is kept only for reference/history.- Raises:
CifNotImplementedError – Always, immediately.
VERSION HISTORY
2021-08-20 freum Original from flux_template_plugin, raising NotImplementedError at beginning
- pycif.plugins.datastreams.fluxes.wrfchem.read.read(self, trcr, varname, in_dates, in_files, comp_type, tracer, model, ddi, **kwargs)[source]#
Read fluxes from files and load them into a xarray.DataArray
Inputs:#
Arguments as in plugins/transforms/system/fromcontrol/forward.py. trcr: string
Name in the yaml
- varname: string
Variable name in file. In yaml it’s “varname”. If it’s not defined in the yaml it’s empty here.
- in_dates: list of datetime.datetime objects
All input dates
- in_files: list of strings
For each in_dates, the file where the flux is found
- comp_type: string
Name of component in yaml, i.e. level above parameter. Currently “flux” in my config_wrfchem_explanations.yml. Probably won’t use it.
- tracerPlugin flux
Full flux object, with everything in the yaml. Use this instead of the self in read.py because that self can be modified. Same with write.
- model: model plugin
So you can use e.g. its domain subplugin
- ddi: datetime.datetime?
Start of model period, probably won’t use it.
- **kwargs:
Ignore, will be removed.
Ouputs:#
- xmod: xarray.DataArray
Flux data. Dimensions: (time, vertical levels, latitude, longitude) Coordinates in increasing order.
VERSION HISTORY (before incremental git commit messages) 2021-09-20 freum Wrote it. 2021-09-17 freum Changed arguments to the ones in
pycif/plugins/transforms/system/fromcontrol/forward.py
- 2021-08-20 freum Original code from flux_plugin_template, put a
NotImplementedError at the beginning.
- pycif.plugins.datastreams.fluxes.wrfchem.times_in_wrf_file.times_in_wrf_file(filename)[source]#
Decode a WRF NetCDF file’s
Timesvariable into a list of datetimes.- Parameters:
filename (str) – Path to the WRF NetCDF file to inspect.
- Returns:
One timestamp per record in the file’s
Timescharacter-array variable, parsed with the format%Y-%m-%d_%H:%M:%S.- Return type:
list[datetime.datetime]
- pycif.plugins.datastreams.fluxes.wrfchem.utils.find_valid_file(ref_dir, file_format, dd)[source]#
Not used; always raises immediately.
The code below the raise is unreachable leftover template code (a nearest-file-lookup pattern, never executed) and is kept only for reference/history.
- Raises:
CifNotImplementedError – Always, immediately.
VERSION HISTORY
2021-08-20 freum Original from flux_template_plugin, raising NotImplementedError at beginning
- pycif.plugins.datastreams.fluxes.wrfchem.write.write(self, name, flx_file, date, flx, domain, mode)[source]#
Write flux data for one timestep to WRF-Chem flux input file
In
mode="w", creates a new NetCDF file with the standard WRF emission dimensions/variables, and copies the relevant global attributes from the domain’swrfinput_d01file. Inmode="a", locates the matching time index in an existing file, creates the variable if missing, checks that the horizontal (and vertical) dimensions match, and writes the flux values (filling masked values with 0). Supports the unstructured WRF domain by reshaping the flattened flux back to(south_north, west_east).- Parameters:
self (Fluxes) – the Fluxes plugin
name (str) – Name of variable in flx file
flx_file (str) – the file where to write fluxes
date (datetime.datetime) – Timestamp of the flux
flx (numpy.ndarray) – fluxes data to write, with a single time index
domain – domain plugin
mode (str) – ‘w’ to overwrite, ‘a’ to append (existing files)
- Raises:
CifValueError – If flx holds more than one time index, if
mode='w'and flx_file already exists, if the requested date is not found exactly once in an existing file (mode='a'), if the horizontal dimensions of flx do not match the file’s, if the vertical dimension of flx exceeds the file’s, or if mode is neither'w'nor'a'.