个人 GitHub 账号下公开仓库的所有者可以登录并验证所有权,自行管理介绍,无需管理员批准。
登录并生成验证文件,在 30 分钟内将其提交到此仓库的默认分支。其他分支或分叉仓库中的文件无效。然后在下方检查文件,即可无需管理员批准直接管理项目。请保留文件以维持管理权限。
如需登录,将前往登录页面。登录后请回到此处,再次点击所选的验证按钮。
在项目文件夹中运行 /nomorevibe verify,即可验证所有权并自行管理介绍。
一分钟完成验证一套用于 Soil and Water Assessment Tool(SWAT)的 Python 软件模块,包括模型运行、程序化配置编辑、模拟结果读取以及使用出色的 SPOTPY 包进行校准
AI 翻译
a set of python modules to work with the Soil and Water Assessment Tool (SWAT), including model run, programmatic config edits, simulation readouts and callibration with the fantastic SPOTPY package
取自仓库 README
正在加载完整 README。 以下为已保存的摘录。
A set of Python modules to work with the Soil and Water Assessment Tool (SWAT2012), including model runs, programmatic edits of the model input files, readout of simulation outputs and calibration with the SPOTPY package.
swatpy requires Python 3.10 or newer. A SWAT2012 executable is not included; it is looked up on the PATH or in the model directory, or it can be set explicitly as model.swat_exec.
A model is a working copy of an ArcSWAT TxtInOut folder with a small metadata file (.swatmodel.json):查看完整 README ↗A set of Python modules to work with the Soil and Water Assessment Tool (SWAT2012), including model runs, programmatic edits of the model input files, readout of simulation outputs and calibration with the SPOTPY package.
pip install swatpy # numpy and chardet only
pip install "swatpy[calibration]" # plus spotpy, scipy and pandas for the calibration scripts
pip install "swatpy[mpi]" # plus mpi4py for parallel spotpy samplers
swatpy requires Python 3.10 or newer. A SWAT2012 executable is not included; it is looked up on the PATH or in the model directory, or it can be set explicitly as model.swat_exec.
A model is a working copy of an ArcSWAT TxtInOut folder with a small metadata file (.swatmodel.json):
from swatpy import SwatModel, ReadOut
model = SwatModel.initFromTxtInOut("path/to/TxtInOut", copy=True, target_dir="work")
# later: model = SwatModel.loadModelFromDirectory("work")
model.enrichModelMeta() # simulation period and printed years from file.cio
# calibration parameters: <v|r|a>__<PARAM>__<file type>
model.setParameter("r__CN2__mgt", -0.1) # relative: CN2 * (1 - 0.1) in all .mgt files
model.setParameter("v__GW_DELAY__gw", 30.0) # replace
model.setParameter("a__SOL_AWC__sol", 0.02) # add, all soil layers
model.swat_exec = "/path/to/swat2012"
model.run(silent=True)
reach = ReadOut.rchOutputManipulator(["FLOW_OUT"], [1], "skip", True, 0, model.working_dir, iprint="month")
flow = reach.outValues["FLOW_OUT"][1]
The file manipulators in swatpy.FileEdit (bsn, gw, mgt, sub, hru, rte, sol, file.cio) read and write parameters at their fixed positions in the SWAT input files. Changes are always computed from the values read when the manipulator was created, so repeated calibration runs do not accumulate; changes of several parameters of the same file are all kept. The line endings of the files are preserved. The SWAT-CUP qualifiers of a parameter name (hydrologic group, soil texture, landuse, subbasin, slope; e.g. v__CANMX__hru______FRSD) are parsed but not evaluated, such a parameter is applied to all files of its type.
The output readers in swatpy.ReadOut take the column positions of the variables from the header line of output.rch, output.sub and output.hru, so a reduced selection of printed variables in file.cio is read correctly. The yearly summary rows of monthly output and the closing average-annual rows are skipped.
The folder data/scripts contains the calibration drivers used with SPOTPY on the University of Tartu HPC cluster (sequential and MPI), and data/params the corresponding parameter ranges.
Version 0.3.0 fixes several errors that affect calibration results produced with earlier versions:
finishChangePar() in between (as in the calibration scripts) overwrote each other, only the last parameter per file type was applied;iprint="month") dropped December and kept the yearly summary row instead;efficiency.nash() and agr() returned a masked value when the observations contain nodata;SOL_ZMX joined two lines of the .sol file, and SOL_ZMX was read without its first digit;file.cio values were written as decimals, and solManipulationCorrection doubled the clay content;output.hru was read from the wrong columns.The packaging moved from setup.py to pyproject.toml; spotpy, scipy and pandas are optional dependencies now.
The user and API documentation lives in docs/ and is published to GitHub Pages at https://allixender.github.io/swatpy/ (built by .github/workflows/docs.yml).
pip install -e ".[docs]" # mkdocs-material + mkdocstrings
mkdocs serve # live preview
pip install -e ".[dev]"
pytest -m "not swat" # unit tests on synthetic fixtures
SWATPY_TEST_DOWNLOAD=1 pytest -m swat -rs # real SWAT2012 project, and model runs on linux x86_64
pytest tests/test_fileedit.py -k sol # a subset
The unit tests use a small synthetic SWAT2012 model and synthetic output files in tests/data, generated by tests/data/make_fixtures.py in the fixed-width layout of SWAT2012 rev 637. The swat tests download the rev 637 demo project and Linux executable from SWATdata (GPL-3, therefore not included here) into ~/.cache/swatpy-tests; SWATPY_SWAT_EXE points them to another SWAT2012 executable.
Releases are published to PyPI with trusted publishing from GitHub Actions (.github/workflows/publish.yml):
__version__ in swatpy/__init__.py and the version in CITATION.cff;v<version>, which builds, checks and uploads the package to PyPI;This requires a trusted publisher for the project swatpy on PyPI (and TestPyPI) with the repository allixender/swatpy, the workflow publish.yml and the environment pypi (testpypi), as well as these two environments in the GitHub repository settings.
If you use swatpy, please cite it via the Zenodo DOI 10.5281/zenodo.6322023, see also CITATION.cff.