Esempio n. 1
0
def main():
    fn = args[0]
    if fn.endswith(".fil"):
        # Filterbank file
        filetype = "filterbank"
        print_debug("Reading filterbank file..")
        rawdatafile = filterbank.filterbank(fn)
        basename = fn[:-4]
    if fn.endswith(".fits"):
        # PSRFITS file
        filetype = "psrfits"
        print_debug("Reading PSRFITS file..")
        rawdatafile = psrfits.PsrfitsFile(fn)
        basename = fn[:-5]
    else:
        raise ValueError("Cannot recognize data file type from "
                         "extension. (Only '.fits' and '.fil' "
                         "are supported.)")

    if options.outbasenm:
        basename = options.outbasenm
    spdcand = spcand.params()
    if not options.man_params:
        print_debug('Maximum number of candidates to plot: %i' %
                    options.maxnumcands)
        make_spd_from_file(spdcand, rawdatafile, \
                           options.txtfile, options.maskfile, \
                           options.min_rank, options.group_rank, \
                           options.plot, options.just_waterfall, \
                           options.integrate_ts, options.integrate_spec, options.disp_pulse, \
                           options.loc_pulse, options.nsub, \
                           options.maxnumcands, \
                           basename, \
                           mask=options.mask, barytime=options.barytime, \
                           bandpass_corr=options.bandpass_corr)
    else:
        print_debug("Making spd files based on mannual parameters. I suggest" \
                    "reading in parameters from the groups.txt file.")
        make_spd_from_man_params(spdcand, rawdatafile, \
                                 options.txtfile, options.maskfile, \
                                 options.plot, options.just_waterfall, \
                                 options.subdm, options.dm, options.sweep_dms, \
                                 options.sigma, \
                                 options.start, options.duration, \
                                 options.width_bins, options.nbins, options.downsamp, \
                                 options.nsub, \
                                 options.scaleindep, \
                                 options.spec_width, options.loc_pulse, \
                                 options.integrate_ts, options.integrate_spec, options.disp_pulse, \
                                 basename, \
                                 options.mask, options.bandpass_corr, options.barytime, \
                                 options.man_params)
Esempio n. 2
0
def main():
    fn = args[0]
    if fn.endswith(".fil"):
        # Filterbank file
        filetype = "filterbank"
        print_debug("Reading filterbank file..")
        rawdatafile = filterbank.filterbank(fn)
        basename = fn[:-4]
    if fn.endswith(".fits"):
        # PSRFITS file
        filetype = "psrfits"
        print_debug("Reading PSRFITS file..")
        rawdatafile = psrfits.PsrfitsFile(fn)
        basename = fn[:-5]
    else:
        raise ValueError("Cannot recognize data file type from "
                         "extension. (Only '.fits' and '.fil' "
                         "are supported.)")

    if options.outbasenm:
        basename=options.outbasenm
    spdcand = spcand.params()
    if not options.man_params:
        print_debug('Maximum number of candidates to plot: %i'%options.maxnumcands)
        make_spd_from_file(spdcand, rawdatafile, \
                           options.txtfile, options.maskfile, \
                           options.min_rank, options.group_rank, \
                           options.plot, options.just_waterfall, \
                           options.integrate_ts, options.integrate_spec, options.disp_pulse, \
                           options.loc_pulse, options.nsub, \
                           options.maxnumcands, \
                           basename, \
                           mask=options.mask, barytime=options.barytime, \
                           bandpass_corr=options.bandpass_corr)
    else:
        print_debug("Making spd files based on mannual parameters. I suggest" \
                    "reading in parameters from the groups.txt file.")
        make_spd_from_man_params(spdcand, rawdatafile, \
                                 options.txtfile, options.maskfile, \
                                 options.plot, options.just_waterfall, \
                                 options.subdm, options.dm, options.sweep_dms, \
                                 options.sigma, \
                                 options.start, options.duration, \
                                 options.width_bins, options.nbins, options.downsamp, \
                                 options.nsub, \
                                 options.scaleindep, \
                                 options.spec_width, options.loc_pulse, \
                                 options.integrate_ts, options.integrate_spec, options.disp_pulse, \
                                 basename, \
                                 options.mask, options.bandpass_corr, options.barytime, \
                                 options.man_params)            
