Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
efc41c0
Updating vax branch to include Immunization History class.
Oct 31, 2022
d9e4fe0
Merge branch 'master' of https://github.com/iirinaab/cv19 into vax
Oct 31, 2022
4c53d09
Added comments throughout vaccine class changes.
Nov 1, 2022
3eff0a5
Change how visitors' vaccine objects are initialized.
Nov 1, 2022
7e80eed
Add class docstring for Immunization history and fix initialization o…
Nov 1, 2022
5e62795
Pull request issue fixes.
Nov 1, 2022
4b199cc
Small fix
Nov 1, 2022
274bb08
Amend test files to include new config files so that the code actuall…
Nov 1, 2022
47a31f3
Fix simulation unit test issue
Nov 1, 2022
659bbf6
More unit test issues ...
Nov 1, 2022
2a8dfaa
amending pr due to feedback, small syntax and organization changes
Jan 23, 2023
28865db
Merge branch 'master' into vax
iirinaab Jan 23, 2023
cf4a78a
updating immunization history class
Jan 30, 2023
d149712
updating vaccine code
Jan 31, 2023
79244fc
Merge branch 'GePPCLab:master' into vax
iirinaab Jan 31, 2023
4feebc6
Merge branch 'master' of https://github.com/iirinaab/cv19 into vax
Jan 31, 2023
8c9b654
Merge branch 'GePPCLab:master' into master
iirinaab Feb 2, 2023
894165a
amending immunization history class again, based on github errors
Feb 13, 2023
bd217f9
Merge branch 'master' of https://github.com/iirinaab/cv19 into vax
Feb 13, 2023
d56b428
Merge branch 'master' into vax
iirinaab Feb 13, 2023
025ba08
Merge branch 'master' of https://github.com/iirinaab/cv19 into vax
Feb 13, 2023
9ecc180
Merge branch 'vax' of https://github.com/iirinaab/cv19 into vax
Feb 13, 2023
42d3695
fix error from merge
Feb 14, 2023
da8b69f
Merge branch 'Queens-Physics:main' into vax
iirinaab Mar 27, 2023
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
19 changes: 19 additions & 0 deletions config_files/immunization_history.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
[vaccine_max_efficacy]
Pfizer = 0.913
Moderna = 0.941
AZ = 0.76

[vaccine_immunity_buildup_days]
Pfizer = 14
Moderna = 14
AZ = 14

[vaccine_efficacy_min_day]
Pfizer = 180
Moderna = 180
AZ = 180

[long_term_vaccine_eff]
Pfizer = 0.7
Moderna = 0.7
AZ = 0.7
22 changes: 13 additions & 9 deletions config_files/main.toml
Original file line number Diff line number Diff line change
@@ -1,20 +1,29 @@
[simulation_data]
disease_config_file = "disease.toml"
immunization_history_config_file = "immunization_history.toml"
nDays = 50
nPop = 10000
vis_default_virus_type = "alpha"
vis_default_severity = "MILD"
student_default_virus_type = "alpha"
num_students = 2000
max_num_res_students = 500
v0 = 0
N_VIS_OPTION = [0, 1, 2, 3]
N_VIS_PROB = [0.7, 0.17, 0.08, 0.05]
vis_age_upper = 60
vis_age_lower = 16
inf_students_upper = 20
inf_students_lower = 2
num_vaccinations = 0
inf_students_upper = 2
inf_students_lower = 0
num_vaccinations = 100
[simulation_data.v0_parameters]
v0 = 1000
v0_interval_start_day = -30
v0_interval_end_day = 0

[simulation_data.vaccine_type]
Pfizer = 0.6
Moderna = 0.35
AZ = 0.05

[simulation_data.variants]
general = 10
Expand All @@ -35,11 +44,6 @@ num_vaccinations = 0
FOOD = 0.1
RES = 1

[simulation_data.vaccine_type]
Pfizer = 0.6
Moderna = 0.35
AZ = 0.05

[policy_data]
initial_mask_mandate = true
mask_trigger = 0.3
Expand Down
86 changes: 86 additions & 0 deletions cv19/immunization_history.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
class ImmunizationHistory:
"""
A class designed to keep track of a Person's vaccination history and vaccination parameters.

Holds the parameters from immunization_history.toml corresponding to the Person's vaccine type,
as well as the attributes listed below.

Attributes
----------
vaccinated: :obj:`bool`
A variable indicating whether or not the person is vaccinated.
list_of_vaccination_dates: :obj:`list` of int
A list of a Person's vaccination dates (corresponding to day in simulation).
"""

def __init__(self, vaccine_type=None, vaccine_max_efficacy=None, vaccine_immunity_buildup_days=None, long_term_vaccine_eff=None, vaccine_efficacy_min_day=None):
"""
The constructor for the Immunization History class.
"""

