def __init__(self, fil_filenm, box): self.fil_filenm = fil_filenm self.basefilenm = fil_filenm.rstrip(".sig") #self.beam = int(self.basefilenm[-1]) self.beam = int(self.basefilenm) filhdr, self.hdrlen = sigproc.read_header(fil_filenm) self.orig_filenm = filhdr['rawdatafile'] self.MJD = filhdr['tstart'] self.nchans = filhdr['nchans'] self.ra_rad = sigproc.ra2radians(filhdr['src_raj']) self.ra_string = psr_utils.coord_to_string(\ *psr_utils.rad_to_hms(self.ra_rad)) self.dec_rad = sigproc.dec2radians(filhdr['src_dej']) self.dec_string = psr_utils.coord_to_string(\ *psr_utils.rad_to_dms(self.dec_rad)) self.az = filhdr['az_start'] self.el = 90.0-filhdr['za_start'] self.BW = abs(filhdr['foff']) * filhdr['nchans'] self.dt = filhdr['tsamp'] self.orig_N = sigproc.samples_per_file(fil_filenm, filhdr, self.hdrlen) self.orig_T = self.orig_N * self.dt self.N = choose_N(self.orig_N) #self.N = 2097152 self.T = self.N * self.dt # Update the RA and DEC from the database file if required #newposn = read_db_posn(self.orig_filenm, self.beam) #if newposn is not None: # self.ra_string, self.dec_string = newposn # ... and use them to update the filterbank file # fix_fil_posn(fil_filenm, self.hdrlen, # self.ra_string, self.dec_string) # Determine the average barycentric velocity of the observation #self.baryv = get_baryv(self.ra_string, self.dec_string, # self.MJD, self.T, obs="NC") # Where to dump all the results # Directory structure is under the base_output_directory # according to base/MJD/filenmbase/beam self.outputdir = os.path.join(base_output_directory,box, self.basefilenm) # Figure out which host we are processing on self.hostname = socket.gethostname() # The fraction of the data recommended to be masked by rfifind self.masked_fraction = 0.0 # Initialize our timers self.rfifind_time = 0.0 self.downsample_time = 0.0 self.subbanding_time = 0.0 self.dedispersing_time = 0.0 self.FFT_time = 0.0 self.lo_accelsearch_time = 0.0 self.hi_accelsearch_time = 0.0 self.singlepulse_time = 0.0 self.sifting_time = 0.0 self.folding_time = 0.0 self.total_time = 0.0 # Inialize some candidate counters self.num_sifted_cands = 0 self.num_folded_cands = 0 self.num_single_cands = 0 self.nb_sp = 0
def __init__(self, fil_filenm): self.fil_filenm = fil_filenm self.basefilenm = fil_filenm[:fil_filenm.find(".fil")] filhdr, hdrlen = sigproc.read_header(fil_filenm) self.MJD = filhdr['tstart'] self.nchans = filhdr['nchans'] self.ra_rad = sigproc.ra2radians(filhdr['src_raj']) self.ra_string = pu.coord_to_string(*pu.rad_to_hms(self.ra_rad)) self.dec_rad = sigproc.dec2radians(filhdr['src_dej']) self.dec_string = pu.coord_to_string(*pu.rad_to_dms(self.dec_rad)) self.str_coords = "J" + "".join(self.ra_string.split(":")[:2]) if self.dec_rad >= 0.0: self.str_coords += "+" self.str_coords += "".join(self.dec_string.split(":")[:2]) self.az = filhdr['az_start'] self.el = 90.0 - filhdr['za_start'] fillen = os.stat(fil_filenm)[6] self.raw_N = (fillen - hdrlen) / (filhdr['nbits'] / 8) / filhdr['nchans'] self.dt = filhdr['tsamp'] self.raw_T = self.raw_N * self.dt self.N = orig_N self.T = self.N * self.dt # Determine the average barycentric velocity of the observation self.baryv = get_baryv(self.ra_string, self.dec_string, self.MJD, self.T, obs="GB") # Where to dump all the results # Directory structure is under the base_output_directory # according to base/MJD/filenmbase/beam self.outputdir = os.path.join(base_output_dir, str(int(self.MJD)), self.str_coords) # Figure out which host we are processing on self.hostname = socket.gethostname() # The fraction of the data recommended to be masked by rfifind self.masked_fraction = 0.0 # Initialize our timers self.rfifind_time = 0.0 self.downsample_time = 0.0 self.dedispersing_time = 0.0 self.FFT_time = 0.0 self.lo_accelsearch_time = 0.0 self.hi_accelsearch_time = 0.0 self.singlepulse_time = 0.0 self.sifting_time = 0.0 self.folding_time = 0.0 self.total_time = 0.0 # Inialize some candidate counters self.num_sifted_cands = 0 self.num_folded_cands = 0 self.num_single_cands = 0
def __init__(self, fil_filenm): self.fil_filenm = fil_filenm self.basefilenm = fil_filenm[:fil_filenm.find(".fil")] filhdr, hdrlen = sigproc.read_header(fil_filenm) self.MJD = filhdr['tstart'] self.nchans = filhdr['nchans'] self.ra_rad = sigproc.ra2radians(filhdr['src_raj']) self.ra_string = pu.coord_to_string(*pu.rad_to_hms(self.ra_rad)) self.dec_rad = sigproc.dec2radians(filhdr['src_dej']) self.dec_string = pu.coord_to_string(*pu.rad_to_dms(self.dec_rad)) self.str_coords = "J"+"".join(self.ra_string.split(":")[:2]) if self.dec_rad >= 0.0: self.str_coords += "+" self.str_coords += "".join(self.dec_string.split(":")[:2]) self.az = filhdr['az_start'] self.el = 90.0-filhdr['za_start'] fillen = os.stat(fil_filenm)[6] self.raw_N = (fillen-hdrlen)/(filhdr['nbits']/8)/filhdr['nchans'] self.dt = filhdr['tsamp'] self.raw_T = self.raw_N * self.dt self.N = orig_N self.T = self.N * self.dt # Determine the average barycentric velocity of the observation self.baryv = get_baryv(self.ra_string, self.dec_string, self.MJD, self.T, obs="GB") # Where to dump all the results # Directory structure is under the base_output_directory # according to base/MJD/filenmbase/beam self.outputdir = os.path.join(base_output_dir, str(int(self.MJD)), self.str_coords) # Figure out which host we are processing on self.hostname = socket.gethostname() # The fraction of the data recommended to be masked by rfifind self.masked_fraction = 0.0 # Initialize our timers self.rfifind_time = 0.0 self.downsample_time = 0.0 self.dedispersing_time = 0.0 self.FFT_time = 0.0 self.lo_accelsearch_time = 0.0 self.hi_accelsearch_time = 0.0 self.singlepulse_time = 0.0 self.sifting_time = 0.0 self.folding_time = 0.0 self.total_time = 0.0 # Inialize some candidate counters self.num_sifted_cands = 0 self.num_folded_cands = 0 self.num_single_cands = 0
print "skip = ", skip print "1st_file_samps = ", first_file_samples print "numfiles = ", numfiles break else: accum_samples += samples_per_file[ii] # Now make a command line option for spigot2filterbank tmpfilenm = "tmp%d.fil" % random.randint(0, 2**30) cmd = "spigot2filterbank -skip %d -numout %d -o %s " % \ (skip, raw_N, tmpfilenm) for goodfile in infilenms[ii:ii + numfiles]: cmd += "%s " % goodfile os.system(cmd) # Now read the header to determine what the correct filename # should be. Use that to rename the fil file. filhdr, hdrlen = sigproc.read_header(tmpfilenm) MJDi = int(filhdr['tstart']) ra_rad = sigproc.ra2radians(filhdr['src_raj']) ra_string = pu.coord_to_string(*pu.rad_to_hms(ra_rad)) dec_rad = sigproc.dec2radians(filhdr['src_dej']) dec_string = pu.coord_to_string(*pu.rad_to_dms(dec_rad)) str_coords = "".join(ra_string.split(":")[:2]) if dec_rad >= 0.0: str_coords += "+" str_coords += "".join(dec_string.split(":")[:2]) filfilenm = "GBT350drift_%d_%s.fil" % (MJDi, str_coords) os.rename(tmpfilenm, filfilenm) print "Renamed '%s' to '%s'." % (tmpfilenm, filfilenm)
def write_inf_file(datfn, hdr, hdrlen): """Write a PRESTO .inf file given a .dat file and a dictionary of SIGPROC-style header values. Inputs: datfn: The PRESTO .dat file to write a .inf file for. hdr: A dictionary of SIGPROC header values, as produced by PRESTO's sigproc.read_header. hdrlen: Length (in bytes) of SIGPROC file's header. Output: inffn: The corresponding .inf file that is created. """ if not datfn.endswith(".dat"): raise ValueError("Was expecting a file name ending with '.dat'. " "Got: %s" % datfn) size = os.path.getsize(datfn) if size % 4: raise ValueError("Bad size (%d bytes) for PRESTO .dat file (%s)" "Should be multiple of 4 because samples are " "32-bit floats." % (size, datfn)) N = size / 4 # Number of samples rarad = sigproc.ra2radians(hdr['src_raj']) decrad = sigproc.dec2radians(hdr['src_dej']) inffn = datfn[:-4]+".inf" with open(inffn, 'w') as ff: ff.write(" Data file name without suffix = %s\n" % os.path.basename(datfn)) ff.write(" Telescope used = %s\n" % sigproc.ids_to_telescope[hdr['telescope_id']]) ff.write(" Instrument used = %s\n" % sigproc.ids_to_machine.get('machine_id', 'UNKNOWN')) ff.write(" Object being observed = %s\n" % hdr['source_name']) ff.write(" J2000 Right Ascension (hh:mm:ss.ssss) = %s\n" % rad_to_hmsstr(rarad)) ff.write(" J2000 Declination (dd:mm:ss.ssss) = %s\n" % rad_to_dmsstr(decrad)) ff.write(" Data observed by = UNKNOWN\n") ff.write(" Epoch of observation (MJD) = %05.15f\n" % hdr['tstart']) ff.write(" Barycentered? (1=yes, 0=no) = %d\n" % hdr['barycentric']) ff.write(" Number of bins in the time series = %d\n" % N) ff.write(" Width of each time series bin (sec) = %.15g\n" % hdr['tsamp']) ff.write(" Orbit removed? (1=yes, 0=no) = %d\n" % hdr['pulsarcentric']) ff.write(" Dispersion measure (cm-3 pc) = %f\n" % hdr['refdm']) ff.write(" Central freq of low channel (Mhz) = %f\n" % hdr['fch1']) ff.write(" Total bandwidth (Mhz) = %f\n" % (hdr['nchans']*hdr['foff'])) ff.write(" Number of channels = %d\n" % hdr['nchans']) ff.write(" Channel bandwidth (Mhz) = %d\n" % hdr['foff']) ff.write(" Data analyzed by = %s\n" % getpass.getuser()) ff.write(" Any additional notes:\n" " File converted from SIGPROC .tim time series\n" " with PRESTO's tim2dat.py, written by Patrick Lazarus") return inffn
break else: accum_samples += samples_per_file[ii] # Now make a command line option for spigot2filterbank tmpfilenm = "tmp%d.fil"%random.randint(0,2**30) cmd = "spigot2filterbank -skip %d -numout %d -o %s " % \ (skip, raw_N, tmpfilenm) for goodfile in infilenms[ii:ii+numfiles]: cmd += "%s "%goodfile os.system(cmd) # Now read the header to determine what the correct filename # should be. Use that to rename the fil file. filhdr, hdrlen = sigproc.read_header(tmpfilenm) MJDi = int(filhdr['tstart']) ra_rad = sigproc.ra2radians(filhdr['src_raj']) ra_string = pu.coord_to_string(*pu.rad_to_hms(ra_rad)) dec_rad = sigproc.dec2radians(filhdr['src_dej']) dec_string = pu.coord_to_string(*pu.rad_to_dms(dec_rad)) str_coords = "".join(ra_string.split(":")[:2]) if dec_rad >= 0.0: str_coords += "+" str_coords += "".join(dec_string.split(":")[:2]) filfilenm = "GBT350drift_%d_%s.fil" % (MJDi, str_coords) os.rename(tmpfilenm, filfilenm) print("Renamed '%s' to '%s'." % (tmpfilenm, filfilenm))
def __init__(self, fil_filenm): self.fil_filenm = fil_filenm self.basefilenm = fil_filenm.rstrip(".fil") self.beam = int(self.basefilenm[-1]) filhdr, self.hdrlen = sigproc.read_header(fil_filenm) self.orig_filenm = filhdr['rawdatafile'] self.MJD = filhdr['tstart'] self.nchans = filhdr['nchans'] self.ra_rad = sigproc.ra2radians(filhdr['src_raj']) self.ra_string = psr_utils.coord_to_string(\ *psr_utils.rad_to_hms(self.ra_rad)) self.dec_rad = sigproc.dec2radians(filhdr['src_dej']) self.dec_string = psr_utils.coord_to_string(\ *psr_utils.rad_to_dms(self.dec_rad)) self.az = filhdr['az_start'] self.el = 90.0 - filhdr['za_start'] self.BW = abs(filhdr['foff']) * filhdr['nchans'] self.dt = filhdr['tsamp'] self.orig_N = sigproc.samples_per_file(fil_filenm, filhdr, self.hdrlen) self.orig_T = self.orig_N * self.dt self.N = psr_utils.choose_N(self.orig_N) self.T = self.N * self.dt # Update the RA and DEC from the database file if required newposn = read_db_posn(self.orig_filenm, self.beam) if newposn is not None: self.ra_string, self.dec_string = newposn # ... and use them to update the filterbank file fix_fil_posn(fil_filenm, self.hdrlen, self.ra_string, self.dec_string) # Determine the average barycentric velocity of the observation self.baryv = presto.get_baryv(self.ra_string, self.dec_string, self.MJD, self.T, obs="AO") # Where to dump all the results # Directory structure is under the base_output_directory # according to base/MJD/filenmbase/beam self.outputdir = os.path.join(base_output_directory, str(int(self.MJD)), self.basefilenm[:-2], str(self.beam)) # Figure out which host we are processing on self.hostname = socket.gethostname() # The fraction of the data recommended to be masked by rfifind self.masked_fraction = 0.0 # Initialize our timers self.rfifind_time = 0.0 self.downsample_time = 0.0 self.subbanding_time = 0.0 self.dedispersing_time = 0.0 self.FFT_time = 0.0 self.lo_accelsearch_time = 0.0 self.hi_accelsearch_time = 0.0 self.singlepulse_time = 0.0 self.sifting_time = 0.0 self.folding_time = 0.0 self.total_time = 0.0 # Inialize some candidate counters self.num_sifted_cands = 0 self.num_folded_cands = 0 self.num_single_cands = 0
def write_inf_file(datfn, hdr, hdrlen): """Write a PRESTO .inf file given a .dat file and a dictionary of SIGPROC-style header values. Inputs: datfn: The PRESTO .dat file to write a .inf file for. hdr: A dictionary of SIGPROC header values, as produced by PRESTO's sigproc.read_header. hdrlen: Length (in bytes) of SIGPROC file's header. Output: inffn: The corresponding .inf file that is created. """ if not datfn.endswith(".dat"): raise ValueError("Was expecting a file name ending with '.dat'. " "Got: %s" % datfn) size = os.path.getsize(datfn) if size % 4: raise ValueError("Bad size (%d bytes) for PRESTO .dat file (%s)" "Should be multiple of 4 because samples are " "32-bit floats." % (size, datfn)) N = size / 4 # Number of samples rarad = sigproc.ra2radians(hdr['src_raj']) decrad = sigproc.dec2radians(hdr['src_dej']) inffn = datfn[:-4] + ".inf" with open(inffn, 'w') as ff: ff.write(" Data file name without suffix = %s\n" % os.path.basename(datfn)) ff.write(" Telescope used = %s\n" % sigproc.ids_to_telescope[hdr['telescope_id']]) ff.write(" Instrument used = %s\n" % sigproc.ids_to_machine.get('machine_id', 'UNKNOWN')) ff.write(" Object being observed = %s\n" % hdr['source_name']) ff.write(" J2000 Right Ascension (hh:mm:ss.ssss) = %s\n" % rad_to_hmsstr(rarad)) ff.write(" J2000 Declination (dd:mm:ss.ssss) = %s\n" % rad_to_dmsstr(decrad)) ff.write(" Data observed by = UNKNOWN\n") ff.write(" Epoch of observation (MJD) = %05.15f\n" % hdr['tstart']) ff.write(" Barycentered? (1=yes, 0=no) = %d\n" % hdr['barycentric']) ff.write(" Number of bins in the time series = %d\n" % N) ff.write(" Width of each time series bin (sec) = %.15g\n" % hdr['tsamp']) ff.write(" Orbit removed? (1=yes, 0=no) = %d\n" % hdr['pulsarcentric']) ff.write(" Dispersion measure (cm-3 pc) = %f\n" % hdr['refdm']) ff.write(" Central freq of low channel (Mhz) = %f\n" % hdr['fch1']) ff.write(" Total bandwidth (Mhz) = %f\n" % (hdr['nchans'] * hdr['foff'])) ff.write(" Number of channels = %d\n" % hdr['nchans']) ff.write(" Channel bandwidth (Mhz) = %d\n" % hdr['foff']) ff.write(" Data analyzed by = %s\n" % getpass.getuser()) ff.write(" Any additional notes:\n" " File converted from SIGPROC .tim time series\n" " with PRESTO's tim2dat.py, written by Patrick Lazarus") return inffn