Skip to content

Commit

Permalink
added activity distributions from global store
Browse files Browse the repository at this point in the history
  • Loading branch information
lrdossan committed Oct 13, 2023
1 parent 88f7f54 commit a96cc18
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 12 deletions.
58 changes: 56 additions & 2 deletions caimira/apps/calculator/global_store/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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.
Expand All @@ -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
Expand All @@ -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

Expand Down
30 changes: 20 additions & 10 deletions caimira/monte_carlo/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'),
),
}


Expand Down

0 comments on commit a96cc18

Please sign in to comment.