self.vaccinated = False
self.list_of_vaccination_dates = list()
self.vaccine_type = vaccine_type
self.vaccine_max_efficacy = vaccine_max_efficacy
self.vaccine_immunity_buildup_days = vaccine_immunity_buildup_days
self.long_term_vaccine_eff = long_term_vaccine_eff
self.vaccine_efficacy_min_day = vaccine_efficacy_min_day

def is_vaccinated(self):
"""Method to retrieve if a person is vaccinated. Returns True if vaccinated, False if not.

Returns
-------
self.vaccinated: :obj:`bool`
"""
return self.vaccinated

def set_vaccinated(self, day):
"""Method to set a person to be vaccinated.

Parameters
----------
day: int
The day in the simulation when a person is vaccinated.

Returns
-------
self.vaccinated: :obj:`bool`
"""

self.vaccinated_day = day
self.list_of_vaccination_dates.append(self.vaccinated_day)
self.vaccinated = True

def vaccine_efficacy(self, day):
"""Method to determine what the efficiency of the vaccine based on the type of vaccine administered,
and other immunization history parameters.

Parameters
----------
day: int
The day in the simulation when a person is vaccinated.

Returns
-------
self.current_vaccine_eff: :obj:`float`
"""

if self.vaccinated:

days_since_vaccination = day - self.list_of_vaccination_dates[-1]
if days_since_vaccination == 0:
self.current_vaccine_eff = 0
elif days_since_vaccination <= self.vaccine_immunity_buildup_days: # linear increase of immunity
self.current_vaccine_eff = ((self.vaccine_max_efficacy) / (self.vaccine_immunity_buildup_days)) * days_since_vaccination
elif (days_since_vaccination > self.vaccine_immunity_buildup_days) and (days_since_vaccination < self.vaccine_efficacy_min_day): # calculate linearly decreasing immunity
self.current_vaccine_eff = (-(self.vaccine_max_efficacy - self.long_term_vaccine_eff) / (self.vaccine_efficacy_min_day - self.vaccine_immunity_buildup_days)) # slope calculation
self.current_vaccine_eff *= days_since_vaccination # scale by days since vaccination
self.current_vaccine_eff += self.vaccine_max_efficacy # add initial value (which is the max efficacy)
else: # plateau in immunity after and including min_day
self.current_vaccine_eff = self.long_term_vaccine_eff

return self.current_vaccine_eff

else:
return 0
23 changes: 10 additions & 13 deletions cv19/interaction_sites.py
Original file line number Diff line number Diff line change
Expand Up @@ -466,7 +466,7 @@ def site_interaction(self, will_go_array, day, personal, grade_code):

if person_1_infected != person_2_infected:
# Have an interaction between those people
did_infect = self.interact(p1_obj, p2_obj)
did_infect = self.interact(p1_obj, p2_obj, day=day)
if did_infect:
if person_1_infected:
new_infections[person_2_index] = True
Expand Down Expand Up @@ -525,15 +525,17 @@ def calc_interactions(self, site_day_pop):

return number_of_interactions

def interact(self, person_1, person_2):
"""Method that models the interaction between two people.

def interact(self, person_1, person_2, day):
"""
Method that models the interaction between two people.
Parameters
----------
person_1 : :obj:`cv19.person.Person`
First person in the two-way interaction.
person_2 : :obj:`cv19.person.Person`
Second person in the two-way interaction.
day : int
The day value that this function is being called on in the encompassing simulation class. Used to determine vaccine efficacy of interacting individuals.

Returns
-------
Expand Down Expand Up @@ -566,11 +568,8 @@ def interact(self, person_1, person_2):
if p2_mask:
spread_prob *= (1 - P2_OUTWARD_EFF)

p1_vaccinated1 = person_1.is_vaccinated()
p2_vaccinated1 = person_2.is_vaccinated()

p1_vaccine_eff = person_1.vaccine_type_efficiency() if p1_vaccinated1 else 0
p2_vaccine_eff = person_2.vaccine_type_efficiency() if p2_vaccinated1 else 0
p1_vaccine_eff = person_1.immunization_history_obj.vaccine_efficacy(day)
p2_vaccine_eff = person_2.immunization_history_obj.vaccine_efficacy(day)

spread_prob *= ((1 - p1_vaccine_eff) * (1 - p2_vaccine_eff))

Expand Down Expand Up @@ -615,8 +614,7 @@ def house_interact(self, day):
virus_name = self.variant_code_map[virus_id]

infection_chance = self.base_infection_spread_prob[virus_name] * self.house_infection_spread_factor
person_vaccinated = housemembers[person].is_vaccinated()
person_vaccine_eff = housemembers[person].vaccine_type_efficiency() if person_vaccinated else 0
person_vaccine_eff = housemembers[person].immunization_history_obj.vaccine_efficacy(day)
infection_chance *= (1 - person_vaccine_eff)
caught_infection = random() < infection_chance

