A simple toolkit for baseflow separation and Baseflow Index (BFI) estimation from daily streamflow.
Project description
🌊 BFI-Toolkit
A lightweight and flexible Python package for estimating Baseflow and Baseflow Index (BFI) from streamflow time series.
This toolkit provides a simple, efficient way to:
- Separate baseflow using forward/backward recession analysis
- Compute optimized decay parameters (k)
- Calculate BFI — a key hydrologic metric for understanding watershed storage and runoff behavior.
📄 Associated Research
This toolkit was developed as part of the work presented in:
Farmani, M. A., Tavakoly, A., Behrangi, A., Qiu, Y., Gupta, A., Jawad, M., Yousefi Sohi, H., Zhang, X., Geheran, M., Niu, G.-Y. (2025).
Improving Streamflow Predictions in the Arid Southwestern United States Through Understanding of Baseflow Generation Mechanisms.
Water Resources Research. https://doi.org/10.1029/2024WR039479
© Author(s) 2025. This work is distributed under the Creative Commons Attribution 4.0 License.
📦 Installation
From PyPI (when released)
pip install bfi-toolkit
From source (development version)
git clone https://github.com/mfarmani95/BFI-Toolkit.git
cd BFI-Toolkit
pip install -e .
This installs the package in editable mode, so any code edits are reflected immediately without reinstalling.
⚡️ Quick Start
import numpy as np
from bfi_toolkit import compute_bfi
# Example: simple synthetic streamflow data
streamflow = np.array([5, 5, 5, 6, 7, 6, 5.8, 5.6, 5.4, 5.2, 5, 4.9, 4.8])
result = compute_bfi(streamflow, day_after_peak=5, start_date="2020-01-01")
print("Optimized k:", result["k"])
print("BFI:", result["bfi"])
print("Baseflow head:\n", result["baseflow"].head())
✅ Supported input types:
- Python
list numpy.ndarraypandas.DataFrame(must contain columnQQ)torch.Tensor(optional, if PyTorch installed)
🧪 Development Setup
Option 1: with pip
git clone https://github.com/mfarmani95/BFI-Toolkit.git
cd BFI-Toolkit
python -m venv .venv
source .venv/bin/activate # (Windows: .venv\Scripts\activate)
pip install -r requirements-dev.txt
Option 2: with Conda (recommended)
git clone https://github.com/mfarmani95/BFI-Toolkit.git
cd BFI-Toolkit
conda env create -f environment.yml
conda activate bfi-toolkit
Then:
make dev # install dev dependencies
make test # run tests
🧰 Useful Makefile Commands
| Command | Description |
|---|---|
make install |
Install package in editable mode |
make dev |
Install dev dependencies |
make test |
Run test suite with pytest |
make format |
Auto-format code with Black |
make lint |
Run static checks with Ruff |
make build |
Build distribution package |
make upload-test |
Upload to TestPyPI |
make upload |
Upload to PyPI |
🧠 Contributing
We welcome contributions from the community 🙌
- Fork the repository
- Create a feature branch
- Commit your changes with clear messages
- Add or update tests if needed
- Submit a Pull Request
Before submitting:
make format
make lint
make test
🧭 Features
- ✅ Supports multiple input formats (NumPy, Pandas, PyTorch, lists)
- 📉 Flexible dry period filtering with
day_after_peak - ⚙️ Optimized decay constant estimation (k)
- 💧 Baseflow separation using forward/backward recession
- 📊 Automatic BFI calculation
- 🧰 Clean modular structure (core, utils, optimization, baseflow)
- 🧪 Fully testable with
pytest
📝 Citation
If you use this toolkit in your research or operational projects, please cite:
Farmani, M. A. (2025). BFI-Toolkit: A lightweight Python package for estimating baseflow and Baseflow Index (BFI).
GitHub: https://github.com//BFI-Toolkit
📜 License
This project is licensed under the MIT License.
You’re free to use, modify, and distribute it — just give credit where it’s due.
🚀 Roadmap
- Add uncertainty quantification for k estimates
- Add multi-resolution time series support (weekly, monthly)
- Add visualization module (hydrograph plotting)
- Add unit conversion utilities for different discharge formats
- Publish as official PyPI package
💧 Acknowledgements
Developed as part of ongoing hydrologic research by
Mohammad Ali Farmani — University of Arizona.
Inspired by the need for transparent, flexible, and efficient baseflow separation tools for hydrologic modeling and water resources applications.
Project details
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
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file bfi_toolkit-0.1.1.tar.gz.
File metadata
- Download URL: bfi_toolkit-0.1.1.tar.gz
- Upload date:
- Size: 10.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.10.18
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0ad31eda9fdf552c7e2c737f4986a0ab1720cb081669c81d7b72cea5e5a41297
|
|
| MD5 |
dcd0caade2e5e39dccf56335320ef57e
|
|
| BLAKE2b-256 |
19125be3a88ff2e5690a542c7f57e3667cc04343d826c6f2c7dd72bd2c9bf408
|
File details
Details for the file bfi_toolkit-0.1.1-py3-none-any.whl.
File metadata
- Download URL: bfi_toolkit-0.1.1-py3-none-any.whl
- Upload date:
- Size: 9.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.10.18
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e1a1eee4dfaeb1bc2b431b553abe9d26d452593306420360edf5542238e23682
|
|
| MD5 |
054924a233d09b6a698bafba1e61cfa4
|
|
| BLAKE2b-256 |
11928063c2086ab2c7990373941ec5167119776f1d04cd9a6dffec6da4dc4750
|