[docs]classExposed:def__init__(self,model,verbose:bool=False):self.model=modelself.verbose=verboseasserthasattr(model,"agents"),"Exposed: model needs to have a 'agents' attribute."model.agents.add_vector_property("E",length=model.params.nticks+1,dtype=np.int32,default=0)asserthasattr(self.model,"params"),"Exposed: model needs to have a 'params' attribute."assert"E_j_initial"inself.model.params,"Exposed: model params needs to have a 'E_j_initial' parameter."model.agents.E[0]=model.params.E_j_initialreturn
[docs]defcheck(self):# Don't bother checking for model.params, we did that in __init__()assert"iota"inself.model.params,"Exposed: model params needs to have a 'iota' (progression rate) parameter."ifnothasattr(self.model.patches,"non_disease_deaths"):self.model.patches.add_vector_property("non_disease_deaths",length=self.model.params.nticks+1,dtype=np.int32,default=0)return
def__call__(self,model,tick:int)->None:E_next=model.agents.E[tick+1]E=model.agents.E[tick]E_next[:]=E# Do non-disease mortality firstnon_disease_deaths=model.prng.binomial(E,-np.expm1(-model.params.d_jt[tick])).astype(E_next.dtype)E_next-=non_disease_deathsndd_next=model.patches.non_disease_deaths[tick+1]ndd_next+=non_disease_deathsreturn
[docs]defplot(self,fig:Figure=None):# pragma: no cover_fig=plt.figure(figsize=(12,9),dpi=128,num="Exposed")iffigisNoneelsefigforipatchinnp.argsort(self.model.params.S_j_initial)[-10:]:plt.plot(self.model.agents.E[:,ipatch],label=f"{self.model.params.location_name[ipatch]}")plt.xlabel("Tick")plt.ylabel("Exposed")plt.legend()yield"Exposed"return