wtbarnes / fiasco

Python interface to the CHIANTI atomic database
http://fiasco.readthedocs.io/
BSD 3-Clause "New" or "Revised" License
21 stars 17 forks source link

Correct level populations for ionization and recombination processes #223

Closed wtbarnes closed 1 year ago

wtbarnes commented 1 year ago

Fixes #24

This PR accomplishes two main things:

  1. It implements the correction to the level populations calculation by incorporating processes due to level-resolved ionization and recombination as stored in the cilvl and reclvl files as described in Landi et al. (2006)
  2. It fixes the interpolation of the ionization equilibrium by switching the interpolation from linear to a Piecewise Cubic Hermite Interpolating Polynomial (PCHIP) approach. This is more accurate over the full temperature range and even for small ionization fractions.

A few remaining TODOs:

codecov-commenter commented 1 year ago

Codecov Report

Patch coverage: 100.00% and project coverage change: -0.42 :warning:

Comparison is base (c674d97) 91.67% compared to head (37fb084) 91.26%.

:mega: This organization is not using Codecov’s GitHub App Integration. We recommend you install it so Codecov can continue to function properly for your repositories. Learn more

Additional details and impacted files ```diff @@ Coverage Diff @@ ## main #223 +/- ## ========================================== - Coverage 91.67% 91.26% -0.42% ========================================== Files 23 23 Lines 1947 2015 +68 ========================================== + Hits 1785 1839 +54 - Misses 162 176 +14 ``` | [Impacted Files](https://codecov.io/gh/wtbarnes/fiasco/pull/223?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Will+Barnes) | Coverage Δ | | |---|---|---| | [fiasco/ions.py](https://codecov.io/gh/wtbarnes/fiasco/pull/223?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Will+Barnes#diff-Zmlhc2NvL2lvbnMucHk=) | `96.59% <100.00%> (+0.53%)` | :arrow_up: | | [fiasco/util/setup\_db.py](https://codecov.io/gh/wtbarnes/fiasco/pull/223?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Will+Barnes#diff-Zmlhc2NvL3V0aWwvc2V0dXBfZGIucHk=) | `64.83% <0.00%> (-15.39%)` | :arrow_down: | Help us with your feedback. Take ten seconds to tell us [how you rate us](https://about.codecov.io/nps?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Will+Barnes). Have a feature suggestion? [Share it here.](https://app.codecov.io/gh/feedback/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Will+Barnes)

:umbrella: View full report at Codecov.
:loudspeaker: Do you have feedback about the report comment? Let us know in this issue.

wtbarnes commented 1 year ago

Based on the test failures, it looks like the free-free and free-bound values have changed, likely due to the differences in how I'm interpolating the ioneq. The differences are surprisingly large which is worrying.

wtbarnes commented 1 year ago

For Mg 12, when comparing to the equivalent IDL correction factors sent by Peter, the calculation here shows good agreement,

image

image

wtbarnes commented 1 year ago

I've finally settled on using PchipInterpolator to perform the cubic interpolation of the ionization fractions in log-space. This seems to be best solution for balancing smoothness and reducing oscillations. see plots of Fe V, VI, and XX ionization fractions below:

image

image

wtbarnes commented 1 year ago

Comparing the correction factors as implemented here and those in CHIANTI IDL for Fe XX for T=10 MK and $n_e=10^{10}$ $\mathrm{cm}^{-3}$,

image