Repository navigation
Add ndoptimize.models.gaussian_binned, a Gaussian averaged over each bin. - #6
Merged
Merged
Conversation
…h bin. It has the same parameters as `gaussian`, the amplitude, center and width, and takes the edges of each bin as its two inputs. Averaging matters when the bins are about as wide as the line: a fit of `gaussian` at the bin centers takes the broadening from the bins as part of the width of the line, about 4% too wide for bins as wide as the line. The average is the difference of two error functions. In the tails, where both are close to 1 or to -1, it is computed from their complements, so it stays accurate where the plain difference would cancel to zero. A bin of zero width gives the Gaussian at that point. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01PZRXiFhGzzrF87vsFg73B9
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #6 +/- ##
==========================================
+ Coverage 99.61% 99.65% +0.03%
==========================================
Files 8 8
Lines 782 861 +79
==========================================
+ Hits 779 858 +79
Misses 3 3
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
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.
Adds
ndoptimize.models.gaussian_binned, a Gaussian averaged over each bin:It has the same parameters as
gaussian(amplitude, center and width), and its two inputs are the lower and upper edges of each bin,x[:, 0]andx[:, 1].Why
Averaging matters when the bins are about as wide as the line, which is the usual case for a CTIS reconstruction. sun-data/ctis#23 integrates its line profile over each velocity bin for this reason. Averaging over bins of width Δ broadens the line by about Δ²/12 in variance, and a fit of
gaussianat the bin centers takes that broadening as part of the line. For bins as wide as the line, the sampled fit comes out 4.2% too wide and 4% too low in amplitude, whilegaussian_binnedrecovers the line exactly.It's also the model that bin-edge inputs to
na.ModelFitFunctionArraywill feed (sun-data/named-arrays#271): when a fit axis of a function array holds bin edges, the model gets each bin's lower and upper edge.Numerics
erfc, so it stays accurate where the plain difference would cancel to zero. A bin 15σ from the center comes out within 1e-11 of numerical integration, at about 1e-47 of the peak.Tests
scipy.integrate.quadover bins in both far tails, on either side of the center, and across it, to a relative 1e-11, with its Jacobian against finite differences.gaussian.gaussianat the bin centers comes out more than 2% too wide.50 tests pass with and without JIT, with
models.py100% covered. ruff, black and pyright 1.1.411 are clean, and the docstring example (the Gaussian next to its bin averages) builds.Follow-up
The README and documentation list the models in #5. Once both merge, that list should add the binned Gaussian. I left it out here to avoid a conflict.
🤖 Generated with Claude Code
https://claude.ai/code/session_01PZRXiFhGzzrF87vsFg73B9