Skip to content

Refactor HBV variants to use BaseHBVModel #142

Description

@MAfarrag

Description

  • Refactor all procedural implementations of HBV model variants into class-based structures that inherit from BaseHBVModel. Each variant should override the step_run() method and any additional behavior needed (e.g., lake routing, special snow handling).

  • Migrate the existing procedural implementations of HBV variants (e.g. hbv.py, hbv_lake.py, hbvold.py, hbvlumped.py, hbv_bergestrom92.py) into class-based implementations that inherit from a newly created BaseHBVModel. This allows shared routines to be reused and variant-specific logic to be isolated via subclassing.

The following modules currently implement procedural HBV variants and will be refactored:

src/Hapi/rrm/
├── hbv.py
├── hbv_lake.py
├── hbvold.py
├── hbvlumped.py
├── hbv_bergestrom92.py

Each file contains functions like:

  • Precipitation()
  • Snow()
  • Soil()
  • Response()
  • StepRun() or _step_run()
  • Routing() or _routing()

These functions follow the HBV model structure, with many repetitions and only minor differences in implementation (e.g., lake evaporation logic, or routing weights).

By inheriting from a BaseHBVModel, we can:

  • Centralize shared logic.
  • Encourage composability and reuse.
  • Support polymorphism (e.g., run different models with the same simulator).
  • Make the codebase easier to maintain and test.

Implementaion

1 - After creating the BaseHBVModel , in #141
2 - Wrap each HBV variant into a class

#hbv.py
from Hapi.rrm.base_model import BaseHBVModel

class HBVModel(BaseHBVModel):
    def step_run(self, p, p2, v, St):
        # call self.precipitation(), self.snow(), etc.
        # customize behavior if needed
        ...

3- Apply similar class wrappers for:

  • HBVLakeModel(BaseHBVModel)
  • HBVLumpedModel(BaseHBVModel)
  • HBVBergestromModel(BaseHBVModel)
  • HBVOldModel(BaseHBVModel)

Checklist

  • Refactor hbv.py → HBVModel
  • Refactor hbv_lake.py → HBVLakeModel
  • Refactor hbvold.py → HBVOldModel
  • Refactor hbvlumped.py → HBVLumpedModel
  • Refactor hbv_bergestrom92.py → HBVBergestromModel
  • Replace procedural step_run() functions
  • Write/adjust unit tests for each class
  • Ensure compatibility with calibration/routing/parameter modules

Issues

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    Projects

    • Status
      Todo

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions