Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Secular Time-trend in Availability of Consumables #1454

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Git LFS file not shown
Git LFS file not shown
3 changes: 2 additions & 1 deletion src/tlo/analysis/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -1127,9 +1127,10 @@ def get_parameters_for_status_quo() -> Dict:
"cons_availability": "default",
"beds_availability": "default",
"equip_availability": "all", # <--- NB. Existing calibration is assuming all equipment is available
# "consumables_availability_time_trend": True, # <-- not included yet, but future update should include.
},
}

def get_parameters_for_standard_mode2_runs() -> Dict:
"""
Returns a dictionary of parameters and their updated values to indicate
Expand Down
30 changes: 27 additions & 3 deletions src/tlo/methods/consumables.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@ def __init__(self,
availability_data: pd.DataFrame = None,
item_code_designations: pd.DataFrame = None,
rng: np.random = None,
availability: str = 'default'
availability: str = 'default',
use_time_trend: bool = False,
time_trend_data: dict = None,
) -> None:

self._options_for_availability = {
Expand All @@ -56,8 +58,10 @@ def __init__(self,
self._is_unknown_item_available = None # Whether an unknown item is available, by facility_id
self._not_recognised_item_codes = set() # The item codes requested but which are not recognised.

# Save designations
# Save designations and time-trend info
self._item_code_designations = item_code_designations
self._time_trend_data = time_trend_data
self._use_time_trend = use_time_trend

# Save all item_codes that are defined and pd.Series with probs of availability from ResourceFile
self.item_codes, self._processed_consumables_data = \
Expand Down Expand Up @@ -266,7 +270,7 @@ def _lookup_availability_of_consumables(self,

def on_simulation_end(self):
"""Do tasks at the end of the simulation.

Raise warnings and enter to log about item_codes not recognised.
"""
if self._not_recognised_item_codes:
Expand All @@ -289,6 +293,26 @@ def on_simulation_end(self):
def on_end_of_year(self):
self._summary_counter.write_to_log_and_reset_counters()

# Update consumables availability (for next year) to reflect secular trend
self._update_availability()

def _update_availability(self):
"""Update availability of consumables"""
if not self._use_time_trend:
return # Do nothing if there should not be a time-trend in the availability

# Data on the changes in availability
data = self._time_trend_data

# Annual multiplier on availability for each category....

# Items in each category.... (look up from the categories provided in the sheet)

# For each group, multiply availabilities in `self._prob_item_codes_available`, and clip to 1.0





def get_item_codes_from_package_name(lookup_df: pd.DataFrame, package: str) -> dict:
"""Helper function to provide the item codes and quantities in a dict of the form {<item_code>:<quantity>} for
Expand Down
15 changes: 14 additions & 1 deletion src/tlo/methods/healthsystem.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,12 @@ class HealthSystem(Module):
" When using 'all' or 'none', requests for consumables are not logged. NB. This parameter is over-ridden"
"if an argument is provided to the module initialiser."
"Note that other options are also available: see the `Consumables` class."),
'consumables_availability_time_trend': Parameter(
Types.BOOL, "Whether to incorporate the observed time-trend in availability of consumables."
),
'availability_estimates_time_trend': Parameter(
Types.DICT, "Dict of dataframes describing the trend over time in the availability of consumables."
),

# Infrastructure and Equipment
'BedCapacity': Parameter(
Expand Down Expand Up @@ -564,6 +570,11 @@ def read_parameters(self, data_folder):
).set_index('Item_Code')
self.parameters['availability_estimates'] = pd.read_csv(
path_to_resourcefiles_for_healthsystem / 'consumables' / 'ResourceFile_Consumables_availability_small.csv')
self.parameters['availability_estimates_time_trend'] = pd.read_excel(
path_to_resourcefiles_for_healthsystem / 'consumables' /
'ResourceFile_Consumables_availability_estimates_time_trend.xlsx',
sheet_name=None
)

# Data on the number of beds available of each type by facility_id
self.parameters['BedCapacity'] = pd.read_csv(
Expand Down Expand Up @@ -663,7 +674,9 @@ def pre_initialise_population(self):
self.parameters['availability_estimates']),
item_code_designations=self.parameters['consumables_item_designations'],
rng=rng_for_consumables,
availability=self.get_cons_availability()
availability=self.get_cons_availability(),
use_time_trend=self.parameters['consumables_availability_time_trend'],
time_trend_data=self.parameters['availability_estimates_time_trend']
)

# Determine equip_availability
Expand Down
Loading