Skip to content

Commit

Permalink
Updated testing date variables for better clarity.
Browse files Browse the repository at this point in the history
  • Loading branch information
pineapple-cat committed Jun 10, 2024
1 parent 964f2b4 commit 4d310ce
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 33 deletions.
12 changes: 7 additions & 5 deletions src/hivpy/data/hiv_testing.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# years during which HIV testing begins
date_start_anc_testing: 2003.5
date_start_testing: 2009
# year during which HIV testing begins
date_start_testing: 2003.5
# year after which rate of testing starts increasing
date_rate_testing_incr: 2009

# starting probability for first tests
init_rate_first_test: 0
Expand Down Expand Up @@ -35,10 +36,11 @@ test_targeting:
Value: [1, 1.25, 1.5]
Probability: [0.2, 0.6, 0.2]

# year during which testing probability plateaus
date_test_rate_plateau:
# years during which testing probability plateaus
date_general_testing_plateau:
Value: [2011.5, 2013.5, 2015.5, 2017.5, 2019.5]
Probability: [0.1, 0.1, 0.2, 0.3, 0.3]
date_specific_testing_plateau: 2015

# multiplier for testing probability
an_lin_incr_test:
Expand Down
25 changes: 12 additions & 13 deletions src/hivpy/hiv_testing.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,8 @@ def __init__(self, **kwargs):
with importlib.resources.path("hivpy.data", "hiv_testing.yaml") as data_path:
self.ht_data = HIVTestingData(data_path)

# FIXME: date_start_anc_testing currently unused, do we need this for anything?
self.date_start_anc_testing = self.ht_data.date_start_anc_testing
self.date_start_testing = self.ht_data.date_start_testing
self.date_rate_testing_incr = self.ht_data.date_rate_testing_incr
self.init_rate_first_test = self.ht_data.init_rate_first_test
self.eff_max_freq_testing = self.ht_data.eff_max_freq_testing
self.test_scenario = self.ht_data.test_scenario
Expand All @@ -33,7 +32,8 @@ def __init__(self, **kwargs):
self.prob_test_tb = self.ht_data.prob_test_tb
self.prob_test_non_tb_who3 = self.ht_data.prob_test_non_tb_who3
self.test_targeting = self.ht_data.test_targeting.sample()
self.date_test_rate_plateau = self.ht_data.date_test_rate_plateau.sample()
self.date_general_testing_plateau = self.ht_data.date_general_testing_plateau.sample()
self.date_specific_testing_plateau = self.ht_data.date_specific_testing_plateau
self.an_lin_incr_test = self.ht_data.an_lin_incr_test.sample()
self.incr_test_rate_sympt = self.ht_data.incr_test_rate_sympt.sample()

Expand Down Expand Up @@ -79,16 +79,16 @@ def test_mark_hiv_symptomatic(self, pop):
"""
Mark HIV symptomatic individuals to undergo testing this time step.
Note: If the simulation is started after 2015 (or if date_start_testing
is set to be after 2015) the HIV symptomatic testing probabilities
will not be updated and this function may not work as expected.
Note: If the simulation is started after date_specific_testing_plateau
(or if date_start_testing is set to be after date_specific_testing_plateau)
the HIV symptomatic testing probabilities will not be updated
and this function may not work as expected.
"""
# testing occurs after a certain year
if (pop.date.year >= self.date_start_testing):
if (pop.date.year > self.date_start_testing):

# update symptomatic test probabilities
# FIXME: where does this year come from? move to yaml later
if pop.date.year <= 2015:
if pop.date.year <= self.date_specific_testing_plateau:
self.prob_test_who4 = min(0.9, self.prob_test_who4 * self.incr_test_rate_sympt)
self.prob_test_tb = min(0.8, self.prob_test_tb * self.incr_test_rate_sympt)
self.prob_test_non_tb_who3 = min(0.7, self.prob_test_non_tb_who3 * self.incr_test_rate_sympt)
Expand Down Expand Up @@ -240,10 +240,9 @@ def test_mark_general_pop(self, pop):
self.test_mark_sex_workers(pop)

