Exemple #1
0
def make_spd_from_file(spdcand, rawdatafile, \
                       txtfile, maskfile, \
                       min_rank, group_rank, \
                       plot, just_waterfall, \
                       integrate_ts, integrate_spec, disp_pulse, \
                       loc_pulse, nsub, \
                       maxnumcands, \
                       basename, \
                       mask=False, bandpass_corr=True, barytime=True, \
                       man_params=None):
    
    """
    Makes spd files from output files of rratrap. 
    Inputs:
        spdcand: spcand parameters instance (read in spcand.params)
        rawdatafile: psrfits file instance
        txtfile: rratrap output file (groups.txt file)
        maskfile: rfifind mask file. need this file if you want to remove the bandpass 
                  or use rfifind mask information.
        min_rank: plot all groups with rank more than this. min 1, max 6
        group_rank: plot groups ranked whatever you specify
        plot: do you want to produce the plots as well? 
        just_waterfall: Do you just want to make the waterfall plots.
        integrate_ts: Do you want to display the dedispersed time series in the plot?
        integrate_spec: Do you want to display the pulse spectrum in the plot?
        disp_pulse: Do you want to see the inset dispersed pulse in the plot?
        loc_pulse: Fraction of the window length where the pulse is located.(eg. 0.25 = 1/4th of the way in.
                                                                             0.5 = middle of the plot)
        maxnumcands: What is the maximum number of candidates you would like to generate?
        basename: output basename of the file. Appended with _DM_TIME(s)_RANK.spd 
    Optional arguments:
        mask: Do you want to mask out rfi contaminated channels?
        bandpass_corr: Do you want to remove the bandpass?
        barytime: Is the given time(s) barycentric?
        man_params: Do you want to specify the parameters for waterfalling 
                    manually? If yes, I suggest using the function make_spd_from_man_params().
                    (I suggest giving it the rratrap output file)    
    Outputs:
       Binary npz file containing the necessary arrays and header information to generate the spd plots.
    """
    numcands=0 # counter for max number of candidates
    loop_must_break = False # dont break the loop unless num of cands >100.
    files = spio.get_textfile(options.txtfile)
    if group_rank:
        groups=[group_rank-1]
    else:
        groups = [i for i in range(6) if(i>=min_rank)][::-1]
     
    for group in groups:
        rank = group+1
        if files[group] != "Number of rank %i groups: 0 "%rank:
            values = spio.split_parameters(rank, txtfile)
            lis = np.where(files == '\tRank:             %i.000000'%rank)[0]
            for ii in range(len(values)):
                #### Arrays for Plotting DM vs SNR
                dm_list, time_list, dm_arr, sigma_arr, width_arr = spio.read_RRATrap_info(txtfile, lis[ii], rank)


                # Array for Plotting Dedispersed waterfall plot - zerodm - OFF
                spdcand.read_from_file(values[ii], rawdatafile.tsamp, rawdatafile.specinfo.N, \
                                       rawdatafile.frequencies[0], rawdatafile.frequencies[-1], \
                                       rawdatafile, loc_pulse=loc_pulse, dedisp = True, \
                                       scaleindep = None, zerodm = None, mask = mask, \
                                       barytime=barytime, \
                                       nsub = nsub, bandpass_corr = bandpass_corr)

                #make an array to store header information for the spd files
                temp_filename = basename+"_DM%.1f_%.1fs_rank_%i"%(spdcand.subdm, \
                                                   spdcand.topo_start_time, rank)
                
                print_debug("Running waterfaller with Zero-DM OFF...")
                
                # Add additional information to the header information array
                data, Data_dedisp_nozerodm = waterfall_array(rawdatafile, spdcand.start, \
                                             spdcand.duration, spdcand.dm, spdcand.nbins, spdcand.nsub, \
                                             spdcand.subdm, spdcand.zerodm, spdcand.downsamp, \
                                             spdcand.scaleindep, spdcand.width_bins, \
                                             spdcand.mask, maskfile, spdcand.bandpass_corr)

                text_array = np.array([args[0], rawdatafile.specinfo.telescope, \
                                       rawdatafile.specinfo.ra_str, rawdatafile.specinfo.dec_str, \
                                       rawdatafile.specinfo.start_MJD[0], \
                                       rank, spdcand.nsub, spdcand.nbins, spdcand.subdm, \
                                       spdcand.sigma, spdcand.sample_number, spdcand.duration, \
                                       spdcand.width_bins, spdcand.pulse_width, rawdatafile.tsamp,\
                                       rawdatafile.specinfo.T, spdcand.topo_start_time, data.starttime, \
                                       data.dt,data.numspectra, data.freqs.min(), data.freqs.max()])

                #### Array for plotting Dedispersed waterfall plot zerodm - ON
                print_debug("Running Waterfaller with Zero-DM ON...")
                zerodm=True
                data, Data_dedisp_zerodm = waterfall_array(rawdatafile, spdcand.start, \
                                           spdcand.duration, spdcand.dm, spdcand.nbins, spdcand.nsub, \
                                           spdcand.subdm, zerodm, spdcand.downsamp, \
                                           spdcand.scaleindep, spdcand.width_bins, \
                                           spdcand.mask, maskfile, spdcand.bandpass_corr)
                ####Sweeped without zerodm
                spdcand.read_from_file(values[ii], rawdatafile.tsamp, rawdatafile.specinfo.N, \
                                      rawdatafile.frequencies[0], rawdatafile.frequencies[-1], \
                                      rawdatafile, loc_pulse=loc_pulse, dedisp = None, \
                                      scaleindep = None, zerodm = None, mask = mask, \
                                      barytime=barytime, \
                                      nsub = nsub, bandpass_corr = bandpass_corr)
                data, Data_nozerodm = waterfall_array(rawdatafile, spdcand.start, \
                                           spdcand.duration, spdcand.dm, spdcand.nbins, spdcand.nsub, \
                                           spdcand.subdm, spdcand.zerodm, spdcand.downsamp, \
                                           spdcand.scaleindep, spdcand.width_bins, \
                                           spdcand.mask, maskfile, spdcand.bandpass_corr)
                text_array = np.append(text_array, spdcand.sweep_duration)
                text_array = np.append(text_array, data.starttime)
                text_array = np.append(text_array, spdcand.bary_start_time)
                text_array = np.append(text_array, man_params)
                # Array to Construct the sweep
                if spdcand.sweep_dm is not None:
                    ddm = spdcand.sweep_dm-data.dm
                    delays = psr_utils.delay_from_DM(ddm, data.freqs)
                    delays -= delays.min()
                    delays_nozerodm = delays
                    freqs_nozerodm = data.freqs
                # Sweeped with zerodm-on 
                zerodm = True
                #downsamp_temp = 1
                data, Data_zerodm = waterfall_array(rawdatafile, spdcand.start, \
                                           spdcand.duration, spdcand.dm, spdcand.nbins, spdcand.nsub, \
                                           spdcand.subdm, zerodm, spdcand.downsamp, \
                                           spdcand.scaleindep, spdcand.width_bins, \
                                           spdcand.mask, maskfile, spdcand.bandpass_corr)
                # Saving the arrays into the .spd file.
                with open(temp_filename+".spd", 'wb') as f:
                    np.savez_compressed(f, \
                                        Data_dedisp_nozerodm = Data_dedisp_nozerodm.astype(np.float16),\
                                        Data_dedisp_zerodm = Data_dedisp_zerodm.astype(np.float16),\
                                        Data_nozerodm = Data_nozerodm.astype(np.float16),\
                                        delays_nozerodm = delays_nozerodm, \
                                        freqs_nozerodm = freqs_nozerodm,\
                                        Data_zerodm = Data_zerodm.astype(np.float16), \
                                        dm_arr= list(map(np.float16, dm_arr)),\
                                        sigma_arr = list(map(np.float16, sigma_arr)), \
                                        width_arr =list(map(np.uint8, width_arr)),\
                                        dm_list= list(map(np.float16, dm_list)), \
                                        time_list = list(map(np.float16, time_list)), \
                                        text_array = text_array)
                #### Arrays for Plotting DM vs Time is in plot_spd.plot(...)
                if plot:
                    print_debug("Now plotting...")
                    plot_spd.plot(temp_filename+".spd", args[1:], \
                                  spec_width=1.5, loc_pulse=loc_pulse, \
                                  xwin=False, outfile=basename, \
                                  just_waterfall=just_waterfall, \
                                  integrate_spec=integrate_spec, \
                                  integrate_ts=integrate_ts, \
                                  disp_pulse=disp_pulse, tar = None)
                    print_debug("Finished plot %i " %ii+strftime("%Y-%m-%d %H:%M:%S"))
                numcands+= 1
                print_debug('Finished sp_candidate : %i'%numcands)
                if numcands >= maxnumcands:    # Max number of candidates to plot 100.
                    loop_must_break = True
                    break
            if loop_must_break:
                break

        print_debug("Finished group %i... "%rank+strftime("%Y-%m-%d %H:%M:%S"))
    print_debug("Finished running waterfaller... "+strftime("%Y-%m-%d %H:%M:%S"))
