Skip to main content

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 recession analysis, compute optimized decay parameters (k), and calculate the BFI — a key hydrologic metric for understanding watershed storage and runoff behavior.


📦 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.ndarray
  • pandas.DataFrame (must contain column QQ)
  • 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 🙌

  1. Fork the repository
  2. Create a feature branch
  3. Commit your changes with clear messages
  4. Add or update tests if needed
  5. 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

bfi_toolkit-0.1.0.tar.gz (10.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

bfi_toolkit-0.1.0-py3-none-any.whl (9.2 kB view details)

Uploaded Python 3

File details

Details for the file bfi_toolkit-0.1.0.tar.gz.

File metadata

  • Download URL: bfi_toolkit-0.1.0.tar.gz
  • Upload date:
  • Size: 10.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.18

File hashes

Hashes for bfi_toolkit-0.1.0.tar.gz
Algorithm Hash digest
SHA256 c3d89e45bb59979761d900b6509f34ece868464270a27e98e9075ac3b6eb9dd1
MD5 bdb1b4e005b7eaa84b2b357d2b1a9f6c
BLAKE2b-256 065fa9c4e53e286f4eed8c96540d65784e35e61726c2da0e0a167dd670f32e42

See more details on using hashes here.

File details

Details for the file bfi_toolkit-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: bfi_toolkit-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 9.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.18

File hashes

Hashes for bfi_toolkit-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 00ed7029e6e86fc70dab9b0a1d4c896629d4575c544687f25aa155da9f9fe071
MD5 00694031397f1f83d5885abc73f6b528
BLAKE2b-256 9180ccd2f67efc2ba29ef90e559daef5403d197235e83faa8bdccac43464997f

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page