The Hydrologic Simulation Program–Python (HSP2) watershed model is is a port of the well-established Hydrological Simulation Program - FORTRAN (HSPF), re-coded with modern scientific Python and data formats.
HSP2 (pronouced "HSP-squared") is being developed by an open source team launched and led by RESPEC with internal funding. Our list of collaborators is growing, now including LimnoTech and with additional support from the U.S. Army Corps of Engineers (Engineer Research and Development Center (ERDC), Environmental Laboratory), modelers at the Virginia Department of Environmental Quality, and others.
HSP2 currently supports all HSPF hydrology and detailed water quality modules. Support for specialty modules is currently in progress. See our Release Notes for up-to-date details.
Read our wiki for more information on our motivation and goals for HSP2: - Wiki Home & HSP2 Goals - About-HSPF - Why-HSP2? - HSP2 Design Details
The HSPF Conversion Project slides (January 2017) and the Introduction to HSP2 by Jason Love (RESPEC) video (December 2017) provide additional background on the initial release.
HSPsquared is released under the GNU Affero General Public License (AGPL), copyrighted 2017 by RESPEC.
- HSP2 contains the hydrology and water quality code modules converted from HSPF, along with the main programs to run HSP2.
- HSP2tools contains supporting software modules such as the code to convert legacy WDM and UCI files to HDF5 files for HSP2, and to provide additional new and legacy capabilities.
- HSP2IO is new in v0.10 and contains an abstracted approach to getting data in and out of HSP2 for flexibility and performance and also to support future automation and model coupling. - NOTE: With v0.10 the I/O abstraction classes provide an alternate approach to running HSP2. Our plan is to migrate solely using the I/O abstracted methods, but we will maintain both approaches for for several more releases for backward compatibility.
- docs contains relevant reference documentation.
- examples contains examples of how to use HSP2, organized as interactive Jupyter Notebook tutorials.
- tests contains HSPF use cases, their input files, code to compare HSP2 vs HSPF model outputs and code to test for performance.
We recommend getting started by:
- Following our HSP2 Installation Instructions.
- Opening our interactive JupyterLab HSP2 tutorials in the examples sub-directory.
We recommend Python 3.10.
Starting with version 0.11.0a1 we provide a PyPI wheel package for HSP2 which should work on any supported platform for Python 3.10, 3.11, and 3.12.
python -m pip install hsp2
On the Releases page, we provide a Windows package in the zip file named HSP2_Driver_MonthYear.zip. HSP2_Driver_MonthYear.zip contains an .exe for running HSP2, enabling a user to run HSP2 without needing to do anything with Python code or Jupyter notebooks. The driver uses a file dialog to prompt for the name of the HDF5 file to run, or if that doesn't exist yet you can give it the name of a UCI or WDM file to import. It also runs with the H5 file name on the command line.
From the HSP2squared Github page, download and extract the code using one of the options found by clicking on the green "Code" drop down button near the upper right of the page, or by downloading one of the compressed source files from the Releases page.
Place your copy of the HSPsquared folder in any convenient location on your computer.
For the rest of the installation steps, let's call this location /path/to/module/hsp2.
We provide two options to installing HSP2, yet recommend option 1.
Install using only one of these options.
Follow these steps to install using the conda package manager.
Install the latest release of the Anaconda Distribution, which includes the conda package manager, a complete Python (and R) data science stack, and the Anaconda Navigator GUI. Follow Anaconda Installation documentation.
A lighter-weight alternative is to install Miniconda.
Although HSP2 can be run from the default base environment created by Anaconda, we recommend creating a custom environment that includes the exact combination of software dependencies that we've in development and testing.
Use the following conda create command in your terminal or console:
conda create -c conda-forge -n hsp2_310 python=3.10
Install the necessary and optional packages for HSP2 in the new environment:
conda install -c conda-forge -n hsp2_310 cltoolbox numba pandas pytables
conda install -c conda-forge -n hsp2_310 h5py jupyterlab matplotlib notebook
conda activate hsp2_310
cd /path/to/module/hsp2
pip install . # or "pip install -e ." to install in editable mode
You should now be able to run the Tutorials and create your own Jupyter Notebooks!
Installing HSP2 using pip, the Package Installer for Python is an alternative method to installing with conda.
Instructions for downloading Python to your computer based on your operating system can be found in this helpful wiki.
Create a custom Python virtual environment for using HSP2, following the venv — Creation of virtual environments package documentation to create and activate a new environment for running HSP2.
python -m venv hsp2_env /path/to/python/virtual/environments/hsp2_env
Navigate to your copy of the HSPsquared folder (for these instructions /path/to/module/hsp2) on your computer in the command line.
To install using pip:
source /path/to/python/virtual/environments/hsp2_env/bin/activate
cd /path/to/module/hsp2
pip install . # or "pip install -e ." to install in editable mode
The pip installed 'hsp2' command has help created from the function docstrings in HSP2tools/HSP2_CLI.py.
Use the help to learn how to use the model and each sub-command:
hsp2 --help
hsp2 import_uci --help
hsp2 run --help
Intended workflow from the command line:
hsp2 import_uci import_test.uci new_model.h5
hsp2 run new_model.h5
The HSP2 API is designed to be used in Python scripts and Jupyter notebooks.
from HSP2 import HSP2