pycif.plugins.models.TM5 — API reference#
Configuration reference: TM5 plugin
- pycif.plugins.models.TM5.compile.macros_to_file(macros, macros_file, macros_all)[source]#
PURPOSE Write a list of macros to a file.
IN/OUT macros = list of macros to write to file. Only unique entries
will be written fo file
macros_file = the file to write the macros to macros_all = each macro in macros should be present in this list
in order to prevent typos
KWARGS none
ASSUMPTIONS none
EXCEPTIONS When this function encounters a problem that it cannot solve, it will raise a RuntimeError. Pythons exeception handling will provide a traceback, including files, calls and line numbers.
PYTHON VERSION 3.7.6
VERSION CHANGE HISTORY 1.2 02-02-2021 by J.C.A. van Peet.
- 1.1 26-01-2021 by J.C.A. van Peet.
Updated the local logger and ‘raise RuntimeError’ statement.
- 1.0 18-01-2021 by J.C.A. van Peet.
Original code.
- pycif.plugins.models.TM5.compile.write_dims_grid(dims_grid_path, dx=6.0, dy=4.0, dz=1.0, nregions=1, len_region_name=10, regions=['glb600x400'], parents=['globe'], xcyc=1, touch_np=1, touch_sp=1, xbeg=-180, xend=180, ybeg=-90, yend=90, im=60, jm=45, maxref=10, xref=1, yref=1, zref=1, tref=1)[source]#
PURPOSE Write the Fortran source file dims_grid.F90
IN/OUT dims_grid_path = path to the location where to write dims_grid.F90. The
filename itself will be added automatically.
KWARGS dx = grid cell size in longitude dy = grid cell size in latitude dz = grid cell size in altitude, set to 1.0 nregions = 1 len_region_name = 10: the length of a string in the regions list regions = list with the name of the regions parents = list with the name of the parent regions
Global region 1 should have parent 0 (globe single cell); global surface region should have parent 1 (global region).
coordinates (in degrees) for each region: xcyc = 1 if the region has cyclic x-boundary conditions touch_np = 1 if region touches the north pole touch_sp = 1 if region touches the south pole xbeg = the westmost border of the region xend = the eastmost border of the region ybeg = the southmost border of the region yend = the northmost border of the region im = number of gridcells in longitude direction jm = number of gridcells in latitude direction
refinement factors for each region (<= maxref) tref may differ from xref/yref. In the current implementation it should be 1,2,4,6,… maxref = maximum refinement factor (can be arbitrary in principle) xref = yref = zref = tref =
ASSUMPTIONS none
EXCEPTIONS When this function encounters a problem that it cannot solve, it will raise a RuntimeError. Pythons exeception handling will provide a traceback, including files, calls and line numbers.
PYTHON VERSION 3.7.6
VERSION CHANGE HISTORY 1.2 02-02-2021 by J.C.A. van Peet.
- 1.1 26-01-2021 by J.C.A. van Peet.
Updated the local logger.
- 1.0 18-01-2021 by J.C.A. van Peet.
Code to fill the list ‘lines’ copied from …TM5/base/py/TM5_Tools.py, class Build_Configure_Grid( object ), __init__(…), using “build_release = 1”.
- pycif.plugins.models.TM5.compile.compile(self)[source]#
PURPOSE Compile the TM5 source tree into an executable
IN/OUT none
KWARGS none
ASSUMPTIONS none
EXCEPTIONS When this function encounters a problem that it cannot solve, it will raise a RuntimeError. Pythons exeception handling will provide a traceback, including files, calls and line numbers.
PYTHON VERSION 3.7.6
VERSION CHANGE HISTORY 2.4 19-04-2021 by J.C.A. van Peet.
After copying the model source from the TM5 source tree to the CIF source tree, I had to prepend self.direxec to a few variables.
- 2.3 02-02-2021 by J.C.A. van Peet.
*) Updated PROG_NAME *) Used new PROG_NAME as local logger name. *) Moved some compilation statements (see 18-01-2021) into
the “auto_recompile” if-statement.
*) Updated the subprocess commands so that the output is logged live. *) Updated comp_dir to self.workdir/model/src
- 2.2 26-01-2021 by J.C.A. van Peet.
- *) Removed function logging.empty(…), you can now simply do
logger.info(“”) to print an empty line.
- *) Initialised a local logger, so replaced all calls to logging with
calls to logger.
*) RuntimeErrors are now also logged in the logfile. *) Added universal_newlines=True to all subprocess.Popen calls. As a
- result, you don’t have to do
logger.debug(”
- “+””.join(stdout.decode(“ascii”)))
- anymore, but you can just do
logger.debug(stdout)
- 2.1 19-01-2021 by J.C.A. van Peet.
Added custom function logging.empty(…) to write empty lines to logfile.
- 2.0 18-01-2021 by J.C.A. van Peet.
*) Added compilation of tm5. *) Renamed the tm5.exe to tm5.x *) Replaced print statements with logging statements.
- 1.0 03-11-2020 by J.C.A. van Peet.
Original code, based on an example by A. Berchet.
- pycif.plugins.models.TM5.flushrun.flushrun(self, rundir, mode, transform_id, full_flush=True)[source]#
Cleaning the simulation directories to limit space usage
- pycif.plugins.models.TM5.ini_mapper.ini_mapper(model, general_mapper={}, backup_comps={}, transforms_order=[], ref_transform='', **kwargs)[source]#
PURPOSE The ini_mapper function is mandatory to make a model work. It informs pycif about the inputs and outputs of the model. It should return a so-called “mapper”. A mapper is a dictionary with two keys:
- Both inputs and outputs keys are them selves dictionaries. Their format is:
*) (“type”, “parameter”): {information dictionary}
The pair (“type”, “parameter”) should cover all the necessary inputs and outputs. In the case when no “parameter” is relevant, and empty string can be specified.
The information dictionary can include the following information, depending on your model:
- *) input_dates: all dates at which the model expects some inputs for the
given type/parameter; e.g., if TM5 needs 3-hourly meteo fields, input_dates will be the list of all dates in the simulation period with a frequency of 3H; it is recommended to initiate this variable in the function ini_periods, that initiates all date related variables for your model
*) domain: usually the same as the model domain *) force_dump: True if the given type/parameter should be dumped before
running the model executable
*) any other parameter that can be used in the native2inputs / outputs2native functions.
IN/OUT none
KWARGS none
ASSUMPTIONS none
EXCEPTIONS When this function encounters a problem that it cannot solve, it will raise a RuntimeError. Pythons exeception handling will provide a traceback, including files, calls and line numbers.
PYTHON VERSION 3.7.5
VERSION CHANGE HISTORY 1.0 18-09-2020 by J.C.A. van Peet.
Original code.
- pycif.plugins.models.TM5.run.silent_remove(filename)[source]#
PURPOSE Delete a file without raising an exception if it doesn’t exist.
IN/OUT filename = string with the filename to remove.
VERSION CHANGE HISTORY 1.1 02-02-2021 by J.C.A. van Peet.
- 1.0 09-11-2020 by J.C.A. van Peet.
Copied from https://stackoverflow.com/a/10840586, changed function name from silentremove to silent_remove.
- pycif.plugins.models.TM5.run.run(self, runsubdir, mode, workdir, ddi, do_simu=True, **kwargs)[source]#
PURPOSE Call this function to run the TM5 model. I’m not sure which module does call this function… The order appears to be to first call compile.py, then params.py and then the current function…
IN/OUT runsubdir = working directory for the current run (str) mode = forward or backward (str) workdir = pyCIF working directory (str)
KWARGS none
ASSUMPTIONS none
EXCEPTIONS When this function encounters a problem that it cannot solve, it will raise a RuntimeError. Pythons exeception handling will provide a traceback, including files, calls and line numbers.
PYTHON VERSION 3.7.6
VERSION CHANGE HISTORY 2.1 22-10-2021 by J.C.A. van Peet.
- Writing point departure files has been moved by Antoine to the module
…/plugins/models/TM5/io/inputs/make_obs.py
which makes use of functions that have been moved from the current run.py module to
…/plugins/models/TM5/io/utils/point_data.py