[docs]defnew_intervention(camp,new_infectivity=1.0,profile="CONST",**kwargs):""" Create new NodeInfectivityModifying intervention. Args: profile: multiplier options include: - CONST(ANT) - new_infectivity lasts forever (or until replaced). - TRAP(EZOID) - rise_dur(ation) - peak_dur(ation) - fall_dur(ation) - EXP(ONENTIAL) (not implemented yet) - rise duration - rise rate - SIN(USOIDAL) (not implemented yet) - period To do boxcar, specify 0 rise and fall durations (or omit). To do sawtooth, specify 0 peak duration (or omit). Returns: new NodeInfectivityMult intervention dictionary. """intervention=s2c.get_class_with_defaults("NodeInfectivityMult",camp.schema_path)ifprofile.startswith("CONST"):intervention.Multiplier_By_Duration.Times=[0,365000]# I'm preferring 1000 years to FLT_MAXintervention.Multiplier_By_Duration.Values=[new_infectivity,new_infectivity]elifprofile.startswith("TRAP"):rise_dur=0if"rise_dur"inkwargs:rise_dur=float(kwargs["rise_dur"])peak_dur=0if"peak_dur"inkwargs:peak_dur=float(kwargs["peak_dur"])fall_dur=0if"fall_dur"inkwargs:fall_dur=float(kwargs["fall_dur"])total_durs=rise_dur+peak_dur+fall_duriftotal_durs==0:raiseValueError("Didn't find any durations.")eliftotal_durs>365:raiseValueError("Total of durations needs to be less than a year.")rise_dur=max(rise_dur,1)peak_dur=max(peak_dur,1)fall_dur=max(fall_dur,1)total_durs=rise_dur+peak_dur+fall_durintervention.Multiplier_By_Duration.Times=[0,rise_dur,rise_dur+peak_dur,rise_dur+peak_dur+fall_dur]intervention.Multiplier_By_Duration.Values=[1.0,new_infectivity,new_infectivity,1.0]else:raiseValueError(f"profile {profile} not supported at this time. Valid profiles are: 'CONST', 'TRAP'.")returnintervention
[docs]defnew_scheduled_event(camp,start_day=1,new_infectivity=1.0,profile="CONST",node_ids=None,recurring=True,**kwargs):""" Create new NodeInfectivityModifying intervention as scheduled campaign event. """#new_iv = new_intervention( camp=camp, new_infectivity=new_infectivity, profile=profile, kwargs=**kwargs )new_iv=new_intervention(camp,new_infectivity,profile,**kwargs)coordinator=s2c.get_class_with_defaults("StandardEventCoordinator",camp.schema_path)coordinator.Intervention_Config=new_ivifrecurring==False:coordinator.Number_Repetitions=1else:coordinator.Number_Repetitions=-1coordinator.Timesteps_Between_Repetitions=365event=s2c.get_class_with_defaults("CampaignEvent",camp.schema_path)event.Nodeset_Config=utils.do_nodes(camp.schema_path,node_ids)event.Event_Coordinator_Config=coordinatorevent.Start_Day=start_dayreturnevent
[docs]defnew_intervention_as_file(camp,timestep,filename=None):""" Create new NodeInfectivityModifying intervention as sole scheduled campaign event inside working campaign json file. """camp.add(new_scheduled_event(camp,profile="CONSTANT",start_day=timestep,node_ids=[]))iffilenameisNone:filename="node_infectivity.json"camp.save(filename)returnfilename