From a96cc18080a1ae427b213d4d487c4445960fff12 Mon Sep 17 00:00:00 2001 From: Luis Aleixo Date: Fri, 13 Oct 2023 11:13:21 +0200 Subject: [PATCH] added activity distributions from global store --- .../apps/calculator/global_store/constants.py | 58 ++++++++++++++++++- caimira/monte_carlo/data.py | 30 ++++++---- 2 files changed, 76 insertions(+), 12 deletions(-) diff --git a/caimira/apps/calculator/global_store/constants.py b/caimira/apps/calculator/global_store/constants.py index e4469183..a1027c1b 100644 --- a/caimira/apps/calculator/global_store/constants.py +++ b/caimira/apps/calculator/global_store/constants.py @@ -4,6 +4,59 @@ # Global variable to keep track of whether data has been fetched data_fetched = False +activity_distributions = { + 'Seated': { + 'inhalation_rate': { + 'associated_distribution': 'Numpy Log-normal Distribution (random.lognormal)', + 'parameters': { 'mean_gaussian': -0.6872121723362303, 'standard_deviation_gaussian': 0.10498338229297108 }, + }, + 'exhalation_rate': { + 'associated_distribution': 'Numpy Log-normal Distribution (random.lognormal)', + 'parameters': { 'mean_gaussian': -0.6872121723362303, 'standard_deviation_gaussian': 0.10498338229297108 }, + }, + }, + 'Standing': { + 'inhalation_rate': { + 'associated_distribution': 'Numpy Log-normal Distribution (random.lognormal)', + 'parameters': { 'mean_gaussian': -0.5742377578494785, 'standard_deviation_gaussian': 0.09373162411398223 }, + }, + 'exhalation_rate': { + 'associated_distribution': 'Numpy Log-normal Distribution (random.lognormal)', + 'parameters': { 'mean_gaussian': -0.5742377578494785, 'standard_deviation_gaussian': 0.09373162411398223 }, + }, + }, + 'Light activity': { + 'inhalation_rate': { + 'associated_distribution': 'Numpy Log-normal Distribution (random.lognormal)', + 'parameters': { 'mean_gaussian': 0.21380242785625422, 'standard_deviation_gaussian': 0.09435378091059601 }, + }, + 'exhalation_rate': { + 'associated_distribution': 'Numpy Log-normal Distribution (random.lognormal)', + 'parameters': { 'mean_gaussian': 0.21380242785625422, 'standard_deviation_gaussian': 0.09435378091059601 }, + }, + }, + 'Moderate activity': { + 'inhalation_rate': { + 'associated_distribution': 'Numpy Log-normal Distribution (random.lognormal)', + 'parameters': { 'mean_gaussian': 0.551771330362601, 'standard_deviation_gaussian': 0.1894616357138137 }, + }, + 'exhalation_rate': { + 'associated_distribution': 'Numpy Log-normal Distribution (random.lognormal)', + 'parameters': { 'mean_gaussian': 0.551771330362601, 'standard_deviation_gaussian': 0.1894616357138137 }, + }, + }, + 'Heavy exercise': { + 'inhalation_rate': { + 'associated_distribution': 'Numpy Log-normal Distribution (random.lognormal)', + 'parameters': { 'mean_gaussian': 1.1644665696723049, 'standard_deviation_gaussian': 0.21744554768657565 }, + }, + 'exhalation_rate': { + 'associated_distribution': 'Numpy Log-normal Distribution (random.lognormal)', + 'parameters': { 'mean_gaussian': 1.1644665696723049, 'standard_deviation_gaussian': 0.21744554768657565 }, + }, + }, +} + viable_to_RNA_ratio = { 'low': 0.01, 'high': 0.6, @@ -72,6 +125,7 @@ }, } + def update_local_reference(local_data, api_data): ''' Recursive function that iterates through the keys and values of local and remote dictionaries. @@ -87,7 +141,7 @@ def update_local_reference(local_data, api_data): async def populate_data(): - global data_fetched, covid_overal_vl_data, infectious_dose, viable_to_RNA_ratio, virus_distributions + global data_fetched, covid_overal_vl_data, infectious_dose, viable_to_RNA_ratio, virus_distributions, activity_distributions if not data_fetched and os.environ.get('DATA_SERVICE_ENABLED', 'False').lower() == 'true': # Fetch data if it hasn't been fetched yet @@ -100,8 +154,8 @@ async def populate_data(): covid_overal_vl_data = update_local_reference(covid_overal_vl_data, data['covid_overal_vl_data']) viable_to_RNA_ratio = update_local_reference(viable_to_RNA_ratio, data['viable_to_RNA_ratio_distribution']) # TODO: reverse (error in schema) - # virus_distributions = update_local_reference(virus_distributions, data['virus_distributions']) virus_distributions = update_local_reference(data['virus_distributions'], virus_distributions) + activity_distributions = update_local_reference(data['activity_distributions'], activity_distributions) data_fetched = True diff --git a/caimira/monte_carlo/data.py b/caimira/monte_carlo/data.py index 5c9edcfc..a8ce44e9 100644 --- a/caimira/monte_carlo/data.py +++ b/caimira/monte_carlo/data.py @@ -172,20 +172,30 @@ def integrate(self, dmin, dmax): # From https://doi.org/10.1101/2021.10.14.21264988 and references therein activity_distributions = { - 'Seated': mc.Activity(LogNormal(-0.6872121723362303, 0.10498338229297108), - LogNormal(-0.6872121723362303, 0.10498338229297108)), + 'Seated': mc.Activity( + inhalation_rate = param_evaluation(constants.activity_distributions['Seated'], 'inhalation_rate'), + exhalation_rate = param_evaluation(constants.activity_distributions['Seated'], 'exhalation_rate'), + ), - 'Standing': mc.Activity(LogNormal(-0.5742377578494785, 0.09373162411398223), - LogNormal(-0.5742377578494785, 0.09373162411398223)), + 'Standing': mc.Activity( + inhalation_rate = param_evaluation(constants.activity_distributions['Standing'], 'inhalation_rate'), + exhalation_rate = param_evaluation(constants.activity_distributions['Standing'], 'exhalation_rate'), + ), - 'Light activity': mc.Activity(LogNormal(0.21380242785625422,0.09435378091059601), - LogNormal(0.21380242785625422,0.09435378091059601)), + 'Light activity': mc.Activity( + inhalation_rate = param_evaluation(constants.activity_distributions['Light activity'], 'inhalation_rate'), + exhalation_rate = param_evaluation(constants.activity_distributions['Light activity'], 'exhalation_rate'), + ), - 'Moderate activity': mc.Activity(LogNormal(0.551771330362601, 0.1894616357138137), - LogNormal(0.551771330362601, 0.1894616357138137)), + 'Moderate activity': mc.Activity( + inhalation_rate = param_evaluation(constants.activity_distributions['Moderate activity'], 'inhalation_rate'), + exhalation_rate = param_evaluation(constants.activity_distributions['Moderate activity'], 'exhalation_rate'), + ), - 'Heavy exercise': mc.Activity(LogNormal(1.1644665696723049, 0.21744554768657565), - LogNormal(1.1644665696723049, 0.21744554768657565)), + 'Heavy exercise': mc.Activity( + inhalation_rate = param_evaluation(constants.activity_distributions['Heavy exercise'], 'inhalation_rate'), + exhalation_rate = param_evaluation(constants.activity_distributions['Heavy exercise'], 'exhalation_rate'), + ), }