[docs]classSusceptible(Component):def__init__(self,model):self.model=modelasserthasattr(model,"agents"),"Susceptible: model needs to have an 'agents' attribute."model.agents.add_vector_property("S",length=model.params.nticks+1,dtype=np.int32,default=0)asserthasattr(model,"patches"),"Susceptible: model needs to have a 'patches' attribute."model.patches.add_vector_property("births",length=model.params.nticks+1,dtype=np.int32,default=0)asserthasattr(self.model,"params"),"Susceptible: model needs to have a 'params' attribute."assert"S_j_initial"inself.model.params,"Susceptible: model params needs to have a 'S_j_initial' parameter."model.agents.S[0]=model.params.S_j_initialreturn
[docs]defcheck(self):asserthasattr(self.model.patches,"N"),"Susceptible: model.patches needs to have a 'N' attribute."asserthasattr(self.model.params,"b_jt"),"Susceptible: model.params needs to have a 'b_jt' attribute."asserthasattr(self.model.params,"d_jt"),"Susceptible: model.params needs to have a 'd_jt' attribute."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
[docs]defplot(self,fig:Figure=None):# pragma: no cover_fig=plt.figure(figsize=(12,9),dpi=128,num="Susceptible")iffigisNoneelsefigforipatchinnp.argsort(self.model.params.S_j_initial)[-10:]:plt.plot(self.model.agents.S[:,ipatch],label=f"{self.model.params.location_name[ipatch]}")plt.xlabel("Tick")plt.ylabel("Susceptible")plt.legend()yield"Susceptible"return