[docs]classAgnTimeLagMetric(BaseMetric):def__init__(self,lag=100,z=1,log=False,threshold=2.2,calc_type="mean",mjd_col="observationStartMJD",filter_col="filter",m5_col="fiveSigmaDepth",dust=True,g_cutoff=22.0,r_cutoff=21.8,metric_name=None,**kwargs,):self.lag=lagself.z=zself.log=logself.threshold=thresholdself.calc_type=calc_typeself.mjd_col=mjd_colself.filter_col=filter_colself.m5_col=m5_colifmetric_nameisNone:metric_name=f"AGN_TimeLag_{lag}_days"self.dust=dustself.g_cutoff=g_cutoffself.r_cutoff=r_cutoffifdust:maps=["DustMap"]dust_properties=DustValues()self.ax1=dust_properties.ax1else:maps=[]super().__init__(col=[self.mjd_col,self.filter_col,self.m5_col],metric_name=metric_name,maps=maps,**kwargs,)# Calculate NQUIST value for time-lag and sampling time# (redshift is included in formula if desired)def_get_nquist_value(self,caden,lag,z):returnlag/((1+z)*caden)
[docs]defrun(self,data_slice,slice_point=None):# Dust extinctionfilterlist=np.unique(data_slice[self.filter_col])ifself.dust:m5=np.zeros(len(data_slice))forfilternameinfilterlist:in_filt=np.where(data_slice[self.filter_col]==filtername)[0]a_x=self.ax1[data_slice[self.filter_col][0]]*slice_point["ebv"]m5[in_filt]=data_slice[self.m5_col][in_filt]-a_xelse:m5=data_slice[self.m5_col]# Identify times which pass magnitude cuts (chosen by AGN contributors)mjds=np.zeros(len(data_slice))forfilternameinfilterlist:in_filt=np.where(data_slice[self.filter_col]==filtername)[0]iffilternamein("u","i","z","y","r","g"):mjds[in_filt]=data_slice[self.mjd_col][in_filt]eliffiltername=="g":faint=np.where(m5[in_filt]>self.g_cutoff)mjds[in_filt][faint]=data_slice[self.mjd_col][in_filt][faint]eliffiltername=="r":faint=np.where(m5[in_filt]>self.r_cutoff)mjds[in_filt][faint]=data_slice[self.mjd_col][in_filt][faint]# Remove the visits which were not faint enoughmjds=mjds[np.where(mjds>0)]# Calculate differences in time between visitsmv=np.sort(mjds)val=np.diff(mv)# If there was only one visit; bail out now.iflen(val)==0:returnself.badval# Otherwise summarize the time differences as:ifself.calc_type=="mean":val=np.mean(val)elifself.calc_type=="min":val=np.min(val)elifself.calc_type=="max":val=np.max(val)else:# find the greatest common divisorval=np.rint(val).astype(int)val=np.gcd.reduce(val)# Will always have a value at this pointnquist=self._get_nquist_value(val,self.lag,self.z)ifself.log:nquist=np.log(nquist)# Threshold nquist value is 2.2,# hence we are aiming to show values higher than threshold (2.2) valuethreshold=self.thresholdifself.log:threshold=np.log(threshold)ifnquist<threshold:nquist=self.badvalreturnnquist