Source code for laser_cholera.metapop.derivedvalues
importmatplotlib.pyplotaspltimportnumpyasnp
[docs]classDerivedValues:def__init__(self,model)->None:self.model=modelasserthasattr(model,"patches"),"DerivedValues: model needs to have a 'patches' attribute."asserthasattr(model,"params"),"DerivedValues: model needs to have a 'params' attribute."nPatches=len(model.params.location_name)model.patches.add_array_property("p_ijt",shape=(model.params.nticks,nPatches,nPatches),dtype=np.float32,default=0.0)model.patches.add_vector_property("spatial_hazard",length=model.params.nticks+1,dtype=np.float32,default=0.0)model.patches.add_vector_property("r_effective",length=model.params.nticks+1,dtype=np.float32,default=0.0)return
[docs]defcheck(self):asserthasattr(self.model,"agents"),"DerivedValues: model needs to have an 'agents' attribute."return
[docs]defplot(self,fig=None):# pragma: no cover_fig=plt.figure(figsize=(12,9),dpi=128,num="Spatial Hazard by Location Over Time")iffigisNoneelsefigplt.imshow(self.model.patches.spatial_hazard.T,aspect="auto",cmap="Reds",interpolation="nearest")plt.colorbar(label="Spatial Hazard")plt.xlabel("Time (Days)")plt.ylabel("Location")plt.yticks(ticks=np.arange(len(self.model.params.location_name)),labels=self.model.params.location_name)yield"Spatial Hazard by Location Over Time"return