Exemple #2
0
def make_spd_from_file(spdcand, rawdatafile, \
                       txtfile, maskfile, \
                       min_rank, group_rank, \
                       plot, just_waterfall, \
                       integrate_ts, integrate_spec, disp_pulse, \
                       loc_pulse, nsub, \
                       maxnumcands, \
                       basename, \
                       mask=False, bandpass_corr=True, barytime=True, \
                       man_params=None):
    
    """
    Makes spd files from output files of rratrap. 
    Inputs:
        spdcand: spcand parameters instance (read in spcand.params)
        rawdatafile: psrfits file instance
        txtfile: rratrap output file (groups.txt file)
        maskfile: rfifind mask file. need this file if you want to remove the bandpass 
                  or use rfifind mask information.
        min_rank: plot all groups with rank more than this. min 1, max 6
        group_rank: plot groups ranked whatever you specify
        plot: do you want to produce the plots as well? 
        just_waterfall: Do you just want to make the waterfall plots.
        integrate_ts: Do you want to display the dedispersed time series in the plot?
        integrate_spec: Do you want to display the pulse spectrum in the plot?
        disp_pulse: Do you want to see the inset dispersed pulse in the plot?
        loc_pulse: Fraction of the window length where the pulse is located.(eg. 0.25 = 1/4th of the way in.
                                                                             0.5 = middle of the plot)
        maxnumcands: What is the maximum number of candidates you would like to generate?
        basename: output basename of the file. Appended with _DM_TIME(s)_RANK.spd 
    Optional arguments:
        mask: Do you want to mask out rfi contaminated channels?
        bandpass_corr: Do you want to remove the bandpass?
        barytime: Is the given time(s) barycentric?
        man_params: Do you want to specify the parameters for waterfalling 
                    manually? If yes, I suggest using the function make_spd_from_man_params().
                    (I suggest giving it the rratrap output file)    
    Outputs:
       Binary npz file containing the necessary arrays and header information to generate the spd plots.
    """
    numcands=0 # counter for max number of candidates
    loop_must_break = False # dont break the loop unless num of cands >100.
    files = spio.get_textfile(options.txtfile)
    if group_rank:
        groups=[group_rank-1]
    else:
        groups = [i for i in range(6) if(i>=min_rank)][::-1]
     
    for group in groups:
        rank = group+1
        if files[group] != "Number of rank %i groups: 0 "%rank:
            values = spio.split_parameters(rank, txtfile)
            lis = np.where(files == '\tRank:             %i.000000'%rank)[0]
            for ii in range(len(values)):
                #### Arrays for Plotting DM vs SNR
                dm_list, time_list, dm_arr, sigma_arr, width_arr = spio.read_RRATrap_info(txtfile, lis[ii], rank)


                # Array for Plotting Dedispersed waterfall plot - zerodm - OFF
                spdcand.read_from_file(values[ii], rawdatafile.tsamp, rawdatafile.specinfo.N, \
                                       rawdatafile.frequencies[0], rawdatafile.frequencies[-1], \
                                       rawdatafile, loc_pulse=loc_pulse, dedisp = True, \
                                       scaleindep = None, zerodm = None, mask = mask, \
                                       barytime=barytime, \
                                       nsub = nsub, bandpass_corr = bandpass_corr)

                #make an array to store header information for the spd files
                temp_filename = basename+"_DM%.1f_%.1fs_rank_%i"%(spdcand.subdm, \
                                                   spdcand.topo_start_time, rank)
                
                print_debug("Running waterfaller with Zero-DM OFF...")
                
                # Add additional information to the header information array
                data, Data_dedisp_nozerodm = waterfall_array(rawdatafile, spdcand.start, \
                                             spdcand.duration, spdcand.dm, spdcand.nbins, spdcand.nsub, \
                                             spdcand.subdm, spdcand.zerodm, spdcand.downsamp, \
                                             spdcand.scaleindep, spdcand.width_bins, \
                                             spdcand.mask, maskfile, spdcand.bandpass_corr)

                text_array = np.array([args[0], rawdatafile.specinfo.telescope, \
                                       rawdatafile.specinfo.ra_str, rawdatafile.specinfo.dec_str, \
                                       rawdatafile.specinfo.start_MJD[0], \
                                       rank, spdcand.nsub, spdcand.nbins, spdcand.subdm, \
                                       spdcand.sigma, spdcand.sample_number, spdcand.duration, \
                                       spdcand.width_bins, spdcand.pulse_width, rawdatafile.tsamp,\
                                       rawdatafile.specinfo.T, spdcand.topo_start_time, data.starttime, \
                                       data.dt,data.numspectra, data.freqs.min(), data.freqs.max()])

                #### Array for plotting Dedispersed waterfall plot zerodm - ON
                print_debug("Running Waterfaller with Zero-DM ON...")
                zerodm=True
                data, Data_dedisp_zerodm = waterfall_array(rawdatafile, spdcand.start, \
                                           spdcand.duration, spdcand.dm, spdcand.nbins, spdcand.nsub, \
                                           spdcand.subdm, zerodm, spdcand.downsamp, \
                                           spdcand.scaleindep, spdcand.width_bins, \
                                           spdcand.mask, maskfile, spdcand.bandpass_corr)
                ####Sweeped without zerodm
                spdcand.read_from_file(values[ii], rawdatafile.tsamp, rawdatafile.specinfo.N, \
                                      rawdatafile.frequencies[0], rawdatafile.frequencies[-1], \
                                      rawdatafile, loc_pulse=loc_pulse, dedisp = None, \
                                      scaleindep = None, zerodm = None, mask = mask, \
                                      barytime=barytime, \
                                      nsub = nsub, bandpass_corr = bandpass_corr)
                data, Data_nozerodm = waterfall_array(rawdatafile, spdcand.start, \
                                           spdcand.duration, spdcand.dm, spdcand.nbins, spdcand.nsub, \
                                           spdcand.subdm, spdcand.zerodm, spdcand.downsamp, \
                                           spdcand.scaleindep, spdcand.width_bins, \
                                           spdcand.mask, maskfile, spdcand.bandpass_corr)
                text_array = np.append(text_array, spdcand.sweep_duration)
                text_array = np.append(text_array, data.starttime)
                text_array = np.append(text_array, spdcand.bary_start_time)
                text_array = np.append(text_array, man_params)
                # Array to Construct the sweep
                if spdcand.sweep_dm is not None:
                    ddm = spdcand.sweep_dm-data.dm
                    delays = psr_utils.delay_from_DM(ddm, data.freqs)
                    delays -= delays.min()
                    delays_nozerodm = delays
                    freqs_nozerodm = data.freqs
                # Sweeped with zerodm-on 
                zerodm = True
                #downsamp_temp = 1
                data, Data_zerodm = waterfall_array(rawdatafile, spdcand.start, \
                                           spdcand.duration, spdcand.dm, spdcand.nbins, spdcand.nsub, \
                                           spdcand.subdm, zerodm, spdcand.downsamp, \
                                           spdcand.scaleindep, spdcand.width_bins, \
                                           spdcand.mask, maskfile, spdcand.bandpass_corr)
                # Saving the arrays into the .spd file.
                with open(temp_filename+".spd", 'wb') as f:
                    np.savez_compressed(f, \
                                        Data_dedisp_nozerodm = Data_dedisp_nozerodm.astype(np.float16),\
                                        Data_dedisp_zerodm = Data_dedisp_zerodm.astype(np.float16),\
                                        Data_nozerodm = Data_nozerodm.astype(np.float16),\
                                        delays_nozerodm = delays_nozerodm, \
                                        freqs_nozerodm = freqs_nozerodm,\
                                        Data_zerodm = Data_zerodm.astype(np.float16), \
                                        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)
                #### Arrays for Plotting DM vs Time is in plot_spd.plot(...)
                if plot:
                    print_debug("Now plotting...")
                    plot_spd.plot(temp_filename+".spd", args[1:], \
                                  spec_width=1.5, loc_pulse=loc_pulse, \
                                  xwin=False, outfile=basename, \
                                  just_waterfall=just_waterfall, \
                                  integrate_spec=integrate_spec, \
                                  integrate_ts=integrate_ts, \
                                  disp_pulse=disp_pulse, tar = None)
                    print_debug("Finished plot %i " %ii+strftime("%Y-%m-%d %H:%M:%S"))
                numcands+= 1
                print_debug('Finished sp_candidate : %i'%numcands)
                if numcands >= maxnumcands:    # Max number of candidates to plot 100.
                    loop_must_break = True
                    break
            if loop_must_break:
                break

        print_debug("Finished group %i... "%rank+strftime("%Y-%m-%d %H:%M:%S"))
    print_debug("Finished running waterfaller... "+strftime("%Y-%m-%d %H:%M:%S"))
