Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 40 additions & 26 deletions tests/models/abiotic/test_abiotic_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@


def test_abiotic_model_initialization(
caplog, dummy_climate_data, fixture_core_components
caplog, dummy_climate_data_varying_canopy, fixture_core_components
):
"""Test `AbioticModel` initialization."""
from virtual_ecosystem.core.base_model import BaseModel
Expand All @@ -59,7 +59,7 @@ def test_abiotic_model_initialization(
):
mock_bypass_setup.return_value = False
model = AbioticModel(
dummy_climate_data,
dummy_climate_data_varying_canopy,
core_components=fixture_core_components,
model_constants=AbioticConsts(),
)
Expand Down Expand Up @@ -178,7 +178,7 @@ def test_abiotic_model_initialization_no_data(caplog, fixture_core_components):
)
def test_generate_abiotic_model(
caplog,
dummy_climate_data,
dummy_climate_data_varying_canopy,
cfg_string,
drag_coeff,
raises,
Expand Down Expand Up @@ -208,7 +208,7 @@ def test_generate_abiotic_model(
# Check whether model is initialised (or not) as expected
with raises:
AbioticModel.from_config(
data=dummy_climate_data,
data=dummy_climate_data_varying_canopy,
core_components=core_components,
config=config,
)
Expand Down Expand Up @@ -246,7 +246,7 @@ def test_generate_abiotic_model(
)
def test_generate_abiotic_model_bounds_error(
caplog,
dummy_climate_data,
dummy_climate_data_varying_canopy,
cfg_string,
raises,
expected_log_entries,
Expand All @@ -270,7 +270,7 @@ def test_generate_abiotic_model_bounds_error(
mock_bypass_setup.return_value = False
with raises:
_ = AbioticModel.from_config(
data=dummy_climate_data,
data=dummy_climate_data_varying_canopy,
core_components=core_components,
config=config,
)
Expand All @@ -279,7 +279,9 @@ def test_generate_abiotic_model_bounds_error(
log_check(caplog, expected_log_entries)


def test_setup_abiotic_model(dummy_climate_data, fixture_core_components):
def test_setup_abiotic_model(
dummy_climate_data_varying_canopy, fixture_core_components
):
"""Test that setup() returns expected output in data object."""

from virtual_ecosystem.models.abiotic.abiotic_model import AbioticModel
Expand All @@ -293,7 +295,7 @@ def test_setup_abiotic_model(dummy_climate_data, fixture_core_components):
):
mock_bypass_setup.return_value = False
model = AbioticModel(
data=dummy_climate_data,
data=dummy_climate_data_varying_canopy,
core_components=fixture_core_components,
)

Expand Down Expand Up @@ -324,18 +326,23 @@ def test_setup_abiotic_model(dummy_climate_data, fixture_core_components):

# Test that soil temperature was created correctly
expected_soil_temp = lyr_strct.from_template()
expected_soil_temp[lyr_strct.index_all_soil] = np.array([20.712458, 20.0])[:, None]
expected_soil_temp[lyr_strct.index_all_soil] = np.array(
[[20.712458, 21.317566, 21.922674, 21.922674], [20.0, 20.0, 20.0, 20.0]]
)
xr.testing.assert_allclose(model.data["soil_temperature"], expected_soil_temp)

# Test that air temperature was interpolated correctly
exp_air_temp = lyr_strct.from_template()
exp_air_temp[0] = 30.0
exp_air_temp[lyr_strct.index_filled_canopy] = np.array(
[29.91965, 29.414851, 28.551891]
)[:, None]
exp_air_temp[lyr_strct.index_surface_scalar] = np.array(
[22.81851, 22.81851, 22.81851, 22.81851]
exp_air_temp[lyr_strct.index_filled_atmosphere] = np.array(
[
[30, 30, 30, 30],
[29.91965, 29.946434, 29.973217, 29.973217],
[29.414851, 29.609901, np.nan, np.nan],
[28.551891, np.nan, np.nan, np.nan],
[22.81851, 25.21234, 27.60617, 27.60617],
]
)

xr.testing.assert_allclose(model.data["air_temperature"], exp_air_temp)

# Test other variables have been inserted and some check values
Expand All @@ -356,7 +363,7 @@ def test_setup_abiotic_model(dummy_climate_data, fixture_core_components):
with patch_static_config(AbioticModel) as mock_static_config:
mock_static_config.return_value = False, False
model = AbioticModel(
data=dummy_climate_data,
data=dummy_climate_data_varying_canopy,
core_components=fixture_core_components,
)

Expand All @@ -365,8 +372,8 @@ def test_setup_abiotic_model(dummy_climate_data, fixture_core_components):
expected_soil_temp1 = lyr_strct.from_template()
expected_soil_temp1[lyr_strct.index_all_soil] = np.array(
[
[22.3935, 22.35095, 21.925444, 21.925444],
[20.040154, 20.03944, 20.032302, 20.032302],
[22.3935, 24.064858, 25.343753, 25.343753],
[20.040154, 20.068193, 20.089648, 20.089648],
],
)
expected_soil_moist = lyr_strct.from_template()
Expand All @@ -377,18 +384,25 @@ def test_setup_abiotic_model(dummy_climate_data, fixture_core_components):
xr.testing.assert_allclose(model.data["soil_moisture"], expected_soil_moist)

exp_air_temp = lyr_strct.from_template()
exp_air_temp[0] = 30.000122
exp_air_temp[lyr_strct.index_filled_canopy] = np.array(
[29.913604, 29.408153, 28.545607]
)[:, None]
exp_air_temp[lyr_strct.index_surface_scalar] = np.array(
[22.478502, 22.444462, 22.104057, 22.104057]

exp_air_temp[lyr_strct.index_filled_atmosphere] = np.array(
[
[30.000105, 30.000091, 30.000047, 30.000047],
[29.925696, 29.938505, 29.970583, 29.970583],
[29.42155, 29.613321, np.nan, np.nan],
[28.558176, np.nan, np.nan, np.nan],
[23.158518, 26.130326, 29.416104, 29.416104],
]
)
xr.testing.assert_allclose(model.data["air_temperature"], exp_air_temp)

exp_canopytemp = lyr_strct.from_template()
exp_canopytemp[lyr_strct.index_filled_canopy] = np.array(
[28.489317, 29.414784, 28.551829]
)[:, None]
[
[28.489317, 31.736854, 31.631768, 31.631768],
[29.414784, 29.609833, np.nan, np.nan],
[28.551829, np.nan, np.nan, np.nan],
]
)

xr.testing.assert_allclose(model.data["canopy_temperature"], exp_canopytemp)
Loading
Loading