Repository navigation
Add utu.spectrum.contribution_function_line(), the contribution function of an observed line - #19
Merged
Merged
Conversation
…ction of an observed line `contribution_function()` returns every transition of an ion and leaves picking one out to the caller. The new function takes the lines by their ion and wavelength, along axes of their own, and sums the contribution functions of every transition of the ion within a tolerance of each wavelength, half a milliangstrom by default, so that a blend is counted whole. A wavelength with no transition there is an error. The result is laid out as `contribution_function()` lays it out, the wavelengths as the inputs and the contribution functions along the temperature and the lines as the outputs, so that it can be handed to `synthesize()`. An ion with more than one of the lines is built once. The ratio of protons to electrons is computed once if it is not given, and `size_chunk` solves the temperatures a few at a time to bound the memory of an ion with hundreds of levels, which changes nothing in the result. The tests check each line against the sum of the transitions picked out of `contribution_function()` by hand, exactly, including a blend of two transitions of O V at 122.133 angstroms, and that chunks, a density on its own axis, a single line given as plain values, and the ratio given with or without its axis all agree. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01BYjDL98znSud1yFh9chnkP
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #19 +/- ##
==========================================
Coverage 100.00% 100.00%
==========================================
Files 21 21
Lines 1537 1698 +161
==========================================
+ Hits 1537 1698 +161 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
…line()` fiasco 0.9.0 takes the ratio of protons to electrons as an argument of `fiasco.Ion`, and `next_ion()` passes it on, so the ion that fiasco builds to recombine from no longer walks the whole database. It also computes the ratio as an ion is built unless it is given one, and the ratio is now a property, so priming it through `__dict__` does nothing. - `contribution_function()` sets a ratio it is given through the property, which also reaches the ion it recombines from. - `contribution_function_line()` and `lines()` give the ratio to each ion as it is built. `lines()` broadcasts it against the temperature first, so that a ratio which does not fit fails rather than skipping every ion. - `ions()` gives each ion a ratio it never reads, so that listing the database does not walk it once for each of five hundred ions. From the review of `contribution_function_line()`: - The default tolerance is a hundredth of a milliangstrom, not half of one. CHIANTI lists some wavelengths to a tenth of a milliangstrom, and many pairs of transitions half a milliangstrom apart, so half a milliangstrom could take in a neighbor or not depending on rounding. No two distinct wavelengths of one ion in the database are closer than a tenth of a milliangstrom. - Every line is matched to its transitions before any ion is solved, so that a wavelength with no transition fails at once. - The lines are grouped by the ion rather than by its name, so that "O 5" and "O V" are solved once. - The result is allocated before anything is solved, so that no lines at all is an empty result rather than outputs of None. - A scalar density is the same density at every temperature and adds no axis, and a density on an axis of its own keeps the name of that axis. A density along the lines, or along the temperature and another axis, is an error. - An empty temperature is an error of its own. - The inputs of the result are a copy, which can be written. - The docstring says what the arguments of fiasco may not do under `size_chunk`, and names the line of Mg X in the example correctly. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01BYjDL98znSud1yFh9chnkP
This was referenced Nov 14, 2026
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
utu.spectrum.contribution_function_line(), the contribution function of an observed line, named by its ion and its wavelength. Also requires fiasco 0.9, which lets the ratio of protons to electrons be given to each ion as it is built.Why
contribution_function()returns every transition of an ion and leaves picking one out to the caller. Two papers now do that picking themselves, each with its own rule:This function gives both of them one rule.
What it does
ionandwavelength, which broadcast against each other. Several lines are an ion and a wavelength for each along the same axis, or one ion and several wavelengths. Each line is the sum of every transition of its ion withintoleranceof its wavelength, so a blend is counted whole.ValueErrorbefore any ion is solved;size_chunkbelow 1, lines along the temperature axis, and a density along the lines or along the temperature and another axis.contribution_function()lays it out, so it can be handed tosynthesize(). The inputs are the wavelengths, a copy of their own, and the outputs are the contribution functions alongaxis_temperatureand the axes of the lines. Two differences, since this is new API:contribution_function()calls it_density."O 5"and"O V";size_chunksolves the temperatures a few at a time to bound the memory of an ion with hundreds of levels, which the ESIS-II paper needs for Si XII in CI, and it leaves the result unchanged.fiasco 0.9
fiasco 0.9.0 (wtbarnes/fiasco#471) makes the ratio of protons to electrons an argument of
fiasco.Ion, whichnext_ion()passes on. Under 0.8, the ion that fiasco builds to recombine from computed its own ratio, walking the whole database, once per call and once per chunk. Measured on 21 temperatures with the full database, with the ratio given:fiasco.proton_electron_ratio()The ratios and contribution functions of O V, Mg X and Si XII are bit-identical between the two versions.
fiasco 0.9 also computes the ratio as an ion is built unless it is given one, and the ratio is now a property, so the old priming through
__dict__does nothing. So:contribution_function()sets a ratio it is given through the property, which also reaches the ion it recombines from. Its docstring now says to give the ratio tofiasco.Ioninstead.contribution_function_line()andlines()give the ratio to each ion as it is built.lines()broadcasts it against the temperature first, so that a ratio that doesn't fit fails, rather than as each ion is built, where a failure means the ion is skipped.ions()gives each ion a ratio it never reads. Without one, listing the 495 ions of the database would walk it once per ion, about 21 minutes.The requirement is
fiasco~=0.9.0. esis and both papers requirefiasco~=0.8.2, so they keep utu 0.6 until they raise it.Tests
Sixteen new tests in
test_lines.py, all comparing whole arrays with exact equality:contribution_function()by hand. The second is a blend of two O V transitions both listed at 122.133 Å, and the test checks that it really does match two."O V", and one ion given once for two wavelengths, match the three lines, and each ion is solved once. The inputs can be written.contribution_function().contribution_function()replaces the ion's, and the ion it recombines from has it too.The existing tests now give the ratio to
fiasco.Ion. All 24 tests intest_lines.pyand the rest of the suite pass locally with fiasco 0.9.0 against the full CHIANTI database. Ruff and black pass. The docstring example uses only O V and Mg X, which the docs' small database includes, and it runs locally.🤖 Generated with Claude Code
https://claude.ai/code/session_01BYjDL98znSud1yFh9chnkP