Exemple #3
0
def make_spd_from_man_params(spdcand, rawdatafile, \
                             txtfile, maskfile, \
                             plot, just_waterfall, \
                             subdm, dm, sweep_dm, \
                             sigma, \
                             start_time, duration, \
                             width_bins, nbins, downsamp, \
                             nsub, \
                             scaleindep, \
                             spec_width, loc_pulse, \
                             integrate_ts, integrate_spec, disp_pulse, \
                             basename, \
                             mask, bandpass_corr, barytime, man_params):            
    """
    Makes spd files from output files of rratrap. 
    Inputs:
        spdcand: spcand parameters instance (read in spcand.params)
        rawdatafile: psrfits file instance
        txtfile: rratrap output file (groups.txt file)
        maskfile: rfifind mask file. need this file if you want to remove the bandpass 
                  or use rfifind mask information.
        plot: do you want to produce the plots as well? 
        just_waterfall: Do you just want to make the waterfall plots.
        subdm: DM to use when subbanding.
        dm: DM to use when dedispersing data for plot. 
        sweep_dm: Show the frequency sweep using this DM.
        sigma: signal-to-noise of the pulse
        start_time: start time of the data to be read in for waterfalling.
        duration: duration of data to be waterfalled.
        width_bins: Smooth each channel/subband with a boxcar width_bins wide.
        nbins: Number of time bins to plot. This option overrides
                the duration argument. 
        downsamp: Factor to downsample in time by. Default: Don't downsample.
        nsub: Number of subbands to use. Must be a factor of number of channels.
        scaleindep:Do you want to scale each subband independently?(Type: Boolean)
        spec_width: Twice this number times the pulse_width around the pulse to consider for the spectrum
        loc_pulse: Fraction of the window length where the pulse is located.(eg. 0.25 = 1/4th of the way in.
                                                                             0.5 = middle of the plot)
        integrate_ts: Do you want to display the dedispersed time series in the plot?
        integrate_spec: Do you want to display the pulse spectrum in the plot?
        disp_pulse: Do you want to see the inset dispersed pulse in the plot?
        basename: output basename of the file. Appended with _DM_TIME(s)_RANK.spd 
        mask: Do you want to mask out rfi contaminated channels?
        bandpass_corr: Do you want to remove the bandpass?
        barytime: Is the given time(s) barycentric?
        man_params: Do you want to specify the parameters for waterfalling 
                    manually? If yes, I suggest using the function make_spd_from_man_params().
                    (I suggest giving it the rratrap output file)    
    Outputs:
       Binary npz file containing the necessary arrays and header information to generate the spd plots.
    """
    rank = None
    if not nsub:
        nsub = rawdatafile.nchan

    # Array for Plotting Dedispersed waterfall plot - zerodm - OFF
    spdcand.manual_params(subdm, dm, sweep_dm, sigma, start_time, \
                         width_bins, downsamp, duration, nbins, nsub, rawdatafile.tsamp, \
                         rawdatafile.specinfo.N, \
                         rawdatafile.frequencies[0], rawdatafile.frequencies[-1], rawdatafile, \
                         loc_pulse=loc_pulse, dedisp=True, scaleindep=False, zerodm=False, \
                         mask=mask, barytime=barytime, bandpass_corr=bandpass_corr)
    #make an array to store header information for the spd files
    temp_filename = basename+"_DM%.1f_%.1fs"%(spdcand.subdm, spdcand.topo_start_time)
           
    print_debug("Running waterfaller with Zero-DM OFF...")
    data, Data_dedisp_nozerodm = waterfall_array(rawdatafile, spdcand.start, \
                                 spdcand.duration, spdcand.dm, spdcand.nbins, spdcand.nsub, \
                                 spdcand.subdm, spdcand.zerodm, spdcand.downsamp, \
                                 spdcand.scaleindep, spdcand.width_bins, \
                                 spdcand.mask, maskfile, spdcand.bandpass_corr)
    # Add additional information to the header information array
    text_array = np.array([args[0], rawdatafile.specinfo.telescope, \
                           rawdatafile.specinfo.ra_str, rawdatafile.specinfo.dec_str, \
                           rawdatafile.specinfo.start_MJD[0], rank, \
                           spdcand.nsub, spdcand.nbins, \
                           spdcand.subdm, spdcand.sigma, spdcand.sample_number, \
                           spdcand.duration, spdcand.width_bins, spdcand.pulse_width, \
                           rawdatafile.tsamp, rawdatafile.specinfo.T, spdcand.topo_start_time, \
                           data.starttime, data.dt,data.numspectra, data.freqs.min(), \
                           data.freqs.max()])

    #### Array for plotting Dedispersed waterfall plot zerodm - ON
    print_debug("Running Waterfaller with Zero-DM ON...")
    zerodm=True
    data, Data_dedisp_zerodm = waterfall_array(rawdatafile, spdcand.start, \
                                 spdcand.duration, spdcand.dm, spdcand.nbins, spdcand.nsub, \
                                 spdcand.subdm, zerodm, spdcand.downsamp, \
                                 spdcand.scaleindep, spdcand.width_bins, \
                                 spdcand.mask, maskfile, spdcand.bandpass_corr)
    ####Sweeped without zerodm
    spdcand.manual_params(subdm, dm, sweep_dm, sigma, start_time, \
                          width_bins, downsamp, duration, nbins, nsub, rawdatafile.tsamp, \
                          rawdatafile.specinfo.N, \
                          rawdatafile.frequencies[0], rawdatafile.frequencies[-1], rawdatafile, \
                          loc_pulse=loc_pulse, dedisp=None, scaleindep=None, zerodm=None, mask=mask, \
                          barytime=barytime, bandpass_corr=bandpass_corr)
    data, Data_nozerodm = waterfall_array(rawdatafile, spdcand.start, \
                                 spdcand.duration, spdcand.dm, spdcand.nbins, spdcand.nsub, \
                                 spdcand.subdm, spdcand.zerodm, spdcand.downsamp, \
                                 spdcand.scaleindep, spdcand.width_bins, \
                                 spdcand.mask, maskfile, spdcand.bandpass_corr)
    text_array = np.append(text_array, spdcand.sweep_duration)
    text_array = np.append(text_array, data.starttime)
    text_array = np.append(text_array, spdcand.bary_start_time)
    text_array = np.append(text_array, man_params)
    # Array to Construct the sweep
    if spdcand.sweep_dm is not None:
        ddm = spdcand.sweep_dm-data.dm
        delays = psr_utils.delay_from_DM(ddm, data.freqs)
        delays -= delays.min()
        delays_nozerodm = delays
        freqs_nozerodm = data.freqs
    # Sweeped with zerodm-on 
    zerodm = True
    #downsamp_temp = 1
    data, Data_zerodm = waterfall_array(rawdatafile, spdcand.start, \
                                 spdcand.duration, spdcand.dm, spdcand.nbins, spdcand.nsub, \
                                 spdcand.subdm, zerodm, spdcand.downsamp, \
                                 spdcand.scaleindep, spdcand.width_bins, \
                                 spdcand.mask, maskfile, spdcand.bandpass_corr)
    with open(temp_filename+".spd", 'wb') as f:
        np.savez_compressed(f, \
                            Data_dedisp_nozerodm = Data_dedisp_nozerodm.astype(np.float16),\
                            Data_dedisp_zerodm = Data_dedisp_zerodm.astype(np.float16),\
                            Data_nozerodm = Data_nozerodm.astype(np.float16),\
                            delays_nozerodm = delays_nozerodm, \
                            freqs_nozerodm = freqs_nozerodm,\
                            Data_zerodm = Data_zerodm.astype(np.float16), \
                            text_array = text_array)
    #### Arrays for Plotting DM vs Time is in plot_spd.plot(...)
    if plot:
        print_debug("Now plotting...")
        plot_spd.plot(temp_filename+".spd", args[1:], \
                      spec_width=spec_width, loc_pulse=loc_pulse, xwin=False, \
                      outfile = basename, just_waterfall=just_waterfall, \
                      integrate_spec=integrate_spec, integrate_ts=integrate_ts, \
                      disp_pulse=disp_pulse, tar = None)
