From a85a05316f6b58f50660a47df823e677bbf0c13e Mon Sep 17 00:00:00 2001 From: jdevine Date: Mon, 25 Apr 2022 11:36:49 +0200 Subject: [PATCH] Adjusted tests, modified expected outputs for new temperature and humidity dependent halflife method --- cara/models.py | 2 +- cara/tests/models/test_exposure_model.py | 12 ++++++------ cara/tests/test_full_algorithm.py | 10 ++++++++-- cara/tests/test_known_quantities.py | 12 ++++++------ cara/tests/test_monte_carlo_full_models.py | 16 ++++++++-------- 5 files changed, 29 insertions(+), 23 deletions(-) diff --git a/cara/models.py b/cara/models.py index d696067a..1adb810e 100644 --- a/cara/models.py +++ b/cara/models.py @@ -462,7 +462,7 @@ class SARSCoV2(Virus): # Updated to use the formula from Dabish et al. https://doi.org/10.1080/02786826.2020.1829536 # with a minimum at hl = 1.1 inside_temp = inside_temp.value(time) - return max(1.1, (0.693/(0.16030 + 0.04018*(((inside_temp-274.15)-20.615)/10.585)+0.02176*((humidity-45.235)/28.665)+0.1))) + return max(1.1, (0.693/(0.16030 + 0.04018*(((inside_temp-273.15)-20.615)/10.585)+0.02176*((humidity-45.235)/28.665)+0.1))) Virus.types = { diff --git a/cara/tests/models/test_exposure_model.py b/cara/tests/models/test_exposure_model.py index 44979024..abc476d0 100644 --- a/cara/tests/models/test_exposure_model.py +++ b/cara/tests/models/test_exposure_model.py @@ -179,12 +179,12 @@ def sr_model(): @pytest.mark.parametrize( ["exposed_time_interval", "expected_deposited_exposure"], [ - [(0., 1.), 45.6008710], - [(1., 1.01), 0.5280401], - [(1.01, 1.02), 0.51314096385], - [(12., 12.01), 0.016255813185], - [(12., 24.), 645.63619275], - [(0., 24.), 700.7322474], + [(0., 1.), 48.19316], + [(1., 1.01), 0.566368], + [(1.01, 1.02), 0.551401], + [(12., 12.01), 0.016278], + [(12., 24.), 691.21381], + [(0., 24.), 750.258043], ] ) def test_exposure_model_integral_accuracy(exposed_time_interval, diff --git a/cara/tests/test_full_algorithm.py b/cara/tests/test_full_algorithm.py index fb6ade81..71f10f05 100644 --- a/cara/tests/test_full_algorithm.py +++ b/cara/tests/test_full_algorithm.py @@ -47,6 +47,9 @@ class SimpleConcentrationModel: #: room volume (m^3) room_volume: _VectorisedFloat + #: The temperature inside the room (Kelvin). + #inside_temp: float = 293.15 + #: ventilation rate (air changes per hour) - including HEPA lambda_ventilation: _VectorisedFloat @@ -84,8 +87,11 @@ class SimpleConcentrationModel: """ removal rate lambda in h^-1, excluding the deposition rate. """ - return (self.lambda_ventilation - + ln2/(6.43 if self.humidity<=0.4 else 1.1) ) + + return (self.lambda_ventilation + + ln2/(max(1.1, (0.693 / (0.16030 + 0.04018 * (((22) - 20.615) / 10.585) + 0.02176 * ( + (self.humidity - 45.235) / 28.665) + 0.1))))) + #6.43 if self.humidity<=0.4 else 1.1) ) @method_cache def deposition_removal_coefficient(self) -> float: diff --git a/cara/tests/test_known_quantities.py b/cara/tests/test_known_quantities.py index ed775312..4eb94d0b 100644 --- a/cara/tests/test_known_quantities.py +++ b/cara/tests/test_known_quantities.py @@ -43,7 +43,7 @@ def test_concentrations(baseline_concentration_model): concentrations = [baseline_concentration_model.concentration(float(t)) for t in ts] npt.assert_allclose( concentrations, - [0.000000e+00, 20.805628, 6.602814e-13, 20.805628, 2.09545e-26], + [0.000000e+00, 2.108144e+01, 1.004741e-12, 2.108144e+01, 4.788592e-26], rtol=1e-6 ) @@ -94,7 +94,7 @@ def test_r0(baseline_exposure_model): # expected r0 was computed with a trapezoidal integration, using # a mesh of 100'000 pts per exposed presence interval. r0 = baseline_exposure_model.reproduction_number() - npt.assert_allclose(r0, 776.941990) + npt.assert_allclose(r0, 781.293793) def test_periodic_window(baseline_periodic_window, baseline_room): @@ -381,8 +381,8 @@ def build_exposure_model(concentration_model, short_range_model): @pytest.mark.parametrize( "month, expected_deposited_exposure", [ - ['Jan', 377.440565819], - ['Jun', 1721.03336729], + ['Jan', 392.994454], + ['Jun', 2127.82386], ], ) def test_exposure_hourly_dep(month,expected_deposited_exposure, baseline_sr_model): @@ -402,8 +402,8 @@ def test_exposure_hourly_dep(month,expected_deposited_exposure, baseline_sr_mode @pytest.mark.parametrize( "month, expected_deposited_exposure", [ - ['Jan', 383.339206111], - ['Jun', 1799.17597184], + ['Jan', 394.000261], + ['Jun', 2239.777906], ], ) def test_exposure_hourly_dep_refined(month,expected_deposited_exposure, baseline_sr_model): diff --git a/cara/tests/test_monte_carlo_full_models.py b/cara/tests/test_monte_carlo_full_models.py index 32fdd460..58f0a57d 100644 --- a/cara/tests/test_monte_carlo_full_models.py +++ b/cara/tests/test_monte_carlo_full_models.py @@ -310,13 +310,13 @@ def waiting_room_mc(): @pytest.mark.parametrize( "mc_model, expected_pi, expected_new_cases, expected_dose, expected_ER", [ - ["shared_office_mc", 6.03, 0.18, 3.198, 809], + ["shared_office_mc", 6.524158, 0.195725, 3.413983, 809], ["classroom_mc", 9.5, 1.85, 9.478, 5624], ["ski_cabin_mc", 16.0, 0.5, 17.315, 7966], - ["skagit_chorale_mc",65.7, 40.0, 102.213, 190422], - ["bus_ride_mc", 12.0, 8.0, 7.65, 5419], + ["skagit_chorale_mc",69.84901, 40.0, 121.265911, 190422], + ["bus_ride_mc", 13.311721, 8.918853, 8.6662, 5419], ["gym_mc", 0.45, 0.13, 0.208, 1145], - ["waiting_room_mc", 1.59, 0.22, 0.821, 737], + ["waiting_room_mc", 1.854373, 0.259612, 0.99173, 737], ] ) def test_report_models(mc_model, expected_pi, expected_new_cases, @@ -337,10 +337,10 @@ def test_report_models(mc_model, expected_pi, expected_new_cases, @pytest.mark.parametrize( "mask_type, month, expected_pi, expected_dose, expected_ER", [ - ["No mask", "Jul", 9.52, 9.920, 809], - ["Type I", "Jul", 1.7, 0.913, 149], - ["FFP2", "Jul", 0.51, 0.239, 149], - ["Type I", "Feb", 0.57, 0.272, 162], + ["No mask", "Jul", 10.966992, 12.357222, 809], + ["Type I", "Jul", 2.084648, 1.137819, 149], + ["FFP2", "Jul", 0.654566, .309637, 149], + ["Type I", "Feb", 0.612366, 0.272, 162], ], ) def test_small_shared_office_Geneva(mask_type, month, expected_pi,