Skip to content

Commit

Permalink
Track incidence and cum-incidence by strain
Browse files Browse the repository at this point in the history
  • Loading branch information
romain-ragonnet committed Nov 1, 2023
1 parent 86c6577 commit 19da4f2
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 3 deletions.
5 changes: 4 additions & 1 deletion autumn/models/sm_covid2/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -523,9 +523,12 @@ def build_model(params: dict, build_options: dict = None, ret_builder=False) ->
)

outputs_builder.request_cumulative_outputs(
params.requested_cumulative_outputs, params.cumulative_start_time
params.requested_cumulative_outputs, params.cumulative_start_time, strain_strata
)

if "incidence" in params.requested_cumulative_outputs:
outputs_builder.request_cumulative_incidence_prop_by_strain(strain_strata)

if params.activate_random_process:
outputs_builder.request_random_process_outputs()
outputs_builder.request_random_process_auc()
Expand Down
44 changes: 42 additions & 2 deletions autumn/models/sm_covid2/outputs.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ def request_incidence(
strain_strata: List[str],
incidence_flow: str,
request_incidence_by_age: bool,
request_incidence_by_strain: bool = True,
):
"""
Calculate incident disease cases. This is associated with the transition to infectiousness if there is only one
Expand All @@ -92,6 +93,7 @@ def request_incidence(
self.model.request_output_for_flow(name="incidence", flow_name=incidence_flow)

# Stratified
strain_incidence_sources = {strain: [] for strain in strain_strata}
for agegroup in age_groups:
agegroup_string = f"Xagegroup_{agegroup}"
age_incidence_sources = []
Expand All @@ -108,6 +110,7 @@ def request_incidence(

output_name = f"incidence{agegroup_string}{immunity_string}{strain_string}"
age_incidence_sources.append(output_name)
strain_incidence_sources[strain].append(output_name)

self.model.request_output_for_flow(
name=output_name,
Expand All @@ -124,6 +127,21 @@ def request_incidence(
save_results=True,
)


# Aggregated incidence by strain
if request_incidence_by_strain:

for strain in strain_strata:
strain_string = f"Xstrain_{strain}" if strain else ""
output_name = f"incidence{strain_string}"

self.model.request_aggregate_output(
name=output_name,
sources=strain_incidence_sources[strain],
save_results=False,
)


def request_elderly_incidence_prop(
self,
age_groups: List[str],
Expand All @@ -136,6 +154,21 @@ def request_elderly_incidence_prop(
save_results=True
)

def request_cumulative_incidence_prop_by_strain(
self,
strain_strata: List[str],
):
for strain in strain_strata:
strain_string = f"Xstrain_{strain}" if strain else ""
cum_output_name = f"cumulative_incidence{strain_string}"

self.model.request_function_output(
name=f"cumulative_incidence_prop{strain_string}",
func=DerivedOutput(cum_output_name) / DerivedOutput("cumulative_incidence"),
save_results=True
)


def request_infection_deaths(
self,
model_times: np.ndarray,
Expand Down Expand Up @@ -647,16 +680,23 @@ def request_immunity_props(self, immunity_strata, age_pops, request_immune_prop_
func=make_age_immune_prop_func(popsize)(DerivedOutput(n_age_immune_name))
)

def request_cumulative_outputs(self, requested_cumulative_outputs, cumulative_start_time):
def request_cumulative_outputs(self, requested_cumulative_outputs, cumulative_start_time, strain_strata):
"""
Compute cumulative outputs for requested outputs.
Args:
requested_cumulative_outputs: List of requested derived outputs to accumulate
cumulative_start_time: reference time for cumulative output calculation
"""
computed_cumulative_outputs = requested_cumulative_outputs

# also request cumulative incidence by strain
for strain in strain_strata:
strain_string = f"Xstrain_{strain}" if strain else ""
output_name = f"incidence{strain_string}"
computed_cumulative_outputs.append(output_name)

for output in requested_cumulative_outputs:
for output in computed_cumulative_outputs:
self.model.request_cumulative_output(
name=f"cumulative_{output}", source=output, start_time=cumulative_start_time
)
Expand Down

0 comments on commit 19da4f2

Please sign in to comment.