Esempio n. 3
0
def GBNCC_wrapper(txtfile, maskfile, fitsfilenm, path_sp_files):
    """
	The pipeline should pass job.fits_filenm as argument.
    """
    files = spio.get_textfile(txtfile)
    min_rank = 3
    groups = [i for i in range(7) if (i >= min_rank)][::-1]
    numcands = 0  # counter for max number of candidates
    loop_must_break = False  # dont break the loop unless num of cands >100.

    values = []
    lis = []
    ranks = []
    for group in groups:
        rank = group + 1
        if files[group] != "Number of rank %i groups: 0 " % rank:
            add_values = spio.split_parameters(rank, txtfile)
            values.extend(add_values)
            lis = np.append(
                lis,
                np.where(files == '\tRank:             %i.000000' % rank)[0])
            add_ranks = np.ones(len(add_values)) * rank
            ranks = np.append(ranks, add_ranks)

    if len(values) > 100:
        values = values[0:100]
        lis = lis[0:100]

    #Sort candidates based on DM
    zip_list = zip(values, lis, ranks)
    zip_list = sorted(zip_list, key=itemgetter(0, 0))
    values = [x[0] for x in zip_list]
    lis = [x[1] for x in zip_list]
    ranks = [x[2] for x in zip_list]

    basename = fitsfilenm[:-5]
    #generate subbanded file at a DM of 0 to extract observation parameters
    cmd = "psrfits_subband -dm 0.0 -nsub 128 -o %s_subband_0.0 %s" % (
        basename, fitsfilenm)
    print "executing %s" % cmd
    subprocess.call(cmd, shell=True)
    subfilenm = basename + "_subband_0.0_0001.fits"
    subfile = psrfits.PsrfitsFile(subfilenm)

    for ii in range(len(values)):
        dm_list, time_list, dm_arr, sigma_arr, width_arr = spio.read_RRATrap_info(
            txtfile, lis[ii], int(ranks[ii]))
        wrapper_cand = spcand.params()
        wrapper_cand.read_from_file(values[ii], subfile.tsamp, subfile.specinfo.N, \
                                       get_obs_info(fitsfilenm)['hifreq'], get_obs_info(fitsfilenm)['lofreq'], \
                                       subfile, loc_pulse=0.5, dedisp = True,\
                                       scaleindep = None, zerodm = None, mask = None,\
                                       barytime=True, nsub = None, bandpass_corr = False)
        temp_filename = basename + "_rank_%i" % int(ranks[ii])
        if ii == 0:  #check if index is 0
            correct_rawdatafile, prevsubfile, prevDM  = pick_rawdatafile(wrapper_cand.subdm, fitsfilenm, \
                                                                get_obs_info(fitsfilenm)['hifreq'], get_obs_info(fitsfilenm)['lofreq'], \
                                                                wrapper_cand.pulse_width, prevDM = 0, prevsubfile = '', \
                                                                init_flag = 1)
        else:
            correct_rawdatafile, prevsubfile, prevDM  = pick_rawdatafile(wrapper_cand.subdm, fitsfilenm, \
                                                                get_obs_info(fitsfilenm)['hifreq'], get_obs_info(fitsfilenm)['lofreq'], \
                                                                wrapper_cand.pulse_width, prevDM = prevDM, \
                                                                prevsubfile=prevsubfile, init_flag = 0)

        path = os.path.dirname(os.path.abspath(__file__))
        cmd = "python " + path + "/make_spd.py --use_manual_params --subdm %f --nsub %d" \
                     " --dm %f -T %f -t %f --width-bins %d --downsamp %d --show-spec"\
                      " --noplot --notopo -o %s %s " %(wrapper_cand.subdm, \
                                                 wrapper_cand.nsub, wrapper_cand.dm, \
                                                 wrapper_cand.topo_start_time, wrapper_cand.duration, \
                                                 wrapper_cand.width_bins, wrapper_cand.downsamp,\
                                                 temp_filename, correct_rawdatafile)
        print "executing %s" % cmd
        subprocess.call(cmd, shell=True)
        # Add additional information to the header information array
        text_array = np.array([correct_rawdatafile, subfile.specinfo.telescope, \
                           subfile.specinfo.ra_str, subfile.specinfo.dec_str, \
                           subfile.specinfo.start_MJD[0], int(ranks[ii]), \
                           wrapper_cand.nsub, wrapper_cand.nbins, \
                           wrapper_cand.subdm, wrapper_cand.sigma, wrapper_cand.sample_number, \
                           wrapper_cand.duration, wrapper_cand.width_bins, wrapper_cand.pulse_width, \
                           subfile.tsamp, subfile.specinfo.T, wrapper_cand.topo_start_time])

        temp_filename += "_DM%.1f_%.1fs" % (wrapper_cand.subdm,
                                            wrapper_cand.topo_start_time)
        spd = read_spd.spd(temp_filename + '.spd')
        spd.man_params = None
        text_array = np.append(text_array, spd.waterfall_start_time)
        text_array = np.append(text_array, spd.waterfall_tsamp)
        text_array = np.append(text_array, spd.waterfall_prededisp_nbins)
        text_array = np.append(text_array, spd.min_freq)
        text_array = np.append(text_array, spd.max_freq)
        text_array = np.append(text_array, spd.sweep_duration)
        text_array = np.append(text_array, spd.sweep_start_time)
        text_array = np.append(text_array, spd.bary_pulse_peak_time)
        text_array = np.append(text_array, spd.man_params)

        with open(temp_filename + ".spd", 'wb') as f:
            np.savez_compressed(f, \
                                        Data_dedisp_nozerodm = spd.data_nozerodm_dedisp,\
                                        Data_dedisp_zerodm = spd.data_zerodm_dedisp,\
                                        Data_nozerodm = spd.data_nozerodm,\
                                        delays_nozerodm = spd.dmsweep_delays, \
                                        freqs_nozerodm = spd.dmsweep_freqs,\
                                        Data_zerodm = spd.data_zerodm, \
                                        dm_arr= map(np.float16, dm_arr),\
                                        sigma_arr = map(np.float16, sigma_arr), \
                                        width_arr =map(np.uint8, width_arr),\
                                        dm_list= map(np.float16, dm_list), \
                                        time_list = map(np.float16, time_list), \
                                        text_array = text_array)
        plot_spd.plot(temp_filename+".spd", glob.glob(path_sp_files+'/*.singlepulse'), maskfile, \
                              outfile=basename, just_waterfall=False, \
                              integrate_spec=True, integrate_ts=True, \
                              disp_pulse=False, bandpass_corr = True, tar = None)
        numcands += 1
        print 'Finished sp_candidate : %i' % numcands
        if numcands >= 100:  # Max number of candidates to plot 100.
            loop_must_break = True
            break
