-
Notifications
You must be signed in to change notification settings - Fork 0
/
TApltflptemp.py
214 lines (167 loc) · 5.36 KB
/
TApltflptemp.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
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
#-- NOTE: only python2 can run this code
#-- NOTE: python3.9.7 can also run this code
import os
import sys
import csv
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.tri as tri
import matplotlib.patches as patches
from matplotlib.patches import Rectangle
if len(sys.argv) != 3:
print("Usage: python3 pltflptemp.py <floorplan_file> <steady_grid_file>")
sys.exit(1)
#-- read in csv format voltage file
#-- format: xloc\tyloc\tvoltage
def ReadCSVfile(filename):
array = np.genfromtxt(filename)
return array
#-- read floorplan file
#-- format: unitname\tdx\tdy\tx0\ty0
def readflpfile(file):
blocks = list(csv.reader(open(file, 'r'), delimiter='\t'))
'''
fp = open(file)
rdr = csv.DictReader(filter(lambda row: row[0] != '#', fp))
blocks = list(row)
'''
return blocks
blocks = readflpfile(sys.argv[1])
max_x = 0
max_y = 0
i = 0
for e in blocks:
#-- skip blank lines
if len(blocks[i]) == 0:
i += 1
continue
#-- skip comment lines
if blocks[i][0][0] == '#':
i += 1
continue
name = blocks[i][0]
left, width = float(blocks[i][3]), float(blocks[i][1])
bottom, height = float(blocks[i][4]), float(blocks[i][2])
right = left + width
top = bottom + height
if max_x < right:
max_x = right
if max_y < top:
max_y = top
i += 1
total_width = max_x
total_height = max_y
#np.random.seed(19680801)
#npts = 200
#ngridx = 100
#ngridy = 200
'''
x = np.random.uniform(-2, 2, npts)
y = np.random.uniform(-2, 2, npts)
z = x * np.exp(-x**2 - y**2)
'''
res_array = ReadCSVfile(sys.argv[2])
npts = len(res_array)
gc = res_array[:,0]
z = res_array[:,1] - 273.15
#-- print statistics
print("Total grid count: %d" %gc.size)
print("Min grid temp: %f[C]" % np.min(z))
print("Avg grid temp: %f[C]" % np.average(z))
print("Max grid temp: %f[C]" % np.max(z))
fig, (ax) = plt.subplots(nrows=1)
'''
# -----------------------
# Interpolation on a grid
# -----------------------
# A contour plot of irregularly spaced data coordinates
# via interpolation on a grid.
# Create grid values first.
xi = np.linspace(-2.1, 2.1, ngridx)
yi = np.linspace(-2.1, 2.1, ngridy)
# Linearly interpolate the data (x, y) on a grid defined by (xi, yi).
triang = tri.Triangulation(x, y)
interpolator = tri.LinearTriInterpolator(triang, z)
Xi, Yi = np.meshgrid(xi, yi)
zi = interpolator(Xi, Yi)
# Note that scipy.interpolate provides means to interpolate data on a grid
# as well. The following would be an alternative to the four lines above:
# from scipy.interpolate import griddata
# zi = griddata((x, y), z, (xi[None, :], yi[:, None]), method='linear')
ax1.contour(xi, yi, zi, levels=14, linewidths=0.5, colors='k')
cntr1 = ax1.contourf(xi, yi, zi, levels=14, cmap="RdBu_r")
fig.colorbar(cntr1, ax=ax1)
ax1.plot(x, y, 'ko', ms=3)
ax1.set(xlim=(-2, 2), ylim=(-2, 2))
ax1.set_title('grid and contour (%d points, %d grid points)' %
(npts, ngridx * ngridy))
'''
x_grid_count = 64
y_grid_count = 64
# x_grid_count = y_grid_count = np.sqrt(np.len(grid_idx))
#-- NOTE: hotspot's grid index is computed from top left corner
x = np.array([])
y = np.array([])
for i in range(y_grid_count):
for j in range(x_grid_count):
x = np.append(x, j*max_x/x_grid_count)
y = np.append(y, total_height - i*max_y/y_grid_count)
'''
for i in range(x_grid_count):
for j in range(y_grid_count):
x = np.append(x, i*max_x/x_grid_count)
y = np.append(y, j*max_y/y_grid_count)
'''
# ----------
# Tricontour
# ----------
# Directly supply the unordered, irregularly spaced coordinates
# to tricontour.
ax.tricontour(x, y, z, levels=14, linewidths=0.5, colors='k')
cntr2 = ax.tricontourf(x, y, z, levels=14, cmap="RdBu_r")
# build a rectangle for each unit in axes coords
i = 0
for e in blocks:
#-- skip blank lines
if len(blocks[i]) == 0:
i += 1
continue
#-- skip comment lines
if blocks[i][0][0] == '#':
i += 1
continue
name = blocks[i][0]
left, width = float(blocks[i][3]), float(blocks[i][1])
bottom, height = float(blocks[i][4]), float(blocks[i][2])
right = left + width
top = bottom + height
ax.add_patch(Rectangle((left, bottom), width, height,
fill=False, clip_on=False,
edgecolor='black', facecolor='blue', lw=1))
ax.text(0.5*(left+right), 0.5*(bottom+top), name,
fontsize=10, color='black')
i += 1
fig.colorbar(cntr2, ax=ax)
ax.plot(x, y, 'ko', ms=3)
#ax2.set(xlim=(2, 2), ylim=(-2, 2))
#ax2.set_title('tricontour (%d points)' % npts)
#ax2.set_title('Voltage noise contour (%s) (%d points)' % sys.argv[1], npts)
ax.set_title('Temperature contour (%s)' % sys.argv[1])
plt.ticklabel_format(style='sci', axis='x', scilimits=(0,0), useMathText=True)
plt.ticklabel_format(style='sci', axis='y', scilimits=(0,0), useMathText=True)
plt.subplots_adjust(hspace=0.5)
plt.show()
#-- plot temperature histogram
n_bins = 20
print("No. of nodes: %d" % len(z))
# Creating histogram
#fig, axs = plt.subplots(1, 1, figsize =(10, 7), tight_layout = True)
fig, axs = plt.subplots(1, 1)
axs.hist(z, bins = n_bins)
#plt.ticklabel_format(style='sci', axis='x', scilimits=(0,0), useMathText=True)
#plt.ticklabel_format(style='sci', axis='y', scilimits=(0,0), useMathText=True)
axs.set_title('Temperature histogram (%s)' % sys.argv[1])
axs.set_xlabel("Temperature [C]")
axs.set_ylabel("Grid count")
# Show plot
plt.show()