Skip to content

Commit

Permalink
adapted data registry to accomodate data schema updates
Browse files Browse the repository at this point in the history
  • Loading branch information
lrdossan committed Mar 4, 2024
1 parent 50627c6 commit c56c68c
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 22 deletions.
4 changes: 3 additions & 1 deletion caimira/apps/calculator/report_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,9 @@ def calculate_report_data(form: VirusFormData, model: models.ExposureModel) -> t
else:
uncertainties_plot_src = None
conditional_probability_data = None
vl_dist = list(np.log10(model.concentration_model.virus.viral_load_in_sputum))
vl = model.concentration_model.virus.viral_load_in_sputum
if isinstance(vl, np.ndarray): vl_dist = list(np.log10(model.concentration_model.virus.viral_load_in_sputum))
else: vl_dist = np.log10(model.concentration_model.virus.viral_load_in_sputum)

return {
"model_repr": repr(model),
Expand Down
14 changes: 7 additions & 7 deletions caimira/monte_carlo/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def evaluate_vl(root: typing.Dict, value: str, data_registry: DataRegistry):
elif root[value] == ViralLoads.SYMPTOMATIC_FREQUENCIES.value:
return symptomatic_vl_frequencies
elif root[value] == "Custom":
return param_evaluation(root, 'Viral load custom distribution')
return param_evaluation(root, 'Viral load custom')
else:
raise ValueError(f"Invalid ViralLoads value {value}")

Expand All @@ -29,7 +29,7 @@ def evaluate_infectd(root: typing.Dict, value: str, data_registry: DataRegistry)
if root[value] == InfectiousDoses.DISTRIBUTION.value:
return infectious_dose_distribution(data_registry)
elif root[value] == "Custom":
return param_evaluation(root, 'Infectious dose custom distribution')
return param_evaluation(root, 'Infectious dose custom')
else:
raise ValueError(f"Invalid InfectiousDoses value {value}")

Expand All @@ -38,7 +38,7 @@ def evaluate_vtrr(root: typing.Dict, value: str, data_registry: DataRegistry):
if root[value] == ViableToRNARatios.DISTRIBUTION.value:
return viable_to_RNA_ratio_distribution(data_registry)
elif root[value] == "Custom":
return param_evaluation(root, 'Viable to RNA ratio custom distribution')
return param_evaluation(root, 'Viable to RNA ratio custom')
else:
raise ValueError(f"Invalid ViableToRNARatios value {value}")

Expand All @@ -61,7 +61,7 @@ def custom_distribution_lookup(dict: dict, key_part: str) -> typing.Any:
try:
for key, value in dict.items():
if (key_part in key):
return value['associated_distribution']
return value['associated_value']
except KeyError:
return f"Key '{key_part}' not found."

Expand All @@ -81,8 +81,8 @@ def evaluate_custom_distribution(dist: str, params: typing.Dict) -> typing.Any:
ValueError: If the distribution type is not recognized.
"""
if dist == 'Linear Space':
return np.linspace(params['start'], params['stop'], params['num'])
if dist == 'Constant':
return params
elif dist == 'Normal':
return Normal(params['normal_mean_gaussian'], params['normal_standard_deviation_gaussian'])
elif dist == 'Log-normal':
Expand Down Expand Up @@ -111,7 +111,7 @@ def param_evaluation(root: typing.Dict, param: typing.Union[str, typing.Any]) ->
value = root.get(param)

if isinstance(value, dict):
dist: str = root[param]['associated_distribution']
dist: str = root[param]['associated_value']
params: typing.Dict = root[param]['parameters']
return evaluate_custom_distribution(dist, params)

Expand Down
28 changes: 14 additions & 14 deletions caimira/store/data_registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,14 @@ class DataRegistry:
activity_distributions = {
"Seated": {
"inhalation_rate": {
"associated_distribution": "Log-normal",
"associated_value": "Log-normal",
"parameters": {
"lognormal_mean_gaussian": -0.6872121723362303,
"lognormal_standard_deviation_gaussian": 0.10498338229297108,
},
},
"exhalation_rate": {
"associated_distribution": "Log-normal",
"associated_value": "Log-normal",
"parameters": {
"lognormal_mean_gaussian": -0.6872121723362303,
"lognormal_standard_deviation_gaussian": 0.10498338229297108,
Expand All @@ -42,14 +42,14 @@ class DataRegistry:
},
"Standing": {
"inhalation_rate": {
"associated_distribution": "Log-normal",
"associated_value": "Log-normal",
"parameters": {
"lognormal_mean_gaussian": -0.5742377578494785,
"lognormal_standard_deviation_gaussian": 0.09373162411398223,
},
},
"exhalation_rate": {
"associated_distribution": "Log-normal",
"associated_value": "Log-normal",
"parameters": {
"lognormal_mean_gaussian": -0.5742377578494785,
"lognormal_standard_deviation_gaussian": 0.09373162411398223,
Expand All @@ -58,14 +58,14 @@ class DataRegistry:
},
"Light activity": {
"inhalation_rate": {
"associated_distribution": "Log-normal",
"associated_value": "Log-normal",
"parameters": {
"lognormal_mean_gaussian": 0.21380242785625422,
"lognormal_standard_deviation_gaussian": 0.09435378091059601,
},
},
"exhalation_rate": {
"associated_distribution": "Log-normal",
"associated_value": "Log-normal",
"parameters": {
"lognormal_mean_gaussian": 0.21380242785625422,
"lognormal_standard_deviation_gaussian": 0.09435378091059601,
Expand All @@ -74,14 +74,14 @@ class DataRegistry:
},
"Moderate activity": {
"inhalation_rate": {
"associated_distribution": "Log-normal",
"associated_value": "Log-normal",
"parameters": {
"lognormal_mean_gaussian": 0.551771330362601,
"lognormal_standard_deviation_gaussian": 0.1894616357138137,
},
},
"exhalation_rate": {
"associated_distribution": "Log-normal",
"associated_value": "Log-normal",
"parameters": {
"lognormal_mean_gaussian": 0.551771330362601,
"lognormal_standard_deviation_gaussian": 0.1894616357138137,
Expand All @@ -90,14 +90,14 @@ class DataRegistry:
},
"Heavy exercise": {
"inhalation_rate": {
"associated_distribution": "Log-normal",
"associated_value": "Log-normal",
"parameters": {
"lognormal_mean_gaussian": 1.1644665696723049,
"lognormal_standard_deviation_gaussian": 0.21744554768657565,
},
},
"exhalation_rate": {
"associated_distribution": "Log-normal",
"associated_value": "Log-normal",
"parameters": {
"lognormal_mean_gaussian": 1.1644665696723049,
"lognormal_standard_deviation_gaussian": 0.21744554768657565,
Expand Down Expand Up @@ -255,7 +255,7 @@ class DataRegistry:
mask_distributions = {
"Type I": {
"η_inhale": {
"associated_distribution": "Uniform",
"associated_value": "Uniform",
"parameters": {
"low": 0.25,
"high": 0.80,
Expand All @@ -266,7 +266,7 @@ class DataRegistry:
},
"FFP2": {
"η_inhale": {
"associated_distribution": "Uniform",
"associated_value": "Uniform",
"parameters": {
"low": 0.83,
"high": 0.91,
Expand All @@ -277,15 +277,15 @@ class DataRegistry:
},
"Cloth": {
"η_inhale": {
"associated_distribution": "Uniform",
"associated_value": "Uniform",
"parameters": {
"low": 0.05,
"high": 0.40,
},
},
"Known filtration efficiency of masks when exhaling?": "Yes",
"η_exhale": {
"associated_distribution": "Uniform",
"associated_value": "Uniform",
"parameters": {
"low": 0.20,
"high": 0.50,
Expand Down

0 comments on commit c56c68c

Please sign in to comment.