Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/separate hydrology #243

Merged
merged 17 commits into from
Jun 21, 2023
Merged
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ kernelspec:
name: vr_python3
---

#  API for the {mod}`~virtual_rainforest.models.abiotic_simple.simple_regression` module
#  API for the {mod}`~virtual_rainforest.models.abiotic_simple.microclimate` module

```{eval-rst}
.. automodule:: virtual_rainforest.models.abiotic_simple.simple_regression
.. automodule:: virtual_rainforest.models.abiotic_simple.microclimate
:autosummary:
:members:
:special-members: __init__
Expand Down
21 changes: 21 additions & 0 deletions docs/source/api/hydrology.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
---
jupytext:
cell_metadata_filter: -all
formats: md:myst
main_language: python
text_representation:
extension: .md
format_name: myst
format_version: 0.13
jupytext_version: 1.13.8
kernelspec:
display_name: vr_python3
language: python
name: vr_python3
---

# API reference for `hydrology` modules

```{eval-rst}
.. automodule:: virtual_rainforest.models.hydrology
```
24 changes: 24 additions & 0 deletions docs/source/api/hydrology/hydrology_constants.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
---
jupytext:
cell_metadata_filter: -all
formats: md:myst
main_language: python
text_representation:
extension: .md
format_name: myst
format_version: 0.13
jupytext_version: 1.13.8
kernelspec:
display_name: vr_python3
language: python
name: vr_python3
---

#  API for the {mod}`~virtual_rainforest.models.hydrology.hydrology_constants` module

```{eval-rst}
.. automodule:: virtual_rainforest.models.hydrology.hydrology_constants
:autosummary:
:members:
:special-members: __init__
```
25 changes: 25 additions & 0 deletions docs/source/api/hydrology/hydrology_model.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
---
jupytext:
cell_metadata_filter: -all
formats: md:myst
main_language: python
text_representation:
extension: .md
format_name: myst
format_version: 0.13
jupytext_version: 1.13.8
kernelspec:
display_name: vr_python3
language: python
name: vr_python3
---

<!-- markdownlint-disable-next-line MD013 -->
# API documentation for the {mod}`~virtual_rainforest.models.hydrology.hydrology_model` module

```{eval-rst}
.. automodule:: virtual_rainforest.models.hydrology.hydrology_model
:autosummary:
:members:
:exclude-members: model_name
```
5 changes: 4 additions & 1 deletion docs/source/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,10 @@ team.
Soil Constants <api/soil/constants.md>
Abiotic Simple Overview <api/abiotic_simple.md>
Abiotic Simple Model <api/abiotic_simple/abiotic_simple_model.md>
Abiotic Simple Regression <api/abiotic_simple/simple_regression.md>
Abiotic Simple Microclimate <api/abiotic_simple/microclimate.md>
Abiotic Hydrology Overview <api/hydrology.md>
Abiotic Hydrology Model <api/hydrology/hydrology_model.md>
Abiotic Hydrology Constants <api/hydrology/hydrology_constants.md>
Abiotic Overview <api/abiotic.md>
Abiotic Model <api/abiotic/abiotic_model.md>
Abiotic Tools <api/abiotic/abiotic_tools.md>
Expand Down
13 changes: 11 additions & 2 deletions docs/source/virtual_rainforest/module_overview.md
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,8 @@ the Virtual Rainforest in high temporal resolution or for representative days pe
### Simple Abiotic Model

The Simple Abiotic Model is a one-column model that operates on a grid cell basis and
does not consider horizontal exchange of energy, water, and momentum. The model uses
linear regressions from {cite}`hardwick_relationship_2015` and
does not consider horizontal exchange of energy, atmospheric water, and momentum.
The model uses linear regressions from {cite}`hardwick_relationship_2015` and
{cite}`jucker_canopy_2018` to predict
atmospheric temperature, relative humidity, and vapour pressure deficit
at ground level (2m) given the above canopy conditions and leaf area index of
Expand All @@ -130,6 +130,15 @@ level prediction. Soil temperature is interpolated between the surface layer and
temperature at 1 m depth which equals the mean annual temperature.
The model also provides a constant vertical profile of atmospheric pressure and
atmospheric $\ce{CO_{2}}$.

### Simple Hydrology Model

The simple version of the Hydrology Model is a one-column model that operates on a grid
cell basis and does not consider horizontal exchange of water. We placed this
functionality in a separate model in order to allow easy replacement with a different
hydrology model, for example a process-based model that runs on a daily time step and
returns monthly statistics to the data object for other modules to use.

Soil moisture and surface runoff are calculated for each grid cell with a simple bucket
model based on {cite}`davis_simple_2017`; vertical flow and horizontal flow (above and
below ground) between grid cells are currently not implemented.
Expand Down
60 changes: 10 additions & 50 deletions tests/models/abiotic_simple/test_abiotic_simple_model.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""Test module for abiotic_simple.abiotic_simple_model.py."""

from contextlib import nullcontext as does_not_raise
from logging import DEBUG, ERROR, INFO
from logging import DEBUG, INFO

import numpy as np
import pint
Expand All @@ -10,17 +10,15 @@
from xarray import DataArray

from tests.conftest import log_check
from virtual_rainforest.core.exceptions import InitialisationError
from virtual_rainforest.models.abiotic_simple.abiotic_simple_model import (
AbioticSimpleModel,
)


@pytest.mark.parametrize(
"ini_soil_moisture,raises,expected_log_entries",
"raises,expected_log_entries",
[
(
0.5,
does_not_raise(),
(
(
Expand All @@ -37,10 +35,6 @@
"abiotic_simple model: required var 'atmospheric_pressure_ref' "
"checked",
),
(
DEBUG,
"abiotic_simple model: required var 'precipitation' checked",
),
(
DEBUG,
"abiotic_simple model: required var 'atmospheric_co2_ref' checked",
Expand All @@ -60,32 +54,11 @@
),
),
),
(
-0.5,
pytest.raises(InitialisationError),
(
(
ERROR,
"The initial soil moisture has to be between 0 and 1!",
),
),
),
(
DataArray([50, 30, 20]),
pytest.raises(InitialisationError),
(
(
ERROR,
"The initial soil moisture must be a float!",
),
),
),
],
)
def test_abiotic_simple_model_initialization(
caplog,
dummy_climate_data,
ini_soil_moisture,
raises,
expected_log_entries,
layer_roles_fixture,
Expand All @@ -101,7 +74,6 @@ def test_abiotic_simple_model_initialization(
pint.Quantity("1 week"),
soil_layers,
canopy_layers,
ini_soil_moisture,
)

# In cases where it passes then checks that the object has the right properties
Expand All @@ -116,7 +88,6 @@ def test_abiotic_simple_model_initialization(
assert model.model_name == "abiotic_simple"
assert repr(model) == "AbioticSimpleModel(update_interval = 1 week)"
assert model.layer_roles == layer_roles_fixture
assert model.initial_soil_moisture == ini_soil_moisture

# Final check that expected logging entries are produced
log_check(caplog, expected_log_entries)
Expand All @@ -143,9 +114,6 @@ def test_abiotic_simple_model_initialization(
"canopy_layers": 10,
},
},
"abiotic_simple": {
"initial_soil_moisture": 0.5,
},
},
pint.Quantity("1 week"),
does_not_raise(),
Expand All @@ -169,10 +137,6 @@ def test_abiotic_simple_model_initialization(
"abiotic_simple model: required var 'atmospheric_pressure_ref' "
"checked",
),
(
DEBUG,
"abiotic_simple model: required var 'precipitation' checked",
),
(
DEBUG,
"abiotic_simple model: required var 'atmospheric_co2_ref' checked",
Expand Down Expand Up @@ -234,9 +198,6 @@ def test_generate_abiotic_simple_model(
"canopy_layers": 10,
},
},
"abiotic_simple": {
"initial_soil_moisture": 0.5,
},
},
pint.Quantity("1 week"),
)
Expand All @@ -261,24 +222,23 @@ def test_setup(

model.setup()

soil_moisture_values = np.repeat(a=[np.nan, 0.5], repeats=[13, 2])

xr.testing.assert_allclose(
dummy_climate_data["soil_moisture"],
model.data["soil_temperature"],
DataArray(
np.broadcast_to(soil_moisture_values, (3, 15)).T,
np.full((15, 3), np.nan),
dims=["layers", "cell_id"],
coords={
"layers": np.arange(15),
"layer_roles": ("layers", layer_roles_fixture),
"layers": np.arange(0, 15),
"layer_roles": (
"layers",
model.layer_roles,
),
"cell_id": [0, 1, 2],
},
name="soil_moisture",
),
)

xr.testing.assert_allclose(
dummy_climate_data["vapour_pressure_deficit_ref"],
model.data["vapour_pressure_deficit_ref"],
DataArray(
np.full((3, 3), 0.141727),
dims=["cell_id", "time_index"],
Expand Down
Loading