# update testing probabilities
self.rate_first_test = self.init_rate_first_test + (min(pop.date.year, self.date_test_rate_plateau)
- self.date_start_testing) * self.an_lin_incr_test
self.rate_rep_test = (min(pop.date.year, self.date_test_rate_plateau)
- self.date_start_testing) * self.an_lin_incr_test
self.rate_rep_test = (min(pop.date.year, self.date_general_testing_plateau)
- self.date_rate_testing_incr) * self.an_lin_incr_test
self.rate_first_test = self.init_rate_first_test + self.rate_rep_test

# general population ready for testing
testing_population = pop.get_sub_pop(AND(COND(col.HARD_REACH, op.eq, False),
Expand Down
5 changes: 3 additions & 2 deletions src/hivpy/hiv_testing_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ def __init__(self, filename):
super().__init__(filename)

try:
self.date_start_anc_testing = self.data["date_start_anc_testing"]
self.date_start_testing = self.data["date_start_testing"]
self.date_rate_testing_incr = self.data["date_rate_testing_incr"]
self.init_rate_first_test = self.data["init_rate_first_test"]
self.eff_max_freq_testing = self.data["eff_max_freq_testing"]
self.test_scenario = self.data["test_scenario"]
Expand All @@ -29,7 +29,8 @@ def __init__(self, filename):
self.prob_test_tb = self.data["prob_test_tb"]
self.prob_test_non_tb_who3 = self.data["prob_test_non_tb_who3"]
self.test_targeting = self._get_discrete_dist("test_targeting")
self.date_test_rate_plateau = self._get_discrete_dist("date_test_rate_plateau")
self.date_general_testing_plateau = self._get_discrete_dist("date_general_testing_plateau")
self.date_specific_testing_plateau = self.data["date_specific_testing_plateau"]
self.an_lin_incr_test = self._get_discrete_dist("an_lin_incr_test")
self.incr_test_rate_sympt = self._get_discrete_dist("incr_test_rate_sympt")

Expand Down
1 change: 1 addition & 0 deletions src/hivpy/pregnancy.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ def update_antenatal_care(self, pop: Population):
# get population that became pregnant this time step
pregnant_population = pop.get_sub_pop([(col.PREGNANT, op.eq, True),
(col.LAST_PREGNANCY_DATE, op.eq, pop.date)])
# FIXME: should be affected by date_start_testing and date_specific_testing_plateau
# update probability of antenatal care attendance
self.prob_anc = min(max(self.prob_anc, 0.1) + self.rate_test_anc_inc, 0.975)

Expand Down
34 changes: 21 additions & 13 deletions src/tests/test_hiv_testing.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ def test_hiv_symptomatic_testing():
pop.data[col.LAST_TEST_DATE] = None
pop.data[pop.get_correct_column(col.ADC, dt=1)] = True
# fixing some values
pop.hiv_testing.date_start_testing = 2009
pop.hiv_testing.date_start_testing = 2003.5
pop.hiv_testing.date_rate_testing_incr = 2009
pop.hiv_testing.prob_test_who4 = 0.6
pop.hiv_testing.prob_test_tb = 0.5
pop.hiv_testing.prob_test_non_tb_who3 = 0.4
Expand Down Expand Up @@ -100,7 +101,8 @@ def test_non_hiv_symptomatic_testing():
pop.data[col.LAST_TEST_DATE] = None
pop.data[pop.get_correct_column(col.HIV_DIAGNOSED, dt=1)] = False
# fixing some values
pop.hiv_testing.date_start_testing = 2009
pop.hiv_testing.date_start_testing = 2003.5
pop.hiv_testing.date_rate_testing_incr = 2009
pop.hiv_testing.prob_test_non_hiv_symptoms = 1
pop.hiv_testing.prob_test_who4 = 0.6
pop.hiv_testing.prob_test_non_tb_who3 = 0.4
Expand Down Expand Up @@ -132,7 +134,8 @@ def test_general_sex_worker_testing():
pop.data[col.HIV_DIAGNOSED] = False
pop.data[col.LAST_TEST_DATE] = start_date - timedelta(days=150)
# fixing some values
pop.hiv_testing.date_start_testing = 2009
pop.hiv_testing.date_start_testing = 2003.5
pop.hiv_testing.date_rate_testing_incr = 2009
pop.hiv_testing.eff_max_freq_testing = 0
pop.hiv_testing.sw_test_regularly = True
pop.hiv_testing.covid_disrup_affected = False
Expand Down Expand Up @@ -167,9 +170,10 @@ def test_general_testing_conditions():
pop.data[col.LAST_TEST_DATE] = date(2008, 1, 1)
pop.data[col.NP_LAST_TEST] = 1
# fixing some values
pop.hiv_testing.date_start_testing = 2009
pop.hiv_testing.date_start_testing = 2003.5
pop.hiv_testing.date_rate_testing_incr = 2009
pop.hiv_testing.eff_max_freq_testing = 1
pop.hiv_testing.date_test_rate_plateau = 2015.5
pop.hiv_testing.date_general_testing_plateau = 2015.5
pop.hiv_testing.an_lin_incr_test = 0.8
pop.hiv_testing.no_test_if_np0 = False
pop.hiv_testing.sw_test_regularly = False
Expand Down Expand Up @@ -211,9 +215,10 @@ def test_first_time_testers():
pop.data[col.CIRCUMCISED] = False
pop.data[col.CIRCUMCISION_DATE] = None
# fixing some values
pop.hiv_testing.date_start_testing = 2009
pop.hiv_testing.date_start_testing = 2003.5
pop.hiv_testing.date_rate_testing_incr = 2009
pop.hiv_testing.init_rate_first_test = 0.1
pop.hiv_testing.date_test_rate_plateau = 2015.5
pop.hiv_testing.date_general_testing_plateau = 2015.5
pop.hiv_testing.an_lin_incr_test = 0.8
pop.hiv_testing.no_test_if_np0 = False
pop.hiv_testing.sw_test_regularly = False
Expand Down Expand Up @@ -245,9 +250,10 @@ def test_repeat_testers():
pop.data[col.CIRCUMCISED] = False
pop.data[col.CIRCUMCISION_DATE] = None
# fixing some values
pop.hiv_testing.date_start_testing = 2009
pop.hiv_testing.date_start_testing = 2003.5
pop.hiv_testing.date_rate_testing_incr = 2009
pop.hiv_testing.eff_max_freq_testing = 1
pop.hiv_testing.date_test_rate_plateau = 2015.5
pop.hiv_testing.date_general_testing_plateau = 2015.5
pop.hiv_testing.an_lin_incr_test = 0.8
pop.hiv_testing.no_test_if_np0 = False
pop.hiv_testing.sw_test_regularly = False
Expand Down Expand Up @@ -282,10 +288,11 @@ def test_partner_reset_after_test():
pop.data[col.NP_LAST_TEST] = 2
pop.data[col.NSTP_LAST_TEST] = 1
# fixing some values
pop.hiv_testing.date_start_testing = 2009
pop.hiv_testing.date_start_testing = 2003.5
pop.hiv_testing.date_rate_testing_incr = 2009
pop.hiv_testing.eff_max_freq_testing = 1
pop.hiv_testing.init_rate_first_test = 0.1
pop.hiv_testing.date_test_rate_plateau = 2015.5
pop.hiv_testing.date_general_testing_plateau = 2015.5
pop.hiv_testing.an_lin_incr_test = 0.8
pop.hiv_testing.no_test_if_np0 = False
pop.hiv_testing.sw_test_regularly = False
Expand Down Expand Up @@ -319,9 +326,10 @@ def test_max_frequency_testing():
pop.data[col.NP_LAST_TEST] = 1
pop.data[col.NSTP_LAST_TEST] = 1
# fixing some values
pop.hiv_testing.date_start_testing = 2009
pop.hiv_testing.date_start_testing = 2003.5
pop.hiv_testing.date_rate_testing_incr = 2009
pop.hiv_testing.eff_max_freq_testing = index
pop.hiv_testing.date_test_rate_plateau = 2015.5
pop.hiv_testing.date_general_testing_plateau = 2015.5
# guaranteed testing
pop.hiv_testing.an_lin_incr_test = 1
pop.hiv_testing.no_test_if_np0 = False
Expand Down

0 comments on commit 4d310ce

Please sign in to comment.