-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathexample_visualization.py
More file actions
83 lines (70 loc) · 2.44 KB
/
example_visualization.py
File metadata and controls
83 lines (70 loc) · 2.44 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
#!/usr/bin/env python3
"""
Simple example demonstrating the new visualization features for Ring and Screen.
Usage:
python example_visualization.py
"""
from python_magnetgeo.Ring import Ring
from python_magnetgeo.Screen import Screen
# Example 1: Visualize a single Ring
print("Example 1: Single Ring visualization")
ring = Ring(
name="Ring_H1H2",
r=[19.3, 24.2, 25.1, 30.7], # 4 radii in ascending order
z=[0, 20], # axial bounds
n=6, # 6 cooling slits
angle=46 # each 46 degrees wide
)
# Plot it - matplotlib is optional
try:
import matplotlib.pyplot as plt
ax = ring.plot_axisymmetric(title="Example Ring")
plt.savefig("example_ring.png", dpi=150, bbox_inches='tight')
print(" ✓ Saved visualization to example_ring.png")
plt.close()
except ImportError:
print(" ! Matplotlib not installed - skipping visualization")
# Example 2: Visualize a single Screen
print("\nExample 2: Single Screen visualization")
screen = Screen(
name="Magnetic_Shield",
r=[50.0, 60.0], # inner and outer radius
z=[0.0, 200.0] # axial extent
)
try:
import matplotlib.pyplot as plt
ax = screen.plot_axisymmetric(title="Example Screen")
plt.savefig("example_screen.png", dpi=150, bbox_inches='tight')
print(" ✓ Saved visualization to example_screen.png")
plt.close()
except ImportError:
print(" ! Matplotlib not installed - skipping visualization")
# Example 3: Combined visualization
print("\nExample 3: Combined Ring + Screen visualization")
try:
import matplotlib.pyplot as plt
# Create figure
fig, ax = plt.subplots(figsize=(10, 12))
# Plot screen (background)
screen.plot_axisymmetric(
ax=ax,
color='lightgray',
alpha=0.3,
show_legend=False
)
# Plot ring (foreground)
ring.plot_axisymmetric(
ax=ax,
color='steelblue',
alpha=0.7,
show_legend=False
)
ax.set_title("Magnet Assembly", fontsize=14, fontweight='bold')
plt.savefig("example_combined.png", dpi=150, bbox_inches='tight')
print(" ✓ Saved visualization to example_combined.png")
plt.close()
except ImportError:
print(" ! Matplotlib not installed - skipping visualization")
print("\n✓ All examples completed!")
print("\nNote: The visualization feature is optional and requires matplotlib.")
print("Install with: pip install matplotlib")