-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Albrja/mic 5805/cpapa implementation (#36)
Albrja/mic 5805/cpapa implementation No CPAP risk factor implementation - *Category*: Implemenation - *JIRA issue*: https://jira.ihme.washington.edu/browse/MIC-5805 - *Research reference*: https://vivarium-research.readthedocs.io/en/latest/models/intervention_models/neonatal/cpap_intervention.html#calibration-strategy Changes and notes -adds Intrapartum component to determine delivery facility type and CPAP availability for simulants -adds No CPAP risk effect component to modify preterm with rds CSMR pipeline ### Verification and Testing <!-- Details on how code was verified. Consider: plots, images, (small) csv files. -->
- Loading branch information
Showing
9 changed files
with
204 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
from __future__ import annotations | ||
|
||
from functools import partial | ||
|
||
import pandas as pd | ||
from vivarium import Component | ||
from vivarium.framework.engine import Builder | ||
from vivarium.framework.event import Event | ||
|
||
from vivarium_gates_mncnh.constants import data_values | ||
from vivarium_gates_mncnh.constants.data_keys import NO_CPAP_RISK | ||
from vivarium_gates_mncnh.constants.data_values import COLUMNS, PIPELINES | ||
from vivarium_gates_mncnh.utilities import get_location | ||
|
||
|
||
class NoCPAPRisk(Component): | ||
"""Component for CPAP intervention. This is essentially a risk effect.""" | ||
|
||
@property | ||
def configuration_defaults(self) -> dict: | ||
return { | ||
self.name: { | ||
"data_sources": { | ||
"relative_risk": NO_CPAP_RISK.RELATIVE_RISK, | ||
"paf": self.load_paf_data, | ||
} | ||
} | ||
} | ||
|
||
@property | ||
def columns_required(self) -> list[str]: | ||
return [COLUMNS.CPAP_AVAILABLE] | ||
|
||
def __init__(self) -> None: | ||
super().__init__() | ||
self.preterm_csmr_target = PIPELINES.NEONATAL_PRETERM_BIRTH_WITH_RDS | ||
|
||
def setup(self, builder: Builder) -> None: | ||
self.randomness = builder.randomness.get_stream(self.name) | ||
self.location = get_location(builder) | ||
self.preterm_with_rds_csmr = builder.value.get_value(self.preterm_csmr_target) | ||
builder.value.register_value_modifier( | ||
self.preterm_with_rds_csmr.name, | ||
self.modify_preterm_with_rds_csmr, | ||
required_resources=[ | ||
self.preterm_with_rds_csmr.name, | ||
COLUMNS.DELIVERY_FACILITY_TYPE, | ||
COLUMNS.CPAP_AVAILABLE, | ||
], | ||
) | ||
|
||
################## | ||
# Helper nethods # | ||
################## | ||
|
||
def load_paf_data(self, builder: Builder) -> pd.Series: | ||
data = builder.data.load(NO_CPAP_RISK.PAF) | ||
data = data.rename(columns=data_values.CHILD_LOOKUP_COLUMN_MAPPER) | ||
return data | ||
|
||
def modify_preterm_with_rds_csmr( | ||
self, index: pd.Index, preterm_with_rds_csmr: pd.Series[float] | ||
) -> pd.Series[float]: | ||
# No CPAP access is like a dichotomous risk factor, meaning those that have access to CPAP will | ||
# not have their CSMR modify by no CPAP RR | ||
pop = self.population_view.get(index) | ||
no_cpap_idx = pop.index[pop[COLUMNS.CPAP_AVAILABLE] == False] | ||
# NOTE: RR is relative risk for no CPAP | ||
no_cpap_rr = self.lookup_tables["relative_risk"](no_cpap_idx) | ||
# NOTE: PAF is for no CPAP | ||
paf = self.lookup_tables["paf"](index) | ||
|
||
# Modify the CSMR pipeline | ||
modified_csmr = preterm_with_rds_csmr * (1 - paf) | ||
modified_csmr.loc[no_cpap_idx] = modified_csmr * no_cpap_rr | ||
return modified_csmr |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
import pandas as pd | ||
from vivarium import Component | ||
from vivarium.framework.engine import Builder | ||
from vivarium.framework.event import Event | ||
from vivarium.framework.population import SimulantData | ||
|
||
from vivarium_gates_mncnh.constants.data_keys import NO_CPAP_RISK | ||
from vivarium_gates_mncnh.constants.data_values import ( | ||
COLUMNS, | ||
CPAP_ACCESS_PROBABILITIES, | ||
DELIVERY_FACILITY_TYPE_PROBABILITIES, | ||
DELIVERY_FACILITY_TYPES, | ||
SIMULATION_EVENT_NAMES, | ||
) | ||
from vivarium_gates_mncnh.utilities import get_location | ||
|
||
|
||
class Intrapartum(Component): | ||
"""This component functions to make key decisions about events in the intrapartum step of the model. | ||
Specifically, it determines the delivery facility type and whether or not CPAP is available to the simulant.""" | ||
|
||
@property | ||
def columns_created(self) -> list[str]: | ||
return [ | ||
COLUMNS.DELIVERY_FACILITY_TYPE, | ||
COLUMNS.CPAP_AVAILABLE, | ||
] | ||
|
||
def setup(self, builder: Builder) -> None: | ||
self._sim_step_name = builder.time.simulation_event_name() | ||
self.randomness = builder.randomness.get_stream(self.name) | ||
self.location = get_location(builder) | ||
|
||
def on_initialize_simulants(self, pop_data: SimulantData) -> None: | ||
anc_data = pd.DataFrame( | ||
{ | ||
COLUMNS.DELIVERY_FACILITY_TYPE: DELIVERY_FACILITY_TYPES.NONE, | ||
COLUMNS.CPAP_AVAILABLE: False, | ||
}, | ||
index=pop_data.index, | ||
) | ||
self.population_view.update(anc_data) | ||
|
||
def on_time_step(self, event: Event) -> None: | ||
if self._sim_step_name() != SIMULATION_EVENT_NAMES.INTRAPARTUM: | ||
return | ||
|
||
pop = self.population_view.get(event.index) | ||
# Choose delivery facility type | ||
delivery_facility_type = self.randomness.choice( | ||
pop.index, | ||
[ | ||
DELIVERY_FACILITY_TYPES.HOME, | ||
DELIVERY_FACILITY_TYPES.CEmONC, | ||
DELIVERY_FACILITY_TYPES.BEmONC, | ||
], | ||
p=list(DELIVERY_FACILITY_TYPE_PROBABILITIES[self.location].values()), | ||
additional_key="delivery_facility_type", | ||
) | ||
pop[COLUMNS.DELIVERY_FACILITY_TYPE] = delivery_facility_type | ||
|
||
# Determine if simulant had access to CPAP | ||
facility_type_mapper = { | ||
DELIVERY_FACILITY_TYPES.BEmONC: NO_CPAP_RISK.P_CPAP_BEmONC, | ||
DELIVERY_FACILITY_TYPES.CEmONC: NO_CPAP_RISK.P_CPAP_CEmONC, | ||
} | ||
for facility_type in [ | ||
DELIVERY_FACILITY_TYPES.BEmONC, | ||
DELIVERY_FACILITY_TYPES.CEmONC, | ||
]: | ||
facility_idx = pop.index[pop[COLUMNS.DELIVERY_FACILITY_TYPE] == facility_type] | ||
cpap_access_probability = CPAP_ACCESS_PROBABILITIES[self.location][ | ||
facility_type_mapper[facility_type] | ||
] | ||
cpap_access_idx = self.randomness.filter_for_probability( | ||
facility_idx, cpap_access_probability, f"cpap_access_{facility_type}" | ||
) | ||
pop.loc[cpap_access_idx, COLUMNS.CPAP_AVAILABLE] = True | ||
|
||
self.population_view.update(pop) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters