refactor: remove stale detector schema keys and single-mode duplicates

- DEFAULT_JSON_SCHEMA: drop the 8 detector_* keys left over from the
  removed detector_response module; CLI dry-run drops the dead
  'Detector: not configured (Phase 4)' line
- CSV export: single-mode no longer writes branch_1_PhaseSpace /
  branch_1_Radiative duplicates next to the bare PhaseSpace/Radiative
  columns; per-branch core factors only in multi-branch mode
- Visualizer: debug panels fall back to the unprefixed core-factor
  columns for single-mode CSVs instead of skipping them
- Spectrum ylabel now states the actual units: normalized spectrum
  [MeV^-1], not 'Normalized Counts / keV'
- tests: defaults assert detector keys gone; column layout pinned for
  single vs multi; panel and ylabel assertions
This commit is contained in:
2026-10-02 10:21:07 +03:00
parent 3590ca91a1
commit 36174b5d25
6 changed files with 92 additions and 39 deletions
+66 -16
View File
@@ -605,9 +605,7 @@ class TestNormalizationModeMatrix:
)
assert np.isclose(area, 1.0, rtol=5e-4)
def test_intensity_concise_branch_columns_sum_to_total(
self, tmp_path: Any
) -> None:
def test_intensity_concise_branch_columns_sum_to_total(self, tmp_path: Any) -> None:
config = make_multi_config()
spectrum = BetaSpectrum.from_config(config)
analyzer = BetaSpectrumAnalyzer(spectrum, config)
@@ -622,10 +620,7 @@ class TestNormalizationModeMatrix:
)
total = df["total_spectrum"].to_numpy()
nonzero = total > 1e-12
assert np.all(
np.abs(summed[nonzero] - total[nonzero])
<= total[nonzero] * 5e-4
)
assert np.all(np.abs(summed[nonzero] - total[nonzero]) <= total[nonzero] * 5e-4)
def test_plot_from_csv_to_one_plots_branches_without_total(
self, tmp_path: Any
@@ -635,9 +630,7 @@ class TestNormalizationModeMatrix:
analyzer = BetaSpectrumAnalyzer(spectrum, config)
path, df = export_and_read(analyzer, tmp_path, "to_one_plot.csv")
fig = Visualizer.plot_from_csv(
path, save_path=None, show_components=True
)
fig = Visualizer.plot_from_csv(path, save_path=None, show_components=True)
assert len(fig.axes) == 4
# Panel 1 has exactly the 3 branch curves — no total spectrum
# exists in to_one mode.
@@ -646,9 +639,7 @@ class TestNormalizationModeMatrix:
assert len(curves) == 3
energies = df["energy_MeV"].to_numpy()
assert np.allclose(curves[0][:, 0], energies)
assert np.allclose(
curves[0][:, 1], df["branch_1_spectrum"].to_numpy()
)
assert np.allclose(curves[0][:, 1], df["branch_1_spectrum"].to_numpy())
def test_plot_analysis_to_one_returns_figure(self, tmp_path: Any) -> None:
config = make_multi_config(normalize_to_one=True)
@@ -669,11 +660,70 @@ class TestNormalizationModeMatrix:
analyzer, tmp_path, "to_one_concise2.csv", csv_verbosity="concise"
)
fig = Visualizer.plot_from_csv(
path, save_path=None, show_components=True
)
fig = Visualizer.plot_from_csv(path, save_path=None, show_components=True)
captured = capsys.readouterr()
assert "Warning" in captured.out
# Simple spectra view: one axis, 3 branch curves, no total curve.
assert len(fig.axes) == 1
assert len(fig.axes[0].lines) == 3
class TestSingleModeColumnCleanup:
"""Single-mode CSVs carry the factorized components once, unprefixed;
multi-mode CSVs carry them per branch; the visualizer reads whichever
naming the file actually uses."""
def test_single_mode_full_export_has_unprefixed_components_only(
self, tmp_path: Any
) -> None:
config = make_single_config(use_radiative=True)
spectrum = BetaSpectrum.from_config(config)
analyzer = BetaSpectrumAnalyzer(spectrum, config)
path, df = export_and_read(analyzer, tmp_path, "single_components.csv")
assert "PhaseSpace" in df.columns
assert "Radiative" in df.columns
assert "Fermi" in df.columns
assert "branch_1_spectrum" in df.columns
assert "branch_1_PhaseSpace" not in df.columns
assert "branch_1_Radiative" not in df.columns
def test_multi_mode_full_export_has_prefixed_core_factors(
self, tmp_path: Any
) -> None:
config = make_multi_config(use_radiative=True)
spectrum = BetaSpectrum.from_config(config)
analyzer = BetaSpectrumAnalyzer(spectrum, config)
path, df = export_and_read(analyzer, tmp_path, "multi_components.csv")
assert "branch_1_PhaseSpace" in df.columns
assert "branch_2_Radiative" in df.columns
assert "Fermi" in df.columns
# The bare core-factor names belong to single mode only.
assert "PhaseSpace" not in df.columns
assert "Radiative" not in df.columns
def test_debug_view_single_csv_includes_core_panels(self, tmp_path: Any) -> None:
config = make_single_config(use_radiative=True)
spectrum = BetaSpectrum.from_config(config)
analyzer = BetaSpectrumAnalyzer(spectrum, config)
path, _df = export_and_read(analyzer, tmp_path, "single_plot.csv")
fig = Visualizer.plot_from_csv(path, None, show_components=True)
assert len(fig.axes) == 4
# Panel 2: Fermi + the single branch's phase space.
assert len(fig.axes[1].lines) == 2
labels = [ln.get_label() for ln in fig.axes[1].lines]
assert "Fermi" in labels
assert any("PS Br" in str(lbl) for lbl in labels)
# Panel 4: the radiative correction for the single branch.
assert len(fig.axes[3].lines) == 1
def test_ylabel_uses_per_MeV_units(self, tmp_path: Any) -> None:
config = make_multi_config()
spectrum = BetaSpectrum.from_config(config)
analyzer = BetaSpectrumAnalyzer(spectrum, config)
path, _df = export_and_read(analyzer, tmp_path, "ylabel.csv")
fig = Visualizer.plot_from_csv(path, None, show_components=True)
assert "MeV$^{-1}$" in fig.axes[0].get_ylabel()