Dear Casperites
I am working on Roach2 and 5Gsps ADC1x5000-8.
During data acquisition for 4 element interferometer I am having following
issue in python code. I want to plot and record all the 6 baselines at a
time from a single python file.
please find the attached python code file.
Kindly help me to sort out that issue.
root@casper:~/4element_code# python corr_plotting_4element.py
192.168.100.192 30augc_12_cang 30augc_12_camp 30augc_13_cang 30augc_13_camp
30augc_14_cang 30augc_14_camp 30augc_23_cang 30augc_23_camp 30augc_24_cang
30augc_24_camp 30augc_34_cang 30augc_34_camp
dumping file is missing
Traceback (most recent call last):
File "corr_plotting_4element.py", line 148, in updatefig
rply[input] = map(eval, reply.arguments[1:n_chans/8+1])
IndexError: list assignment index out of range
Done with all
Thanks & Regards
Nikita Rathore
--
You received this message because you are subscribed to the Google Groups
"[email protected]" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/a/lists.berkeley.edu/d/msgid/casper/CAOvmUY787FyLpGGLSDzEQAjZrg9-%2BKDLV1S11zTEk91B0oQEew%40mail.gmail.com.
#!/usr/bin/python
#from katcp import BlockingClient, Message
'''PLOTS CROSS AND AUTO CORRELATION FUNCTION OF WIDEBAND POCO n-CH DESIGN ON ROACH BOARD
'''
import matplotlib
from matplotlib import rcParams
matplotlib.use('GTKAgg')
import katcp, numpy, pylab
import gtk, gobject, time, struct, sys, math
f_1=str(sys.argv[2])
f_2=str(sys.argv[3])
f_3=str(sys.argv[4])
f_4=str(sys.argv[5])
f_5=str(sys.argv[6])
f_6=str(sys.argv[7])
f_7=str(sys.argv[8])
f_8=str(sys.argv[9])
f_9=str(sys.argv[10])
f_10=str(sys.argv[11])
f_11=str(sys.argv[12])
f_12=str(sys.argv[13])
def interleave(*args):
x=[]
for idx in range(0, max(len(arg) for arg in args)):
for arg in args:
try:
#yield arg[idx]
x.append(arg[idx])
except IndexError:
continuie
return x
device_host = "192.168.100.192" # For Lab Testing
#device_host = "192.168.4.91" # For Receiver Room Testing
device_port = 7147
#acq_time = 2**27/(100.0*(10**6)) # 0.89 is 1 sync period time
n_chans = 2048 #512 fft
ants = 1
if __name__ == '__main__':
from optparse import OptionParser
p = OptionParser()
p.set_usage('tut4_poco_plot.py <ROACH_HOSTNAME_or_IP> [options] ')
p.set_description(__doc__)
p.add_option('-l', '--log', dest='log', action='store_true', default=False,
help='''Plot the power in logarithmic scale (requires some non-zero value signal).''')
p.add_option('--hold', dest='hold', action='store_true', default=False,
help='''Turn on hold. This will plot subsequent specra on top of each other.''')
p.add_option('-f', '--file', action='store', type='string', dest='filename',
help='''file dump the data in native tax format''', metavar='FILE')
opts, args = p.parse_args(sys.argv[1:])
if args==[]:
print 'Please specify a ROACH board. \nExiting.'
exit()
else:
roach = args[0]
client = katcp.BlockingClient(roach, device_port)
client.start()
bram_map=['s1_aa_real','s1_a1a1_real','s1_aa1_real','s1_a1a2_real','s2_aa_real','s2_a1a1_real','s2_aa1_real','s2_a1a2_real','c12_aa_real','c12_a1a1_real','c12_aa1_real','c12_a1a2_real','c12_aa_imag','c12_a1a1_imag','c12_aa1_imag','c12_a1a2_imag','s3_aa_real','s3_a1a1_real','s3_aa1_real','s3_a1a2_real','c13_aa_real','c13_a1a1_real','c13_aa1_real','c13_a1a2_real','c13_aa_imag','c13_a1a1_imag','c13_aa1_imag','c13_a1a2_imag','s4_aa_real','s4_a1a1_real','s4_aa1_real','s4_a1a2_real','c14_aa_real','c14_a1a1_real','c14_aa1_real','c14_a1a2_real','c14_aa_imag','c14_a1a1_imag','c14_aa1_imag','c14_a1a2_imag','c23_aa_real','c23_a1a1_real','c23_aa1_real','c23_a1a2_real','c23_aa_imag','c23_a1a1_imag','c23_aa1_imag','c23_a1a2_imag','c24_aa_real','c24_a1a1_real','c24_aa1_real','c24_a1a2_real','c24_aa_imag','c24_a1a1_imag','c24_aa1_imag','c24_a1a2_imag','c34_aa_real','c34_a1a1_real','c34_aa1_real','c34_a1a2_real','c34_aa_imag','c34_a1a1_imag','c34_aa1_imag','c34_a1a2_imag']
x=numpy.arange(0.0,299.70,0.2929)
#x=range(0,n_chans/2)
xlab=('Frequency in MHz')
fig = pylab.figure(1)
manager = pylab.get_current_fig_manager()
cnt = 0
#creating file to dump data-------------------------------------------------------------------------------------------
if (opts.filename != None):
f_name = opts.filename #+ opts.filename
#f_name = "phase"
print "dumping File is %s" %f_name
fptr = open (f_name,'w')
else:
print "dumping file is missing\n"
#continuous loop
def updatefig(*args):
global cnt, ants
cnt += 2
print 'Grabbing spectrum number %i'%cnt
rply = [[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[]]
Acomplex_0 = []
Acomplex_1 = []
Acomplex_2 = []
Bcomplex_0 = []
Bcomplex_1 = []
Bcomplex_2 = []
Ccomplex_0 = []
Ccomplex_1 = []
Ccomplex_2 = []
Ccomplex_3 = []
Ccomplex_4 = []
Ccomplex_5 = []
Ccomplex_6 = []
Ccomplex_7 = []
Ccomplex_8 = []
Ccomplex_9 = []
Ccomplex_10 = []
Ccomplex_11 = []
Ccomplex_12 = []
Ccomplex_13 = []
Ccomplex_14 = []
Ccomplex_15 = []
Ccomplex_16 = []
Ccomplex_17 = []
Ccomplex_18 = []
Ccomplex_19 = []
Ccomplex_20 = []
Ccomplex_21 = []
Ccomplex_22 = []
Ccomplex_23 = []
Ccomplex_24 = []
Ccomplex_25 = []
Ccomplex_26 = []
Ccomplex_27 = []
Ccomplex_28 = []
Ccomplex_29 = []
Ccomplex_30 = []
Ccomplex_31 = []
Ccomplex_32 = []
Ccomplex_33 = []
Ccomplex_34 = []
Ccomplex_35 = []
Ccomplex_36 = []
Ccomplex_37 = []
Ccomplex_38 = []
Ccomplex_39 = []
Ccomplex_40 = []
Ccomplex_41 = []
main_loop_t = time.time()
# DATA GRABBING UTILITY-----------------------------------------------------------------------------------------------------
for input in range(64):
reply, inform = client.blocking_request(katcp.Message.request("wordread", bram_map[input], "0", "256"))
#print "reply", numpy.size(reply)
print"reply[%i]=%i"%(input, numpy.size(reply))
rply[input] = map(eval, reply.arguments[1:n_chans/8+1])
for i in range(256): # For 2's Complement interpretation :)
if (rply[input][i] > 2147483647):
rply[input][i] = rply[input][i] - 4294967296
# DATA
Acomplex_0 =numpy.array(interleave(rply[0],rply[1]))#real part of 1st input after interleaving even odd
Acomplex_1 =numpy.array(interleave(rply[2],rply[3]))
Acomplex_2 =numpy.array(interleave(Acomplex_0,Acomplex_1))
Bcomplex_0 =numpy.array(interleave(rply[4],rply[5]))#real part of 1st input after interleaving even odd
Bcomplex_1 =numpy.array(interleave(rply[6],rply[7]))
Bcomplex_2 =numpy.array(interleave(Bcomplex_0,Bcomplex_1))
Ccomplex_0 =numpy.array(interleave(rply[8],rply[9]))#real part of 1st input after interleaving even odd
Ccomplex_1 =numpy.array(interleave(rply[10],rply[11]))
Ccomplex_2 =numpy.array(interleave(Ccomplex_0,Ccomplex_1))
Ccomplex_3 =numpy.array(interleave(rply[12],rply[13]))
Ccomplex_4 =numpy.array(interleave(rply[14],rply[15]))
Ccomplex_5 =numpy.array(interleave(Ccomplex_3,Ccomplex_4))
Ccomplex_6=numpy.copy(numpy.array(Ccomplex_2) + numpy.array(Ccomplex_5)*1j)
Ccomplex_7 =numpy.array(interleave(rply[21],rply[22]))
Ccomplex_8 =numpy.array(interleave(rply[23],rply[24]))
Ccomplex_9 =numpy.array(interleave(Ccomplex_7,Ccomplex_8))
Ccomplex_10 =numpy.array(interleave(rply[25],rply[26]))
Ccomplex_11 =numpy.array(interleave(rply[27],rply[28]))
Ccomplex_12 =numpy.array(interleave(Ccomplex_10,Ccomplex_11))
Ccomplex_13=numpy.copy(numpy.array(Ccomplex_9) + numpy.array(Ccomplex_12)*1j)
Ccomplex_14 =numpy.array(interleave(rply[33],rply[34]))
Ccomplex_15 =numpy.array(interleave(rply[35],rply[36]))
Ccomplex_16 =numpy.array(interleave(Ccomplex_14,Ccomplex_15))
Ccomplex_17 =numpy.array(interleave(rply[37],rply[38]))
Ccomplex_18 =numpy.array(interleave(rply[39],rply[40]))
Ccomplex_19 =numpy.array(interleave(Ccomplex_17,Ccomplex_18))
Ccomplex_20=numpy.copy(numpy.array(Ccomplex_16) + numpy.array(Ccomplex_19)*1j)
Ccomplex_21 =numpy.array(interleave(rply[41],rply[42]))
Ccomplex_22 =numpy.array(interleave(rply[43],rply[44]))
Ccomplex_23 =numpy.array(interleave(Ccomplex_21,Ccomplex_22))
Ccomplex_24 =numpy.array(interleave(rply[45],rply[46]))
Ccomplex_25 =numpy.array(interleave(rply[47],rply[48]))
Ccomplex_26 =numpy.array(interleave(Ccomplex_24,Ccomplex_25))
Ccomplex_27=numpy.copy(numpy.array(Ccomplex_23) + numpy.array(Ccomplex_26)*1j)
Ccomplex_28 =numpy.array(interleave(rply[49],rply[50]))
Ccomplex_29 =numpy.array(interleave(rply[51],rply[52]))
Ccomplex_30 =numpy.array(interleave(Ccomplex_28,Ccomplex_29))
Ccomplex_31 =numpy.array(interleave(rply[53],rply[54]))
Ccomplex_32 =numpy.array(interleave(rply[55],rply[56]))
Ccomplex_33 =numpy.array(interleave(Ccomplex_31,Ccomplex_32))
Ccomplex_34=numpy.copy(numpy.array(Ccomplex_30) + numpy.array(Ccomplex_33)*1j)
Ccomplex_35 =numpy.array(interleave(rply[57],rply[58]))
Ccomplex_36 =numpy.array(interleave(rply[59],rply[60]))
Ccomplex_37 =numpy.array(interleave(Ccomplex_35,Ccomplex_36))
Ccomplex_38 =numpy.array(interleave(rply[61],rply[62]))
Ccomplex_39 =numpy.array(interleave(rply[63],rply[64]))
Ccomplex_40 =numpy.array(interleave(Ccomplex_38,Ccomplex_39))
Ccomplex_41=numpy.copy(numpy.array(Ccomplex_37) + numpy.array(Ccomplex_40)*1j)
#DATA DUMPING UTILITY-------------------#
if(opts.filename!= None):
k=0
for k in range (512):
fptr.write('%f\n'%numpy.angle(Rcomplex[k],deg=True))
k=0
for k in range (512):
fptr.write('%f\n'%numpy.angle(Lcomplex[k],deg=True))
#creat files---------------------------------#
outfile='file1'
numpy.savetxt(outfile, Acomplex_0 , fmt='%.2f')
outfile='file2'
numpy.savetxt(outfile, Acomplex_1 , fmt='%.2f')
outfile='file3'
numpy.savetxt(outfile, Acomplex_2 , fmt='%.2f')
#DATA PLOTTING UTILITY-------------- #
y=numpy.abs(Acomplex_2)
pylab.subplot(412) #plotting self amplitude of 1st element
pylab.ioff()
pylab.hold(False)
print 'size of Acomplex = %i'%numpy.size(Acomplex_2)
if opts.log:
pylab.semilogy(x, numpy.abs(Acomplex_2))
pylab.ylabel('Power (log, arb units)')
else:
pylab.plot(x, numpy.abs(Acomplex_2))
pylab.ylabel('Power (linear, arb units)')
pylab.xlim(x[0],x[1023])
#pylab.ylim(y[446],y[510])
pylab.grid()
pylab.title('Power:antenna1 self Amplitude Spectrum number %i'%cnt)
pylab.xlabel(xlab)
pylab.draw()
y=numpy.abs(Bcomplex_2)
pylab.subplot(411) #plotting self amplitude of 1st element
pylab.ioff()
pylab.hold(False)
print 'size of Acomplex = %i'%numpy.size(Bcomplex_2)
if opts.log:
pylab.semilogy(x, numpy.abs(Bcomplex_2))
pylab.ylabel('Power (log, arb units)')
else:
pylab.plot(x, numpy.abs(Bcomplex_2))
pylab.ylabel('Power (linear, arb units)')
pylab.xlim(x[0],x[1023])
#pylab.ylim(y[446],y[510])
pylab.grid()
pylab.title('Power:antenna1 self Amplitude Spectrum number %i'%cnt)
pylab.xlabel(xlab)
pylab.draw()
y=numpy.abs(Ccomplex_6)
pylab.subplot(413) #plotting self amplitude of 1st element
pylab.ioff()
pylab.hold(False)
print 'size of Acomplex = %i'%numpy.size(Ccomplex_6)
if opts.log:
pylab.semilogy(x, numpy.abs(Ccomplex_6))
pylab.ylabel('Power (log, arb units)')
else:
pylab.plot(x, numpy.abs(Ccomplex_6))
pylab.ylabel('Power (linear, arb units)')
pylab.xlim(x[0],x[1023])
#pylab.ylim(y[446],y[510])
pylab.grid()
pylab.title('Power:antenna1 self Amplitude Spectrum number %i'%cnt)
pylab.xlabel(xlab)
pylab.draw()
pylab.subplot(414)
pylab.ioff()
pylab.hold(opts.hold)
pylab.plot(x,(numpy.angle(Ccomplex_6,deg=True)))
# filename1 = "antenna1_auto.txt"
# file =open(filename1,'w')
# file.write(numpy.angle(Rcomplex,deg=True))
# file.close()
pylab.xlim(x[0],x[1023])
pylab.ylim(-180,+180)
pylab.ylabel('Phase in Deg')
pylab.grid()
pylab.title('Power: cross correlation of antenna one and two Phase Spectrum number %i'%cnt)
f1=open(f_1,"a")
numpy.savetxt(f1,(numpy.angle(Ccomplex_6,deg=True)),fmt='%.2f')
f2=open(f_2,"a")
numpy.savetxt(f2,(numpy.abs(Ccomplex_6)),fmt='%.2f')
f3=open(f_3,"a")
numpy.savetxt(f3,(numpy.angle(Ccomplex_13,deg=True)),fmt='%.2f')
f4=open(f_4,"a")
numpy.savetxt(f4,(numpy.abs(Ccomplex_13)),fmt='%.2f')
f5=open(f_5,"a")
numpy.savetxt(f5,(numpy.angle(Ccomplex_20,deg=True)),fmt='%.2f')
f6=open(f_6,"a")
numpy.savetxt(f6,(numpy.abs(Ccomplex_20)),fmt='%.2f')
f7=open(f_7,"a")
numpy.savetxt(f7,(numpy.angle(Ccomplex_27,deg=True)),fmt='%.2f')
f8=open(f_8,"a")
numpy.savetxt(f8,(numpy.abs(Ccomplex_27)),fmt='%.2f')
f9=open(f_9,"a")
numpy.savetxt(f9,(numpy.angle(Ccomplex_34,deg=True)),fmt='%.2f')
f10=open(f_10,"a")
numpy.savetxt(f10,(numpy.abs(Ccomplex_34)),fmt='%.2f')
f11=open(f_11,"a")
numpy.savetxt(f11,(numpy.angle(Ccomplex_41,deg=True)),fmt='%.2f')
f12=open(f_12,"a")
numpy.savetxt(f12,(numpy.abs(Ccomplex_41)),fmt='%.2f')
return True
gobject.idle_add(updatefig)
pylab.show()
client.stop()
client.join()
if(opts.filename != None):
fptr.close()
print 'Done with all'