Package: mhm
mHM - Python bindings[TOC]Python bindings to control mHM.The wrapper (mhm/wrapper.f90) is just a small layer on top of the
interfaces provided by mHM to be compatible withf2py.InstallationThere is aPyPI packageto install the latest release:pipinstallmhmInstalling the mHM Python package will provide themhmcommand to execute mHM the traditional way.In order to compile the Python bindings from scratch you need:Pythonwith version at least v3.8 andpipa Fortran, a C and a C++ compiler (set the environment variablesFC(andF77),CCandCXXaccordingly).
In case of gcc, this could look like:exportFC="gfortran"exportF77="gfortran"exportCC="gcc"exportCXX="g++"NetCDF-Fortraninstalled in your system pathSee theCompilationinstructions for these dependencies.You can also use a conda environment (set up withminiforgefor example)
to get everything:condainstall-ypipnetcdf-fortranfortran-compilerc-compilercxx-compilerTo compile everything after cloning/downloading, you can use pip:pipinstall-v.To install it directly from the git repository you can type:pipinstall-vgit+https://git.ufz.de/mhm/mhm.gitEnvironment variablesThe following environment variables can be used to control the compilation and installation of the python bindings for mHM:SKBUILD_CMAKE_BUILD_TYPE=[Release|Debug]: build type for the mhm library (default:Release)MHM_BUILD_FORCES_PATH=<path>: custom path to forces source dir (default: None)MHM_BUILD_PARALLEL=[0|1]: whether to use OpenMP with mHM (default:0)Test domain download toolTogether with the Python bindings comes a command line script to download the test domains:mhm-download--verbose--branchdevelop--domain1--pathmhm_domain/You can then run mHM on this test domain with:mhmmhm_domain/You can get help on how to use this script withmhm-download -h:$ mhm-download -h
usage: mhm-download [-h] [-V] [-v] [-b BRANCH] [-d {1,2}] [-p PATH]

Download tool to retrieve the test domains for mHM.

optional arguments:
  -h, --help            show this help message and exit
  -V, --version         display version information
  -v, --verbose         be verbose (default: False)
  -b BRANCH, --branch BRANCH
                        branch, tag, or commit of the mHM repository to take the test domain from,
                        by default tag determined from the mHM version (default: None)
  -d {1,2}, --domain {1,2}
                        test domain '1' or '2' (default: 1)
  -p PATH, --path PATH  destination path for the downloaded folder,
                        by default the original folder name in the current directory (default: None)Within python scripts, you can use this tool withmhm.download_test. See below for examples.DocumentationSeemhm.toolsandwrapper.f90for further information on the provided routines.ExamplesIf you have cloned the repository, you can do the following to simply run mhm without optimization:importmhm# download test domain 1mhm.download_test(path="example_domain")# run the downloaded examplemhm.model.init(cwd="example_domain")mhm.model.run()mhm.model.finalize()Or you can do the following to control each timestep:importmhm# assuming to run from the mhm repo rootmhm.model.init()mhm.run.prepare()ndomians=mhm.run.get_ndomains()foriinrange(1,ndomians+1):mhm.run.prepare_domain(domain=i)# 0 by defaultwhilenotmhm.run.finished():mhm.run.do_time_step()mhm.run.write_output()mhm.run.finalize_domain()mhm.run.finalize()mhm.model.finalize()See also theexamplesfolder.LicenseLGPLv3 (c) 2005-2023 mHM-Developers