Exemplo n.º 1
0
def waterfall_array(rawdatafile, start, duration, dm, nbins, nsub, subdm, zerodm, \
                    downsamp, scaleindep, width_bins, mask, maskfn, bandpass_corr):
    """
    Runs the waterfaller. If dedispersing, there will be extra bins added to the 2D plot.
    Inputs:
        Inputs required for the waterfaller. dm, nbins, etc. 
    Outputs:
       data: 2D array as an "object" 
       array: 2D array ready to be plotted by sp_pgplot.plot_waterfall(array). 
    """
    data, bins, nbins, start = waterfaller.waterfall(rawdatafile, start, duration, dm=dm, nbins=nbins, \
                                                     nsub=nsub, subdm=subdm, zerodm=zerodm, \
                                                     downsamp=downsamp, scaleindep=scaleindep, \
                                                     width_bins=width_bins, mask=mask, \
                                                     maskfn=maskfn, bandpass_corr=bandpass_corr)
    array = np.array(data.data)
    if dm is not None:  # If dedispersing the data, extra bins will be added. We need to cut off the extra bins to get back the appropriate window size.
        ragfac = float(nbins) / bins
        dmrange, trange = array.shape
        nbinlim = np.int(trange * ragfac)
    else:
        nbinlim = nbins
    array = array[..., :nbinlim]
    array = (array[::-1]).astype(np.float16)
    return data, array
Exemplo n.º 2
0
def waterfall_array(rawdatafile, start, duration, dm, nbins, nsub, subdm, zerodm, \
                    downsamp, scaleindep, width_bins, mask, maskfn, bandpass_corr):
    """
    Runs the waterfaller. If dedispersing, there will be extra bins added to the 2D plot.
    Inputs:
        Inputs required for the waterfaller. dm, nbins, etc. 
    Outputs:
       data: 2D array as an "object" 
       array: 2D array ready to be plotted by sp_pgplot.plot_waterfall(array). 
    """
    data, bins, nbins, start = waterfaller.waterfall(rawdatafile, start, duration, dm=dm, nbins=nbins, \
                                                     nsub=nsub, subdm=subdm, zerodm=zerodm, \
                                                     downsamp=downsamp, scaleindep=scaleindep, \
                                                     width_bins=width_bins, mask=mask, \
                                                     maskfn=maskfn, bandpass_corr=bandpass_corr)
    array = np.array(data.data)
    if dm is not None:            # If dedispersing the data, extra bins will be added. We need to cut off the extra bins to get back the appropriate window size.   
        ragfac = float(nbins)/bins
        dmrange, trange = array.shape
        nbinlim = np.int(trange * ragfac)
    else:
        nbinlim = nbins
    array = array[..., :nbinlim]
    array = (array[::-1]).astype(np.float16)
    return data, array
Exemplo n.º 3
0
def waterfall_array(duration, nbins, zerodm, nsub, subdm, dm, downsamp, scaleindep, width_bins, rawdatafile, start, mask , maskfn, bandpass_corr):
    """
    Runs the waterfaller. If dedispersing, there will be extra bins added to the 2D plot.
    Inputs:
        Inputs required for the waterfaller. dm, nbins, etc. 
    Outputs:
       data: 2D array as an "object" 
       array: 2D array ready to be plotted by sp_pgplot.plot_waterfall(array). 
    """
    data, bins, nbins, new_start = waterfaller.waterfall(rawdatafile, start, \
          duration, dm=dm, nbins=nbins, nsub=nsub, subdm=subdm, zerodm=zerodm, \
          downsamp=downsamp, scaleindep=scaleindep, width_bins=width_bins, \
          mask=mask, maskfn=maskfn, bandpass_corr=bandpass_corr)
    array = np.array(data.data)
    #if dm is not None:            # If dedispersing the data, extra bins will be added. We need to cut off the extra bins to get back the appropriate window size.   
    #    ragfac = float(nbins)/bins
    #    dmrange, trange = array.shape
    #    nbinlim = np.int(trange * ragfac)
    #else:
    #    nbinlim = nbins
    if dm is None:
        nbinlim = nbins # this can be handled by sweep_duration (since already replicated)
    else:
        nbinlim = np.int(duration/data.dt) # should be equivalent of above, may be able to stop returning bins and nbins
    array = array[..., :nbinlim]
    array = (array[::-1]).astype(np.float16)
    return data, array, new_start
Exemplo n.º 4
0
def fil2spec(fname,
             num_channels,
             num_time,
             spectra_array,
             total_samples,
             samples_per_file=50):
    """
    Given a filename, takes time samples from filterbank file
    and converts them into Spectra objects, which will then be
    randomly dedispersed and used to inject FRBs into.

    Returns:
        spectra_array : list
            A list of Spectra objects.
        freq : numpy.ndarray
            Frequency range of filterbank file.
    """

    # get filterbank file as input and output a Spectra object
    raw_filterbank_file = filterbank.FilterbankFile(fname)

    # grab total observation time to split up samples
    t_obs = float(
        subprocess.check_output(
            ['/usr/local/sigproc/bin/header', fname, '-tobs']))

    # generate samples_per_file random timesteps to sample from in filterbank file
    random_timesteps = np.random.choice(np.arange(int(t_obs)),
                                        size=samples_per_file)

    # grab time samples beginning at random start times + ending at num_time bins
    for timestep in tqdm(random_timesteps):
        # get spectra object at some timestep, incrementing timestep if successful
        spectra_obj = waterfall(raw_filterbank_file,
                                start=timestep,
                                duration=1,
                                dm=0,
                                nbins=num_time,
                                nsub=num_channels)[0]
        spectra_array.append(spectra_obj)

    freq = raw_filterbank_file.frequencies

    return spectra_array, freq
