-
Notifications
You must be signed in to change notification settings - Fork 2
/
plotAmpPattern.py
130 lines (114 loc) · 3.41 KB
/
plotAmpPattern.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
#import matplotlib
#matplotlib.use('Agg')
# Taken from Efield_2Dmap.py
import sys
from sys import argv
import glob
import numpy as np
import pylab as pl
import scipy.interpolate as itp
import matplotlib.colors as colors
import os
#import re
from retro.event import EventIterator, EventLogger
from mpl_toolkits.mplot3d import Axes3D
#pl.ion()
pl.ioff()
###########################
### Test arguments ###
###########################
if len(sys.argv)<3:
print """\
This script plot the 2D map of the Efield & voltages amplitude pattern
Usage: python plotAmpPattern.py [folder containing the .traces file] [file extension]
"""
sys.exit(1)
###########################
wkdir = sys.argv[1] # path where the simulation file is
# First load json infos
try:
json_file = glob.glob(wkdir+'*'+'.voltage.json')[0]
for evt in EventIterator(json_file):
# Ants infos
ants = np.array(evt["antennas"])
except:
try:
print wkdir
ants = np.loadtxt(wkdir+"/antpos.dat")
except:
print "caca"
xants = ants[:,0]
yants = ants[:,1]
zants = ants[:,2]
alpha = ants[:,3]
beta = ants[:,4]
Nant = np.size(xants)
# Now load traces
Ampx = np.zeros((Nant,1))
Ampy = np.zeros((Nant,1))
Ampz = np.zeros((Nant,1))
for iant in range(0,Nant):
if sys.argv[2]=="trace":
filename = wkdir+"/a"+str(iant)+".trace"
else:
filename = wkdir+"/out_"+str(iant)+".txt"
if os.path.isfile(filename):
b = np.loadtxt(filename, dtype='float', comments='#')
ti = b[:,0]
#pl.figure(iant)
#for i in range(1,4):
# pl.plot(ti-min(ti),b[:,i])
# pl.grid(True)
# pl.xlabel('Time (ns)')
# pl.ylabel('Efield ($\mu$V/m)')
#pl.title('Antenna {0}: ({1},{2})'.format(iant,x0[iant],y0[iant]))
#pl.show()
Ampx[iant] = max(b[:,1])-min(b[:,1])
Ampy[iant] = max(b[:,2])-min(b[:,2])
Ampz[iant] = max(b[:,3])-min(b[:,3])
print 'Antenna',iant,': max(Ex,Ey,Ez):',Ampx[iant],Ampy[iant],Ampz[iant]
# Antenna array 2D-plots
DISPLAYX = 1
fig = pl.figure()
ax = fig.add_subplot(111, projection='3d')
ax.scatter(xants, yants, zants, c='r', marker='o')
pl.xlabel("SN [m]")
pl.ylabel("EW [m]")
if DISPLAYX:
figx1 = pl.figure(12)
#norm = colors.LogNorm(vmin=1, vmax=Ampx.max())
norm = colors.Normalize(vmin=Ampx.min(),vmax=Ampx.max())
pl.scatter(xants,yants,c=Ampx,cmap='jet',s=100,norm=norm)
#pl.title('Amplitude Ex [$\mu$V/m]')
pl.xlabel("SN [m]")
pl.ylabel("EW [m]")
for i in range(len(xants)):
pl.annotate(str(i),(xants[i]+100,yants[i]+100))
cbar = pl.colorbar()
cbar.set_label('peak-peak Ex [$\mu$V/m]')
figname = 'Ex_lin.png'
pl.savefig(figname,dpi=500)
figy1 = pl.figure(13)
norm = colors.Normalize(vmin=Ampy.min(),vmax=Ampy.max())
pl.scatter(xants,yants,c=Ampy,cmap='jet',s=100,norm=norm)
pl.xlabel("SN [m]")
pl.ylabel("EW [m]")
cbar = pl.colorbar()
cbar.set_label('peak-peak Ey [$\mu$V/m]')
figname = 'Ey_lin.png'
pl.savefig(figname,dpi=500)
figz1 = pl.figure(14)
norm = colors.Normalize(vmin=Ampz.min(),vmax=Ampz.max())
pl.scatter(xants,yants,c=Ampz,cmap='jet',s=100,norm=norm)
pl.xlabel("SN [m]")
pl.ylabel("EW [m]")
cbar = pl.colorbar()
cbar.set_label('peak-peak Ez [$\mu$V/m]')
figname = 'Ez_lin.png'
pl.savefig(figname,dpi=500)
if DISPLAYX:
pl.show()
raw_input()
pl.close(figx1)
pl.close(figy1)
pl.close(figz1)