Skip to content

Commit 9014b01

Browse files
committed
Add rescaling to daily HR capabilities due to either a constant factor or pop grown
1 parent ea1eac6 commit 9014b01

File tree

2 files changed

+40
-2
lines changed

2 files changed

+40
-2
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
version https://git-lfs.github.com/spec/v1
2-
oid sha256:187302cf1744ee6a9538665c5dff5650f58e4d00c8d74844ff8b569b6b38f9d1
3-
size 335
2+
oid sha256:1cc35f571076244f7bb0ee964ad4c44d57d4943dc35b044302b98de6b0f4b0b6
3+
size 391

src/tlo/methods/healthsystem.py

+38
Original file line numberDiff line numberDiff line change
@@ -554,6 +554,15 @@ class HealthSystem(Module):
554554
"and custom (user can freely set these factors as parameters in the analysis).",
555555
),
556556

557+
'dynamic_HR_scaling_factor': Parameter(
558+
Types.REAL, "Factor by which HR capabilities are scaled at regular intervals of 1 year"
559+
),
560+
561+
'scale_HR_by_popsize': Parameter(
562+
Types.BOOL, "Decide whether to scale HR capabilities by population size every year. Can be used in addition to"
563+
"dynamic_HR_scaling_factor"
564+
),
565+
557566
'tclose_overwrite': Parameter(
558567
Types.INT, "Decide whether to overwrite tclose variables assigned by disease modules"),
559568

@@ -904,6 +913,12 @@ def initialise_simulation(self, sim):
904913
sim.schedule_event(HealthSystemChangeMode(self),
905914
Date(self.parameters["year_mode_switch"], 1, 1))
906915

916+
# Schedule recurring event which will rescale daily capabilities at regular intervals.
917+
# Note: if want to use Demography's popsize_by_year for current year too (see options in DynamicRescalingHRCapabilities),
918+
# need to ensure that the DynamicRescalingHRCapabilities event takes place *after* the DemographyLoggerEvent has been called.
919+
# Could achieve this for example by scheduling the former to happen on 2nd of Feb..
920+
sim.schedule_event(DynamicRescalingHRCapabilities(self), Date(sim.date+DateOffset(years=1)))
921+
907922
def on_birth(self, mother_id, child_id):
908923
self.bed_days.on_birth(self.sim.population.props, mother_id, child_id)
909924

@@ -2842,6 +2857,29 @@ def apply(self, population):
28422857
self.module.bed_days.availability = self._parameters['beds_availability']
28432858

28442859

2860+
class DynamicRescalingHRCapabilities(RegularEvent, PopulationScopeEventMixin):
2861+
""" This event exists to scale the daily capabilities assumed at fixed time intervals"""
2862+
def __init__(self, module):
2863+
super().__init__(module, frequency=DateOffset(years=1))
2864+
2865+
def apply(self, population):
2866+
2867+
# The following assumes that self.module._daily_capabilities is initialised once at start of simulation,
2868+
# which I believe is correct
2869+
2870+
# Rescale daily capabilities by specified amount
2871+
self.module._daily_capabilities *= self.module.parameters['dynamic_HR_scaling_factor']
2872+
2873+
# Rescale daily capabilities by population size, if this option is included
2874+
if self.module.parameters['scale_HR_by_popsize']:
2875+
demog = self.sim.modules['Demography']
2876+
if self.sim.date.year>2010:
2877+
# Either
2878+
self.module._daily_capabilities *= population.props.is_alive.sum()/demog.popsize_by_year[self.sim.date.year - 1]
2879+
# Or, if ensuring DemographyLoggingEvent at start of the year takes place *before* this rescaling
2880+
# self.module._daily_capabilities *= demog.popsize_by_year[self.sim.date.year]/demog.popsize_by_year[self.sim.date.year - 1]
2881+
2882+
28452883
class HealthSystemChangeMode(RegularEvent, PopulationScopeEventMixin):
28462884
""" This event exists to change the priority policy adopted by the
28472885
HealthSystem at a given year. """

0 commit comments

Comments
 (0)