Skip to content

Commit edd9e0b

Browse files
committed
Allow option to overwrite parameter file
1 parent fd761f7 commit edd9e0b

File tree

4 files changed

+12
-89
lines changed

4 files changed

+12
-89
lines changed
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
version https://git-lfs.github.com/spec/v1
2-
oid sha256:788332259649a19889355820b194fe0d16af44436f208e3a948e833f0ad5139a
3-
size 419
2+
oid sha256:172a0c24c859aaafbad29f6016433cac7a7324efc582e6c4b19c74b6b97436e7
3+
size 420

src/scripts/analysis_data_generation/scenario_generate_chains.py

Lines changed: 5 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@
4848
wasting,
4949
)
5050

51-
class GenerateDataChains(BaseScenario):
51+
class GenerateEventChains(BaseScenario):
5252
def __init__(self):
5353
super().__init__()
5454
self.seed = 42
@@ -71,101 +71,30 @@ def log_configuration(self):
7171
'tlo.methods.demography.detail': logging.WARNING,
7272
'tlo.methods.healthburden': logging.INFO,
7373
'tlo.methods.healthsystem.summary': logging.INFO,
74+
'tlo.methods.collect_event_chains': logging.INFO
7475
}
7576
}
7677

7778
def modules(self):
78-
# MODIFY
79-
# Here instead of running full module
80-
"""
81-
return [demography.Demography(resourcefilepath=self.resources),
82-
enhanced_lifestyle.Lifestyle(resourcefilepath=self.resources),
83-
healthburden.HealthBurden(resourcefilepath=self.resources),
84-
symptommanager.SymptomManager(resourcefilepath=self.resources, spurious_symptoms=False),#,
85-
#rti.RTI(resourcefilepath=self.resources),
86-
pregnancy_supervisor.PregnancySupervisor(resourcefilepath=self.resources),
87-
labour.Labour(resourcefilepath=self.resources),
88-
care_of_women_during_pregnancy.CareOfWomenDuringPregnancy(resourcefilepath=self.resources),
89-
contraception.Contraception(resourcefilepath=self.resources),
90-
newborn_outcomes.NewbornOutcomes(resourcefilepath=self.resources),
91-
postnatal_supervisor.PostnatalSupervisor(resourcefilepath=self.resources),
92-
hiv.Hiv(resourcefilepath=self.resources),
93-
tb.Tb(resourcefilepath=self.resources),
94-
epi.Epi(resourcefilepath=self.resources),
95-
healthseekingbehaviour.HealthSeekingBehaviour(resourcefilepath=self.resources),
96-
#simplified_births.SimplifiedBirths(resourcefilepath=resourcefilepath),
97-
healthsystem.HealthSystem(resourcefilepath=self.resources,
98-
mode_appt_constraints=1,
99-
cons_availability='all')]
100-
"""
10179
return (
102-
fullmodel(resourcefilepath=self.resources)
103-
+ [ImprovedHealthSystemAndCareSeekingScenarioSwitcher(resourcefilepath=self.resources)]
80+
fullmodel()
10481
)
105-
"""
106-
def draw_parameters(self, draw_number, rng):
107-
return mix_scenarios(
108-
get_parameters_for_status_quo(),
109-
{
110-
'HealthSystem': {
111-
'Service_Availability': list(self._scenarios.values())[draw_number],
112-
},
113-
}
114-
)
115-
116-
def _get_scenarios(self) -> Dict[str, list[str]]:
117-
Return the Dict with values for the parameter `Service_Availability` keyed by a name for the scenario.
118-
The sequences of scenarios systematically omits one of the TREATMENT_ID's that is defined in the model.
11982

120-
# Generate list of TREATMENT_IDs and filter to the resolution needed
121-
treatments = get_filtered_treatment_ids(depth=2)
122-
treatments_RTI = [item for item in treatments if 'Rti' in item]
123-
124-
# Return 'Service_Availability' values, with scenarios for everything, nothing, and ones for which each
125-
# treatment is omitted
126-
service_availability = dict({"Everything": ["*", "Nothing": []})
127-
#service_availability.update(
128-
# {f"No {t.replace('_*', '*')}": [x for x in treatments if x != t] for t in treatments_RTI}
129-
#)
130-
131-
return service_availability
132-
133-
"""
13483
def draw_parameters(self, draw_number, rng):
13584
if draw_number < self.number_of_draws:
13685
return list(self._scenarios.values())[draw_number]
13786
else:
13887
return
13988

