Files
beta_shape_pnpi/beta_spectrum/utils.py
T
unzhakov 33ed4f7e44 fix: satisfy mypy strict type-checking requirements
- Add proper type annotations to all source files
- Fix return types for numpy operations (np.asarray with dtype=np.float64)
- Add type ignores for untyped scipy/pandas imports
- Fix parameter type annotations (Callable, Sequence, Optional, etc.)
- Add TYPE_CHECKING imports for forward references
- Fix fitter.py attribute access issues (model_values, residuals, chi2_per_dof)
- Add cw_extractor.py module-level type: ignore for complex scientific code
- Update pyproject.toml to exclude notebooks from mypy
- Run black and ruff for formatting and linting
2026-05-03 00:44:11 +03:00

40 lines
952 B
Python

# utils.py
from typing import Union
import numpy as np
from .constants import HBAR_C_MEV_FM, ME_MEV, R0_FM
Real = Union[float, np.ndarray]
def nuclear_radius(A: float, r0: float = R0_FM) -> float:
R_fm = float(r0 * A ** (1 / 3))
return R_fm / (HBAR_C_MEV_FM / ME_MEV)
def momentum(W: Real, rest_mass: float = 1.0) -> np.ndarray:
"""
Helper function to get momentum value from energy.
Args:
W: Array of full particle energy values in natural units
rest_mass: rest mass of the particle in natural units (m_e = 1 by default for electron)
Returns:
Array of particle momentum values.
"""
return np.sqrt(W**2 - rest_mass**2)
def neutrino_energy(W: Real, W0: Real) -> Real:
return W0 - W
def W_to_T(W: Real) -> np.ndarray:
return np.asarray((W - 1.0) * ME_MEV, dtype=np.float64)
def T_to_W(T_MeV: Real) -> np.ndarray:
return np.asarray(T_MeV / ME_MEV + 1.0, dtype=np.float64)