🌊 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.
🧠 Scientific Background
This toolkit builds on established methods for baseflow estimation using recession analysis and BFI calculation.
The underlying baseflow recession concept is based on:
van Dijk, A. I. J. M. (2010). Climate and terrain factors explaining streamflow response and recession in Australian catchments.
Hydrology and Earth System Sciences, 14(1), 159–169.
https://doi.org/10.5194/hess-14-159-2010
📦 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=2,min_events=1,min_pairs=3, start_date="2020-01-01")
# day_after_peak : Number of days to exclude after each detected runoff peak.
# min_events : Minimum number of runoff events required.
# min_pairs : Minimum number of Q–Q* pairs required.
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.
Metadata
Release files for bfi-toolkit 0.1.3
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| bfi_toolkit-0.1.3.tar.gz | 12.2 kB | Without provenance | Details for bfi_toolkit-0.1.3.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| bfi_toolkit-0.1.3-py3-none-any.whl | Python 3 | none | any | Details for bfi_toolkit-0.1.3-py3-none-any.whl |
Total release size: 22.6 kB
Release files / bfi_toolkit-0.1.3.tar.gz
| Download URL | bfi_toolkit-0.1.3.tar.gz |
|---|---|
| Size | 12.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
3cdafd5a16851071e22919563ec8ab48e27e79e1a3614045d7f38566730324f0
|
|
BLAKE2b-256 checksum How to use checksums |
bd994153d7ca013db0bffe12e6e948637f0bf3eb447f514512b9769713ce0a78
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.10.18
|
Release files / bfi_toolkit-0.1.3-py3-none-any.whl
| Download URL | bfi_toolkit-0.1.3-py3-none-any.whl |
|---|---|
| Size | 10.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
9f4226e11a23f2261ffab38a22f738958c4c0203aa0fa176c5c43a05d45f9732
|
|
BLAKE2b-256 checksum How to use checksums |
1a1b83fec5189db9a059ce999d45fd3f06508231f090627979bc9c6792a3508c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.10.18
|
Security for bfi-toolkit 0.1.3
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.