#!/usr/bin/env python from __future__ import print_function import sys from presto import prepfold if len(sys.argv) == 1: sys.stderr.write("""usage: pfd_for_timing.py PFDFILES\n This script returns 'true' or 'false' if a .pfd file can be used for timing via get_TOAs.py or not.\n""") sys.exit(0) for pfdfile in sys.argv[1:]: try: pfd = prepfold.pfd(pfdfile) if pfd.use_for_timing(): print("%s: true" % pfdfile) else: print("%s: false" % pfdfile) except: sys.stderr.write("Error: Can't check '%s'\n" % pfdfile)
for subs in a.split(','): if (subs.find("-") > 0): lo, hi = subs.split("-") kill.extend(list(range(int(lo), int(hi)+1))) else: kill.append(int(subs)) if o in ("-i", "--kints"): for ints in a.split(','): if (ints.find("-") > 0): lo, hi = ints.split("-") kints.extend(list(range(int(lo), int(hi)+1))) else: kints.append(int(ints)) # Read the prepfold output file and the binary profiles fold_pfd = pfd(sys.argv[-1]) # Check to make sure we can use this .pfd for timing purposes if not fold_pfd.use_for_timing(): sys.stderr.write( "Error: '%s' was made allowing prepfold to search!\n" % \ sys.argv[-1]) sys.exit(2) # Read key information from the bestprof file if fold_pfd.bestprof: fold = fold_pfd.bestprof else: sys.stderr.write( "Error: Can't open '%s.bestrof'! Regenerate with show_pfd.\n" % \ sys.argv[-1])
def calc_features_from_pfd(pfd_filepath): pfd_data = prepfold.pfd(str(pfd_filepath)) if pfd_filepath.parent.name == 'positive': label = 1 elif pfd_filepath.parent.name == 'negative': label = 0 else: label = -1 # return (label, 0, 0, 0, 0, 0, 0, 0, 0, 0, # np.empty(shape=(0,)), np.empty(shape=(0,0)), # np.empty(shape=(0,0)), np.empty(shape=(0,))) pfd_data.dedisperse() #### As done in: prepfold.pfd.plot_sumprofs profile = pfd_data.sumprof profile = normalise_1d(profile) #### profiles_sum_axis0 = pfd_data.profs.sum(0) #### As done in: prepfold.pfd.plot_chi2_vs_DM loDM = 0 hiDM = pfd_data.numdms N = pfd_data.numdms profs = profiles_sum_axis0.copy() # = pfd_data.profs.sum(0) DMs = psr_utils.span(loDM, hiDM, N) chis = np.zeros(N, dtype='f') subdelays_bins = pfd_data.subdelays_bins.copy() for ii, DM in enumerate(DMs): subdelays = psr_utils.delay_from_DM(DM, pfd_data.barysubfreqs) hifreqdelay = subdelays[-1] subdelays = subdelays - hifreqdelay delaybins = subdelays * pfd_data.binspersec - subdelays_bins new_subdelays_bins = np.floor(delaybins + 0.5) for jj in range(pfd_data.nsub): profs[jj] = psr_utils.rotate(profs[jj], int(new_subdelays_bins[jj])) subdelays_bins += new_subdelays_bins sumprof = profs.sum(0) chis[ii] = pfd_data.calc_redchi2(prof=sumprof, avg=pfd_data.avgprof) #### # best_dm = pfd_data.bestdm # crop_radius = 100 # best_dm_index = np.searchsorted(DMs, best_dm) # Not accurate, but close. # bloated_chis = np.insert(chis, N, np.full(crop_radius, chis[-1])) # bloated_chis = np.insert(bloated_chis, 0, np.full(crop_radius, chis[0])) # cropped_chis = bloated_chis[ best_dm_index : best_dm_index+2*crop_radius ] # chis = cropped_chis #### As done in: prepfold.pfd.plot_intervals intervals = pfd_data.profs.sum(1) intervals = normalise_2d_rowwise(intervals) #### #### As done in: prepfold.pfd.plot_subbands subbands = profiles_sum_axis0.copy() # = pfd_data.profs.sum(0) subbands = normalise_2d_rowwise(subbands) #### return label, profile, intervals, subbands, chis
sumprof = Num.zeros(numbins, dtype='d') base_T = None base_BW = None orig_fctr = None Tprerfi = 0.0 Tpostrfi = 0.0 avg_S = 0.0 # Step through the profiles and determine the offsets for pfdfilenm, killsubs, killints in zip(pfdfilenms, killsubss, killintss): print("\n Processing '%s'..." % pfdfilenm) # Read the fold data and de-disperse at the requested DM current_pfd = pfd(pfdfilenm) current_pfd.dedisperse(DM) # This corrects for any searching that prepfold did to find the peak current_pfd.adjust_period() T = current_pfd.T Tprerfi += T BW = current_pfd.nsub * current_pfd.subdeltafreq fctr = current_pfd.lofreq + 0.5 * BW # If there are subbands to kill, kill em' if killsubs is not None: print(" killing subbands: ", killsubs) current_pfd.kill_subbands(killsubs) BW *= (current_pfd.nsub - len(killsubs)) / float(current_pfd.nsub) # If there are intervals to kill, kill em' if killints is not None:
def __init__(self, pfdfile, pointingfile, profilefile=None, offpulse=None, autoroll=True): """ OTF_Scan(pfdfile, pointingfile, profilefile=None, offpulse=None, autoroll=True) create an OTF_Scan object needs a pfd file and a pointing file (a Table which has columns OFFS_SUB, RA_SUB, DEC_SUB) if specified will also read in a file with the results of pygaussfit to determine the profile offpulse will be pairs [min,max] where min and max are limits of phase window (phase is 0->1) if autoroll, will roll the profile to center the pulse (makes some edge effects easier) """ self.pfd = pfd(pfdfile) self.pfdfile = pfdfile self.pointing = Table.read(pointingfile) self.pointingfile = pointingfile self.RA = Longitude( np.interp(self.pfd.mid_secs, self.pointing["OFFS_SUB"], self.pointing["RA_SUB"]) * u.deg) self.Dec = Latitude( np.interp(self.pfd.mid_secs, self.pointing["OFFS_SUB"], self.pointing["DEC_SUB"]) * u.deg) # is it a RA scan or Dec scan if (self.RA.max() - self.RA.min()) * np.cos(self.Dec.mean()) > ( self.Dec.max() - self.Dec.mean()): self.scantype = "RA" self.offset = (self.RA - self.RA.mean()) * np.cos(self.Dec.mean()) else: self.scantype = "Dec" self.offset = self.Dec - self.Dec.mean() self.freq = (self.pfd.hifreq + self.pfd.lofreq) / 2 * u.MHz if self.pfd.telescope == "GBT": self.diameter = 100 * u.m else: self.diameter = None if profilefile is not None: self.profile = PulseProfile(profilefile) else: self.profile = None # Axis 0 = subints, axis 1 = channels, axis 2 = phase bins self.pfd.dedisperse() self.subints = np.arange(self.pfd.profs.shape[0]) self.channels = np.arange(self.pfd.profs.shape[1]) self.phasebins = np.arange(self.pfd.profs.shape[2]) self.phases = self.phasebins / (len(self.phasebins)) self.rollvalue = 0 # basic preparation # define off-pulse window self.set_offpulse(offpulse) # determine the bandpass self.get_bandpass() # remove the bandpass self.apply_bandpass() # remove the variable sub-integration power self.remove_subintpower() # roll the pulse to center it (if desired) if autoroll: self.autoroll() # fit a pulse profile if it is not already set if self.profile is None: self.profile = PulseProfile.fit_gaussian_profile( self.phases, np.nanmean(self.squeezed_profs, axis=0))