def getDMcurve( M): # return the normalized DM curve downsampled to M points feature = '%s:%s' % ('DMbins', M) if M == 0: return np.array([]) if not feature in self.extracted_feature: ddm = (self.dms.max() - self.dms.min()) / 2. loDM, hiDM = (self.bestdm - ddm, self.bestdm + ddm) loDM = max((0, loDM)) #make sure cut off at 0 DM hiDM = max((ddm, hiDM)) #make sure cut off at 0 DM N = 100 interp = False sumprofs = self.profs.sum(0) if not interp: profs = sumprofs else: profs = np.zeros(np.shape(sumprofs), dtype='d') DMs = psr_utils.span(loDM, hiDM, N) chis = np.zeros(N, dtype='f') subdelays_bins = self.subdelays_bins.copy() for ii, DM in enumerate(DMs): subdelays = psr_utils.delay_from_DM(DM, self.barysubfreqs) hifreqdelay = subdelays[-1] subdelays = subdelays - hifreqdelay delaybins = subdelays * self.binspersec - subdelays_bins if interp: interp_factor = 16 for jj in range(self.nsub): profs[jj] = psr_utils.interp_rotate( sumprofs[jj], delaybins[jj], zoomfact=interp_factor) # Note: Since the interpolation process slightly changes the values of the # profs, we need to re-calculate the average profile value avgprof = (profs / self.proflen).sum() else: new_subdelays_bins = np.floor(delaybins + 0.5) for jj in range(self.nsub): #profs[jj] = psr_utils.rotate(profs[jj], new_subdelays_bins[jj]) delay_bins = int(new_subdelays_bins[jj] % len(profs[jj])) if not delay_bins == 0: profs[jj] = np.concatenate( (profs[jj][delay_bins:], profs[jj][:delay_bins])) subdelays_bins += new_subdelays_bins avgprof = self.avgprof sumprof = profs.sum(0) chis[ii] = self.calc_redchi2(prof=sumprof, avg=avgprof) DMcurve = normalize(downsample(chis, M)) self.extracted_feature[feature] = DMcurve return self.extracted_feature[feature]
def getDMcurve(M): # return the normalized DM curve downsampled to M points feature = '%s:%s' % ('DMbins', M) if M == 0: return np.array([]) if not feature in self.extracted_feature: ddm = (self.dms.max() - self.dms.min())/2. loDM, hiDM = (self.bestdm - ddm , self.bestdm + ddm) loDM = max((0, loDM)) #make sure cut off at 0 DM hiDM = max((ddm, hiDM)) #make sure cut off at 0 DM N = 100 interp = False sumprofs = self.profs.sum(0) if not interp: profs = sumprofs else: profs = np.zeros(np.shape(sumprofs), dtype='d') DMs = psr_utils.span(loDM, hiDM, N) chis = np.zeros(N, dtype='f') subdelays_bins = self.subdelays_bins.copy() for ii, DM in enumerate(DMs): subdelays = psr_utils.delay_from_DM(DM, self.barysubfreqs) hifreqdelay = subdelays[-1] subdelays = subdelays - hifreqdelay delaybins = subdelays*self.binspersec - subdelays_bins if interp: interp_factor = 16 for jj in range(self.nsub): profs[jj] = psr_utils.interp_rotate(sumprofs[jj], delaybins[jj], zoomfact=interp_factor) # Note: Since the interpolation process slightly changes the values of the # profs, we need to re-calculate the average profile value avgprof = (profs/self.proflen).sum() else: new_subdelays_bins = np.floor(delaybins+0.5) for jj in range(self.nsub): #profs[jj] = psr_utils.rotate(profs[jj], new_subdelays_bins[jj]) delay_bins = int(new_subdelays_bins[jj] % len(profs[jj])) if not delay_bins==0: profs[jj] = np.concatenate((profs[jj][delay_bins:], profs[jj][:delay_bins])) subdelays_bins += new_subdelays_bins avgprof = self.avgprof sumprof = profs.sum(0) chis[ii] = self.calc_redchi2(prof=sumprof, avg=avgprof) DMcurve = normalize(downsample(chis, M)) self.extracted_feature[feature] = DMcurve return self.extracted_feature[feature]
def plot_chi2_vs_DM(self, loDM, hiDM, N=100, interp=0, device='/xwin'): """ plot_chi2_vs_DM(self, loDM, hiDM, N=100, interp=0, device='/xwin'): Plot (and return) an array showing the reduced-chi^2 versus DM (N DMs spanning loDM-hiDM). Use sinc_interpolation if 'interp' is non-zero. """ # Sum the profiles in time sumprofs = self.profs.sum(0) if not interp: profs = sumprofs else: profs = Num.zeros(Num.shape(sumprofs), dtype='d') DMs = psr_utils.span(loDM, hiDM, N) chis = Num.zeros(N, dtype='f') subdelays_bins = self.subdelays_bins.copy() for ii, DM in enumerate(DMs): subdelays = psr_utils.delay_from_DM(DM, self.barysubfreqs) hifreqdelay = subdelays[-1] subdelays = subdelays - hifreqdelay delaybins = subdelays * self.binspersec - subdelays_bins if interp: interp_factor = 16 for jj in range(self.nsub): profs[jj] = psr_utils.interp_rotate(sumprofs[jj], delaybins[jj], zoomfact=interp_factor) # Note: Since the interpolation process slightly changes the values of the # profs, we need to re-calculate the average profile value avgprof = (profs / self.proflen).sum() else: new_subdelays_bins = Num.floor(delaybins + 0.5) for jj in range(self.nsub): profs[jj] = psr_utils.rotate(profs[jj], int(new_subdelays_bins[jj])) subdelays_bins += new_subdelays_bins avgprof = self.avgprof sumprof = profs.sum(0) chis[ii] = self.calc_redchi2(prof=sumprof, avg=avgprof) # Now plot it Pgplot.plotxy(chis, DMs, labx="DM", laby="Reduced-\gx\u2\d", device=device) return (chis, DMs)
def plot_chi2_vs_DM(self, loDM, hiDM, N=100, interp=0, device='/xwin'): """ plot_chi2_vs_DM(self, loDM, hiDM, N=100, interp=0, device='/xwin'): Plot (and return) an array showing the reduced-chi^2 versus DM (N DMs spanning loDM-hiDM). Use sinc_interpolation if 'interp' is non-zero. """ # Sum the profiles in time sumprofs = self.profs.sum(0) if not interp: profs = sumprofs else: profs = Num.zeros(Num.shape(sumprofs), dtype='d') DMs = psr_utils.span(loDM, hiDM, N) chis = Num.zeros(N, dtype='f') subdelays_bins = self.subdelays_bins.copy() for ii, DM in enumerate(DMs): subdelays = psr_utils.delay_from_DM(DM, self.barysubfreqs) hifreqdelay = subdelays[-1] subdelays = subdelays - hifreqdelay delaybins = subdelays*self.binspersec - subdelays_bins if interp: interp_factor = 16 for jj in range(self.nsub): profs[jj] = psr_utils.interp_rotate(sumprofs[jj], delaybins[jj], zoomfact=interp_factor) # Note: Since the interpolation process slightly changes the values of the # profs, we need to re-calculate the average profile value avgprof = (profs/self.proflen).sum() else: new_subdelays_bins = Num.floor(delaybins+0.5) for jj in range(self.nsub): profs[jj] = psr_utils.rotate(profs[jj], int(new_subdelays_bins[jj])) subdelays_bins += new_subdelays_bins avgprof = self.avgprof sumprof = profs.sum(0) chis[ii] = self.calc_redchi2(prof=sumprof, avg=avgprof) # Now plot it Pgplot.plotxy(chis, DMs, labx="DM", laby="Reduced-\gx\u2\d", device=device) return (chis, DMs)