def importAndMakeDoubleAveragedLogMags(fileList=-1): """ Lets just average together a few in the time domain, then a few in the freq domain """ eventAvgNum = 16 if fileList==-1: baseDir=localDir+"/Attempt_3_23July2012/NewSeavey/Hpol/*degCW*" fileList = glob.glob(baseDir+"*.dat") else: try: fileList[0] except: fileList = [fileList] avgFFTs = {} for fileName in fileList: shortName = fileName.split("/")[-1] print shortName allEvents = importAll(fileName) avgFFT = "" numAvgs = len(allEvents)/eventAvgNum print "Number of Big Averages: "+str(numAvgs) print "Using "+str(numAvgs*eventAvgNum) for i in range(0,numAvgs): avgEvent = tf.correlateAndAverage(allEvents[i*eventAvgNum:(i+1)*eventAvgNum]) if avgFFT == "": avgFFT = np.array(tf.genLogMag(avgEvent[0]*1e9,avgEvent[1])) print avgFFT[1] else: avgFFT[1] += tf.genLogMag(avgEvent[0],avgEvent[1])[1] avgFFTs[shortName] = (avgFFT[0],avgFFT[1]/numAvgs) return avgFFTs
def getLogMags(avgEvents): logMags = [] for event in avgEvents: logMags.append(tf.genLogMag(np.array(event[0]),np.array(event[1]))) return logMags
def getDictLogMags(avgEvents): keys = avgEvents.keys() keys.sort() logMags = {} for shortName in keys: currPlot = avgEvents[shortName] logMags[shortName] = tf.genLogMag(np.array(currPlot[0]),np.array(currPlot[1])) return logMags
def main(): """ does whatever silly thing I am trying on the command line """ files = localFileList_ANITA2chamberHPol() fig = lab.figure() axes = [] colors=["red","blue"] numFiles = len(files) index=1 logMags = {} for file in files: if index!=1: axes.append(fig.add_subplot(numFiles,1,index,sharex=axes[0])) else: axes.append(fig.add_subplot(numFiles,1,index)) for chan in range(0,2): events = importAll(file,numEvents=100,channel=chan) avgEvent = tf.correlateAndAverage(events) peak = np.argmax(np.abs(avgEvent[1])) + 500 procAvgEvent = processAllEvents([avgEvent],totalWidth=2000,peak=peak)[0] logMag = tf.genLogMag(procAvgEvent[0],procAvgEvent[1]*1000) grpDly = tf.genGroupDelay(procAvgEvent[0]*1e9,procAvgEvent[1]*1000) offPhi = file.split("/")[-1].split("_")[1][1:4] offTheta = file.split("/")[-1].split("_")[2][1:4] print "Phi="+str(offPhi)+" Theta="+str(offTheta) label = str(offPhi)+","+str(offTheta) axes[-1].plot(grpDly[0], grpDly[1], label = label, color = colors[chan]) # axes[-1].plot(grpDly[0][1:],grpDly[1][1:],label=label,color=colors[chan]) index += 1 for ax in axes: ax.legend() fig.show() return
def ANITA2_HchamberAnglePlot(): files = localFileList_ANITA2chamberHPol() #Where on the grid the antenna was pointing for the chamber data graphPositions = (2,4,5,6,8) fig = lab.figure() axes = [] colors=["red","blue"] index=0 logMags = {} for file in files: if index!=0: axes.append(fig.add_subplot(3,3,graphPositions[index],sharex=axes[0])) else: axes.append(fig.add_subplot(3,3,graphPositions[index])) for chan in range(0,2): events = importAll(file,numEvents=100,channel=chan) avgEvent = tf.correlateAndAverage(events) peak = np.argmax(np.abs(avgEvent[1])) + 500 procAvgEvent = processAllEvents([avgEvent],totalWidth=2000,peak=peak)[0] logMag = tf.genLogMag(procAvgEvent[0],procAvgEvent[1]*1000) grpDly = tf.genGroupDelay(procAvgEvent[0]*1e9,procAvgEvent[1]*1000) offPhi = file.split("/")[-1].split("_")[1][1:4] offTheta = file.split("/")[-1].split("_")[2][1:4] print "Phi="+str(offPhi)+" Theta="+str(offTheta) label = str(offPhi)+","+str(offTheta) # axes[-1].plot(grpDly[0][1:],grpDly[1][1:],label=label,color=colors[chan]) axes[-1].plot(logMag[0][:200],logMag[1][:200],label=label,color=colors[chan]) # axes[-1].plot(logMag[0][1:200],logMag[1][1:200],label=label,color=colors[chan]) index += 1 for ax in axes: ax.legend() fig.show() return
def ANITA3_rooftopResponse(files=-1,rotate="phi",channel=0,eventAvgs=50): """ imports and generates some arrays for angle, frequency, and spectral magnitude of correlated and averaged waveforms in a series of chamber data the defaults are for HPol rotating in phi, but you can do others. channel==0 is Vpol and channel==1 is Hpol (I think) """ if files==-1: files = localFileList_ANITA3rooftopHPol() print "number of files:"+str(len(files)) freqs = [] allFreqs = [] mags = [] allMags = [] angles = [] #params numFreqs = 25 stop = 100 #~1GHz start = 2 step = stop/float(numFreqs) sns.set_palette(sns.color_palette("husl",numFreqs)) inPulse = antChamberResponse(chamberRefPulse,channel=0) for file in files: events = importAll(file,channel=channel) print len(events) fftAvgs = len(events)/eventAvgs for fftAvgNum in range(0,fftAvgs): avgEvent = tf.correlateAndAverage(events[eventAvgs*fftAvgNum:eventAvgs*(fftAvgNum+1)]) peak = np.argmax(np.abs(avgEvent[1])) + 500 procAvgEvent = processAllEvents([avgEvent],totalWidth=2000,peak=peak).T transFunc = HpolTransferFunctionAnalysis(pulse=inPulse,respo=procAvgEvent) logMag = tf.genLogMag(transFunc[0],transFunc[1]*1000) if freqs == []: freqs = np.ceil(logMag[0][start:stop:step]/1e6) print freqs allFreqs = np.ceil(logMag[0][start:stop]/1e6) if fftAvgNum == 0: logMagAvg = logMag[1]/fftAvgs else: logMagAvg += logMag[1]/fftAvgs mags.append(logMagAvg[start:stop:step]) allMags.append(logMagAvg[start:stop]) try: angle = file.split("/")[-1].split("_")[1].split("deg")[0] direction = file.split("/")[-1].split("_")[1].split("deg")[1] if direction == "CW": angles.append(float(angle)) elif direction == "CCW": angles.append(-1*float(angle)) except: angles.append("0") print angles[-1] lab.close("all") fig = lab.figure() ax = fig.add_subplot(111) for freqNum in range(0,numFreqs): curve = [] for angleNum in range(0,len(angles)): curve.append(mags[angleNum][freqNum]) curve = np.array(curve)-np.max(curve) ax.plot(angles,curve,label=freqs[freqNum]) ax.legend() fig.show() return angles,allFreqs,allMags