Expand Down Expand Up @@ -667,8 +665,7 @@ def student_house_interact(self, day):
virus_name = self.variant_code_map[virus_id]

infection_chance = self.base_infection_spread_prob[virus_name] * self.house_infection_spread_factor
person_vaccinated = housemembers[person].is_vaccinated()
person_vaccine_eff = housemembers[person].vaccine_type_efficiency() if person_vaccinated else 0
person_vaccine_eff = housemembers[person].immunization_history_obj.vaccine_efficacy(day)
infection_chance *= (1 - person_vaccine_eff)
caught_infection = random() < infection_chance
if caught_infection:
Expand Down
62 changes: 9 additions & 53 deletions cv19/person.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from random import random

import numpy as np
from .immunization_history import ImmunizationHistory


class Person(object):
Expand All @@ -17,11 +18,11 @@ class Person(object):

"""

def __init__(self, index, sim_obj, infected=False, recovered=False, dead=False, hospitalized=False, ICU=False,
quarantined=False, quarantined_day=None, infected_day=None, recovered_day=None, death_day=None,
others_infected=None, cure_days=None, recent_infections=None, vaccinated=False, vaccine_type=None,
def __init__(self, index, sim_obj, infected=False, recovered=False, dead=False, hospitalized=False, ICU=False, quarantined=False,
quarantined_day=None, infected_day=None, recovered_day=None, death_day=None, others_infected=None,
cure_days=None, recent_infections=None, vaccine_info=None,
age=None, job=None, house_index=0, isolation_tendencies=None, case_severity=None, mask_type=None,
has_mask=True, virus_type=None, days_until_symptoms=None):
has_mask=True, virus_type=None):
"""Method to load in attributes from the provided simulation class object.

Sets all objects in the "person_data" dictionary key as self attributes of the
Expand All @@ -45,10 +46,8 @@ def __init__(self, index, sim_obj, infected=False, recovered=False, dead=False,
Determines if person is quarentined or not, defaults False.
quarantined_day : int
The day a person is put into quarantine, defaults None.
vaccinated : bool
Determines if a person is vaccinated or not, defaults to True.
vaccine_type : string
Determines type of vaccine received by person, defaults to None.
vaccine_info : dict
Dictionary containing vaccine parameters, defaults None.
infected_day : int
The day a person is infected, defaults None.
recovered_day : int
Expand Down Expand Up @@ -90,8 +89,7 @@ def __init__(self, index, sim_obj, infected=False, recovered=False, dead=False,
self.others_infected = [] if others_infected is None else others_infected
self.cure_days = cure_days
self.recent_infections = recent_infections
self.vaccinated = vaccinated
self.vaccine_type = vaccine_type
self.immunization_history_obj = ImmunizationHistory(**vaccine_info) if vaccine_info is not None else ImmunizationHistory()
self.index = index
self.age = age
self.job = job
Expand All @@ -100,7 +98,7 @@ def __init__(self, index, sim_obj, infected=False, recovered=False, dead=False,
self.case_severity = case_severity
self.mask_type = mask_type
self.show_symptoms = False
self.days_until_symptoms = days_until_symptoms
self.days_until_symptoms = None
self.knows_infected = False
self.will_get_symptoms = False
self.has_mask = has_mask
Expand Down Expand Up @@ -769,45 +767,3 @@ def update_lockdown_days(self, lockdown_level):
elif self.days_in_lockdown != 0:
self.days_in_lockdown -= 1
return self.days_in_lockdown

def is_vaccinated(self):
"""Method to retrieve if a person is vaccinated. Returns True if vaccinated, False if not.

Returns
-------
self.vaccinated: :obj:`bool`
"""
return self.vaccinated

def set_vaccinated(self, day):
"""Method to set a person to be vaccinated.

Parameters
----------
day: int
The day in the simulation when a person is vaccinated.

Returns
-------
self.vaccinated: :obj:`bool`
"""
# Make sure person is not already vaccinated.
if not self.is_vaccinated():
self.vaccinated_day = day
self.vaccinated = True

def vaccine_type_efficiency(self):
"""Method to determines what the efficiency of the vaccine based on the type of vaccine administered.

Returns
-------
self.sim_obj.vaccine_eff[self.vaccine_type]: :obj:`float`
"""
if self.vaccinated:
try:
return self.sim_obj.vaccine_eff[self.vaccine_type]
except KeyError as e:
raise ValueError((f"'{self.vaccine_type}' is not a valid vaccine type "
"and has no associated efficiency.")) from e
else:
return 1
Loading