Skip to content

Commit a58cea4

Browse files
committed
Update rad2_spectrum_stitcher.py
1 parent 4e2021a commit a58cea4

File tree

1 file changed

+55
-7
lines changed

1 file changed

+55
-7
lines changed
Lines changed: 55 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,65 @@
1-
from geecs_data_utils import ScanData
1+
"""
2+
Plot Rad2 per-shot spectrum for a given scan.
3+
4+
This script loads and visualizes the spectrum data saved by
5+
`Rad2SpecAnalysis` for a specific scan. It uses the scan tag
6+
(year, month, day, number, experiment) to locate the corresponding
7+
analysis folder, loads the saved spectrum (`scan_spectrum.npy`),
8+
and plots the shot-by-shot lineouts as an image.
9+
10+
Workflow
11+
--------
12+
1. Construct a `ScanTag` for the target scan.
13+
2. Initialize `Rad2SpecAnalysis` and check if the analyzer
14+
corresponds to visa station 9.
15+
3. If so, locate the analysis folder and spectrum file.
16+
4. Load the spectrum file:
17+
- The first row contains the energy axis.
18+
- Subsequent rows contain the per-shot spectra.
19+
5. Plot the spectra as a 2D image with energy on the x-axis
20+
and shot index on the y-axis.
21+
22+
Dependencies
23+
------------
24+
- geecs_data_utils
25+
- scan_analysis
26+
- numpy
27+
- matplotlib
28+
29+
Notes
30+
-----
31+
If the analyzer does not correspond to visa station 9, no plot
32+
is generated. The script assumes the spectrum file exists;
33+
missing files will raise a `FileNotFoundError`.
34+
35+
"""
36+
37+
from geecs_data_utils import ScanPaths, ScanTag
238
from scan_analysis.analyzers.Undulator.rad2_spec_analysis import Rad2SpecAnalysis
339

440
import numpy as np
541
import matplotlib.pyplot as plt
642

743
# Get the tag for the given date+scan number
8-
tag = ScanData.get_scan_tag(year=2025, month=3, day=6, number=90, experiment='Undulator')
44+
tag = ScanTag(year=2025, month=3, day=6, number=90, experiment="Undulator")
945

1046
# Load the analyzer to determine if it is visa9 (it is not running any new analysis)
11-
analyzer = Rad2SpecAnalysis(scan_tag=tag, skip_plt_show=False, debug_mode=False, background_mode=False)
47+
analyzer = Rad2SpecAnalysis(
48+
skip_plt_show=False, debug_mode=False, background_mode=False
49+
)
1250
if analyzer.get_visa_station() == 9:
13-
1451
# Get analysis folder and spectrum file
15-
analysis_folder = ScanData.get_daily_scan_folder(tag=tag).parent / 'analysis' / f"Scan{tag.number:03d}"
16-
spectrum_file = analysis_folder / 'UC_UndulatorRad2' / 'CameraImageAnalyzer' / 'scan_spectrum.npy'
52+
analysis_folder = (
53+
ScanPaths.get_daily_scan_folder(tag=tag).parent
54+
/ "analysis"
55+
/ f"Scan{tag.number:03d}"
56+
)
57+
spectrum_file = (
58+
analysis_folder
59+
/ "UC_UndulatorRad2"
60+
/ "CameraImageAnalyzer"
61+
/ "scan_spectrum.npy"
62+
)
1763

1864
# Load full file, extract energy from the first row and data from the rest
1965
lineout_data = np.load(spectrum_file)
@@ -22,5 +68,7 @@
2268

2369
number_of_shots = np.shape(scan_spectrums)[0]
2470

25-
plt.imshow(scan_spectrums, extent=([energy_axis[0], energy_axis[-1], 0, number_of_shots]))
71+
plt.imshow(
72+
scan_spectrums, extent=([energy_axis[0], energy_axis[-1], 0, number_of_shots])
73+
)
2674
plt.show()

0 commit comments

Comments
 (0)