Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add new GauntFactor class and add Itoh integrated Gaunt factors to f-f radiative loss #293

Merged
merged 69 commits into from
Sep 27, 2024

Conversation

jwreep
Copy link
Collaborator

@jwreep jwreep commented Aug 15, 2024

Fixes #248

  • Parse the new files
  • Implement new GauntFactor class
  • Add Itoh options to total f-f Gaunt factor
  • Add Itoh options to f-f radiative loss function
  • Tests

@jwreep
Copy link
Collaborator Author

jwreep commented Aug 15, 2024

For my own reference, the equations from Itoh et al 2002 for the two forms of the Gaunt factor. (They're using log base 10.)

Relativistic:
Screenshot 2024-08-15 at 11 42 37 AM

Non-relativistic:
Screenshot 2024-08-15 at 11 42 56 AM

@wtbarnes
Copy link
Owner

As we implement this, I'd like to think carefully about how these are related to the other Gaunt factor methods. Currently, we have the following methods for calculating Gaunt factors:

  • gaunt_factor_free_free--function of wavelength and temperature
  • _gaunt_factor_free_free_itoh
    • used by gaunt_factor_free_free in the relativistic regime
  • _gaunt_factor_free_free_sutherland
    • used by gaunt_factor_free_free in the non-relativistic regime
  • _gaunt_factor_free_free_total
    • function of temperature
    • wavelength-integrated version of _gaunt_factor_free_free_sutherland (I think)
    • used by free_free_radiative_loss
  • _gaunt_factor_free_bound_total
    • function of temperature
    • used by free_bound_radiative_loss

In our current organization of the API, even though most of these are private methods, it can be confusing why we have so many methods named very similar things and why/where each is relevant. While implementing these new methods, whether there is some better top level API for calculating these such that we minimize the number of entry points for calculating a Gaunt factor and make it more obvious to a user (or future developer, including ourselves, why method is preferred over and another).

@jwreep
Copy link
Collaborator Author

jwreep commented Aug 16, 2024

I'll spend a bit of time thinking about this. Open to suggestions!

@jwreep
Copy link
Collaborator Author

jwreep commented Aug 23, 2024

Unless I'm missing something, the actual data that's read in by fiasco.io for every type of Gaunt factor does not depend on the properties of an ion. That is, the fitting coefficients are the same for all ions.

If that's correct, perhaps it would be better to create a new module or class just dedicated to the Gaunt factor, and pull these functions out of the ion class. Then, call some overarching function along the lines of gaunt_factor(free_free=True, free_bound=False, wavelength_integrated=False) that then calls the appropriate function from the class.

This is trivial for free-free emission. For example, ion._gaunt_factor_free_free_itoh doesn't depend on any ion properties, ion._gaunt_factor_free_free_sutherland only depends on charge state and thus gives the same Gaunt factors for He III, Fe III, etc. at a given temperature.

The free-bound case is slightly more involved, because it depends on charge, ionization potential, and principal quantum number. However, nothing about this needs to be inherently tied to the ion class and each could be passed to a function.

Would something along those lines make sense?

Copy link

codecov bot commented Aug 31, 2024

Codecov Report

Attention: Patch coverage is 75.00000% with 92 lines in your changes missing coverage. Please review.

Project coverage is 90.46%. Comparing base (6642b07) to head (ee77037).
Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
fiasco/io/sources/continuum_sources.py 43.29% 55 Missing ⚠️
fiasco/gaunt.py 86.20% 24 Missing ⚠️
fiasco/tests/test_gaunt.py 88.52% 7 Missing ⚠️
fiasco/tests/test_collections.py 66.66% 3 Missing ⚠️
fiasco/tests/test_ion.py 66.66% 3 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #293      +/-   ##
==========================================
- Coverage   93.14%   90.46%   -2.68%     
==========================================
  Files          38       40       +2     
  Lines        3165     3367     +202     
==========================================
+ Hits         2948     3046      +98     
- Misses        217      321     +104     

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

@jwreep
Copy link
Collaborator Author

jwreep commented Sep 13, 2024

@wtbarnes, before I take this much further, your input would be welcome. I've created a new GauntFactor class with a bit of logic that should hopefully be readable code. It doesn't (shouldn't) affect anything outward-facing, but it does nest the various functions that calculate the different Gaunt factors into one object. Would something along these lines be a reasonable way to deal with the convoluted mess of Gaunt factors? Or did you have something else in mind?

Edit: also, I was wrong in my previous comment that some of the Gaunt factors don't depend on any ion properties. The Ion._itoh data is attached to an ion, though some of the other data is not.

(It still needs error handling and debugging, of course. It's a bit clumsy with .gf to get the actual values at the end as well.)

@wtbarnes
Copy link
Owner

Sorry for neglecting this for so long!

tl;dr I'm pro this approach overall. I have some thoughts on how exactly to implement this object. I've left a few high-level comments below and some inline comments on the code.

At first I was a bit skeptical of having these on a separate object, but I'm now thinking this is probably a good idea. Exposed as a separate object, they can still use the same data ingestion model as Ion which means we don't have to change anything at the I/O layer.

This also helps to shorten the ions.py file which seems to be ever expanding.

Edit: also, I was wrong in my previous comment that some of the Gaunt factors don't depend on any ion properties. The Ion._itoh data is attached to an ion, though some of the other data is not.

We could always change this in the way the parsing is done to be agnostic of Ion and then select the row appropriate to the given ion when doing the necessary calculation in the gaunt factor. I think it is per element anyway so it doesn't even need the granularity of per ion.

Copy link
Owner

@wtbarnes wtbarnes left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some implementation comments at this point. My overall thinking is that GauntFactor should not care about the Ion object at all and should just provide the relevant datasets and methods for computing the gaunt factor in various scenarios. It is then the job of the Ion object to provide the ion-specific inputs to those methods when using the appropriate gaunt factor calculation.

fiasco/gaunt.py Outdated Show resolved Hide resolved
fiasco/gaunt.py Outdated Show resolved Hide resolved
fiasco/gaunt.py Outdated Show resolved Hide resolved
fiasco/gaunt.py Outdated Show resolved Hide resolved
fiasco/gaunt.py Outdated Show resolved Hide resolved
fiasco/gaunt.py Outdated Show resolved Hide resolved
fiasco/gaunt.py Outdated Show resolved Hide resolved
fiasco/gaunt.py Outdated Show resolved Hide resolved
fiasco/gaunt.py Outdated Show resolved Hide resolved
@jwreep
Copy link
Collaborator Author

jwreep commented Sep 13, 2024

Thanks for the suggestions! I'll try to flesh this out a bit more.

@jwreep jwreep changed the title Add Itoh integrated Gaunt factors to f-f radiative loss Add new GauntFactor class and add Itoh integrated Gaunt factors to f-f radiative loss Sep 13, 2024
@jwreep
Copy link
Collaborator Author

jwreep commented Sep 14, 2024

@wtbarnes, has something changed with the github actions in the recent pulls? Pytest is passing on my machine, but failing on Github (including lots of tests not related to this PR).

fiasco/ions.py Outdated Show resolved Hide resolved
Co-authored-by: Will Barnes <will.t.barnes@gmail.com>
jwreep and others added 3 commits September 23, 2024 13:54
Co-authored-by: Will Barnes <will.t.barnes@gmail.com>
Co-authored-by: Will Barnes <will.t.barnes@gmail.com>
@jwreep
Copy link
Collaborator Author

jwreep commented Sep 24, 2024

Thank you for the clarification, Peter!

I'll add a citation to this technical report in fiasco.

@wtbarnes
Copy link
Owner

Looking at the docs, I now realize that the API docs for the new GauntFactor object aren't rendered anywhere because I asked for it to be excluded from the top-level namespace. It probably makes sense to just add it back to the top-level namespace. Sorry!

@jwreep
Copy link
Collaborator Author

jwreep commented Sep 24, 2024

Yeah, that probably explains why the docs build failed. lol

@wtbarnes
Copy link
Owner

I also take back what I said about only needing this in the context of the Ion object. It's not unreasonable one might want to calculate a Gaunt factor for other reasons as well so making the API more visible is only a good thing.

@jwreep
Copy link
Collaborator Author

jwreep commented Sep 26, 2024

I think that should've addressed all of your comments! Let me know if there are any more changes you'd like.

@wtbarnes
Copy link
Owner

I think that should've addressed all of your comments! Let me know if there are any more changes you'd like.

Everything is looking pretty good to me! i just pushed a few changes mostly cleaning up the docstrings, linking between methods, and enforcing some consistency between a few of the equations. Have a look over the rendered docs for GauntFactor and relevant methods on Ion and let me know what you think. I think this should be basically done.

@jwreep
Copy link
Collaborator Author

jwreep commented Sep 26, 2024

Looks fine to me. Thanks for touching that up.

@wtbarnes wtbarnes enabled auto-merge (squash) September 27, 2024 00:35
Copy link
Owner

@wtbarnes wtbarnes left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good to me! Thanks as always. I like the way this has turned out and make the Gaunt factor calculations much more readable and maintainable.

@wtbarnes wtbarnes merged commit a896483 into wtbarnes:main Sep 27, 2024
13 of 15 checks passed
@jwreep
Copy link
Collaborator Author

jwreep commented Sep 27, 2024

Thanks for the help! This ended up being a lot more involved than just parsing two new data sets. Hopefully the new format is easy to maintain and extend. For example, the CHIANTI technical report mentions a newer data set that's more accurate, that could potentially be readily built in to fiasco.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Run v9 tests Run the test suite using CHIANTI database version 9
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Use additional Itoh files when computing free-free emission
3 participants