Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
uvahotspot
GitHub Repository: uvahotspot/HotSpot
Path: blob/master/scripts/grid_thermal_map.py
612 views
1
#! /usr/bin/python3
2
3
import matplotlib.pyplot as plt
4
import numpy as np
5
import sys
6
7
usage = \
8
"""
9
usage: grid_thermal_map.py <flp_file> <grid_temp_file> <filename>.png (or)
10
grid_thermal_map.py <flp_file> <grid_temp_file> <rows> <cols> <filename>.png (or)
11
grid_thermal_map.py <flp_file> <grid_temp_file> <rows> <cols> <min> <max> <filename>.png
12
13
Saves a heat map as a PNG image with the filename <filename>.png
14
15
<flp_file> -- path to the file containing the floorplan (eg: example.flp)
16
<grid_temp_file> -- path to the grid temperatures file (eg: layer_0.grid.steady)
17
<rows> -- no. of rows in the grid (default 64)
18
<cols> -- no. of columns in the grid (default 64)
19
<min> -- min. temperature of the scale (defaults to min. from <grid_temp_file>)
20
<max> -- max. temperature of the scale (defaults to max. from <grid_temp_file>)
21
"""
22
23
if len(sys.argv) == 4:
24
flp_filename = sys.argv[1]
25
temperatures_filename = sys.argv[2]
26
output_filename = sys.argv[3]
27
rows = 64
28
cols = 64
29
min_temp = None
30
max_temp = None
31
elif len(sys.argv) == 6:
32
flp_filename = sys.argv[1]
33
temperatures_filename = sys.argv[2]
34
rows = int(sys.argv[3])
35
cols = int(sys.argv[4])
36
output_filename = sys.argv[5]
37
min_temp = None
38
max_temp = None
39
elif len(sys.argv) == 8:
40
flp_filename = sys.argv[1]
41
temperatures_filename = sys.argv[2]
42
rows = int(sys.argv[3])
43
cols = int(sys.argv[4])
44
min_temp = float(sys.argv[5])
45
max_temp = float(sys.argv[6])
46
output_filename = sys.argv[7]
47
else:
48
print(usage)
49
sys.exit(0)
50
51
fig, axs = plt.subplots(1)
52
total_width = -np.inf
53
total_length = -np.inf
54
with open(flp_filename, "r") as fp:
55
for line in fp:
56
57
# Ignore blank lines and comments
58
if line == "\n" or line[0] == '#':
59
continue
60
61
parts = line.split()
62
name = parts[0]
63
width = float(parts[1])
64
length = float(parts[2])
65
x = float(parts[3])
66
y = float(parts[4])
67
68
rectangle = plt.Rectangle((x, y), width, length, fc="none", ec="black")
69
axs.add_patch(rectangle)
70
plt.text(x, y, name)
71
72
total_width = max(total_width, x + width)
73
total_length = max(total_length, y + length)
74
75
temps = []
76
with open(temperatures_filename, "r") as fp:
77
for line in fp:
78
temps.append(float(line.strip().split()[1]))
79
80
temps = np.reshape(temps, (rows, cols))
81
82
im = axs.imshow(temps, cmap='hot_r', extent=(0, total_width, 0, total_length))
83
84
if min_temp is None and max_temp is None:
85
im.set_clim(np.min(temps), np.max(temps))
86
else:
87
im.set_clim(min_temp, max_temp)
88
89
cbar = fig.colorbar(im, ax=axs)
90
91
axs.set_title(f"Heat Map\nMaximum Temperature = {np.max(temps)}")
92
93
axs.set_xticks([n for n in np.linspace(0, total_width, 5)])
94
axs.set_xticklabels([n*(10**3) for n in np.linspace(0, total_width, 5)])
95
axs.set_xlabel("Horizontal Position (mm)")
96
97
axs.set_yticks([n for n in np.linspace(0, total_length, 5)])
98
axs.set_yticklabels([n*(10**3) for n in np.linspace(0, total_length, 5)])
99
axs.set_ylabel("Vertical Position (mm)")
100
101
plt.axis('scaled')
102
plt.savefig(output_filename)
103
104