Skip to content

Commit

Permalink
added model_config helper function and tests
Browse files Browse the repository at this point in the history
  • Loading branch information
richardarsenault committed Jan 24, 2024
1 parent aec3460 commit 8135979
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 1 deletion.
21 changes: 20 additions & 1 deletion tests/test_hydrological_modelling.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@
import numpy as np
import pytest

from xhydro.modelling.hydrological_modelling import run_hydrological_model
from xhydro.modelling.hydrological_modelling import (
get_hydrological_model_inputs,
run_hydrological_model,
)


def test_hydrological_modelling():
Expand Down Expand Up @@ -31,3 +34,19 @@ def test_import_unknown_model():
model_config = {"model_name": "fake_model"}
_ = run_hydrological_model(model_config)
assert pytest_wrapped_e.type == NotImplementedError


def test_get_unknown_model_requirements():
"""Test for required inputs for models with unknown name"""
with pytest.raises(NotImplementedError) as pytest_wrapped_e:
model_name = "fake_model"
_ = get_hydrological_model_inputs(model_name)
assert pytest_wrapped_e.type == NotImplementedError


def test_get_model_requirements():
"""Test for required inputs for models"""
model_name = "Dummy"
required_config = get_hydrological_model_inputs(model_name)
print(required_config.keys())
assert len(required_config.keys()) == 4
32 changes: 32 additions & 0 deletions xhydro/modelling/hydrological_modelling.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,38 @@ def run_hydrological_model(model_config: dict):
return qsim


def get_hydrological_model_inputs(model_name: str):
"""Required hydrological model inputs for model_config objects.
Parameters
----------
model_name : str
Model name that must be one of the models in the list of possible
models.
Returns
-------
dict
Elements that must be found in the model_config object.
"""
if model_name == "Dummy":
required_config = dict(
precip="Daily precipitation in mm.",
temperature="Daily average air temperature in °C",
drainage_area="Drainage area of the catchment",
parameters="Model parameters, length 3",
)

elif model_name == "ADD_OTHER_HERE":
# ADD OTHER MODELS HERE
required_config = {}

else:
raise NotImplementedError(f"The model '{model_name}' is not recognized.")

return required_config


def _dummy_model(model_config: dict):
"""Dummy model.
Expand Down

0 comments on commit 8135979

Please sign in to comment.