Source code for emodpy_measles.interventions.simple_sia
from emod_api import schema_to_class as s2c
from emod_api.interventions import utils
schema_path = None
cases = -1
[docs]def SimpleSIA(camp, Event_Name = "SIA", timestep=1, Target_Age_Min=0.75, Target_Age_Max=5.0, Coverage=1.0, nodes = None ):
"""
Create and return a vaccine campaign event.
Args:
timestep: When? Timestep at which vaccine event occurs. Defaults to 1.
Target_Age_Min: Who (youngest)? Youngest age to distribute vaccine to (defaults to 9 months).
Target_Age_Max: Who (oldest)? Oldest age to distribute vaccine to (defaults to 5yo).
Coverage: Who (%age)? Percentage of population, in given age ranges, to get vaccine. Defaults to all.
nodes: Where? Node ids where vaccine should be distributed. Defaults to everywhere.
Returns:
New campaign event which can be added to campaign accumulator.
"""
global schema_path
if camp is not None:
schema_path = camp.schema_path
event = s2c.get_class_with_defaults( "CampaignEvent", schema_path )
coordinator = s2c.get_class_with_defaults( "StandardInterventionDistributionEventCoordinator", schema_path )
if coordinator is None:
print( "s2c.get_class_with_defaults returned None. Maybe no schema.json was provided." )
return ""
try:
coordinator.Max_Distributions_Per_Node = cases
except Exception as ex:
# This can be fine because this is a new parameter only in some branches.
# Obviously this question is more general and needs a better general solution
# if at all possible. Max_Distributions_Per_Node is an event coordinator optional param.
print( str( ex ) )
#coordinator.Target_Demographic = "ExplicitAgeRanges" # implicit
coordinator.Target_Age_Max=Target_Age_Max
coordinator.Target_Age_Min=Target_Age_Min
event.Event_Coordinator_Config = coordinator
# The intervention itself should be reused from another module
# intervention = emodpy-measles.interventions.standard_measles_vaccine
intervention = s2c.get_class_with_defaults( "Vaccine", schema_path )
intervention.Acquire_Config = utils.get_waning_from_params(schema_path, initial=0.999, box_duration=-1)
coordinator.Intervention_Config = intervention
event.Start_Day = float(timestep+1)
if nodes and len(nodes) > 0:
event.Nodeset_Config = utils.do_nodes( camp.schema_path, nodes )
event["Event_Name"] = Event_Name
return 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 SimpleSIA style
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 "sia.json".
Returns:
string with filename of newly created file.
"""
camp.add( SimpleSIA( camp, timestep ) )
if filename is None:
filename = "sia.json"
camp.save( filename )
return filename