Skip to content

Raise DegenerateBaselineWindowError on degenerate baseline windows (fixes #639) - #679

Merged
HongSik-Yun-Fusion merged 2 commits into
developfrom
fix/639-magnetics-baseline-error-handling
Sep 9, 2026
Merged

Raise DegenerateBaselineWindowError on degenerate baseline windows (fixes #639)#679
HongSik-Yun-Fusion merged 2 commits into
developfrom
fix/639-magnetics-baseline-error-handling

Conversation

@HongSik-Yun-Fusion

Copy link
Copy Markdown
Contributor

Closes #639.

Summary of Changes

  • Define DegenerateBaselineWindowError: Subclass of ValueError in vaft.process.magnetics (re-exported in __all__) raised when fewer than two valid samples fall inside the baseline window.
  • Diagnostic context: Reports shot number, channel, valid count vs required, requested index/window bounds, and signal time span / sample count in the exception message.
  • Configurable Opt-In Fallback: Added allow_zero_fallback: bool = False to VestMagneticsProcessingConfig and as a keyword argument across vest_* magnetics functions. When explicitly enabled (allow_zero_fallback=True), falls back to zero-baseline subtraction and emits an informative UserWarning.
  • Downstream Callers Updated: vest_b_field_pol_probe_legacy, vest_flux_loop_flux_from_voltage, vest_flux_loop_legacy, vest_equilibrium_magnetics_detailed, and vest_equilibrium_magnetics_signals forward diagnostic context and fallback policy.
  • Tests: Added tests in test/test_equilibrium_magnetics_processing.py covering probe and flux loop degenerate windows, message format assertions, opt-in fallback warnings, and multi-channel aggregation behavior.

…ixes #639)

- Define DegenerateBaselineWindowError subclassing ValueError in vaft.process.magnetics
- Add allow_zero_fallback configuration to VestMagneticsProcessingConfig (defaulting to False)
- Support allow_zero_fallback and diagnostic context in _linear_baseline and vest_* callers
- Raise informative diagnostic error message when valid baseline sample count < 2
- When allow_zero_fallback=True, warn via UserWarning and fall back to zero baseline
- Add unit tests verifying error raising, error message contents, and opt-in fallback
…allback in machine mapping

- Filter non-finite (NaN/Inf) samples in _linear_baseline so NaN-contaminated baseline windows raise DegenerateBaselineWindowError
- Fix channel falsy check in vest_b_field_pol_probe_legacy to preserve integer channel 0
- Expose allow_zero_fallback in vfit_equilibrium_magnetics_detailed and vfit_equilibrium_magnetics
- Parse allow_zero_fallback from vest.yaml window dictionary in equilibrium_magnetics_processing_config
- Add tests for integer channel 0 and NaN baseline windows
@HongSik-Yun-Fusion
HongSik-Yun-Fusion merged commit 4010ef6 into develop Sep 9, 2026
8 checks passed
@HongSik-Yun-Fusion
HongSik-Yun-Fusion deleted the fix/639-magnetics-baseline-error-handling branch September 9, 2026 02:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant