from emod_api import schema_to_class as s2c
from emod_api.interventions import common, utils
schema_path = None
iv_name = "MCV1"
#dupe_policy = "Replace" # or "Add" or "Abort" -- from covid branch
# Note that duration (what we call waning profile) needs to be configurable, but in an intuitive way
def _SimpleMCV( camp, timestep, coverage=1.0, age_at_vacc_in_days=1, mv_name=iv_name, nodes=None ):
"""
Create 'type 1' vaccine intervention campaign event at a specified time with a specified coverage
in the specified nodes.
Vaccine is distributed to infants 270 days after birth.
Args:
timestep: When? Timestep to distribute vaccine on.
coverage: Who? The percentage of the population in the nodes who should receive
the vaccine. Defaults to everyone if omitted.
age_at_vacc_in_days: Who/When? Delay period constant for intervention. This controls the age at which
people get the vaccnation.
mv_name: What? This doesn't matter unless you want to be able to give up multiple vaccines to individuals
but have them appear to be different, avoid de-duplication issues.
nodes: Where? The list of node ids where the vaccine should be distribution. Defaults to all if omitted.
Returns:
campaign event.
"""
# First, get the objects
event = s2c.get_class_with_defaults( "CampaignEvent", schema_path )
coordinator = s2c.get_class_with_defaults( "StandardEventCoordinator", schema_path )
if coordinator is None:
print( "s2c.get_class_with_defaults returned None. Maybe no schema.json was provided." )
return ""
intervention = s2c.get_class_with_defaults( "Vaccine", schema_path )
waning = utils.get_waning_from_params(schema_path, initial=0.999, box_duration=-1)
intervention.Acquire_Config = waning
event.Event_Coordinator_Config = coordinator
coordinator.Intervention_Config = common.NLHTI( camp, ['Births'], [ common.DelayedIntervention( camp, [ intervention ], { "Delay_Period_Constant": age_at_vacc_in_days } ) ], None, coverage )
event.Start_Day = float(timestep+1)
# Third, do the actual settings
intervention.Intervention_Name = mv_name
if nodes and len(nodes) > 0:
event.Nodeset_Config = utils.do_nodes( camp.schema_path, nodes )
event["Name"] = "MCV1" # ???
return event
[docs]def SimpleMCV1( camp, timestep, coverage=1.0, nodes=None ):
"""
Create 'type 1' vaccine intervention campaign event at a specified time with a specified coverage
in the specified nodes.
Vaccine is distributed to infants 270 days after birth.
Args:
timestep: When? Timestep to distribute vaccine on.
coverage: Who? The percentage of the population in the nodes who should receive the vaccine. Defaults to everyone if omitted.
nodes: Where? The list of node ids where the vaccine should be distribution. Defaults to all if omitted.
Returns:
campaign event.
"""
if camp is not None:
global schema_path
schema_path = camp.schema_path
return _SimpleMCV( camp, timestep, coverage, age_at_vacc_in_days=270, mv_name="MCV1", nodes=nodes )
[docs]def SimpleMCV2( camp, timestep, coverage=1.0, nodes=None):
"""
Create 'type 2' vaccine intervention campaign event at a specified time with a specified coverage
in the specified nodes.
Vaccine is distributed to infants 475 days after birth.
Args:
timestep: When? Timestep to distribute vaccine on.
coverage: Who? The percentage of the population in the nodes who should receive the vaccine. Defaults to everyone if omitted.
nodes: Where? The list of node ids where the vaccine should be distribution. Defaults to all if omitted.
Returns:
campaign event.
"""
if camp is not None:
global schema_path
schema_path = camp.schema_path
return _SimpleMCV( camp, timestep, coverage, age_at_vacc_in_days=475, mv_name="MCV2", nodes=nodes )
[docs]def SingleDoseRI( camp, RI_MCV1, dose_dist=None, nodes=None, waning=1.0, start_day=0, take_by_age_ages=None, take_by_age_values=None):
"""
Single dose measles vaccine with a dosing delay distribution and take by age.
Args:
camp (:py:obj:`emod_api.campaign`): The campaign instance
RI_MCV1 (float): Demographic coverage of routine immunization in the range [0,1]
dose_dist (:obj:`dict`, optional): Dose delay distribution. Defaults to ``{'Delay_Period_Distribution': "GAUSSIAN_DISTRIBUTION",
'Delay_Period_Gaussian_Mean': 300.0,
'Delay_Period_Gaussian_Std_Dev': 90.0}``)
nodes (list, optional): Node ids where the vaccine should be distribution. Defaults to all.
waning (float, optional): Constant rate of dose efficacy (See :doc:`WaningEffectConstant <emod-generic:parameter-campaign-waningeffects>`). Defaults to 1.0.
start_day (int, optional): Day to start the campaign. Defaults to 0.
take_by_age_ages (list, optional): List of ages in years for the vaccines take-by-age.
take_by_age_values (list, optional): List of take values for the vaccines take-by-age. Default is 0.85 < 9mo and 0.95 after.
Returns:
A :py:obj:`emod_api.schema_to_class.ReadOnlyDict` intervention
"""
# Routine immunization for MCV1
camp_event = s2c.get_class_with_defaults('CampaignEvent', schema_path)
camp_coord = s2c.get_class_with_defaults('StandardEventCoordinator', schema_path)
camp_iv01 = s2c.get_class_with_defaults('NodeLevelHealthTriggeredIV', schema_path)
camp_iv02 = s2c.get_class_with_defaults('DelayedIntervention', schema_path)
camp_iv03 = s2c.get_class_with_defaults('Vaccine', schema_path)
camp_event.Event_Coordinator_Config = camp_coord
camp_event.Start_Day = start_day
camp_coord.Intervention_Config = camp_iv01
camp_iv01.Actual_IndividualIntervention_Config = camp_iv02
camp_iv01.Demographic_Coverage = RI_MCV1
camp_iv01.Trigger_Condition_List = ['Births']
camp_iv02.Actual_IndividualIntervention_Configs = [camp_iv03]
if dose_dist is None:
# default dose distribution follows from 2013 DHS in Nigeria
camp_iv02.update({'Delay_Period_Distribution': "GAUSSIAN_DISTRIBUTION",
'Delay_Period_Gaussian_Mean': 300.0,
'Delay_Period_Gaussian_Std_Dev': 90.0})
else:
camp_iv02.update(dose_dist)
# no waning
camp_iv03.Acquire_Config = utils.get_waning_from_params(schema_path, initial=waning, box_duration=-1)
# take by age multiplier
if any( [ take_by_age_ages is None, take_by_age_values is None ] ) and any( [ take_by_age_ages is not None, take_by_age_values is not None ] ):
raise ValueError( f"Can't specify only one of take_by_age_ages and take_by_age_values." )
if take_by_age_ages is None and take_by_age_values is None:
camp_iv03.Take_By_Age_Multiplier.update({'Times': [0, 9*30, 9*30+1, 1000*365], "Values": [0.85, 0.85, 0.95, 0.95]})
else:
# convert ages from years to days.
take_by_age_ages_in_days = []
for age in take_by_age_ages:
take_by_age_ages_in_days.append( age*365 )
camp_iv03.Take_By_Age_Multiplier.Times = take_by_age_ages_in_days
camp_iv03.Take_By_Age_Multiplier.Values = take_by_age_values
# check that the schema was good
if camp_coord is None:
print( "s2c.get_class_with_defaults returned None. Maybe no schema.json was provided." )
return ""
# associate the nodes with the intervention
if nodes and len(nodes) > 0:
camp_event.Nodeset_Config = utils.do_nodes( camp.schema_path, nodes )
camp_event["Name"] = __name__
return camp_event
[docs]def new_intervention_as_file( camp, timestep, filename=None ):
"""
Create a new 'campaign.json'-type file with a single campaign event containing a Measles Vaccine intervention.
This is mostly a test or didactic capability.
Args:
timestep: When? Timestep to distribute vaccine on.
filename: The name of the file to write to disk. Defaults to "measles_vaccine.json".
Returns:
string with filename of newly created file.
"""
camp.add( _SimpleMCV( camp, timestep ) )
if filename is None:
filename = "measles_vaccine.json"
camp.save( filename )
return filename