Fix pyright type errors and correct paceENSDF Q-value extraction

- nuclear_data.py: Extract Q-value from ground state branch state[7] instead of
  halflife_data (was reading half-life seconds as Q-value)
- nuclear_data.py: Use ground state branch for forbiddenness code, with fallback
- nuclear_data.py: Add None guards for beta_data and pairs
- spectrum.py: Pass Z=config.Z_daughter, A=config.A_number to RadiativeCorrection
- phase_space.py: Add __init__ debug logging (W0, transition_type, m_e, m_nu)
- phase_space.py: Add output range logging in __call__
- phase_space.py: Fix possibly unbound forbid_factor variable
- logging_utils.py: Fix broken get_git_short_hash indentation
- cli.py: Add explicit SpectrumConfig annotation to fix pyright type identity
- cw_extractor.py: Fix T_to_W ndarray→float conversions (6 locations)
- cw_extractor.py: Fix FermiFunction() calls — was passing Z as __call__ arg
- fitter.py: Add explicit dict type annotation for least_squares kwargs
This commit is contained in:
2026-05-05 12:43:43 +03:00
parent 297778d780
commit 3749220efc
7 changed files with 89 additions and 45 deletions
+13 -13
View File
@@ -256,9 +256,9 @@ class CWExtractor:
if self.config.use_radiative:
from .components.radiative import RadiativeCorrection
W0 = T_to_W(self.config.endpoint_MeV)
W0_float = float(T_to_W(self.config.endpoint_MeV))
rad = RadiativeCorrection(
W0=W0,
W0=W0_float,
Z=self.config.Z_parent,
A=self.config.A_number,
use_endpoint_resummation=True,
@@ -291,9 +291,9 @@ class CWExtractor:
Extracted C(W) values with uncertainties.
"""
if endpoint_keV is not None:
W0 = T_to_W(endpoint_keV / 1000.0)
W0_float = float(T_to_W(endpoint_keV / 1000.0))
else:
W0 = self._determine_endpoint()
W0_float = float(self._determine_endpoint())
# Compute theoretical factors (excluding C(W))
factors = self._theoretical_factors(self.energies_W)
@@ -310,12 +310,12 @@ class CWExtractor:
product *= factors[key]
# Endpoint factor: (W0 - W)^2
endpoint_factor = (W0 - self.energies_W) ** 2
endpoint_factor = (W0_float - self.energies_W) ** 2
# Overall normalization
if normalize_method == "endpoint":
# Use flux at lowest energy where C(W) ≈ 1 for allowed decay
low_E_mask = self.energies_W < W0 - 0.02
low_E_mask = self.energies_W < W0_float - 0.02
if np.any(low_E_mask):
C0 = np.median(
self.flux[low_E_mask]
@@ -325,7 +325,7 @@ class CWExtractor:
C0 = 1.0
else:
# Fit normalization
C0 = self._fit_normalization(W0, product, endpoint_factor)
C0 = self._fit_normalization(W0_float, product, endpoint_factor)
# Extract C(W)
cw = self.flux / (C0 * product * endpoint_factor)
@@ -347,8 +347,8 @@ class CWExtractor:
cw_errors=cw_errors,
flux=self.flux.copy(),
flux_errors=self.flux_errors.copy(),
endpoint_W=W0,
endpoint_keV=W_to_T(W0) * 1000.0,
endpoint_W=W0_float,
endpoint_keV=float(W_to_T(W0_float)) * 1000.0,
fit_result=None,
)
@@ -585,7 +585,7 @@ class CWExtractor:
p = momentum(W)
from .components.fermi import FermiFunction
F = FermiFunction()(W, self.config.Z_parent)
F = FermiFunction(Z=self.config.Z_parent, A=self.config.A_number)(W)
kurie = np.sqrt(flux / (p * W * F))
@@ -605,7 +605,7 @@ class CWExtractor:
except np.linalg.LinAlgError:
continue
return T_to_W(best_endpoint / 1000.0)
return float(T_to_W(best_endpoint / 1000.0))
def _fit_kurie_endpoint(self, cw_result: CWExtractionResult) -> FitResult:
"""Fit Kurie plot to determine endpoint energy."""
@@ -620,7 +620,7 @@ class CWExtractor:
p = momentum(W)
from .components.fermi import FermiFunction
F = FermiFunction()(W, self.config.Z_parent)
F = FermiFunction(Z=self.config.Z_parent, A=self.config.A_number)(W)
kurie = np.sqrt(flux / (p * W * F))
E_keV = self.energies_keV[mask]
@@ -639,7 +639,7 @@ class CWExtractor:
)
return fitter.fit(
x0=[np.mean(kurie), -np.mean(kurie) / E_keV[-1]],
x0=[float(np.mean(kurie)), float(-np.mean(kurie) / E_keV[-1])],
param_names=["a", "b"],
)