Example #1
0
def average(log_in, lo, l, b, record_id, noise=False, notes=None):
    """Averages spectra in a .log file and saves average to .npz with metadata

    Arguments:
        log_in: path to the .log file generated by takespec.takeSpec
        lo: lo frequency in MHz used
        l: galactic longitude of pointing, in degrees
        b: galactic latitude of pointing, in degrees
        noise (default=False): set to True if noise was turned on

    Puts averaged spectra into .npz file with following information
    "spec": averaged spectral data for each frequency bin
    "N": the number of spectra averaged
    "lo", "l", "b", "noise": the parameters passed in
    """
    # name the output directory by the galactic coords of the pointing
    pointing_dir = os.path.join(DATA, "l%.4f_b%.4f_%s" % (l, b, record_id))
    if not os.path.exists(pointing_dir):
        os.makedirs(pointing_dir)

    # name the file according to the lo frequency + time so it doesnt get overwritten
    time_str = time.strftime("%m-%d-%Y_%H%M%S")

    output_filename = "%slo-%.1f_%s" % ("noise-" if noise else "", lo, time_str)
    spec_out = os.path.join(pointing_dir, output_filename)

    specs = readspec_mod.readSpec(log_in)
    averaged_spec = np.mean(specs, 1)
    np.savez(spec_out, spec=averaged_spec, lo=lo, N=specs.shape[1],
            l=l, b=b, noise=noise, notes=notes)
Example #2
0
def spec_average(fname, fname_out):
    """Put in filename of .log binary (from takespec.takeSpec)
    Write output file as npy
    """
    # readspec_mod.readSpec has the side effect of writing file.npz...
    specs = readspec_mod.readSpec(fname)
    specAve = np.sum(specs, 1) / float(specs.shape[1])
    np.save(fname_out, specAve)
Example #3
0
def plot_spectra(files, fc=1272.4+150, title='', median=False, outfile=None):
    f_range = np.linspace(fc-6, fc+6, 8192)

    for filename in files:
        spec = readspec_mod.readSpec(filename)
        plt.plot(f_range, np.mean(spec,1), label=filename.split('/')[-1].split('.')[0])
        plt.title(title)
        plt.xlabel('MHz')
        plt.legend()
    if outfile:
        plt.savefig(outfile+'.png')
    plt.show()
Example #4
0
def spec_average(Data, verbose=True):
    '''
    Load all files relavent to Data, turn into .npy. Does not return anything; this
    makes the data; we want to separate this procedurally from loading it, as
    loading is far cheaper than creating.
    '''
    data_lognames = fm.Get_File_Names(Data['Paths']['dependencies-dir'],
                                      ['log'],
                                      Data['fname'])
    for fname in data_lognames:
        f_out = Data['Paths']['save-dir']+'/'+os.path.basename(fname)[:-4]+'.npy'
        if os.path.exists(f_out) and os.path.isfile(f_out):
            if verbose:
                print 'Skipping file:', f_out
            continue

        if verbose:
            print 'Creating file:', f_out
        specs = readspec_mod.readSpec(fname)
        specAve = np.sum(specs, 1) / float(specs.shape[1])
        np.save(f_out,specAve)
Example #5
0
b = [-32.]
for i in b:
    File = np.load('Points/'+str(i)+'.npz')
    longpts = File['x'] #the longitude points we will need to plot
    for n in longpts:
        onept = n
        if not os.path.isfile('bubbleOFF'+str(n)+','+str(i)+'0.log'): #if for some reason, the file does not exist, as in we have not 
            continue
        if not os.path.isfile('bubbleON'+str(n)+','+str(i)+'0.log'):  #taken any data for that position in the sky,
            continue
        if not os.path.isfile('bubbleNOISE_OFF'+str(n)+','+str(i)+'0.log'): #then this part of the code will skip over it without
            continue
        if not os.path.isfile('bubbleNOISE_ON'+str(n)+','+str(i)+'0.log'):  #having to break the for-loop
            continue
        
        spec_off = rsm.readSpec('bubbleOFF'+str(n)+','+str(i)+'0.log') #shifted the below by 4 MHz
        spec_off = boxavg(np.mean(spec_off,1))#[250:-250] 

        spec_on = rsm.readSpec('bubbleON'+str(n)+','+str(i)+'0.log') #on frequency 
        spec_on = boxavg(np.mean(spec_on,1))#[250:-250]

        noise_off = rsm.readSpec('bubbleNOISE_OFF'+str(n)+','+str(i)+'0.log') #spec_off with noise diode
        noise_off = boxavg(np.mean(noise_off,1))#[250:-250]

        noise_on = rsm.readSpec('bubbleNOISE_ON'+str(n)+','+str(i)+'0.log') #spec_on freq with noise diode on
        noise_on = boxavg(np.mean(noise_on,1))#[250:-250]

        fc = 1272.4+150
        f_range = np.linspace(fc-6, fc+6, spec_off.shape[0])        

        plt.plot(f_range, spec_off, label = "Spec off") 
		    break	
	    index += 1
	if havepoint:
	    continue

        if not os.path.isfile('raw/specOFF/bubbleOFF'+str(n)+','+str(i)+'0.log'):                       
            continue
        if not os.path.isfile('raw/specON/bubbleON'+str(n)+','+str(i)+'0.log'):                                            
            continue


        if not os.path.isfile('raw/noiseOFF/bubbleNOISE_OFF'+str(n)+','+str(i)+'0.log'):                            
            continue
        if not os.path.isfile('raw/noiseON/bubbleNOISE_ON'+str(n)+','+str(i)+'0.log'):                                       
            continue
	spec_off = rsm.readSpec('raw/specOFF/bubbleOFF'+str(n)+','+str(i)+'0.log')                                                            
        spec_off = boxavg(np.mean(spec_off,1))           

        spec_on = rsm.readSpec('raw/specON/bubbleON'+str(n)+','+str(i)+'0.log')                                                                        
        spec_on = boxavg(np.mean(spec_on,1))

        noise_off = rsm.readSpec('raw/noiseOFF/bubbleNOISE_OFF'+str(n)+','+str(i)+'0.log')                                                      
        noise_off = boxavg(np.mean(noise_off,1))    

        noise_on = rsm.readSpec('raw/noiseON/bubbleNOISE_ON'+str(n)+','+str(i)+'0.log')                                                
        noise_on = boxavg(np.mean(noise_on,1))                     

        fc = 1272.4+150
        f_range = np.linspace(fc-6, fc+6, spec_off.shape[0])

        plt.plot(f_range, spec_off, label = "Spec off")
