Skip to content

Commit

Permalink
changed global store directory and imported BLOmodel parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
lrdossan committed Oct 24, 2023
1 parent 00681f8 commit 82adc10
Show file tree
Hide file tree
Showing 9 changed files with 48 additions and 24 deletions.
2 changes: 1 addition & 1 deletion caimira/apps/calculator/defaults.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import typing

import caimira.apps.calculator.global_store.constants as constants
import caimira.global_store.constants as constants

# ------------------ Default form values ----------------------

Expand Down
2 changes: 1 addition & 1 deletion caimira/apps/calculator/model_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
from .defaults import (NO_DEFAULT, DEFAULT_MC_SAMPLE_SIZE, DEFAULTS, ACTIVITIES, ACTIVITY_TYPES, COFFEE_OPTIONS_INT, CONFIDENCE_LEVEL_OPTIONS,
MECHANICAL_VENTILATION_TYPES, MASK_TYPES, MASK_WEARING_OPTIONS, MONTH_NAMES, VACCINE_BOOSTER_TYPE, VACCINE_TYPE,
VENTILATION_TYPES, VIRUS_TYPES, VOLUME_TYPES, WINDOWS_OPENING_REGIMES, WINDOWS_TYPES)
import caimira.apps.calculator.global_store.constants as constants
import caimira.global_store.constants as constants

LOG = logging.getLogger(__name__)

Expand Down
2 changes: 1 addition & 1 deletion caimira/apps/calculator/report_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
from ... import monte_carlo as mc
from .model_generator import FormData, DEFAULT_MC_SAMPLE_SIZE
from ... import dataclass_utils
import caimira.apps.calculator.global_store.constants as constants
import caimira.global_store.constants as constants


def model_start_end(model: models.ExposureModel):
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import asyncio
import typing
import os

# Global variable to keep track of whether data has been fetched
Expand Down Expand Up @@ -212,33 +213,44 @@
'repeats': 1
}

def update_local_reference(local_data, api_data):
BLOmodel = {
'cn': {'B': 0.06, 'L': 0.2, 'O': 0.0010008},
'mu': {'B': 0.989541, 'L': 1.38629, 'O': 4.97673},
'sigma': {'B': 0.262364, 'L': 0.506818, 'O': 0.585005},
}

def update_local_reference(local_data, api_data: typing.Union[dict, typing.Any]):
'''
Recursive function that iterates through the keys and values of local and remote dictionaries.
'''
for key, value in api_data.items():
if isinstance(value, dict):
# If the value is a dictionary, recursively update it
local_data[key] = update_local_reference(
local_data.get(key, {}), value)
else:
# Update the value at the current key
local_data[key] = value
if isinstance(api_data, dict):
for key, value in api_data.items():
if isinstance(value, dict):
# If the value is a dictionary, recursively update it
local_data[key] = update_local_reference(
local_data.get(key, {}), value)
else:
# Update the value at the current key
local_data[key] = value
else:
local_data = api_data
return local_data


async def populate_data():
global data_fetched, covid_overal_vl_data, infectious_dose_distribution, viable_to_RNA_ratio_distribution, virus_distributions, activity_distributions, mask_distributions
global expiration_BLO_factors, long_range_expiration_distributions, short_range_expiration_distributions, short_range_distances, infected_population_scenario_activity
global monte_carlo_sample_size, conditional_prob_inf_given_viral_load, exposure_model

global data_fetched, BLOmodel, covid_overal_vl_data, infectious_dose_distribution, viable_to_RNA_ratio_distribution, virus_distributions, activity_distributions
global mask_distributions, expiration_BLO_factors, long_range_expiration_distributions, short_range_expiration_distributions, short_range_distances
global infected_population_scenario_activity, monte_carlo_sample_size, conditional_prob_inf_given_viral_load, exposure_model
if not data_fetched and os.environ.get('DATA_SERVICE_ENABLED', 'False').lower() == 'true':
# Fetch data if it hasn't been fetched yet
from caimira.apps.calculator.global_store.data_store import GlobalStore
from caimira.global_store.data_store import GlobalStore

await GlobalStore.populate_from_api()
data = GlobalStore.get_data()['data']

BLOmodel = update_local_reference(
BLOmodel, data['BLOmodel'])
infectious_dose_distribution = update_local_reference(
infectious_dose_distribution, data['infectious_dose_distribution'])
covid_overal_vl_data = update_local_reference(
Expand Down Expand Up @@ -267,7 +279,7 @@ async def populate_data():
conditional_prob_inf_given_viral_load, data['conditional_prob_inf_given_viral_load'])
exposure_model = update_local_reference(
exposure_model, data['exposure_model'])

data_fetched = True

# Executed when this module is imported
Expand Down
File renamed without changes.
20 changes: 16 additions & 4 deletions caimira/monte_carlo/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import caimira.monte_carlo as mc
from caimira.monte_carlo.sampleable import LogCustom, LogNormal, LogCustomKernel, CustomKernel, Uniform, Custom, Normal
import caimira.apps.calculator.global_store.constants as constants
import caimira.global_store.constants as constants

sqrt2pi = np.sqrt(2.*np.pi)
sqrt2 = np.sqrt(2.)
Expand Down Expand Up @@ -137,15 +137,27 @@ class BLOmodel:

#: cn (cm^-3) for resp. the B, L and O modes. Corresponds to the
# total concentration of aerosols for each mode.
cn: typing.Tuple[float, float, float] = (0.06, 0.2, 0.0010008)
cn: typing.Tuple[float, float, float] = (
param_evaluation(constants.BLOmodel['cn'], 'B'),
param_evaluation(constants.BLOmodel['cn'], 'L'),
param_evaluation(constants.BLOmodel['cn'], 'O')
)

# Mean of the underlying normal distributions (represents the log of a
# diameter in microns), for resp. the B, L and O modes.
mu: typing.Tuple[float, float, float] = (0.989541, 1.38629, 4.97673)
mu: typing.Tuple[float, float, float] = (
param_evaluation(constants.BLOmodel['mu'], 'B'),
param_evaluation(constants.BLOmodel['mu'], 'L'),
param_evaluation(constants.BLOmodel['mu'], 'O')
)

# Std deviation of the underlying normal distribution, for resp.
# the B, L and O modes.
sigma: typing.Tuple[float, float, float] = (0.262364, 0.506818, 0.585005)
sigma: typing.Tuple[float, float, float] = (
param_evaluation(constants.BLOmodel['sigma'], 'B'),
param_evaluation(constants.BLOmodel['sigma'], 'L'),
param_evaluation(constants.BLOmodel['sigma'], 'O')
)

def distribution(self, d):
"""
Expand Down
2 changes: 1 addition & 1 deletion caimira/tests/apps/calculator/test_model_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from caimira.apps.calculator.model_generator import minutes_since_midnight
from caimira import models
from caimira.monte_carlo.data import expiration_distributions
import caimira.apps.calculator.global_store.constants as constants
import caimira.global_store.constants as constants


def test_model_from_dict(baseline_form_data):
Expand Down
2 changes: 1 addition & 1 deletion caimira/tests/models/test_short_range_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from caimira.apps.calculator.model_generator import build_expiration
from caimira.monte_carlo.data import short_range_expiration_distributions,\
expiration_distributions, short_range_distances, activity_distributions
import caimira.apps.calculator.global_store.constants as constants
import caimira.global_store.constants as constants

SAMPLE_SIZE = constants.monte_carlo_sample_size

Expand Down

0 comments on commit 82adc10

Please sign in to comment.