140-
# case 1: gfHE = -0.030, factor = 1.01074
141-
# case 2: gfHE = -0.020, factor = 1.02116
142-
# case 3: gfHE = -0.015, factor = 1.02637
143-
# case 4: gfHE = 0.015, factor = 1.05763
144-
# case 5: gfHE = 0.020, factor = 1.06284
145-
# case 6: gfHE = 0.030, factor = 1.07326
146-
14789
def _get_scenarios(self) -> Dict[str, Dict]:
148-
#Return the Dict with values for the parameters that are changed, keyed by a name for the scenario.
149-
150-
treatments = get_filtered_treatment_ids(depth=2)
151-
treatments_RTI = [item for item in treatments if 'Rti' in item]
152-
153-
# Return 'Service_Availability' values, with scenarios for everything, nothing, and ones for which each
154-
# treatment is omitted
155-
service_availability = dict({"Everything": ["*"], "Nothing": []})
156-
service_availability.update(
157-
{f"No {t.replace('_*', '*')}": [x for x in treatments if x != t] for t in treatments_RTI}
158-
)
159-
print(service_availability.keys())
16090

16191
return {
162-
# =========== STATUS QUO ============
16392
"Baseline":
16493
mix_scenarios(
16594
self._baseline(),
16695
{
167-
"HealthSystem": {
168-
"Service_Availability": service_availability["No Rti_ShockTreatment*"],
96+
"CollectEventChains": {
97+
"generate_event_chains": True,
16998
},
17099
}
171100
),

src/tlo/events.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,11 +60,10 @@ def apply(self, target):
6060
:param target: the target of the event
6161
"""
6262
raise NotImplementedError
63-
6463

6564
def run(self):
6665
"""Make the event happen."""
67-
66+
6867
# Dispatch notification that event is about to run
6968
notifier.dispatch("event.about_to_run", data={"target": self.target, "module" : self.module.name, "link_info" : {"EventName": type(self).__name__}})
7069

src/tlo/methods/collect_event_chains.py

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -58,17 +58,9 @@ def initialise_simulation(self, sim):
5858
notifier.add_listener("event.has_just_ran", self.on_notification_event_has_just_ran)
5959

6060
def read_parameters(self, resourcefilepath: Optional[Path] = None):
61-
print("resource file path", resourcefilepath)
6261
self.load_parameters_from_dataframe(pd.read_csv(resourcefilepath/"ResourceFile_GenerateEventChains/parameter_values.csv"))
63-
64-
# If modules of interest is '*', set by default to all modules included in the simulation
65-
if self.parameters["modules_of_interest"] == ['*']:
66-
self.parameters["modules_of_interest"] = list(self.sim.modules.keys())
6762

6863
def initialise_population(self, population):
69-
pass
70-
71-
def initialise_simulation(self, sim):
7264
# Use parameter file values by default, if not overwritten
7365
self.generate_event_chains = self.parameters['generate_event_chains'] \
7466
if self.generate_event_chains is None \
@@ -81,6 +73,10 @@ def initialise_simulation(self, sim):
8173
self.events_to_ignore = self.parameters['events_to_ignore'] \
8274
if self.events_to_ignore is None \
8375
else self.events_to_ignore
76+
77+
# If modules of interest is '*', set by default to all modules included in the simulation
78+
if self.modules_of_interest == ['*']:
79+
self.modules_of_interest = list(self.sim.modules.keys())
8480

8581
def get_generate_event_chains(self) -> bool:
8682
"""Returns `generate_event_chains`. (Should be equal to what is specified by the parameter, but
@@ -134,7 +130,6 @@ def on_notification_event_about_to_run(self, data):
134130
if not self.generate_event_chains or (data['module'] not in self.modules_of_interest) or (data['link_info']['EventName'] in self.events_to_ignore):
135131
return
136132
else:
137-
138133
# Initialise these variables
139134
self.print_chains = False
140135
self.df_before = []

0 commit comments

Comments
 (0)