예제 #1
0
def freq_average_file(filename, freqs, pol, bw=1.):
    '''
    take a list of frequency bands of width bw centered at freq from 
    each filterbank sample calculate the average over time.
    the minimum value of this averaged time series will be returned.

    Parameters
    ----------
    filename : str
        the data file to process
    freqs : int or list
        list of the selected center frequencies in MHz
    pol : str
        polarization to process
    bw : float, optional
        the bandwidth to include in the frequency averaging

    Returns
    -------
    freq_avg : numpy.array
                       array of frequency averaged time series minimum values,
                       each corresponding to its respective center
                       frequency at input
    '''
    _, filedata = _load_data(filename, pol)
    freq_avg_list = []
    if isinstance(freqs, list):
        freqs.sort()
        for i in range(len(freqs)):
            lfbin = freq2bin(freqs[i] - bw / 2.)
            hfbin = freq2bin(freqs[i] + bw / 2.)
            num_fbins = hfbin - lfbin
            num_tbins = np.shape(filedata)[1]        
            avg_ts = np.average(filedata[lfbin:hfbin,:], axis=0)
            freq_avg_list.append(deepcopy(avg_ts))
        rows = len(freq_avg_list)
        cols = max([len(x) for x in freq_avg_list])
        data = np.zeros((rows,cols), dtype=np.float64)
        for i in range(rows):
            data[i,:] = freq_avg_list[i]
    else:
        lfbin = freq2bin(freqs - bw / 2.)
        hfbin = freq2bin(freqs + bw / 2.)
        num_fbins = hfbin - lfbin
        avg_ts = np.average(filedata[lfbin:hfbin,:], axis=0)
        data = avg_ts
        

    return data
예제 #2
0
def freq_average_file(filename, freqs, pol, bw=1.):
    '''
    take a list of frequency bands of width bw centered at freq from 
    each filterbank sample calculate the average over time.
    the minimum value of this averaged time series will be returned.

    Parameters
    ----------
    filename : str
        the data file to process
    freqs : int or list
        list of the selected center frequencies in MHz
    pol : str
        polarization to process
    bw : float, optional
        the bandwidth to include in the frequency averaging

    Returns
    -------
    freq_avg : numpy.array
                       array of frequency averaged time series minimum values,
                       each corresponding to its respective center
                       frequency at input
    '''
    _, filedata = _load_data(filename, pol)
    freq_avg_list = []
    if isinstance(freqs, list):
        freqs.sort()
        for i in range(len(freqs)):
            lfbin = freq2bin(freqs[i] - bw / 2.)
            hfbin = freq2bin(freqs[i] + bw / 2.)
            num_fbins = hfbin - lfbin
            num_tbins = np.shape(filedata)[1]
            avg_ts = np.average(filedata[lfbin:hfbin, :], axis=0)
            freq_avg_list.append(deepcopy(avg_ts))
        rows = len(freq_avg_list)
        cols = max([len(x) for x in freq_avg_list])
        data = np.zeros((rows, cols), dtype=np.float64)
        for i in range(rows):
            data[i, :] = freq_avg_list[i]
    else:
        lfbin = freq2bin(freqs - bw / 2.)
        hfbin = freq2bin(freqs + bw / 2.)
        num_fbins = hfbin - lfbin
        avg_ts = np.average(filedata[lfbin:hfbin, :], axis=0)
        data = avg_ts

    return data
예제 #3
0
    def chfreq(self, new_freq):
        """Change to a new calibration frequency.

		Parameters
		----------
		new_freq : int or float
			The new frequency to work with in megahertz.
		"""
        self.freq = new_freq
        self.freqbin = pd.freq2bin(new_freq)
예제 #4
0
파일: lofasmcal.py 프로젝트: ldartez/lofasm
    def chfreq(self, new_freq):
        """Change to a new calibration frequency.

        Parameters
        ----------
        new_freq : int or float
            The new frequency to work with in megahertz.
        """
        self.freq = new_freq
        self.freqbin = pd.freq2bin(new_freq)