Exemple #4
0
def make_spd_from_man_params(spdcand, rawdatafile, \
                             txtfile, maskfile, \
                             plot, just_waterfall, \
                             subdm, dm, sweep_dm, \
                             sigma, \
                             start_time, duration, \
                             width_bins, nbins, downsamp, \
                             nsub, \
                             scaleindep, \
                             spec_width, loc_pulse, \
                             integrate_ts, integrate_spec, disp_pulse, \
                             basename, \
                             mask, bandpass_corr, barytime, man_params):            
    """
    Makes spd files from output files of rratrap. 
    Inputs:
        spdcand: spcand parameters instance (read in spcand.params)
        rawdatafile: psrfits file instance
        txtfile: rratrap output file (groups.txt file)
        maskfile: rfifind mask file. need this file if you want to remove the bandpass 
                  or use rfifind mask information.
        plot: do you want to produce the plots as well? 
        just_waterfall: Do you just want to make the waterfall plots.
        subdm: DM to use when subbanding.
        dm: DM to use when dedispersing data for plot. 
        sweep_dm: Show the frequency sweep using this DM.
        sigma: signal-to-noise of the pulse
        start_time: start time of the data to be read in for waterfalling.
        duration: duration of data to be waterfalled.
        width_bins: Smooth each channel/subband with a boxcar width_bins wide.
        nbins: Number of time bins to plot. This option overrides
                the duration argument. 
        downsamp: Factor to downsample in time by. Default: Don't downsample.
        nsub: Number of subbands to use. Must be a factor of number of channels.
        scaleindep:Do you want to scale each subband independently?(Type: Boolean)
        spec_width: Twice this number times the pulse_width around the pulse to consider for the spectrum
        loc_pulse: Fraction of the window length where the pulse is located.(eg. 0.25 = 1/4th of the way in.
                                                                             0.5 = middle of the plot)
        integrate_ts: Do you want to display the dedispersed time series in the plot?
        integrate_spec: Do you want to display the pulse spectrum in the plot?
        disp_pulse: Do you want to see the inset dispersed pulse in the plot?
        basename: output basename of the file. Appended with _DM_TIME(s)_RANK.spd 
        mask: Do you want to mask out rfi contaminated channels?
        bandpass_corr: Do you want to remove the bandpass?
        barytime: Is the given time(s) barycentric?
        man_params: Do you want to specify the parameters for waterfalling 
                    manually? If yes, I suggest using the function make_spd_from_man_params().
                    (I suggest giving it the rratrap output file)    
    Outputs:
       Binary npz file containing the necessary arrays and header information to generate the spd plots.
    """
    rank = None
    if not nsub:
        nsub = rawdatafile.nchan

    # Array for Plotting Dedispersed waterfall plot - zerodm - OFF
    spdcand.manual_params(subdm, dm, sweep_dm, sigma, start_time, \
                         width_bins, downsamp, duration, nbins, nsub, rawdatafile.tsamp, \
                         rawdatafile.specinfo.N, \
                         rawdatafile.frequencies[0], rawdatafile.frequencies[-1], rawdatafile, \
                         loc_pulse=loc_pulse, dedisp=True, scaleindep=False, zerodm=False, \
                         mask=mask, barytime=barytime, bandpass_corr=bandpass_corr)
    #make an array to store header information for the spd files
    temp_filename = basename+"_DM%.1f_%.1fs"%(spdcand.subdm, spdcand.topo_start_time)
           
    print_debug("Running waterfaller with Zero-DM OFF...")
    data, Data_dedisp_nozerodm = waterfall_array(rawdatafile, spdcand.start, \
                                 spdcand.duration, spdcand.dm, spdcand.nbins, spdcand.nsub, \
                                 spdcand.subdm, spdcand.zerodm, spdcand.downsamp, \
                                 spdcand.scaleindep, spdcand.width_bins, \
                                 spdcand.mask, maskfile, spdcand.bandpass_corr)
    # Add additional information to the header information array
    text_array = np.array([args[0], rawdatafile.specinfo.telescope, \
                           rawdatafile.specinfo.ra_str, rawdatafile.specinfo.dec_str, \
                           rawdatafile.specinfo.start_MJD[0], rank, \
                           spdcand.nsub, spdcand.nbins, \
                           spdcand.subdm, spdcand.sigma, spdcand.sample_number, \
                           spdcand.duration, spdcand.width_bins, spdcand.pulse_width, \
                           rawdatafile.tsamp, rawdatafile.specinfo.T, spdcand.topo_start_time, \
                           data.starttime, data.dt,data.numspectra, data.freqs.min(), \
                           data.freqs.max()])

    #### Array for plotting Dedispersed waterfall plot zerodm - ON
    print_debug("Running Waterfaller with Zero-DM ON...")
    zerodm=True
    data, Data_dedisp_zerodm = waterfall_array(rawdatafile, spdcand.start, \
                                 spdcand.duration, spdcand.dm, spdcand.nbins, spdcand.nsub, \
                                 spdcand.subdm, zerodm, spdcand.downsamp, \
                                 spdcand.scaleindep, spdcand.width_bins, \
                                 spdcand.mask, maskfile, spdcand.bandpass_corr)
    ####Sweeped without zerodm
    spdcand.manual_params(subdm, dm, sweep_dm, sigma, start_time, \
                          width_bins, downsamp, duration, nbins, nsub, rawdatafile.tsamp, \
                          rawdatafile.specinfo.N, \
                          rawdatafile.frequencies[0], rawdatafile.frequencies[-1], rawdatafile, \
                          loc_pulse=loc_pulse, dedisp=None, scaleindep=None, zerodm=None, mask=mask, \
                          barytime=barytime, bandpass_corr=bandpass_corr)
    data, Data_nozerodm = waterfall_array(rawdatafile, spdcand.start, \
                                 spdcand.duration, spdcand.dm, spdcand.nbins, spdcand.nsub, \
                                 spdcand.subdm, spdcand.zerodm, spdcand.downsamp, \
                                 spdcand.scaleindep, spdcand.width_bins, \
                                 spdcand.mask, maskfile, spdcand.bandpass_corr)
    text_array = np.append(text_array, spdcand.sweep_duration)
    text_array = np.append(text_array, data.starttime)
    text_array = np.append(text_array, spdcand.bary_start_time)
    text_array = np.append(text_array, man_params)
    # Array to Construct the sweep
    if spdcand.sweep_dm is not None:
        ddm = spdcand.sweep_dm-data.dm
        delays = psr_utils.delay_from_DM(ddm, data.freqs)
        delays -= delays.min()
        delays_nozerodm = delays
        freqs_nozerodm = data.freqs
    # Sweeped with zerodm-on 
    zerodm = True
    #downsamp_temp = 1
    data, Data_zerodm = waterfall_array(rawdatafile, spdcand.start, \
                                 spdcand.duration, spdcand.dm, spdcand.nbins, spdcand.nsub, \
                                 spdcand.subdm, zerodm, spdcand.downsamp, \
                                 spdcand.scaleindep, spdcand.width_bins, \
                                 spdcand.mask, maskfile, spdcand.bandpass_corr)
    with open(temp_filename+".spd", 'wb') as f:
        np.savez_compressed(f, \
                            Data_dedisp_nozerodm = Data_dedisp_nozerodm.astype(np.float16),\
                            Data_dedisp_zerodm = Data_dedisp_zerodm.astype(np.float16),\
                            Data_nozerodm = Data_nozerodm.astype(np.float16),\
                            delays_nozerodm = delays_nozerodm, \
                            freqs_nozerodm = freqs_nozerodm,\
                            Data_zerodm = Data_zerodm.astype(np.float16), \
                            text_array = text_array)
    #### Arrays for Plotting DM vs Time is in plot_spd.plot(...)
    if plot:
        print_debug("Now plotting...")
        plot_spd.plot(temp_filename+".spd", args[1:], \
                      spec_width=spec_width, loc_pulse=loc_pulse, xwin=False, \
                      outfile = basename, just_waterfall=just_waterfall, \
                      integrate_spec=integrate_spec, integrate_ts=integrate_ts, \
                      disp_pulse=disp_pulse, tar = None)