Repository navigation
fix: Fourier-ratio leaves a pixel with a non-finite power-law continuation unanswered - #80
Merged
Merged
Conversation
…ation unanswered instead of failing the whole image Found in an app EELS room on a real spectrum image: one pixel whose low-loss window gives a large negative r (A finite, A x^-r overflows on the continuation) made the extrapolated image unformable, so fourierRatio threw nonFiniteCounts(pixel:) for every pixel. exSpy 0.3.2 gives NaN at that pixel only (RuntimeWarning) and deconvolves the rest. fourierRatio now extrapolates through a package helper that zeroes and flags such a pixel (low loss or core loss); the pixel gets zeros and nonFiniteResult, the others are bit-identical to before. When the flagged pixel is the first low-loss pixel and the FWHM is estimated from it, exSpy is NaN everywhere and the kit throws noPeakWidth. The public powerLawExtrapolation is unchanged. Done: per-pixel unavailability for a non-finite continuation, three red-first tests. Next: the app shows unanswered pixels and turns raw errors into sentences. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Contributor
Author
|
Checked on 3 real EELS spectrum images through the macTEM EELS room, with this change on top of 0.12.0: the one image that failed before (the whole Fourier-ratio map, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Requested by Paul · project thread
Found in an app EELS room on a real STEM spectrum image: Fourier-ratio failed the whole map when one pixel had a bad low-loss tail.
Cause
fourierRatioextends both spectra with the two-area power law before the FFT. On a pixel whose last 100 low-loss channels are near zero then large, r comes out large and negative (here -143), A stays finite (8e-296), and(scale * A) * pow(x, -r)overflows to inf on the continuation. The extendedLowLossSpectrumImagethen refuses its counts, so the call threwnonFiniteCounts(pixel: 5)and no pixel was deconvolved.Refuted if: a pixel with a finite continuation fails the same way. Checked: the public
powerLawExtrapolationof the bad image throws, the clean image does not.What exSpy 0.3.2 does (References venv,
python -I)power_law_extrapolationwarnsoverflow encountered in powerand leaves inf at that pixel;fourier_ratio_deconvolutionreturns NaN at that pixel only and finite, unchanged values everywhere else. When the bad pixel is pixel 0 and the FWHM is estimated (exSpy measures the first pixel), the FWHM is NaN and every pixel is NaN.Fix
fourierRatiogives that pixel zeros andunavailable = .nonFiniteResult, the same convention as its other unanswered pixels. The other pixels are bit-identical.noPeakWidth(exSpy: NaN everywhere). WithfwhmEVgiven, only pixel 0 is unanswered.powerLawExtrapolationis unchanged (it still throws on an overflowing pixel). No public API change.Numbers move
The failed pixel goes from a whole-map error to an unanswered pixel. Synthetic 4 x 3 image, 256 channels, threshold 2.5 eV:
nonFiniteCounts(pixel: 5), 0 of 12 pixelsnonFiniteResult; 11 of 12 answerednonFiniteCounts(pixel: 0)nonFiniteCounts(pixel: 0)noPeakWidth(pass a FWHM)nonFiniteCounts(pixel: 0)Tests
testFourierRatioPixelWithNonFiniteContinuationIsUnavailableandtestFourierRatioFirstPixelNonFiniteContinuationfailed withnonFiniteCountsbefore the fix;testFourierRatioCoreLossNonFiniteContinuationadded after review.swift test -c release --parallel --skip SpectroKitParityTestsgreen (133 + 322 + 66 + 1 tests, the known issues unchanged).DeconvolutionPinsTestsincluded.This PR changes numbers a user sees: it waits for Paul.
🤖 Generated with Claude Code