def GBNCC_wrapper(txtfile, maskfile, fitsfilenm, path_sp_files):
    """
	The pipeline should pass job.fits_filenm as argument.
    """
    files = spio.get_textfile(txtfile)
    min_rank = 3
    groups = [i for i in range(7) if(i>=min_rank)][::-1]
    numcands=0 # counter for max number of candidates
    loop_must_break = False # dont break the loop unless num of cands >100.
    
    values = []
    lis = [] 
    ranks = []
    for group in groups:
        rank = group+1
        if files[group] != "Number of rank %i groups: 0 "%rank:
            add_values = spio.split_parameters(rank, txtfile) 
            values.extend(add_values)
            lis = np.append(lis, np.where(files == '\tRank:             %i.000000'%rank)[0])
            add_ranks = np.ones(len(add_values)) * rank
            ranks = np.append(ranks, add_ranks)
     
    if len(values) > 100:
        values = values[0:100]
        lis = lis[0:100]

    #Sort candidates based on DM
    zip_list = zip(values, lis, ranks)
    zip_list = sorted(zip_list, key=itemgetter(0,0))
    values = [x[0] for x in zip_list]
    lis = [x[1] for x in zip_list]
    ranks = [x[2] for x in zip_list]
    
    basename = fitsfilenm[:-5]
    #generate subbanded file at a DM of 0 to extract observation parameters
    cmd = "psrfits_subband -dm 0.0 -nsub 128 -o %s_subband_0.0 %s"%(basename,fitsfilenm)
    print "executing %s" %cmd
    subprocess.call(cmd, shell=True)
    subfilenm = basename + "_subband_0.0_0001.fits"
    subfile = psrfits.PsrfitsFile(subfilenm)
    
    for ii in range(len(values)):
        dm_list, time_list, dm_arr, sigma_arr, width_arr = spio.read_RRATrap_info(txtfile, lis[ii], int(ranks[ii]))
        wrapper_cand = spcand.params() 
        wrapper_cand.read_from_file(values[ii], subfile.tsamp, subfile.specinfo.N, \
                                       get_obs_info(fitsfilenm)['hifreq'], get_obs_info(fitsfilenm)['lofreq'], \
                                       subfile, loc_pulse=0.5, dedisp = True,\
                                       scaleindep = None, zerodm = None, mask = None,\
                                       barytime=True, nsub = None, bandpass_corr = False) 
        temp_filename = basename+"_rank_%i"%int(ranks[ii])
        if ii == 0: #check if index is 0
            correct_rawdatafile, prevsubfile, prevDM  = pick_rawdatafile(wrapper_cand.subdm, fitsfilenm, \
                                                                get_obs_info(fitsfilenm)['hifreq'], get_obs_info(fitsfilenm)['lofreq'], \
                                                                wrapper_cand.pulse_width, prevDM = 0, prevsubfile = '', \
                                                                init_flag = 1)
        else:
            correct_rawdatafile, prevsubfile, prevDM  = pick_rawdatafile(wrapper_cand.subdm, fitsfilenm, \
                                                                get_obs_info(fitsfilenm)['hifreq'], get_obs_info(fitsfilenm)['lofreq'], \
                                                                wrapper_cand.pulse_width, prevDM = prevDM, \
                                                                prevsubfile=prevsubfile, init_flag = 0)
            
        
        path = os.path.dirname(os.path.abspath(__file__))
        cmd = "python " + path + "/make_spd.py --use_manual_params --subdm %f --nsub %d" \
              	      " --dm %f -T %f -t %f --width-bins %d --downsamp %d --show-spec"\
                      " --noplot --notopo -o %s %s " %(wrapper_cand.subdm, \
                                                 wrapper_cand.nsub, wrapper_cand.dm, \
                                                 wrapper_cand.topo_start_time, wrapper_cand.duration, \
                                                 wrapper_cand.width_bins, wrapper_cand.downsamp,\
                                                 temp_filename, correct_rawdatafile)
        print "executing %s" %cmd
        subprocess.call(cmd, shell=True)       
        # Add additional information to the header information array
        text_array = np.array([correct_rawdatafile, subfile.specinfo.telescope, \
                           subfile.specinfo.ra_str, subfile.specinfo.dec_str, \
                           subfile.specinfo.start_MJD[0], int(ranks[ii]), \
                           wrapper_cand.nsub, wrapper_cand.nbins, \
                           wrapper_cand.subdm, wrapper_cand.sigma, wrapper_cand.sample_number, \
                           wrapper_cand.duration, wrapper_cand.width_bins, wrapper_cand.pulse_width, \
                           subfile.tsamp, subfile.specinfo.T, wrapper_cand.topo_start_time])
                
        temp_filename +="_DM%.1f_%.1fs"%(wrapper_cand.subdm, wrapper_cand.topo_start_time)
        spd = read_spd.spd(temp_filename+'.spd')
        spd.man_params = None 
        text_array = np.append(text_array, spd.waterfall_start_time)
        text_array = np.append(text_array, spd.waterfall_tsamp)
        text_array = np.append(text_array, spd.waterfall_prededisp_nbins)
        text_array = np.append(text_array, spd.min_freq)
        text_array = np.append(text_array, spd.max_freq)
        text_array = np.append(text_array, spd.sweep_duration)
        text_array = np.append(text_array, spd.sweep_start_time)
        text_array = np.append(text_array, spd.bary_pulse_peak_time)
        text_array = np.append(text_array, spd.man_params)

        with open(temp_filename+".spd", 'wb') as f:
            np.savez_compressed(f, \
                                        Data_dedisp_nozerodm = spd.data_nozerodm_dedisp,\
                                        Data_dedisp_zerodm = spd.data_zerodm_dedisp,\
                                        Data_nozerodm = spd.data_nozerodm,\
                                        delays_nozerodm = spd.dmsweep_delays, \
                                        freqs_nozerodm = spd.dmsweep_freqs,\
                                        Data_zerodm = spd.data_zerodm, \
                                        dm_arr= map(np.float16, dm_arr),\
                                        sigma_arr = map(np.float16, sigma_arr), \
                                        width_arr =map(np.uint8, width_arr),\
                                        dm_list= map(np.float16, dm_list), \
                                        time_list = map(np.float16, time_list), \
                                        text_array = text_array)
        plot_spd.plot(temp_filename+".spd", glob.glob(path_sp_files+'/*.singlepulse'), maskfile, \
                              outfile=basename, just_waterfall=False, \
                              integrate_spec=True, integrate_ts=True, \
                              disp_pulse=False, bandpass_corr = True, tar = None)
        numcands+= 1
        print 'Finished sp_candidate : %i'%numcands
        if numcands >= 100:    # Max number of candidates to plot 100.
            loop_must_break = True
            break