unzhakov
5c2b12c0e6
feat: experimental data calibration pipeline with ROOT I/O
...
- Fix chi2 calculation bug in calibration.py (remove incorrect
coeffs[::-1] reversal in np.polyval)
- Fix broken beta_spectrum/cli.py (remove orphaned detector response
add_argument calls and unused imports)
- Add ExpSpectrum.apply_calibration() and EnergyCalibrator.from_am241_spectrum()
- Add LivetimeDetermination class for pulser-based livetime
- Add SpectrumPipeline orchestration (read→subtract→calibrate→livetime→validate)
- Add ROOT I/O with PyROOT primary + uproot fallback
- Add bs_exp CLI with process, livetime, export subcommands
- Add exp_calibration notebook with pre-calibration visualization
- Add comprehensive tests (73 passing)
- Add bs_exp console script and [root] extra to pyproject.toml
- Remove obsolete detector_response module and unused notebooks
2026-05-21 16:01:25 +03:00
unzhakov
38b44b56e6
feat: v0.4.0 package restructuring — split into 4 modules
...
Separate monolithic beta_spectrum package into:
beta_spectrum — pure theory (components, spectrum, CLI, visualize)
exp_data — experimental data handling (spectrum, calibration,
fitters, corrections)
fitter — analysis framework (model, fit_engine, extractor,
result)
beta_spectrum.visualize — plotting (BetaSpectrumAnalyzer)
Phase 1 — exp_data module:
ExpSpectrum dataclass with metadata, normalization, serialization
EnergyCalibrator (linear/quadratic calibration)
GaussianFitter + PeakFitter for calibration sources
DeadTimeCorrection, PileUpCorrection, BackgroundSubtractor
43 new tests, ruff + mypy clean
Phase 2 — fitter module:
SpectrumModel wraps BetaSpectrum + DetectorResponse with convolution
SpectrumFitter with χ² minimization, covariance, profile likelihood,
confidence intervals, robust loss functions
CWExtractor + GVAExtractor for C(W) and g_V/g_A extraction
AnalysisResult + FitSummary for physics-specific results
CurveFitter general-purpose callable model fitter
34 new tests, ruff + mypy clean
Phase 3 — clean up beta_spectrum:
Remove cw_extractor.py and fitter.py (moved to fitter/)
Clean __init__.py to export only theory classes
Add backward-compat methods to CWExtractor
Fix BetaSpectrumAnalyzer._get_branch_spectrum returning BetaSpectrum
objects instead of numpy arrays (plot fix)
Phase 4 — package structure:
Auto-discovered by setuptools (4 packages)
All imports updated across 26 source files
Black formatting applied
322 tests pass (262 original + 60 new)
ruff + mypy clean on all source files
Bug fixes:
- Fix multi-branch spectrum plotting: universal component keys
(Fermi, Screening, etc.) don't have per-branch prefix; fixed
fallback lookup.
- Fix negative phase space beyond endpoint: BetaSpectrum returns
negative values for W > W0; clamp branch spectra to zero.
2026-05-17 18:58:04 +03:00
unzhakov
745bbae4cd
refactor: rename 'analyzer' to 'visualize' — analysis belongs to fitter module
2026-05-17 01:33:13 +03:00
unzhakov
f05a2de1b8
refactor: move BetaSpectrumAnalyzer to separate analyzer module
2026-05-16 20:41:58 +03:00
unzhakov
76d183b913
test: Phase 5 — advanced improvements
...
1. pytest-timeout (30s, thread-based) added to pyproject.toml
- Prevents hangs in CI
- timeout_method='thread' for clean cancellation
2. hypothesis added for property-based edge case discovery
- tests/common/test_hypothesis_tests.py: 5 tests
- Fermi: random Z, A, W — checks stability, monotonicity
- Phase space: random W0, W — checks threshold/endpoint properties
- Hypothesis already found real bugs:
* Fermi monotonicity fails for Z < 10 (expected — finite-size dominates)
* Phase space negative when W > W0 (test constrains W < W0)
3. pytest.mark.requires_ensdf marker added to TestPaceENSDFIntegration
- Replaces bare @pytest.mark.skipif with documented marker
- Allows running only ENSDF tests: pytest -m requires_ensdf
4. Updated test-migration-todo.md: Phase 5 complete
Final state: 256 tests passing (250 regular + 6 hypothesis + 6 skipped ENSDF)
2026-05-15 16:48:46 +03:00
unzhakov
c96fb6175a
test: add .gitkeep files and update TODO with phase 1-4 complete
...
- Add .gitkeep to tests/common/ and tests/integration/ directories
- Mark phases 1-4 as complete in test-migration-todo.md
- All migration work done: 251 tests passing
- Final structure:
- tests/common/ — 3 files (shared helpers)
- tests/physics/ — 10 files (physics behavior)
- tests/quality/ — 8 files (API contracts)
- tests/integration/ — 2 files (end-to-end)
2026-05-15 15:56:28 +03:00
unzhakov
c78d0655a0
test: complete migration to structured test suite
...
Phase 1: Removed 6 duplicate old test files (fermi, finite_size, screening,
exchange, radiative, phase_space) — their tests are now in physics/ and quality/
using shared helpers from common/.
Phase 2: Migrated remaining 7 old test files:
- test_spectrum.py → integration/test_spectrum_pipeline.py (integration tests)
- test_fitter.py → physics/test_fitter.py (fit quality tests)
- test_cw_extractor.py → physics/test_cw_extractor.py (extraction accuracy)
- test_multi_branch.py → physics/test_multi_branch.py (branching physics)
- test_detector_response.py → physics/ + quality/ (split into physics + API)
- test_nuclear_data.py → quality/test_nuclear_data.py (parsing/API)
- test_logging_utils.py → quality/test_logging_utils.py (API tests)
Removed 12 old flat files, created 4 new files.
Total: 251 tests passing (6 skipped), down from 230 → 251 (net +21
from better coverage, not duplicates).
Test structure:
- tests/common/ — shared property/API helpers (eliminates ~18 duplicates)
- tests/physics/ — 10 files, unique physics behavior tests
- tests/quality/ — 8 files, API contract + parsing tests
- tests/integration/ — 1 file, end-to-end pipeline tests
2026-05-15 15:52:50 +03:00
unzhakov
4b08df3873
test: create new test architecture with shared property/API tests
...
- Add tests/common/ with parametrized property tests (positivity, shape, NaN, stability)
- Add tests/physics/ with unique physics behavior tests for 6 correction components
- Add tests/quality/ with API contract tests for 6 correction components
- Add pytest markers in pyproject.toml: property, physics, api, quality, integration
- New tests: 94 tests passing (physics + quality + common helpers)
- Old tests in tests/ root still present — migration in progress
- Total: 261 tests collected (230 old + 94 new - 63 duplicates removed)
The shared helpers eliminate 18 duplicate test patterns across correction
components. Each component now has:
- tests/physics/test_<name>.py — unique physics behavior
- tests/quality/test_api_<name>.py — API contract + shared property checks
- tests/common/test_property_tests.py — shared helpers (imported, not duplicated)
2026-05-15 15:04:52 +03:00
unzhakov
984c4f6884
Add regression test for Tc99 ENSDF intensity values
2026-05-08 16:11:06 +03:00
unzhakov
c404d83418
Remove 'universal_' prefix from CSV column names in multi-branch mode
...
Universal components (Fermi, Screening, etc.) are exported under their
plain names — no redundant prefix needed.
2026-05-08 15:54:13 +03:00
unzhakov
b02159ba5c
Remove repeated per-branch metadata columns from CSV export
...
Branch intensity, endpoint, and transition are constant per branch and
already documented in the CSV header. No need to repeat them as columns
for every energy row.
2026-05-08 15:41:10 +03:00
unzhakov
69eca97736
test: comprehensive multi-branch decay test suite (30 tests)
...
- BranchConfig validation (intensity bounds, positive endpoint)
- Single-branch via multi-branch path compatibility
- Multi-branch spectrum calculation and intensity weighting
- Per-branch spectra with correct endpoint and transition type
- Component extraction (universal vs branch-dependent)
- CSV export with total, per-branch, and universal components
- Transition type propagation from BranchInfo
- Branch values <= total spectrum verification
- Branch integral proportionality to intensity
- High-Z multi-branch stability
- No-branches defaults to single-branch mode
2026-05-08 08:34:30 +03:00
unzhakov
330ebddaef
refactor: refine CLI options and enhance debug logging
...
- Remove --mode, --transition-type, and --decay-index CLI flags
(parameters now come from ENSDF data or custom JSON input)
- Clarify energy units in all CLI help text (MeV throughout, keV for detector params)
- Enhance logging verbosity:
- -v (INFO): shows source, component initialization, workflow steps
- -vv (DEBUG): shows detailed internals of all spectrum components
(parameters, evaluation counts, input/output ranges)
- Improve CSV headers with element notation (e.g. Tc99 -> Ru99)
- Add CONVENTIONS.md documenting energy unit and logging conventions
- Update TODO.md with completion status
2026-05-05 09:08:08 +03:00
unzhakov
9050019ddd
feat: add structured logging, CSV metadata headers, and CLI improvements
...
- New module: beta_spectrum/logging_utils.py
- LoggingConfig dataclass with level, log_file, format options
- setup_logging() one-shot configuration (opt-in for library use)
- get_logger() for named child loggers
- get_git_short_hash() for commit identification
- _find_git_root() for repo detection
- CLI enhancements (beta_spectrum/cli.py):
- --verbose/-v (repeatable): -v=INFO, -vv=DEBUG
- --quiet/-q: suppress all terminal output
- --log-file PATH: append log to file
- --dry-run: validate input, display resolved config, exit
- --version: show package version
- Replace print() with structured logging throughout
- Handle KeyboardInterrupt gracefully
- CSV metadata headers (BetaSpectrumAnalyzer.export_to_csv):
- YAML-style # comments with version, timestamp, source, nuclide info
- Corrections enabled, e_step, detector settings, git commit hash
- Base class integration (SpectrumComponent):
- Optional logger parameter for debug/info output (opt-in)
- BetaSpectrum integration:
- Optional logger parameter passed through from_config()
- Detector logging in create_detector_from_config()
- Convolution logging in convolve_with_detector()
- Tests: tests/test_logging_utils.py (28 tests)
- LoggingConfig, setup_logging, get_logger, git hash, CSV headers, CLI flags
- Update TODO.md: mark B8 as complete, update Current Status
2026-05-04 15:11:01 +03:00
unzhakov
66a93d9cac
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
- Add mypy disable_error_code configuration for test files
- Run black and ruff for formatting and linting
2026-05-03 01:00:47 +03:00
unzhakov
1269244b93
feat: add paceENSDF integration and CLI interface (Track B1)
...
- Add nuclear_data.py module for paceENSDF integration and JSON input
- Add DecayInfo and BranchInfo dataclasses for parsed nuclear data
- Implement get_decay_info_from_paceENSDF() to retrieve decay parameters
- Implement load_json_input() and json_to_config() for custom JSON input
- Add create_config_from_source() unified interface for both sources
- Add bs_pnpi CLI with --nuclide, --input, --output, --plot, and detector options
- Add 23 comprehensive tests for nuclear_data module
- Add sample JSON input file
- Update __init__.py and pyproject.toml with new exports and entry point
- Add paceENSDF as optional dependency
2026-05-02 22:09:25 +03:00
unzhakov
272841f50d
feat: add χ² fitter and C(W) shape factor extraction modules
...
Add CurveFitter with scipy least_squares, configurable loss functions
(soft_l1, huber, cauchy), profile likelihood, confidence intervals, and
goodness-of-fit metrics. Add CWExtractor for extracting shape factors
from beta spectra via Kurie analysis, parametrization fitting, and
g_V/g_A extraction. Includes 32 new tests (18 fitter + 14 CW extractor).
Bump version to 0.3.0.
2026-05-02 09:40:38 +03:00
unzhakov
bb5ce636ce
style: fix black formatting in test_spectrum.py
2026-05-01 19:21:18 +03:00
unzhakov
5f99566a0e
feat(detector): add detector response module, convolution, and integration
...
- Analytical detector response: gaussian, gaussian_tail, tikhonov models
- Low-energy tail modeling for charge collection effects
- Response matrix convolution via R^T · (Φ·ΔW)
- Declarative API: create_detector_from_config(), convolve_detector()
- BetaSpectrumAnalyzer.convolved_spectrum() for auto-convolution
- Integration tests: TestBetaSpectrumIntegration, TestDeclarativeDetectorResponse
- Documentation: docs/08-detector-response.md
2026-05-01 19:20:59 +03:00
unzhakov
c9a738baab
chore(gitignore): remove notebooks and ipynb from gitignore
...
style: fix black formatting in test files (unused imports, assert reformatting)
2026-05-01 19:16:50 +03:00
unzhakov
c99ce51487
fix(radiative): only apply endpoint resummation within delta_cut per spec Section 3.4
...
The resummation was previously applied to all energy points when the
flag was set, causing resummed and standard modes to differ everywhere.
Per spec, it should only replace C(beta)*ln(W0-W) with the resummed
power-law form when (W0-W) < delta_cut (~1e-3).
Adds delta_cut parameter (default 1e-3) and corrects the resummation
switch test to verify identical results far from endpoint.
2026-04-30 21:06:00 +03:00
unzhakov
ed3fd5dc9d
feat(radiative): implement O(Z*alpha^2) correction and improve numerical stability
...
- Add Z (nuclear charge) and A (mass number) parameters to RadiativeCorrection
- Implement O(Z*alpha^2) finite nuclear size correction per Sirlin 1987:
- Energy-dependent part: ln(m_p) - (5/12)*ln(2W) + 43/18
- Nuclear-structure-dependent part: Delta_F(Z,A) from modified Gaussian model
- Add small-beta Taylor expansion for numerical stability at threshold (beta < 1e-6)
- Extract _safe_beta() and _safe_tanh_inv_beta_over_beta() helper methods
- Remove unused log_wright_bessel import
- Add 14 new tests: Z-dependence, numerical stability, A parameter coverage
- Update docs/06-radiative-corrections.md with new API usage examples
All 70 tests pass. 14 new tests in 3 new test classes.
2026-04-30 07:18:02 +03:00
unzhakov
bce6e63663
Add pytest test suite (56 tests) for all spectrum components
2026-04-26 23:45:53 +03:00