Skip to content

ENH: Add ssd parameter to fourier_log_deconvolution#178

Draft
francisco-dlp wants to merge 2 commits into
hyperspy:mainfrom
francisco-dlp:fix/ssd-deconvolution
Draft

ENH: Add ssd parameter to fourier_log_deconvolution#178
francisco-dlp wants to merge 2 commits into
hyperspy:mainfrom
francisco-dlp:fix/ssd-deconvolution

Conversation

@francisco-dlp

Copy link
Copy Markdown
Member

Description

Adds an ssd parameter to fourier_log_deconvolution that optionally returns the normalised single-scattering distribution S(E) instead of the default J^1(E) = I₀ · S(E).

Parameter Returns Integral Use case
ssd=False (default) J¹(E) I₀ · t/λ Backward-compatible; relative quantification
ssd=True S(E) t/λ Absolute quantification (no I₀ needed)

Additional fixes

  • add_zlp scaling: When add_zlp=True with ssd=True, the ZLP is now correctly scaled by 1/I₀ to match SSD normalisation. Previously raw ZLP counts were added, producing nonsense output 7–9 orders of magnitude too large.
  • Docstring: Added quantification-pitfall warning explaining that J¹(E) must be divided by I₀ for areal-density quantification.

Changes

  • exspy/signals/_eels.pyssd parameter + add_zlp scaling fix + docstring warning
  • exspy/tests/signals/test_eels.py — 7 new tests in TestFourierLogDeconvolution
  • doc/user_guide/eels.rst — expanded Deconvolutions section
  • upcoming_changes/168.enhancements.rst — towncrier changelog

Test results

  • 7/7 new deconvolution tests pass
  • 622/627 pass suite-wide (5 pre-existing two_area_powerlaw_estimation* failures unrelated to this PR)

References

  • Egerton, R.F. Electron Energy-Loss Spectroscopy in the Electron Microscope. Springer, 2011, §4.4.

Default (ssd=False) returns J¹(E) = I₀·S(E), the single-scattering component
that an idealized (plural-scattering-free) experiment would record.
Set ssd=True to divide by I₀ and recover S(E) directly, whose integral
equals t/λ, for absolute quantification.

Constraint: default behaviour is unchanged from prior releases
Confidence: high
Scope-risk: narrow

Assisted-by: opus:deepseek-v4-pro
When add_zlp=True and ssd=True the ZLP must be divided by I₀ to keep
units coherent with the normalised SSD output.  Without scaling the raw
ZLP counts (typically 10⁴–10⁶) would dominate the dimensionless SSD
by 7–9 orders of magnitude.

- add_zlp block computes zlp_add = zlp.data / i0 for ssd=True
- Add quantification-pitfall warning to docstring
- Strengthen test_add_zlp_with_ssd: verify integral = t/λ + 1 and
  consistency with J¹ output outside taper region
- Add test_add_zlp_j1_raw_zlp: verify J¹ case adds raw ZLP
- Expand user guide with J¹/SSD distinction and quantification guidance

Assisted-by: deepseek-v4-pro:deepseek-v4-pro
@codecov

codecov Bot commented Jun 7, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 96.05263% with 3 lines in your changes missing coverage. Please review.
✅ Project coverage is 88.70%. Comparing base (10e53fa) to head (a0f928d).

Files with missing lines Patch % Lines
exspy/signals/_eels.py 62.50% 2 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #178      +/-   ##
==========================================
+ Coverage   88.33%   88.70%   +0.37%     
==========================================
  Files         100      100              
  Lines        7764     7838      +74     
  Branches      932      934       +2     
==========================================
+ Hits         6858     6953      +95     
+ Misses        632      607      -25     
- Partials      274      278       +4     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@francisco-dlp francisco-dlp marked this pull request as draft June 8, 2026 16:22
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