Skip to content

Commit 08d9e14

Browse files
committed
feat: automated geometry visualization with matplotlib
1 parent dc29db0 commit 08d9e14

4 files changed

Lines changed: 48 additions & 0 deletions

File tree

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import matplotlib.pyplot as plt
2+
import re
3+
import sys
4+
5+
def plot_geometry(file_path):
6+
fig, ax = plt.subplots(figsize=(8, 6))
7+
found_geometry = False
8+
9+
with open(file_path, 'r') as f:
10+
for line in f:
11+
# Box check: #box: x1 y1 z1 x2 y2 z2 material
12+
if line.startswith('#box:'):
13+
parts = line.split(': ')[1].split()
14+
x1, y1, x2, y2 = float(parts[0]), float(parts[1]), float(parts[3]), float(parts[4])
15+
rect = plt.Rectangle((x1, y1), x2-x1, y2-y1, edgecolor='r', fill=False, label='Box')
16+
ax.add_patch(rect)
17+
found_geometry = True
18+
19+
# Cylinder check: #cylinder: x y z_start z_end radius material
20+
elif line.startswith('#cylinder:'):
21+
parts = line.split(': ')[1].split()
22+
x, y, r = float(parts[0]), float(parts[1]), float(parts[4])
23+
circle = plt.Circle((x, y), r, color='b', fill=False, label='Cylinder')
24+
ax.add_patch(circle)
25+
found_geometry = True
26+
27+
if not found_geometry:
28+
print("❌ No geometry found to plot!")
29+
sys.exit(1)
30+
31+
ax.set_aspect('equal')
32+
plt.title("gprMax Geometry Preview (X-Y Plane)")
33+
plt.xlabel("X (m)")
34+
plt.ylabel("Y (m)")
35+
plt.grid(True)
36+
plt.savefig('.github/workflows/geometry_preview.png')
37+
print("✅ Geometry plot saved as geometry_preview.png")
38+
39+
if __name__ == "__main__":
40+
plot_geometry('user_model.in')
18.2 KB
Loading

.github/workflows/user_model.in

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#domain: 0.240 0.210 0.170
2+
#dx_dy_dz: 0.002 0.002 0.002
3+
#box: 0.100 0.100 0.000 0.150 0.150 0.170 concrete
4+
#cylinder: 0.050 0.050 0.000 0.170 0.020 metal

user_model.in

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#domain: 0.240 0.210 0.170
2+
#dx_dy_dz: 0.002 0.002 0.002
3+
#box: 0.100 0.100 0.000 0.150 0.150 0.170 concrete
4+
#cylinder: 0.050 0.050 0.000 0.170 0.020 metal

0 commit comments

Comments
 (0)