From c56c68c25b1c55175821ac806cae247b594ad401 Mon Sep 17 00:00:00 2001 From: Luis Aleixo Date: Wed, 21 Feb 2024 14:38:35 +0100 Subject: [PATCH] adapted data registry to accomodate data schema updates --- caimira/apps/calculator/report_generator.py | 4 ++- caimira/monte_carlo/data.py | 14 +++++------ caimira/store/data_registry.py | 28 ++++++++++----------- 3 files changed, 24 insertions(+), 22 deletions(-) diff --git a/caimira/apps/calculator/report_generator.py b/caimira/apps/calculator/report_generator.py index 6eff7181..f0c83ecf 100644 --- a/caimira/apps/calculator/report_generator.py +++ b/caimira/apps/calculator/report_generator.py @@ -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), diff --git a/caimira/monte_carlo/data.py b/caimira/monte_carlo/data.py index b8332ae2..094edcdc 100644 --- a/caimira/monte_carlo/data.py +++ b/caimira/monte_carlo/data.py @@ -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}") @@ -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}") @@ -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}") @@ -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." @@ -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': @@ -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) diff --git a/caimira/store/data_registry.py b/caimira/store/data_registry.py index 7189e253..e5cec66e 100644 --- a/caimira/store/data_registry.py +++ b/caimira/store/data_registry.py @@ -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, @@ -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, @@ -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, @@ -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, @@ -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, @@ -255,7 +255,7 @@ class DataRegistry: mask_distributions = { "Type I": { "η_inhale": { - "associated_distribution": "Uniform", + "associated_value": "Uniform", "parameters": { "low": 0.25, "high": 0.80, @@ -266,7 +266,7 @@ class DataRegistry: }, "FFP2": { "η_inhale": { - "associated_distribution": "Uniform", + "associated_value": "Uniform", "parameters": { "low": 0.83, "high": 0.91, @@ -277,7 +277,7 @@ class DataRegistry: }, "Cloth": { "η_inhale": { - "associated_distribution": "Uniform", + "associated_value": "Uniform", "parameters": { "low": 0.05, "high": 0.40, @@ -285,7 +285,7 @@ class DataRegistry: }, "Known filtration efficiency of masks when exhaling?": "Yes", "η_exhale": { - "associated_distribution": "Uniform", + "associated_value": "Uniform", "parameters": { "low": 0.20, "high": 0.50,