Fix mypy type errors and black formatting
- spectrum.py: Use Axes from TYPE_CHECKING instead of plt.Axes - fitter.py: Remove unused type: ignore comment - phase_space.py: Black formatting
This commit is contained in:
@@ -33,7 +33,10 @@ class PhaseSpace(SpectrumComponent):
|
|||||||
if self._logger:
|
if self._logger:
|
||||||
self._logger.debug(
|
self._logger.debug(
|
||||||
"PhaseSpace: W0=%.5f, transition_type=%s, m_e=%.6f, m_nu=%.6f",
|
"PhaseSpace: W0=%.5f, transition_type=%s, m_e=%.6f, m_nu=%.6f",
|
||||||
W0, transition_type, m_e, m_nu,
|
W0,
|
||||||
|
transition_type,
|
||||||
|
m_e,
|
||||||
|
m_nu,
|
||||||
)
|
)
|
||||||
if self.tr_type not in ["A", "F1", "F1U", "F2", "F2U", "F3", "F3U", "F4"]:
|
if self.tr_type not in ["A", "F1", "F1U", "F2", "F2U", "F3", "F3U", "F4"]:
|
||||||
raise ValueError(
|
raise ValueError(
|
||||||
@@ -66,6 +69,7 @@ class PhaseSpace(SpectrumComponent):
|
|||||||
if self._logger:
|
if self._logger:
|
||||||
self._logger.debug(
|
self._logger.debug(
|
||||||
"PhaseSpace: output range=[%.6e, %.6e]",
|
"PhaseSpace: output range=[%.6e, %.6e]",
|
||||||
result.min(), result.max(),
|
result.min(),
|
||||||
|
result.max(),
|
||||||
)
|
)
|
||||||
return result
|
return result
|
||||||
|
|||||||
@@ -405,7 +405,7 @@ class CurveFitter:
|
|||||||
if bounds is not None:
|
if bounds is not None:
|
||||||
ls_kwargs["bounds"] = bounds_array
|
ls_kwargs["bounds"] = bounds_array
|
||||||
|
|
||||||
result = least_squares(**ls_kwargs) # type: ignore[arg-type]
|
result = least_squares(**ls_kwargs)
|
||||||
|
|
||||||
# Compute covariance matrix from Jacobian
|
# Compute covariance matrix from Jacobian
|
||||||
# Cov = (J^T J)^(-1) * χ² / (n - p)
|
# Cov = (J^T J)^(-1) * χ² / (n - p)
|
||||||
|
|||||||
+12
-14
@@ -3,9 +3,13 @@ from __future__ import annotations
|
|||||||
|
|
||||||
import logging
|
import logging
|
||||||
from datetime import datetime, timezone
|
from datetime import datetime, timezone
|
||||||
|
from typing import TYPE_CHECKING
|
||||||
|
|
||||||
import numpy as np
|
import numpy as np
|
||||||
import matplotlib.pyplot as plt
|
import matplotlib.pyplot as plt
|
||||||
|
|
||||||
|
if TYPE_CHECKING:
|
||||||
|
from matplotlib.axes import Axes
|
||||||
from typing import TYPE_CHECKING, Any, Dict, List, Optional, Tuple
|
from typing import TYPE_CHECKING, Any, Dict, List, Optional, Tuple
|
||||||
from dataclasses import dataclass
|
from dataclasses import dataclass
|
||||||
|
|
||||||
@@ -435,17 +439,11 @@ class BetaSpectrumAnalyzer:
|
|||||||
timestamp = datetime.now(timezone.utc).strftime("%Y-%m-%d %H:%M:%S UTC")
|
timestamp = datetime.now(timezone.utc).strftime("%Y-%m-%d %H:%M:%S UTC")
|
||||||
|
|
||||||
if show_components:
|
if show_components:
|
||||||
self._plot_debug_view(
|
self._plot_debug_view(total, components, save_path, commit, timestamp)
|
||||||
total, components, save_path, commit, timestamp
|
|
||||||
)
|
|
||||||
else:
|
else:
|
||||||
self._plot_spectrum_only(
|
self._plot_spectrum_only(total, save_path, commit, timestamp)
|
||||||
total, save_path, commit, timestamp
|
|
||||||
)
|
|
||||||
|
|
||||||
def _add_id_textbox(
|
def _add_id_textbox(self, ax: "Axes", commit: str, timestamp: str) -> None:
|
||||||
self, ax: plt.Axes, commit: str, timestamp: str
|
|
||||||
) -> None:
|
|
||||||
"""Add ID text box with commit hash and timestamp to plot."""
|
"""Add ID text box with commit hash and timestamp to plot."""
|
||||||
id_text = f"commit: {commit} | {timestamp}"
|
id_text = f"commit: {commit} | {timestamp}"
|
||||||
ax.text(
|
ax.text(
|
||||||
@@ -460,7 +458,7 @@ class BetaSpectrumAnalyzer:
|
|||||||
fontfamily="monospace",
|
fontfamily="monospace",
|
||||||
)
|
)
|
||||||
|
|
||||||
def _add_nuclear_data_header(self, ax: plt.Axes) -> None:
|
def _add_nuclear_data_header(self, ax: "Axes") -> None:
|
||||||
"""Add nuclear data information header to plot."""
|
"""Add nuclear data information header to plot."""
|
||||||
parent = self._element_symbol(self.config.Z_parent)
|
parent = self._element_symbol(self.config.Z_parent)
|
||||||
daughter = self._element_symbol(self.config.Z_daughter)
|
daughter = self._element_symbol(self.config.Z_daughter)
|
||||||
@@ -503,7 +501,9 @@ class BetaSpectrumAnalyzer:
|
|||||||
fontsize=8,
|
fontsize=8,
|
||||||
verticalalignment="top",
|
verticalalignment="top",
|
||||||
horizontalalignment="right",
|
horizontalalignment="right",
|
||||||
bbox=dict(boxstyle="round,pad=0.3", facecolor="white", alpha=0.8, edgecolor="none"),
|
bbox=dict(
|
||||||
|
boxstyle="round,pad=0.3", facecolor="white", alpha=0.8, edgecolor="none"
|
||||||
|
),
|
||||||
)
|
)
|
||||||
|
|
||||||
def _plot_spectrum_only(
|
def _plot_spectrum_only(
|
||||||
@@ -516,9 +516,7 @@ class BetaSpectrumAnalyzer:
|
|||||||
"""Plot only the total spectrum with nuclear data header."""
|
"""Plot only the total spectrum with nuclear data header."""
|
||||||
fig, ax = plt.subplots(figsize=(10, 6))
|
fig, ax = plt.subplots(figsize=(10, 6))
|
||||||
|
|
||||||
ax.plot(
|
ax.plot(self.energies_MeV, total, "b-", lw=2, label="Normalized spectrum")
|
||||||
self.energies_MeV, total, "b-", lw=2, label="Normalized spectrum"
|
|
||||||
)
|
|
||||||
ax.set_xlabel(r"Electron kinetic energy $E$ [MeV]", fontsize=11)
|
ax.set_xlabel(r"Electron kinetic energy $E$ [MeV]", fontsize=11)
|
||||||
ax.set_ylabel("Normalized Counts", fontsize=11)
|
ax.set_ylabel("Normalized Counts", fontsize=11)
|
||||||
ax.set_title(
|
ax.set_title(
|
||||||
|
|||||||
Reference in New Issue
Block a user