跳转到主要内容

mHM的Python绑定版。

项目描述

mHM - Python绑定

[目录]

控制mHM的Python绑定。

包装器(mhm/wrapper.f90)只是mHM提供的接口上的一个薄层,以便与f2py兼容。

安装

有一个PyPI包可以安装最新版本

pip install mhm

安装 mHM Python 包将提供 mhm 命令来以传统方式执行 mHM。

要从头编译 Python 绑定,你需要

  1. Python 版本至少为 v3.8,以及 pip
  2. Fortran、C 和 C++ 编译器(相应地设置环境变量 FC(和 F77),CCCXX)。如果使用 gcc,这可能是这样的
    export FC="gfortran"
    export F77="gfortran"
    export CC="gcc"
    export CXX="g++"
    
  3. NetCDF-Fortran 已安装在你的系统路径中

查看这些依赖项的 编译 指令。

你也可以使用 conda 环境(例如,使用 miniforge 设置)来获取所有内容

conda install -y pip netcdf-fortran fortran-compiler c-compiler cxx-compiler

在克隆/下载后编译所有内容,可以使用 pip

pip install -v .

要从 git 仓库直接安装,可以输入

pip install -v git+https://git.ufz.de/mhm/mhm.git

环境变量

以下环境变量可用于控制 mHM Python 绑定的编译和安装

  • SKBUILD_CMAKE_BUILD_TYPE=[Release|Debug]:mhm 库的构建类型(默认:Release
  • MHM_BUILD_FORCES_PATH=<path>:自定义 forces 源目录路径(默认:None)
  • MHM_BUILD_PARALLEL=[0|1]:是否使用 OpenMP 与 mHM(默认:0

测试域下载工具

与 Python 绑定一起提供了一个命令行脚本,用于下载测试域

mhm-download --verbose --branch develop --domain 1 --path mhm_domain/

然后你可以使用以下命令在测试域上运行 mHM

mhm mhm_domain/

使用 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)

在 Python 脚本中,你可以使用此工具的 mhm.download_test。下面是示例。

文档

有关提供的例程的更多信息,请参阅 mhm.toolswrapper.f90

示例

如果你已克隆了存储库,你可以按以下方式简单地运行 mhm 而不进行优化

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()

或者你可以这样做来控制每个时间步

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()

请参阅 examples 文件夹。

许可证

LGPLv3 (c) 2005-2023 mHM-Developers

项目详情


下载文件

下载适合您平台的文件。如果您不确定要选择哪个,请了解有关 安装包 的更多信息。

源代码分发

mhm-5.13.1.tar.gz (699.7 kB 查看哈希

上传时间 源代码

构建分发

mhm-5.13.1-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (5.4 MB 查看哈希

上传时间 CPython 3.11 manylinux: glibc 2.17+ x86-64

mhm-5.13.1-cp311-cp311-macosx_10_9_x86_64.whl (5.2 MB 查看哈希

上传时间 CPython 3.11 macOS 10.9+ x86-64

mhm-5.13.1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (5.4 MB 查看哈希值)

上传时间: CPython 3.10 manylinux: glibc 2.17+ x86-64

mhm-5.13.1-cp310-cp310-macosx_10_9_x86_64.whl (5.2 MB 查看哈希值)

上传时间: CPython 3.10 macOS 10.9+ x86-64

mhm-5.13.1-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (5.4 MB 查看哈希值)

上传时间: CPython 3.9 manylinux: glibc 2.17+ x86-64

mhm-5.13.1-cp39-cp39-macosx_10_9_x86_64.whl (5.2 MB 查看哈希值)

上传时间: CPython 3.9 macOS 10.9+ x86-64

mhm-5.13.1-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (5.4 MB 查看哈希值)

上传时间: CPython 3.8 manylinux: glibc 2.17+ x86-64

mhm-5.13.1-cp38-cp38-macosx_10_9_x86_64.whl (5.2 MB 查看哈希值)

上传时间: CPython 3.8 macOS 10.9+ x86-64

支持者

AWS AWS 云计算和安全赞助商 Datadog Datadog 监控 Fastly Fastly CDN Google Google 下载分析 Microsoft Microsoft PSF赞助商 Pingdom Pingdom 监控 Sentry Sentry 错误记录 StatusPage StatusPage 状态页面