tardisbase.testing.regression_comparison.visualization module¶
- class tardisbase.testing.regression_comparison.visualization.SpectrumSolverComparator(ref1_path, ref2_path, plot_dir=None)[source]¶
Bases:
object
A class for comparing and visualizing spectrum solver data between two regression datasets.
This class provides visualization capabilities for spectrum solver analysis, generating both matplotlib and Plotly plots that show luminosity comparisons and fractional residuals between two reference datasets. It supports multiple spectrum types including integrated, real packets, reabsorbed packets, and virtual packets.
- Parameters:
ref1_path (str or Path) – Path to the first reference HDF5 file containing spectrum solver data. This file should contain the expected spectrum solver data structure.
ref2_path (str or Path) – Path to the second reference HDF5 file containing spectrum solver data. This file should have the same structure as ref1_path for comparison.
plot_dir (str, Path, or None, optional) – Directory path where plots should be saved when SAVE_COMP_IMG environment variable is set to ‘1’, by default None. If None, plots are displayed but not saved to disk.
Notes
The class expects HDF5 files with spectrum solver data stored under the path: ‘simulation/spectrum_solver/{spectrum_type}/{wavelength|luminosity}’
Each spectrum type should contain both wavelength and luminosity datasets as 1D arrays of the same length.
- plot_matplotlib()[source]¶
Generate comprehensive matplotlib plots comparing spectrum solver data.
This method creates a 4x2 grid of subplots showing luminosity comparisons and fractional residuals for each spectrum type. Each spectrum type gets two vertically stacked subplots: luminosity comparison (top) and fractional residuals (bottom).
Notes
Plot structure: - Figure size: 20x20 inches for high-resolution output - Grid layout: 4 rows × 2 columns with height ratios [3,1,3,1] - Top subplots: Luminosity vs wavelength for both references - Bottom subplots: Fractional residuals (Ref2-Ref1)/Ref1 vs wavelength
Visualization features: - Ref1 data: solid lines - Ref2 data: dashed lines - Residuals: purple lines with horizontal zero-reference line - Grid lines and legends for clarity - Shared x-axes between luminosity and residual plots
Fractional residuals calculation: residuals = (luminosity_ref2 - luminosity_ref1) / luminosity_ref1
Division by zero is handled by setting residuals to 0 where luminosity_ref1 = 0.
File saving: If environment variable SAVE_COMP_IMG=’1’ and plot_dir is specified, saves high-resolution PNG (300 DPI) to plot_dir/spectrum.png.
- plot_plotly()[source]¶
Generate interactive Plotly plots for spectrum solver data comparison.
This method creates an interactive web-based visualization using Plotly with the same data structure as the matplotlib version but with enhanced interactivity, hover information, and modern styling.
Notes
Plot configuration: - Layout: 4 rows × 2 columns with height ratios [0.3, 0.15] repeated - Total dimensions: 1200px width × 900px height - Shared x-axes between luminosity and residual plots - Reduced spacing for compact visualization
Visualization features: - Interactive hover tooltips with data values - Solid lines for Ref1, dashed lines for Ref2 - Purple residual lines with horizontal zero-reference lines - Light blue background for enhanced readability - Grid lines and consistent axis labeling
Subplot organization: - Rows 1,3: Luminosity plots for spectrum types - Rows 2,4: Corresponding fractional residual plots - Column 1: spectrum_integrated, spectrum_real_packets_reabsorbed - Column 2: spectrum_real_packets, spectrum_virtual_packets
Interactive features: - Zoom and pan capabilities - Legend toggling for hiding/showing traces - Hover data inspection - Export capabilities (PNG, SVG, PDF)
The plot automatically handles missing data gracefully and maintains consistent axis ranges across related subplots for easy comparison.
- setup()[source]¶
Load spectrum solver data from both reference HDF5 files.
This method reads wavelength and luminosity data for all spectrum types from both reference files and stores them in the internal data structure. It handles missing files and keys with warning messages.
Notes
The method populates self.data with the following structure: data[‘Ref1’|’Ref2’][spectrum_key][‘wavelength’|’luminosity’] = numpy.ndarray
For each spectrum type, the method expects to find: - simulation/spectrum_solver/{spectrum_type}/wavelength - simulation/spectrum_solver/{spectrum_type}/luminosity
Error handling includes: - FileNotFoundError: Warns if HDF5 files are missing - KeyError: Warns if expected spectrum data keys are not found
After successful execution, all data is available as NumPy arrays for plotting and analysis operations.