예제 #5
0
    def get(self):
        '''
        retrieve values
        '''
        if self.correlation_variable.get():
            results.current_correlation = self.correlation_variable.get()
            self.current_correlation_label.configure(
                text=results.current_correlation)

        if self.lfEntry.get():  # If the Entry field is not empty
            results.lower_freq = float(self.lfEntry.get())  # Get the new value
            self.l7.configure(text=str(results.lower_freq) +
                              ' MHz')  # update label
            #self.pow_spec_plot.set_xlim(int(results.lower_freq),int(results.upper_freq))
            #self.filter_bank_plot.set_ylim(int(int(results.lower_freq)*10.24),int(int(results.upper_freq)*10.24))
            self.pow_spec_plot.set_xlim(pdat.freq2bin(results.lower_freq),
                                        pdat.freq2bin(results.upper_freq))
            self.filter_bank_plot.set_ylim(pdat.freq2bin(results.lower_freq),
                                           pdat.freq2bin(results.upper_freq))

        if self.ufEntry.get():  # If the Entry field is not empty
            results.upper_freq = float(self.ufEntry.get())  # Get the new value
            self.l8.configure(text=str(results.upper_freq) +
                              ' MHz')  # update label
            #self.pow_spec_plot.set_xlim(int(results.lower_freq),int(results.upper_freq))
            #self.filter_bank_plot.set_ylim(int(int(results.lower_freq)*10.24),int(int(results.upper_freq)*10.24))
            self.pow_spec_plot.set_xlim(pdat.freq2bin(results.lower_freq),
                                        pdat.freq2bin(results.upper_freq))
            self.filter_bank_plot.set_ylim(pdat.freq2bin(results.lower_freq),
                                           pdat.freq2bin(results.upper_freq))

        if self.upEntry.get():  # If the Entry field is not empty
            results.upper_power = self.upEntry.get()  # Get the new value
            self.l9.configure(text=str(results.upper_power) +
                              ' dBm')  # update label
            self.pow_spec_plot.set_ylim(int(results.lower_power),
                                        int(results.upper_power))

        if self.lpEntry.get():  # If the Entry field is not empty
            results.lower_power = self.lpEntry.get()  # Get the new value
            self.l10.configure(text=str(results.lower_power) +
                               ' dBm')  # update label
            self.pow_spec_plot.set_ylim(int(results.lower_power),
                                        int(results.upper_power))
예제 #6
0
cwd2 = os.getcwd()
i = 0

lst = os.listdir(cwd2)
lst.sort()
for filename2 in lst:
    if filename2.endswith(".bbx.gz"):
        lf = bbx.LofasmFile(os.path.join(filename2))
        lf.read_data()

        countavgCC[i] = np.average(lf.data)
        print(filename2 + " average added to array")
        print("\naverage = " + str(countavgCC[i]))

        spect_avg = np.average(lf.data, axis=0)
        countfreqCC[i] = spect_avg[pdat.freq2bin(50)]
        print(filename2 + " freq added to array")
        print("average freq = " + str(countfreqCC[i]))

        countbinCC[i] = np.average(lf.data, axis=0)
        print(filename2 + " avg bin added to array")

        i += 1

        lf.close()

#go into DD channel and take an average of the values in the array
os.chdir(cwd1)
os.chdir(cwd1 + "/bbx/DD")
cwd3 = os.getcwd()
i = 0
예제 #7
0
def avgpow(lf, freq):
    x = lf.data[freq2bin(freq), :]
    return (np.mean(x))
예제 #8
0
    return (np.mean(x))


if __name__ == '__main__':
    import argparse
    p = argparse.ArgumentParser()
    p.add_argument('fnames', nargs='+')
    p.add_argument('freq', type=float)
    args = p.parse_args()

    x = []

    for f in args.fnames:
        lf = bbx.LofasmFile(f)
        lf.read_data()
        pows = lf.data[freq2bin(args.freq), :]
        avg = np.mean(pows)
        start = lf.header['start_time']
        start_cv = Time(start, scale='utc')
        st = int(lf.header['station'])
        lfstation = LoFASM_Stations[st]
        lon = lfstation.lon * 180 / np.pi
        start_sr = start_cv.sidereal_time('mean', lon)
        start_hr = start_sr.hour

        powmodel = galaxyPower.calculatepower(start_hr, st, args.freq, 0)
        x.append((start_hr, avg, powmodel))

    t, avg, gal = zip(*x)

    def lst2pow(lst):
