Skip to content

Use the cached proton-electron ratio in Ion.emissivity and make it settable - #471

Open
jacobdparker wants to merge 1 commit into
wtbarnes:mainfrom
jacobdparker:use-cached-proton-electron-ratio
Open

jacobdparker wants to merge 1 commit into
wtbarnes:mainfrom
jacobdparker:use-cached-proton-electron-ratio

Conversation

@jacobdparker

@jacobdparker jacobdparker commented Sep 18, 2026

Copy link
Copy Markdown
Collaborator

Fixes #470

Ion.emissivity called the module-level proton_electron_ratio directly on every call, walking the entire database each time, instead of using the cached property on the instance. Since intensity and IonCollection.spectrum go through emissivity, a collection of N ions paid for the walk N times.

Changes:

  • Ion.emissivity now uses self.proton_electron_ratio.
  • Ion.proton_electron_ratio is now a lazily computed property with a setter, in the same style as abundance and ionization_fraction, so a ratio computed once with fiasco.proton_electron_ratio can be assigned to every ion sharing a temperature array. Setting it does not change _instance_kwargs, so ions created through next_ion and friends compute their own as before.
  • Two tests: the setter accepts a scalar or an array of the temperature's shape, and emissivity reflects a ratio that was set.

Timing with the full database, O V, 61 temperatures, before and after:

before after
emissivity (first call) 15.2 s 15.9 s
emissivity (second call) 15.0 s 3.1 s

The first call still computes the ratio once; #466 makes that part cheaper. Results are unchanged.

🤖 Generated with Claude Code

…settable

`Ion.emissivity` called the module-level `proton_electron_ratio` directly,
walking the entire database on every call, instead of using the cached
property on the instance. Replace the `cached_property` with a lazily
computed property that has a setter, so a ratio computed once with
`fiasco.proton_electron_ratio` can be shared between ions with the same
temperature.

Fixes wtbarnes#470

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
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.

emissivity recomputes proton_electron_ratio on every call instead of using the cached property; no way to pass a precomputed ratio

1 participant