Add a test for interesting_times which covers a model containing temperatures.

This commit is contained in:
Phil Elson 2021-08-25 09:58:45 +02:00
parent d1833955dd
commit 0861abcdba
3 changed files with 35 additions and 2 deletions

View file

@ -66,3 +66,19 @@ def test_interesting_times_small(baseline_exposure_model):
result = rep_gen.interesting_times(baseline_exposure_model, approx_n_pts=10)
np.testing.assert_allclose(result, expected, atol=1e-04)
def test_interesting_times_w_temp(exposure_model_w_outside_temp_changes):
# Ensure that the state change times are returned (minus the temperature changes) by
# requesting n_points=1.
result = rep_gen.interesting_times(exposure_model_w_outside_temp_changes, approx_n_pts=1)
expected = [0.0, 1.8, 2.2, 3.6, 4.0, 5.0, 5.4, 5.8, 7.2, 7.6, 8.0]
np.testing.assert_allclose(result, expected, atol=1e-04)
# Now request more than the state-change times.
result = rep_gen.interesting_times(exposure_model_w_outside_temp_changes, approx_n_pts=20)
expected = [
0., 0.4, 0.8, 1.2, 1.6, 1.8, 2.2, 2.2, 2.6, 3., 3.4, 3.6, 4.,
4.4, 4.8, 5., 5.4, 5.4, 5.8, 5.8, 6.2, 6.6, 7., 7.2, 7.6, 7.6, 8.,
]
np.testing.assert_allclose(result, expected, atol=1e-04)

View file

@ -1,4 +1,6 @@
from cara import models
import cara.data
import cara.dataclass_utils
import pytest
@ -33,5 +35,20 @@ def baseline_exposure_model(baseline_model):
activity=baseline_model.infected.activity,
mask=baseline_model.infected.mask,
),
fraction_deposited = 1.,
fraction_deposited=1.,
)
@pytest.fixture
def exposure_model_w_outside_temp_changes(baseline_exposure_model: models.ExposureModel):
exp_model = cara.dataclass_utils.nested_replace(
baseline_exposure_model, {
'concentration_model.ventilation': models.SlidingWindow(
active=models.PeriodicInterval(1.8 * 60, 2.2 * 60),
inside_temp=models.PiecewiseConstant((0., 24.), (293,)),
outside_temp=cara.data.GenevaTemperatures['Jan'],
window_height=1.6,
opening_length=0.6,
)
})
return exp_model

View file

@ -312,7 +312,7 @@ def test_concentrations_hourly_dep_temp_vs_constant(month, temperatures, time):
)
def test_concentrations_hourly_dep_temp_startup(month, temperatures, time):
# The concentrations should be the zero up to the first presence time
# of an infecter person.
# of an infected person.
m = build_hourly_dependent_model(
month,
((0., 0.5), (1., 1.5), (4., 4.5), (7.5, 8), ),