MHMRestartFile#

class mhm_tools.pre.create_mhm_restart_file.MHMRestartFile(grid: Grid, nml_template: Path, output_path: Path, mpr: MPRRunner, work_path=None, increment_l1=2, ncpus=1, run_on_whole_domain=False, use_split_grids=False, merge=True, merge_only=False, clean_temp_files=False)[source]#

Bases: object

A class for creating a restart file for the MHM model.

This class provides methods to split the grid (if necessary), write the grid namelist, call the mpr executable, merge the restart files (if applicable), and delete temporary files (if specified).

Parameters:
  • input_file_path (Path) – The path to the input file.

  • nml_template (Path) – The path to the namelist template file.

  • output_path (Path) – The path to the output directory.

  • work_path (Path) – The path to the working directory.

  • l0 (LatLon) – The LatLon object representing the high resolution grid.

  • l1 (LatLon) – The LatLon object representing the low resolution grid.

  • mpr (MPRRunner) – The MPRRunner object for executing the mpr executable.

  • increment_l1 (int, optional) – The increment for the low resolution grid. Defaults to 2.

  • run_on_whole_domain (bool, optional) – Whether to run on the whole domain. Defaults to False.

  • use_split_grids (bool, optional) – Whether to use split grids. Defaults to False.

  • ncpus (int, optional) – The number of CPUs to use for parallelization. Defaults to 1.

  • clean_temp_files (bool, optional) – Whether to clean temporary files. Defaults to False.

  • merge (bool, optional) – Whether to merge the restart files. Defaults to True.

  • merge_only (bool, optional) – Whether to only merge the restart files. Defaults to False.

Variables:
  • (Path) (output_path)

  • (Path)

  • (Grid) (grid)

  • (list) (subgrids)

  • (int) (increment_l0)

  • (bool) (clean_temp_files)

  • (bool)

  • (bool)

  • (bool)

  • (bool)

  • (MPRRunner) (mpr)

  • (str) (work_dir)

  • (int)

  • (int)

_create_namelist(replace_dict, out_file_path): Create a namelist file by replacing placeholders in the template.
_write_grid_namelist(grid): Write the grid namelist file.
_create_latlon(lon_min, lat_min): Create a LatLon object from the given lon_min and lat_min.
_read_subgrids_from_files(): Read the subgrids from the files on disk.
_split_grid(): Split the grid into subgrids and write them to disk.
_split_file(name, file_path): Split a file into subgrids and write them to disk.
_delete_temp_files(): Delete temporary files.
_merge_restart_files(): Merge the restart files.
_correct_restart_file(ds): Correct the restart file parameters.

Methods

create_restart_file()

Create a restart file for the MHM model.

create_restart_file()[source]#

Create a restart file for the MHM model.

This method creates a restart file by splitting the grid (if necessary), writing the grid namelist, calling the mpr executable, merging the restart files (if applicable), and deleting temporary files (if specified).

Return type:

None

Raises:

Any exceptions that occur during the execution of the method.