Example #7
0
#! /usr/bin/env python

import readspec_mod
import pylab as p, sys, numpy as n

for filename in sys.argv[1:]:
    print 'REading', filename
    d = readspec_mod.readSpec(filename)
    print d.shape
    d = n.average(d, axis=-1)
    p.plot(d)
p.show()
Example #8
0
#code run on our test data to do whatever the hell we needed to do to it, oh yeah, cleaning it.
import numpy as np
import matplotlib.pyplot as plt
import readspec_mod as rsm
import scipy.constants as spc

n_off = rsm.readSpec('test_220_0_noise_off0.log') #noise on data
n_on = rsm.readSpec('test_220_0_noise_on0.log') #noise off data
#n_off_lo = 
#n_on_lo = 
index = [] 
value = 0
x = x - x[0] 
fc = 1272.4+150
f_range = np.linspace(fc-6, fc+6, n_off.shape[0])
radius = 100
#x_mean = average(x, y) 
x_avg = n_off[100:-100] - x_mean

for i in range (x_avg.size):
    if i == len(x_avg):
        break
    if x_avg[i] < -.0023: #a placeholder number
        index.append(i+100)
    if y_avg[i] > .0023:
        index.append(i+100)

d = np.delete(x, index)
#y = np.delete(y, index)

def boxcar(array, radius): #here we take the average of the data in order to clean it
            continue

        if not os.path.isfile('raw/specOFF/bubbleOFF' + str(n) + ',' + str(i) +
                              '0.log'):
            continue
        if not os.path.isfile('raw/specON/bubbleON' + str(n) + ',' + str(i) +
                              '0.log'):
            continue

        if not os.path.isfile('raw/noiseOFF/bubbleNOISE_OFF' + str(n) + ',' +
                              str(i) + '0.log'):
            continue
        if not os.path.isfile('raw/noiseON/bubbleNOISE_ON' + str(n) + ',' +
                              str(i) + '0.log'):
            continue
        spec_off = rsm.readSpec('raw/specOFF/bubbleOFF' + str(n) + ',' +
                                str(i) + '0.log')
        spec_off = boxavg(np.mean(spec_off, 1))

        spec_on = rsm.readSpec('raw/specON/bubbleON' + str(n) + ',' + str(i) +
                               '0.log')
        spec_on = boxavg(np.mean(spec_on, 1))

        noise_off = rsm.readSpec('raw/noiseOFF/bubbleNOISE_OFF' + str(n) +
                                 ',' + str(i) + '0.log')
        noise_off = boxavg(np.mean(noise_off, 1))

        noise_on = rsm.readSpec('raw/noiseON/bubbleNOISE_ON' + str(n) + ',' +
                                str(i) + '0.log')
        noise_on = boxavg(np.mean(noise_on, 1))

        fc = 1272.4 + 150
Example #10
0
#!/usr/bin/env python
import numpy as np
import matplotlib.pyplot as plt
import readspec_mod

noise_off = readspec_mod.readSpec('test_220_0_noise_off0.log')
noise_on = readspec_mod.readSpec('test_220_0_noise_on0.log')

fc = 1272.4+150

f_range = np.linspace(fc-6, fc+6, noise_off.shape[0])

plt.plot(f_range, np.mean(noise_off,1), label="Noise Off")
plt.plot(f_range, np.mean(noise_on,1), label="Noise On")
plt.title('Galactic Coordinates: long=$220^{\circ}$ lat=$0^{\circ}$\nLO=1272.4MHz 04/22 at 21:40 PDT')
plt.xlabel('MHz')
plt.legend()
plt.show()