예제 #9
0
'''
pars_dict = vars(parser.parse_args())
bbxFileHandel = bbx.LofasmFile(pars_dict['path'])
bbxfile = pars_dict['path']
print "File to be read open. "

bbxFileHeader = bbxFileHandel.header
outPath = os.getcwd()
outPath = outPath + '/' + pars_dict['outfile']
outFile = bbx.LofasmFile(outPath, bbxFileHeader, mode='write')
print "File to write created. "

for i in range(int(bbxFileHeader['metadata']['dim1_len'])):
    bbxFileHandel.read_data(1)  # Read one line of data
    spectra = bbxFileHandel.data[:, :]  #.astype(np.float32)
    spectra[:, pdat.freq2bin(float(pars_dict['freq']))] = 0
    #    report(outFile)
    append_data(outFile, spectra)
    #    report(outFile)
    outFile.write()

outFile.close()
'''
data = bbxFileHandel.data[:, :].astype(np.float32)

# select frequancy to zero 
userin = float(pars_dict['freq'])
freqbin = pdat.freq2bin(userin)

# zero out that frequancy
data[:, freqbin] = 0
예제 #10
0
    x = []

    start_hr_arr = np.zeros(len(args.fnames))

    fil = args.fnames[0]
    lf = bbx.LofasmFile(fil)
    st = int(lf.header['station'])

    # lsts, pows = galaxyPower.loadfile(st, args.freq, args.hor)

    for ii, f in enumerate(args.fnames):  #for loop to read through the data
        lf = bbx.LofasmFile(f)  #and append to an empty list
        lf.read_data()  #the time in lst, the average power
        lofasm_pows = lf.data[:,
                              freq2bin(args.freq)]  #and the given galaxy power
        avg = np.mean(lofasm_pows)  #at that time

        #LOFASM 3 [
        # start = float(lf.header['start_mjd'])
        # start_postmjd = Time(start, format = 'mjd')
        # st = int(lf.header['station'])
        # lfstation = LoFASM_Stations[st]
        # lon = lfstation.lon * 180 / np.pi
        # start_sr = start_postmjd.sidereal_time('mean', lon)
        # start_hr = start_sr.hour
        # start_hr_arr[ii] = start_hr
        # #powmodel = galaxyPower.calculatepower(start_hr, lsts, pows)
        # ]

        # LOFASM 1 [
예제 #11
0
    fout = open("{}_{}{}".format(args.output,args.polarization.upper(), ".lofasm2d") \
                if not args.output.endswith('.lofasm2d') else args.output,'wb')
    
    #parse input filelist
    with open(args.filelist, 'r') as f:
        #only take files which end in ".lofasm" and are not commented out with '#'
        flist = [x.rstrip('\n') for x in f if x.rstrip('\n').endswith('.lofasm') and not x.startswith('#')]

    Nfiles = len(flist)
    Tsamp = pdat.getSampleTime(8192)
    dur_sec = 300.0 #file duration in seconds
    cadence = args.cadence
    medfilt_stride = args.stride
    #pol = args.polarization.upper()
    MAXSIZE = int(Nfiles * dur_sec / Tsamp / cadence) + 1
    HBIN = pdat.freq2bin(args.hf)
    LBIN = pdat.freq2bin(args.lf)
    Nbins = HBIN - LBIN
    print "bins: ({}, {}), BW: {}".format(HBIN,LBIN, args.hf-args.lf)


    #initialize complex data array in memory
    data = np.zeros((Nbins,MAXSIZE), dtype=np.complex)
    timestamps = []

    print "shape of initialized array: {}".format(np.shape(data))

    #loop over files and extract necessary samples
    i=0
    enterDataset = time()
예제 #12
0
    #output file
    fout = open("{}_{}{}".format(args.output,args.polarization.upper(), ".lofasm2d") \
                if not args.output.endswith('.lofasm2d') else args.output,'wb')

    #parse input filelist
    flist = glob(os.path.join(args.dataDir, '*.lofasm'))
    flist.sort()

    Nfiles = len(flist)
    Tsamp = pdat.getSampleTime(8192)
    dur_sec = 300.0  #file duration in seconds
    cadence = args.cadence
    medfilt_stride = args.stride
    #pol = args.polarization.upper()
    MAXSIZE = int(Nfiles * dur_sec / Tsamp / cadence) + 1
    HBIN = pdat.freq2bin(args.hf)
    LBIN = pdat.freq2bin(args.lf)
    Nbins = HBIN - LBIN
    print "bins: ({}, {}), BW: {}".format(HBIN, LBIN, args.hf - args.lf)

    #initialize complex data array in memory
    data = np.zeros((Nbins, MAXSIZE), dtype=np.complex)
    timestamps = []

    print "shape of initialized array: {}".format(np.shape(data))

    #loop over files and extract necessary samples
    i = 0
    enterDataset = time()

    for f in flist: