diff --git a/cara/tests/apps/calculator/test_report_generator.py b/cara/tests/apps/calculator/test_report_generator.py index e3975a59..ad9b6b60 100644 --- a/cara/tests/apps/calculator/test_report_generator.py +++ b/cara/tests/apps/calculator/test_report_generator.py @@ -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) diff --git a/cara/tests/conftest.py b/cara/tests/conftest.py index e69b44c5..053544cc 100644 --- a/cara/tests/conftest.py +++ b/cara/tests/conftest.py @@ -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 diff --git a/cara/tests/test_known_quantities.py b/cara/tests/test_known_quantities.py index 1556df75..89c0268d 100644 --- a/cara/tests/test_known_quantities.py +++ b/cara/tests/test_known_quantities.py @@ -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), ),