""" This program will read in a data file from Gnu Radio and plot it.
Ellie White 25 Feb. 2017
"""
import pylab as plt
import os
import numpy as np
from tempCorrections import tempCorrections
def main():
fftsize = 8192.0
tot_time = 20
srate = 4000000.0
decimation = 100.0
rpi_samptime = 5 # number of seconds between sensor readings
infile = 'data-raw2.obs'
in_tfilename = 'timefile2.txt'
out_tfilename = 'timestamps2.txt'
tc_b = tempCorrections('balun', 1, 'RPI_DATA_07_11_2019_21-33-04.txt', 0)
#tc_rx = tempCorrections('rx', 1, '/home/ewhite/rpi-data/RPI_DATA_07_11_2019_21-33-04.txt', 0)
size = os.path.getsize(infile) / 4
shape = (size/fftsize, fftsize)
#print(str(size/fftsize))
#print(str(size))
x = np.memmap(infile, dtype='float32', mode = 'r', shape=shape)
freqPlot = np.mean(x, axis=0)
#print freqPlot
fmin = (169010000-(srate/2))/1000000
fmax = (169010000+(srate/2))/1000000
fidx = np.linspace(fmin, fmax, freqPlot.size)
#fraction of a second between bursts...
delta_t = tot_time / (size / fftsize)
'''tfile = open(in_tfilename, 'r')
start_time = float(tfile.read())'''
#read in data from RPI file as array
#balun temps:
balun_temps = []
btemps = tc_b.getTemps()
for b in btemps:
balun_temps.append(b)
#receiver temps
#rx_temps = tc_rx.getTemps()
#read times from RPI file...
times = tc_b.getTimes()
#print times
start_time = times[0] - rpi_samptime
#tsfile = open(out_tfilename, 'w')
data_btemps = []
ant_power = []
for i in range(int(size/fftsize)):
#assign sensor row to row i of xarray
row_time = (i+1)*delta_t
#print row_time
#print len(times)
for j in range(len(times)):
#print "in the loop"
#print times[j] - start_time
if j == 0:
if row_time <= (times[j] - start_time):
t_index = j
break
else:
continue
elif j == (len(times)-1):
if row_time >= times[j]:
t_index = j
break
elif row_time <= (times[j] - start_time):
t_index = j
else:
print "An error has occurred -- no t_index set!"
else:
if (row_time >= (times[j-1] - start_time)) and (row_time < (times[j] - start_time)):
t_index = j
break
else:
continue
#get temperatures for balun and rx from sensor row
btemp_i = balun_temps[t_index]
data_btemps.append(btemp_i)
#get representative power value from data array:
pval = x[i, fftsize/2]
#print pval
ant_power.append(pval)
ant_temps = []
print "Ant. Temp\tPhys. Temp"
for p in range(len(ant_power)):
atemp = (float(ant_power[p])/(488.28125*1.3806*pow(10,-23))) + 57.2
ant_temps.append(atemp)
print "{0}\t{1}".format(atemp, data_btemps[p])
#mod_curves = np.empty([int(size/fftsize), freqPlot.size])
#s21mod_mag, s21mod_ph = tc_b.getS21MagPhase()
#print s21mod_mag
#call tempCorrections with given temperature to get model curve
'''for k in range(len(data_btemps)):
btemp = data_btemps[k]
index = balun_temps.index(btemp)
mod_curves[k] = s21mod_mag[index]
#plt.plot(fidx, mod_curves[k])'''
#convert model curve to power
#apply any offsets to row i data
#subtract model from row i data
#corrected data becomes part of new corrected data array
#correctedPlot = np.mean(x_corr, axis=0)
#clip out and replace RFI channels with noise data from nearby channels
#tsfile.close()
plt.plot(fidx, freqPlot)
plt.show()
if __name__ == "__main__":
main()
No comments:
Post a Comment