-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplt_grid_diff.py
125 lines (106 loc) · 3.12 KB
/
plt_grid_diff.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
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
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
path = './outputs/case2/'
blocks = readflpfile(path + "table_modelL4_ChipLayer.flp")
array1 = ReadCSVfile(path + 'step_999.grid.steady')
array2 = ReadCSVfile(path + 'table_model.grid.steady')
z1 = array1[:,1] - 273.15
z2 = array2[:,1] - 273.15
num1 = len(z1)
num2 = len(z2)
assert(num1 == num2)
#for i in range(num2):
# z2[i] = float(array2[i]) - 45
#array_sum = [0]*num
diff = np.array([])
absdiff = np.array([])
for i in range(num1):
diff = np.append(diff, (z1[i] - z2[i]))
absdiff = np.append(absdiff, abs(z1[i] - z2[i]))
# if diff[i]<0.005:
# count1 += 1
# if diff[i]<0.05:
# count2 += 1
# if diffmax<diff[i]:
# diffmax = diff[i]
# countmax = i
# if diffmin>diff[i]:
# diffmin = diff[i]
# countmin = i
## if z1[i] <= 1:
## count += 1
#print("gridtemp_diffmin:",diffmin)
#print("gridtemp_diffmax:",diffmax)
##print("seqmax",countmax)
##print("seqmin",countmin)
#
#print("diff<0.005C grid count:",count1)
#print("diff<0.05C grid count:",count2)
fig,(ax) = plt.subplots(nrows=1)
x = np.array([])
y = np.array([])
x_grid_count = 64
y_grid_count = 64
max_x = 1e-3*50
max_y = 1e-3*50
total_width = max_x
total_height = max_y
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)
# ----------
# Tricontour
# ----------
# Directly supply the unordered, irregularly spaced coordinates
# to tricontour.
ax.tricontour(x, y, absdiff, levels=14, linewidths=0, colors='k')
cntr2 = ax.tricontourf(x, y, absdiff, 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)
ax.set_title('abs(difference) between every grid')
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()