Skip to content
Merged
2 changes: 2 additions & 0 deletions docs/source/using_the_ve/virtual_ecosystem_in_use.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ language_info:
nbconvert_exporter: python
pygments_lexer: ipython3
version: 3.10.14
execution:
timeout: 60
jupytext:
formats: md:myst
text_representation:
Expand Down
16 changes: 12 additions & 4 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -425,20 +425,28 @@ def dummy_carbon_data(fixture_core_components):
lyr_str = fixture_core_components.layer_structure

data["soil_moisture"] = lyr_str.from_template()
data["soil_moisture"][lyr_str.index_topsoil] = np.array(
[232.61550125, 196.88733175, 126.065797, 75.63195175]
data["soil_moisture"][lyr_str.index_all_soil] = np.array(
[
[232.61550125, 196.88733175, 126.065797, 75.63195175],
[66.248474, 194.91137, 121.29988, 52.04422],
]
)

data["matric_potential"] = lyr_str.from_template()
data["matric_potential"][lyr_str.index_topsoil] = np.array(
[-3.0, -10.0, -250.0, -10000.0]
data["matric_potential"][lyr_str.index_all_soil] = np.array(
[[-3.0, -10.0, -250.0, -10000.0], [-2.8625, -8.978, -137.8, -8553.25]]
)

data["soil_temperature"] = lyr_str.from_template()
data["soil_temperature"][lyr_str.index_all_soil] = np.array(
[[35.0, 37.5, 40.0, 25.0], [22.5, 22.5, 22.5, 22.5]]
)

data["air_temperature"] = lyr_str.from_template()
data["air_temperature"][lyr_str.index_filled_atmosphere] = np.array(
[30.0, 29.844995, 28.87117, 27.206405, 16.145945]
)[:, None]

return data


Expand Down
37 changes: 37 additions & 0 deletions tests/models/soil/test_env_factors.py
Original file line number Diff line number Diff line change
Expand Up @@ -392,3 +392,40 @@ def test_calculate_leaching_rate(dummy_carbon_data, fixture_core_components):
)

assert np.allclose(expected_rate, actual_rate)


@pytest.mark.parametrize(
"increased_depth,expected_soil_moisture",
[
pytest.param(
True,
[265.73973825, 294.34301675, 186.715737, 101.65406175],
id="increased depth",
),
pytest.param(
False,
[116.307750625, 98.443665875, 63.0328985, 37.815975875],
id="normal depth",
),
],
)
def test_find_total_soil_moisture_for_microbially_active_depth(
dummy_carbon_data, fixture_core_components, increased_depth, expected_soil_moisture
):
"""Test that finding the total soil moisture works as expected."""
from virtual_ecosystem.models.soil.env_factors import (
find_total_soil_moisture_for_microbially_active_depth,
)

if increased_depth:
fixture_core_components.layer_structure.soil_layer_active_thickness = np.array(
[0.5, 0.25]
)
fixture_core_components.layer_structure.max_depth_of_microbial_activity = 0.75

actual_soil_moisture = find_total_soil_moisture_for_microbially_active_depth(
soil_moistures=dummy_carbon_data["soil_moisture"],
layer_structure=fixture_core_components.layer_structure,
)

assert np.allclose(actual_soil_moisture, expected_soil_moisture)
44 changes: 22 additions & 22 deletions tests/models/soil/test_pools.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,29 +46,29 @@ def test_calculate_all_pool_updates(
)

change_in_pools = {
"soil_c_pool_lmwc": [0.1178918, 0.06892161, 0.2489136, 0.03425211],
"soil_c_pool_maom": [0.03734787, 0.00340136, 0.05447554, 0.07275546],
"soil_c_pool_bacteria": [-0.0543618, -0.0226100, -0.1185237, -0.0071954],
"soil_c_pool_fungi": [-0.00832584, -0.08196413, -0.02280126, -0.03266732],
"soil_c_pool_pom": [0.00021589, -0.02918772, -0.0247599, 0.00520792],
"soil_c_pool_necromass": [0.01141213, 0.09537438, 0.05971513, -0.0566864],
"soil_enzyme_pom_bacteria": [-5.4395e-4, -2.2795e-4, -1.19323e-3, -7.2103e-5],
"soil_enzyme_maom_bacteria": [-8.5406e-4, -2.7893e-4, -5.9417e-4, -1.093e-4],
"soil_enzyme_pom_fungi": [-0.00062555, -0.00012062, -0.00015158, -0.00010522],
"soil_enzyme_maom_fungi": [-2.07924e-4, -1.46441e-4, -8.79093e-5, -5.1289e-5],
"soil_n_pool_don": [0.00180422, 0.00529461, 0.00549027, 0.00240583],
"soil_n_pool_particulate": [-1.005585e-4, 4.899227e-5, 7.96678e-5, 4.723906e-6],
"soil_n_pool_necromass": [0.00948372, 0.00118049, 0.00843786, -0.00381522],
"soil_n_pool_maom": [0.00099458, 0.01041398, 0.01326356, 0.00772835],
"soil_n_pool_ammonium": [0.00075125671, 0.02001151359, 0.00030892, 0.000172988],
"soil_n_pool_nitrate": [-0.003295899, -0.003990944, -0.00105915, -0.000642911],
"soil_p_pool_dop": [2.02317351e-4, 1.64662024e-4, 2.0799736e-4, 9.62312501e-5],
"soil_p_pool_particulate": [6.77587e-6, -7.228e-6, -1.29451192e-6, 1.898709e-7],
"soil_p_pool_necromass": [0.00297253, 0.00350535, 0.00755271, 0.0008742],
"soil_p_pool_maom": [5.44660113e-4, -6.28584725e-5, 4.528133e-4, 3.0913116e-4],
"soil_c_pool_lmwc": [0.117290490, 6.96565834e-2, 0.247627966, 3.42642831e-2],
"soil_c_pool_maom": [3.7894322e-2, 4.8705495e-3, 5.6793727e-2, 7.2757916e-2],
"soil_c_pool_bacteria": [-4.24905e-2, -1.71527e-2, -8.74104e-2, -6.36844e-3],
"soil_c_pool_fungi": [-6.507313e-3, -6.211968e-2, -1.680347e-2, -2.891271e-2],
"soil_c_pool_pom": [3.73447584e-4, -2.62977207e-2, -2.214249e-2, 5.219897e-3],
"soil_c_pool_necromass": [-2.296284e-3, 6.9255912e-2, 2.2051989e-2, -6.1268e-2],
"soil_enzyme_pom_bacteria": [-5.44018e-4, -2.2835e-4, -1.19517e-3, -7.21028e-5],
"soil_enzyme_maom_bacteria": [-8.54122e-4, -2.79326e-4, -5.9611e-4, -1.0930e-4],
"soil_enzyme_pom_fungi": [-6.25574e-4, -1.24304e-4, -1.52398e-4, -1.05217e-4],
"soil_enzyme_maom_fungi": [-2.07949e-4, -1.50128e-4, -8.87255e-5, -5.12891e-5],
"soil_n_pool_don": [1.60498e-3, 5.24092e-3, 5.31639e-3, 2.42007e-3],
"soil_n_pool_particulate": [-8.93041e-5, 5.105645e-5, 9.035108e-5, 5.212779e-6],
"soil_n_pool_necromass": [6.917627e-3, -3.050687e-3, 1.431913e-3, -4.551887e-3],
"soil_n_pool_maom": [1.183733e-3, 1.082948e-2, 1.343197e-2, 7.72882e-3],
"soil_n_pool_ammonium": [9.35035e-4, 2.72159e-2, 5.31626e-4, 1.83631e-4],
"soil_n_pool_nitrate": [-3.053041e-3, -3.922566e-3, -1.050268e-3, -9.197065e-4],
"soil_p_pool_dop": [1.99425697e-4, 1.39742546e-4, 1.99748943e-4, 9.68009312e-5],
"soil_p_pool_particulate": [6.820884e-6, -6.40228e-6, -8.6718e-7, 2.094258e-7],
"soil_p_pool_necromass": [2.184141e-3, 2.644765e-3, 5.429799e-3, 7.286432e-4],
"soil_p_pool_maom": [5.47518e-4, -3.2943e-5, 4.6272e-4, 3.0915e-4],
"soil_p_pool_primary": [-4.473516e-10, -1.222973e-9, -6.33411e-10, -1.3674e-10],
"soil_p_pool_secondary": [-5.050797e-7, -2.77311e-6, -7.40324e-7, -2.187697e-7],
"soil_p_pool_labile": [-1.643259e-5, -0.000295103, -1.212019e-4, -1.313285e-6],
"soil_p_pool_labile": [-1.54646e-5, -2.773006e-4, -9.46854e-5, -2.062198e-6],
}

# Make order of pools object
Expand All @@ -78,7 +78,7 @@ def test_calculate_all_pool_updates(

delta_pools = soil_pools.calculate_all_pool_updates(
delta_pools_ordered=pool_order,
top_soil_layer_index=fixture_core_components.layer_structure.index_topsoil_scalar,
layer_structure=fixture_core_components.layer_structure,
soil_moisture_capacity=CoreConsts.soil_moisture_capacity,
top_soil_layer_thickness=fixture_core_components.layer_structure.soil_layer_thickness[
0
Expand Down
Loading