Repository navigation
Expand file tree
/
Copy pathorbitplot.py
More file actions
60 lines (52 loc) · 1.84 KB
/
Copy pathorbitplot.py
File metadata and controls
60 lines (52 loc) · 1.84 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
import sys
import pandas as pd
import matplotlib.pyplot as plt
def plot_from_file(file_path):
"""
Reads orbit data from a text file and generates plots.
"""
try:
# Extract run_id from the filename
run_id = file_path.split('orbit_error_')[-1].split('.txt')[0]
except IndexError:
run_id = "unknown"
try:
data = pd.read_csv(file_path, sep='\t')
except FileNotFoundError:
print(f"Error: The file {file_path} was not found.")
return
z_col = 'Z(cm)_1'
if z_col not in data.columns:
print(f"Error: Base Z column '{z_col}' not found in {file_path}.")
return
# Find all X and Y columns dynamically
x_cols = [col for col in data.columns if col.startswith('<X>(mm)_')]
y_cols = [col for col in data.columns if col.startswith('<Y>(mm)_')]
# Plot X orbits
plt.figure(figsize=(10, 6))
for x_col in x_cols:
plt.plot(data[z_col], data[x_col])
plt.xlabel('Z (cm)')
plt.ylabel('<X> (mm)')
plt.title(f'Orbit Error Analysis (X) - Run ID: {run_id}')
plt.grid(True)
plt.savefig(f'orbit_X_{run_id}.png', dpi=300)
print(f"Saved high-resolution plot to orbit_X_{run_id}.png")
plt.show()
# Plot Y orbits
plt.figure(figsize=(10, 6))
for y_col in y_cols:
plt.plot(data[z_col], data[y_col])
plt.xlabel('Z (cm)')
plt.ylabel('<Y> (mm)')
plt.title(f'Orbit Error Analysis (Y) - Run ID: {run_id}')
plt.grid(True)
plt.savefig(f'orbit_Y_{run_id}.png', dpi=300)
print(f"Saved high-resolution plot to orbit_Y_{run_id}.png")
plt.show()
if __name__ == "__main__":
if len(sys.argv) != 2:
print("Usage: python orbitplot.py <path_to_orbit_error_file.txt>")
sys.exit(1)
input_file = sys.argv[1]
plot_from_file(input_file)