A Python package creating an interface with the ParFlow hydrologic model.
Project description
pftools
This is a package to run ParFlow via a Python interface. This package allows the user to build a script in Python that builds the database (.pfidb file) which ParFlow reads as input.
How to use this package
-
Install with the following command:
pip install pftools
-
Open a new Python script in your favorite text editor or IDE.
- You can find example Python scripts in the main ParFlow repo under /parflow/test/python/
-
At the top of the script, make sure you include the following lines:
from parflow import Run runname = Run("runname", __file__)
This imports the package and initializes your run as the object "runname"
-
Set your desired keys and values on your ParFlow run object, such as:
runname.FileVersion = 4
Note: for user-defined key names, make sure you've defined the names before you use them as a key name. For example:
runname.GeomInput.Names = 'domain_input'
needs to be set before:
runname.GeomInput.domain_input.InputType = 'SolidFile'
-
After you have assigned values to your keys, you can call multiple methods on your ParFlow run object:
validate()
: This will validate your set of key/value pairs and print validation messages. This does not require ParFlow.write(file_name=None, file_format='pfidb')
: This will write your key/value pairs to a file with your choice of format (default is the ParFlow databasepfidb
format). Other acceptable formats passed as thefile_format
argument includeyml
,yaml
, andjson
. This method does not require ParFlow.clone(name)
: This will generate a clone object of your run with the givenname
. Seeparflow/test/python/new_features/serial_runs/serial_runs.py
for an example of how to use this.run(working_directory=None, skip_validation=False)
: This will execute thewrite()
method. Ifskip_validation
is set toFalse
, it will also execute thevalidate()
method. Theworking_directory
can be defined as an argument if you would like to change the directory where the output files will be written, but it defaults to the directory of the Python script. Finally,run()
will execute ParFlow. This will print the data for your environment (ParFlow directory, ParFlow version, working directory, and the generated ParFlow database file). If ParFlow runs successfully, you will get a messageParFlow ran successfully
. Otherwise, you will get a messageParFlow run failed.
followed by a print of the contents of therunname.out.txt
file.
-
Once you have completed your input script, save and run it via the Python terminal or command line:
python3 runname.py
You can append one or more of the following arguments to the run:
--parflow-directory [None]
: overrides environment variable for$PARFLOW_DIR
.--parflow-version [None]
: overrides the sourced version of ParFlow used to validate keys.--working-directory [None]
: overrides the working directory for the ParFlow run. This is identical to specifyingworking_directory
in therun()
method.--skip-validation [False]
: skips thevalidate()
method if set toTrue
. This is identical to specifyingskip_validation
in therun()
method.--show-line-error [False]
: shows the line where an error occurs when set toTrue
.--exit-on-error [False]
: causes the run to exit whenever it encounters an error when set toTrue
.--write-yaml [False]
: writes the key/value pairs to a yaml file when set toTrue
. This is identical to calling the methodrunname.write(file_format='yaml)
.-p [0]
: overrides the value forProcess.Topology.P
(must be an integer).-q [0]
: overrides the value forProcess.Topology.Q
(must be an integer).-r [0]
: overrides the value forProcess.Topology.R
(must be an integer).
How to update this package (developers only)
This assumes that you are using CMake with the pftools package as it is contained within the main ParFlow repo (see https://github.com/parflow/parflow)
-
Update the version number in
setup.py
. -
Build with the cmake command line. Make sure that Python is enabled through the
PARFLOW_ENABLE_PYTHON
option.mkdir build cd build cmake .. \ -D PARFLOW_ENABLE_PYTHON=TRUE
-
Run the following command to create and test a source archive and a wheel distribution of the package. Make sure you are running this command in an environment with the
twine
Python package installed.make PythonCreatePackage
-
If the distributions pass, run the following command to publish the distributions. In order to run this command successfully, you must first set the
TWINE_USERNAME
andTWINE_PASSWORD
environment variables to the username and password that you will use to authenticate with PyPI.make PythonPublishPackage
-
Check PyPI to make sure your package update was published correctly. Thanks for contributing!
Getting help
If you have any issues or questions about the code, please refer to one of the following options:
- User mailing list: Parflow-Users
- ParFlow blog: Parflow Blog
- GitHub repo (for tracking issues and requesting features): Parflow Issue Tracker
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 Distribution
File details
Details for the file pftools-1.3.11.tar.gz
.
File metadata
- Download URL: pftools-1.3.11.tar.gz
- Upload date:
- Size: 119.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.0.0 CPython/3.9.12
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | a3b80b9950033da17c6b4c17a6be41fd38ce12f14dffc87ae91b6b805df28514 |
|
MD5 | 1e7c7a06d2e0806b750a76ad92189838 |
|
BLAKE2b-256 | 69d3fcc040f38223cf331bc8bdb8f5a233d79ecc5611ea0d8a942f04b8a3203d |
File details
Details for the file pftools-1.3.11-py3-none-any.whl
.
File metadata
- Download URL: pftools-1.3.11-py3-none-any.whl
- Upload date:
- Size: 124.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.0.0 CPython/3.9.12
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7364be2f18de25482b05e8bd81e98b2ed06f747904e3f913e4cb0e73a3b05d26 |
|
MD5 | 00807ea11c8dfbe4443da1d27d1db24a |
|
BLAKE2b-256 | d8adf3716d7f399d35184af52f5f48928918af1d0f6241e126737d577dd7e3ce |