-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathtest_insert_visualization.py
More file actions
148 lines (127 loc) · 3.53 KB
/
test_insert_visualization.py
File metadata and controls
148 lines (127 loc) · 3.53 KB
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
#!/usr/bin/env python3
"""
Test Insert visualization with multiple helices.
"""
import sys
from pathlib import Path
sys.path.insert(0, str(Path(__file__).parent))
from python_magnetgeo.Insert import Insert
from python_magnetgeo.Helix import Helix
from python_magnetgeo.ModelAxi import ModelAxi
from python_magnetgeo.Model3D import Model3D
print("="*60)
print("Insert Visualization Test")
print("="*60)
print()
# Create helices for the insert
# h=50.0 → sum(pitch*turns) = 100.0
modelaxi1 = ModelAxi(
name="modelaxi_H1",
h=50.0,
turns=[2, 16, 2],
pitch=[5.0, 5.0, 5.0]
)
model3d1 = Model3D(name="", cad="H1", with_channels=False, with_shapes=False)
helix1 = Helix(
name="H1",
r=[30.0, 40.0],
z=[0.0, 100.0],
cutwidth=3.0,
odd=True,
dble=False,
modelaxi=modelaxi1,
model3d=model3d1
)
# h=45.0 → sum(pitch*turns) = 90.0
modelaxi2 = ModelAxi(
name="modelaxi_H2",
h=45.0,
turns=[2, 14, 2],
pitch=[5.0, 5.0, 5.0]
)
model3d2 = Model3D(name="", cad="H2", with_channels=False, with_shapes=False)
helix2 = Helix(
name="H2",
r=[45.0, 55.0],
z=[0.0, 100.0],
cutwidth=3.0,
odd=False,
dble=False,
modelaxi=modelaxi2,
model3d=model3d2
)
# h=40.0 → sum(pitch*turns) = 80.0
modelaxi3 = ModelAxi(
name="modelaxi_H3",
h=40.0,
turns=[2, 12, 2],
pitch=[5.0, 5.0, 5.0]
)
model3d3 = Model3D(name="", cad="H3", with_channels=False, with_shapes=False)
helix3 = Helix(
name="H3",
r=[60.0, 70.0],
z=[0.0, 100.0],
cutwidth=3.0,
odd=True,
dble=False,
modelaxi=modelaxi3,
model3d=model3d3
)
# Create Insert
insert = Insert(
name="Test_Insert",
helices=[helix1, helix2, helix3],
rings=[],
currentleads=[],
hangles=[0.0, 0.0, 0.0],
rangles=[],
innerbore=25.0,
outerbore=75.0
)
print(f"Created Insert: {insert.name}")
print(f" Number of helices: {len(insert.helices)}")
for i, h in enumerate(insert.helices):
print(f" {i+1}. {h.name}: r={h.r}, z={h.z}")
print()
try:
import matplotlib.pyplot as plt
# Test 1: Insert with modelaxi zones
print("Test 1: Insert with ModelAxi zones")
ax = insert.plot_axisymmetric(
title=f"Insert: {insert.name} (with ModelAxi zones)",
figsize=(12, 14)
)
plt.savefig("test_insert_with_modelaxi.png", dpi=150, bbox_inches='tight')
print(" ✓ Saved as test_insert_with_modelaxi.png")
plt.close()
# Test 2: Insert without modelaxi zones
print("\nTest 2: Insert without ModelAxi zones")
ax = insert.plot_axisymmetric(
title=f"Insert: {insert.name} (main bodies only)",
show_modelaxi=False,
figsize=(12, 14)
)
plt.savefig("test_insert_no_modelaxi.png", dpi=150, bbox_inches='tight')
print(" ✓ Saved as test_insert_no_modelaxi.png")
plt.close()
# Test 3: Insert with custom colors
print("\nTest 3: Insert with custom helix colors")
ax = insert.plot_axisymmetric(
title=f"Insert: {insert.name} (custom colors)",
helix_colors=['darkblue', 'darkred', 'darkgreen'],
helix_alpha=0.7,
figsize=(12, 14)
)
plt.savefig("test_insert_custom_colors.png", dpi=150, bbox_inches='tight')
print(" ✓ Saved as test_insert_custom_colors.png")
plt.close()
print("\n" + "="*60)
print("✓ All Insert visualization tests passed!")
print("="*60)
except ImportError:
print("! Matplotlib not installed - skipping visualization tests")
except Exception as e:
print(f"✗ Error: {e}")
import traceback
traceback.print_exc()