-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathVertexPlot.py
187 lines (163 loc) · 6.16 KB
/
VertexPlot.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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
#!/usr/bin/env python
#Author: Craig Lage, NYU;
#Date: 16-Nov-15
#This program plots the pixel area plots from the Poisson CCD solver
import matplotlib
matplotlib.use("PDF")
from pylab import *
import sys, time, h5py
#****************SUBROUTINES*****************
def ReadConfigFile(filename):
# This reads the Poisson simulator config file for
# the settings that were run
# and returns a dictionary with the values
ConfigData = {}
try:
file = open(filename,'r')
lines=file.readlines()
file.close()
except IOError:
print "Configuration file %s not found"%filename
return False, ConfigData
try:
for line in lines:
ThisLine=line.strip().split()
ThisLineLength=len(ThisLine)
if ThisLineLength < 3:
continue
if list(ThisLine[0])[0]=='#' or ThisLine[0]=='\n':
continue
try:
ParamName = ThisLine[0]
ThisLine.remove(ThisLine[0])
for counter,item in enumerate(ThisLine):
if list(item)[0] == '#':
del ThisLine[counter:] # Strip the rest of the line as a comment
continue
if item == '=':
ThisLine.remove(item)
continue
if len(ThisLine) == 0:
continue
elif len(ThisLine) == 1:
ThisParam = ThisLine[0]
try: ConfigData[ParamName] = int(ThisParam)
except ValueError:
try:
ConfigData[ParamName] = float(ThisParam)
except ValueError:
try:
ConfigData[ParamName] = ThisParam
except ValueError:
return False, ConfigData
else:
ThisParam = []
for item in ThisLine:
try: ThisParam.append(int(item))
except ValueError:
try: ThisParam.append(float(item))
except ValueError:
ThisParam.append(item)
ConfigData[ParamName] = ThisParam
except (IOError, ValueError):
continue
except Exception as e:
print "Error reading configuration file %s. Exception of type %s and args = \n"%(filename,type(e).__name__), e.args
return False, ConfigData
return True, ConfigData
def ReadAreaFile(filename, nx, ny):
area = zeros([nx, ny])
file = open(filename, 'r')
lines = file.readlines()
file.close()
for line in lines:
items = line.split()
if items[0] == "Nx":
continue
i = int(items[0])
j = int(items[1])
area[i,j] = float(items[2])
return area
def ReadVertexFile(filename, nx, ny, NumAngles):
vx = zeros([nx, ny, NumAngles])
vy = zeros([nx, ny, NumAngles])
file = open(filename, 'r')
lines = file.readlines()
file.close()
FirstPass = True
for line in lines:
items = line.split()
if items[0] == "X0":
continue
x = int(float(items[0]))
y = int(float(items[1]))
if FirstPass:
lastx = x; lasty = y; i = 0; j = 0; k = 0; FirstPass = False
if y != lasty:
k = 0
j += 1
lasty = y
if x != lastx:
k = 0
j = 0
i += 1
lastx = x
lasty = y
#print i,j,k
vx[i,j,k] = float(items[3])
vy[i,j,k] = float(items[4])
k += 1
return (vx, vy)
#****************MAIN PROGRAM*****************
# First, read the .cfg file
configfile = sys.argv[1]
run = int(sys.argv[2])
cfg_success, ConfigData = ReadConfigFile(configfile)
if not cfg_success:
print "Configuration file issue. Quitting"
sys.exit()
outputfilebase = ConfigData["outputfilebase"]
outputfiledir = ConfigData["outputfiledir"]
Nx = ConfigData["PixelBoundaryNx"]
Ny = ConfigData["PixelBoundaryNy"]
XCenter = ConfigData["FilledPixelCoords_0_0"][0]
YCenter = ConfigData["FilledPixelCoords_0_0"][1]
PixelSize = ConfigData["PixelSize"]
NxCenter = int((XCenter - ConfigData["PixelBoundaryLowerLeft"][0]) / PixelSize)
NyCenter = int((YCenter - ConfigData["PixelBoundaryLowerLeft"][1]) / PixelSize)
Area_0 = 100.0
NumAngles = 4 * ConfigData["NumVertices"] + 4
NumElec = ConfigData["CollectedCharge_0_0"]
PlotDelta = int(sys.argv[3])
filename = outputfiledir + '/' + outputfilebase +'_%d_Area'%run + '.dat'
area = ReadAreaFile(filename, Nx, Ny)
figure()
subplot(1,1,1,aspect = 1)
title("Pixel Area: %d e-"%NumElec)
filename = outputfiledir + '/' + outputfilebase +'_%d_Vertices'%run + '.dat'
(vx, vy) = ReadVertexFile(filename, Nx, Ny, NumAngles)
LineXMin = XCenter - (PlotDelta + 0.5) * PixelSize
LineXMax = XCenter + (PlotDelta + 0.5) * PixelSize
LineYMin = YCenter - (PlotDelta + 0.5) * PixelSize
LineYMax = YCenter + (PlotDelta + 0.5) * PixelSize
title("Pixel Vertices: %d e-"%NumElec)
for i in range(NxCenter-PlotDelta, NxCenter+PlotDelta+1):
plot([XCenter+PixelSize*(i-NxCenter-0.5), XCenter+PixelSize*(i-NxCenter-0.5)], [LineYMin, LineYMax], color = 'black', ls = '--')
for j in range(NyCenter-PlotDelta, NyCenter+PlotDelta+1):
plot([LineXMin, LineXMax], [YCenter+PixelSize*(j-NyCenter-0.5), YCenter+PixelSize*(j-NyCenter-0.5)], color = 'black', ls = '--')
for i in range(NxCenter-PlotDelta, NxCenter+PlotDelta+1):
for j in range(NyCenter-PlotDelta, NyCenter+PlotDelta+1):
if i == NxCenter and j == NyCenter:
textcolor = 'red'
else:
textcolor = 'black'
text(XCenter+PixelSize*(i-NxCenter-0.2), YCenter+PixelSize*(j-NyCenter-0.1), "%.4f"%area[i,j], color = textcolor, fontsize = 12/PlotDelta, fontweight = 'bold')
x = []
y = []
for k in range(NumAngles):
x.append(vx[i,j,k])
y.append(vy[i,j,k])
x.append(vx[i,j,0])
y.append(vy[i,j,0])
plot(x, y, lw = 0.5)
savefig(outputfiledir+"/plots/PixelVertices_%d.pdf"%run)