|
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 |
2 | 38 | from scan_analysis.analyzers.Undulator.rad2_spec_analysis import Rad2SpecAnalysis |
3 | 39 |
|
4 | 40 | import numpy as np |
5 | 41 | import matplotlib.pyplot as plt |
6 | 42 |
|
7 | 43 | # 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") |
9 | 45 |
|
10 | 46 | # 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 | +) |
12 | 50 | if analyzer.get_visa_station() == 9: |
13 | | - |
14 | 51 | # 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 | + ) |
17 | 63 |
|
18 | 64 | # Load full file, extract energy from the first row and data from the rest |
19 | 65 | lineout_data = np.load(spectrum_file) |
|
22 | 68 |
|
23 | 69 | number_of_shots = np.shape(scan_spectrums)[0] |
24 | 70 |
|
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 | + ) |
26 | 74 | plt.show() |
0 commit comments