Python distribution of mHM with bindings.
Project description
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 with f2py.
Installation
There is a PyPI package to install the latest release:
pip install mhm
Installing the mHM Python package will provide the mhm
command to execute mHM the traditional way.
In order to compile the Python bindings from scratch you need:
- Python with version at least v3.8 and pip
- a Fortran, a C and a C++ compiler (set the environment variables
FC
(andF77
),CC
andCXX
accordingly). In case of gcc, this could look like:export FC="gfortran" export F77="gfortran" export CC="gcc" export CXX="g++"
- NetCDF-Fortran installed in your system path
See the Compilation instructions for these dependencies.
You can also use a conda environment (set up with miniforge for example) to get everything:
conda install -y pip netcdf-fortran fortran-compiler c-compiler cxx-compiler
To compile everything after cloning/downloading, you can use pip:
pip install -v .
To install it directly from the git repository you can type:
pip install -v git+https://git.ufz.de/mhm/mhm.git
Environment variables
The following environment variables can be used to control the compilation and installation of the python bindings for mHM:
MHM_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
)MHM_BUILD_PY_SCRIPT=[0|1]
: whether to create a console script for mHM with the Python bindings (default:1
)
Test domain download tool
Together with the Python bindings comes a command line script to download the test domains:
mhm-download --verbose --branch develop --domain 1 --path mhm_domain/
You can then run mHM on this test domain with:
mhm mhm_domain/
You can get help on how to use this script with mhm-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 with mhm.download_test
. See below for examples.
Documentation
See mhm.tools
and wrapper.f90
for further information on the provided routines.
Examples
If you have cloned the repository, you can do the following to simply run mhm without optimization:
import mhm
# download test domain 1
mhm.download_test(path="example_domain")
# run the downloaded example
mhm.model.init(cwd="example_domain")
mhm.model.run()
mhm.model.finalize()
Or you can do the following to control each timestep:
import mhm
# assuming to run from the mhm repo root
mhm.model.init()
mhm.run.prepare()
ndomians = mhm.run.get_ndomains()
for i in range(1, ndomians + 1):
mhm.run.prepare_domain(domain=i) # 0 by default
while not mhm.run.finished():
mhm.run.do_time_step()
mhm.run.write_output()
mhm.run.finalize_domain()
mhm.run.finalize()
mhm.model.finalize()
See also the examples
folder.
License
LGPLv3 (c) 2005-2023 mHM-Developers
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distributions
Hashes for mhm-5.13.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5e15dff96b03340d8ad0360e5505cb6336db9d46365ba5293b91ba3c113b02b3 |
|
MD5 | 757cba2b20d47531f817458c186123cf |
|
BLAKE2b-256 | fadb82a7f92ffd4a5eaf90f6dc24273fee7ac73c92c03db738bff36f4805bb0f |
Hashes for mhm-5.13.0-cp311-cp311-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f1111602056508e46e75465f6c199e360fbd7a85fdc2b775cb000d11379d3966 |
|
MD5 | 6d64b9dcb862a89f3f04cd9003533822 |
|
BLAKE2b-256 | 0931bc28bf1383059bf12d20c0d5b076628532284ee13987f44761cad5ebc9d2 |
Hashes for mhm-5.13.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 47182de62ca84c19cc452007640496c839c7ff195f3bf84383ef468c33db0464 |
|
MD5 | b75c2f33042450ff8f0a54788dee7560 |
|
BLAKE2b-256 | 2c31543653ce027dfbb1aa407dcf29af142996c37cbdcb67fc0b1c2ec689da38 |
Hashes for mhm-5.13.0-cp310-cp310-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c5ab365071120bb08193e765f7f9f466449b4f51b6fc4eb21d57741b90db64e3 |
|
MD5 | bd4cc567efe65159d8c45b81b5b73f31 |
|
BLAKE2b-256 | 46b3ef5ede7ffc0dc1e30131cd88a2740e148b46b46f36c36f082df4b00fa590 |
Hashes for mhm-5.13.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ef713e3c9546cfca38cb7108e7eaef0c5d8202d7d6c7f1c0c988eb5030b4aae1 |
|
MD5 | 1fce7cdcc8594edb40659e6db03710b2 |
|
BLAKE2b-256 | 4ba4833588652930c473fc7472fbbedef9123892c2279f2908e032fdfbae12c5 |
Hashes for mhm-5.13.0-cp39-cp39-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 64bb98e570d9dfcde576af58fbd1bccd97467db33ec92830228e950d5d19122a |
|
MD5 | d2c593dba21223fd009a0afd95211d01 |
|
BLAKE2b-256 | f6beac37b2242a3884cdfd039762f4c2f5c6ee5b255f382e6cfd006f24ddb43d |
Hashes for mhm-5.13.0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 390b1466c862e2c406879b120346af6d9ad9e787abef1af2368249374d00c4b0 |
|
MD5 | 9e7bff918d0ae8382b0866bc122f1a00 |
|
BLAKE2b-256 | 99c762b906e2001b4134f7131295cf205827a04da364db6679e696e877fe752f |
Hashes for mhm-5.13.0-cp38-cp38-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9f10a658ecac99a9f35dc693a1989e7c4db35addb57fcd8611e01ab4d2341526 |
|
MD5 | afa393edb12bbf8b382e2a8acd6011fd |
|
BLAKE2b-256 | 5260b0820f073b10ae2de5c677fa2b3d19e6d83594370ab0c4916bb78d8243f5 |