Exemplo n.º 5
0
def main(fits, database, time, DM, IMJD, SMJD, sigma, duration=0.01, pulse_id=4279, top_freq=0., directory='.',\
    FRB_name='FRB121102', downsamp=1., beam=0, group=0, plot_standard=True, plot_zoom=True, plot_wide=False):
    num_elements = time.size
    if isinstance(DM, float) or isinstance(DM, int):
        DM = np.zeros(num_elements) + DM
    if isinstance(sigma, float) or isinstance(sigma, int):
        sigma = np.zeros(num_elements) + sigma
    if isinstance(duration, float) or isinstance(duration, int):
        duration = np.zeros(num_elements) + duration
    if isinstance(pulse_id, float) or isinstance(pulse_id, int):
        pulse_id = np.zeros(num_elements) + pulse_id
    if isinstance(downsamp, float) or isinstance(downsamp, int):
        downsamp = np.zeros(num_elements) + downsamp

    if FRB_name == 'FRB121102':
        rawdata = psrfits.PsrfitsFile(fits)
        observation = os.path.basename(fits)
        observation = observation[:observation.find('_subs_')]
    if FRB_name == 'FRB180814':
        rawdata = filterbank.FilterbankFile(fits)
        observation = os.path.basename(fits)
        observation = observation[:observation.find('.0001.')]
    events = pd.read_hdf(database, 'events')

    #Fractional day
    SMJD = SMJD / 86400.

    for i, t in enumerate(time):
        if FRB_name == 'FRB130628':
            fits = glob("%s/*b%ds%d*.fits" % (fits, beam[i], group[i]))[0]
            rawdata = psrfits.PsrfitsFile(fits)
            observation = os.path.basename(fits)
            observation = os.path.splitext(observation)[0]
        pulse_events = events[events.Pulse == pulse_id[i]]

        #zero-DM filering version
        start_time = t - 0.05
        plot_duration = 0.1
        if plot_standard:
            zero_dm_data, nbinsextra, nbins, zero_dm_start = waterfall(rawdata, start_time, plot_duration, DM[i],\
             nbins=None, nsub=None, subdm = DM, zerodm=True, downsamp=1,\
             scaleindep=False, width_bins=1, mask=False, maskfn=None,\
             bandpass_corr=False, ref_freq=None)
            #non-zero-DM filtering version
            data, nbinsextra, nbins, start = waterfall(rawdata, start_time, plot_duration, DM[i],\
             nbins=None, nsub=None, subdm = DM, zerodm=False, downsamp=1,\
             scaleindep=False, width_bins=1, mask=False, maskfn=None,\
             bandpass_corr=False, ref_freq=None)
            plotter(data, start, plot_duration, t, DM[i], IMJD[i], SMJD[i], duration[i], top_freq,\
             sigma[i], directory, FRB_name, observation, zero_dm_data, zero_dm_start, pulse_events=pulse_events, zoom=False, idx=i, pulse_id=pulse_id[i], downsamp=False)

#Zoomed version
        start_time = t - 0.01
        plot_duration = 0.03
        if plot_zoom:
            zero_dm_data, nbinsextra, nbins, zero_dm_start = waterfall(rawdata, start_time, plot_duration, DM[i],\
             nbins=None, nsub=None, subdm = DM, zerodm=True, downsamp=1,\
             scaleindep=False, width_bins=1, mask=False, maskfn=None,\
             bandpass_corr=False, ref_freq=None)
            data, nbinsextra, nbins, start = waterfall(rawdata, start_time, plot_duration, DM[i],\
             nbins=None, nsub=None, subdm = DM, zerodm=False, downsamp=1,\
             scaleindep=False, width_bins=1, mask=False, maskfn=None,\
             bandpass_corr=False, ref_freq=None)
            plotter(data, start, plot_duration, t, DM[i], IMJD[i], SMJD[i], duration[i], top_freq,\
             sigma[i], directory, FRB_name, observation, zero_dm_data, zero_dm_start, pulse_events=pulse_events, zoom=True, idx=i, pulse_id=pulse_id[i], downsamp=False)

#Wide version
        start_time = t - 0.5
        plot_duration = 1.
        if plot_wide:
            zero_dm_data, nbinsextra, nbins, zero_dm_start = waterfall(rawdata, start_time, plot_duration, DM[i],\
                    nbins=None, nsub=None, subdm = DM, zerodm=True, downsamp=1,\
                    scaleindep=False, width_bins=1, mask=False, maskfn=None,\
                    bandpass_corr=False, ref_freq=None)
            #non-zero-DM filtering version
            data, nbinsextra, nbins, start = waterfall(rawdata, start_time, plot_duration, DM[i],\
                    nbins=None, nsub=None, subdm = DM, zerodm=False, downsamp=1,\
                    scaleindep=False, width_bins=1, mask=False, maskfn=None,\
                    bandpass_corr=False, ref_freq=None)

            plotter(data, start, plot_duration, t, DM[i], IMJD[i], SMJD[i], duration[i], top_freq,\
                    sigma[i], directory, FRB_name, observation, zero_dm_data, zero_dm_start, pulse_events=pulse_events, zoom=False, idx=i, pulse_id=pulse_id[i], downsamp=False)