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

Issue 285: Add ionization energy data from NIST #2657

Merged
merged 97 commits into from
May 14, 2024
Merged

Conversation

chasepd
Copy link
Contributor

@chasepd chasepd commented May 3, 2024

Description

Adds ionization energy data from NIST to the particle data json files, as well as a property in the Particle class to retrieve this information. Returns a descriptive MissingParticleDataError if ionization energy data is not available for the particle.

Motivation and context

Addresses the requested feature at: #285.

A commonly needed in plasma physics is the energy it takes to ionize a single atom or ion. The Particle class should have an attribute called ionization_energy that returns this value.

Related issues

#285

@chasepd chasepd requested a review from a team as a code owner May 3, 2024 15:06
@chasepd chasepd requested review from namurphy and removed request for a team May 3, 2024 15:06
Copy link

github-actions bot commented May 3, 2024

Thank you for submitting a pull request (PR) to PlasmaPy! ✨ The future of the project depends on contributors like you, so we deeply appreciate it! 🌱

Our contributor guide has information on:

Important

PlasmaPy recently switched to an src layout. The source code previously in plasmapy/ is now in src/plasmapy/. Tests are now in tests/. If you have previously done an editable installation, it will likely need to be re-done (i.e., with pip install -e .[tests,docs] in the top-level directory of the repository). The former plasmapy/ directory will need to be deleted manually in old clones because git does not track directories.

The bottom of this page shows several checks that are run for every PR. Don't worry if something broke! We break stuff all the time. 😺 Click on "Details" to learn why a check didn't pass. Please also feel free to ask for help. We do that all the time as well. 🌸 You can find us in our chat room or weekly community meeting & office hours. Here are some tips:

  • Try fixing CI / Python 3.12 test failures first.
  • Most pre-commit.ci - pr failures can be automagically fixed by commenting pre-commit.ci autofix below, followed by a git pull to bring the changes back to your computer. Please also see our pre-commit troubleshooting guide.
  • If pre-commit.ci - pr says that a function is too long or complex, try breaking up that function into multiple short functions that each do one thing. See also these tips on writing clean scientific software.
  • If the CI / Documentation check ends with a cryptic error message, check out our documentation troubleshooting guide.
  • For a documentation preview, click on Details next to docs/readthedocs.org:plasmapy.

If this PR is marked as ready for review, someone should stop by to provide a code review and offer suggestions soon. ✅ If you don't get a review within a few days, please feel free to send us a reminder.

Please also use SI units within PlasmaPy, except when there is strong justification otherwise or in some examples.

We thank you once again!

@github-actions github-actions bot added the packaging Related to packaging or distribution label May 3, 2024
@github-actions github-actions bot added the docs PlasmaPy Docs at http://docs.plasmapy.org label May 3, 2024
@chasepd
Copy link
Contributor Author

chasepd commented May 3, 2024

pre-commit.ci autofix

Copy link

codecov bot commented May 3, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 95.23%. Comparing base (79b1c19) to head (793270a).
Report is 6 commits behind head on main.

❗ Current head 793270a differs from pull request most recent head c0e42bb. Consider uploading reports for the commit c0e42bb to get more accurate results

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2657      +/-   ##
==========================================
+ Coverage   95.21%   95.23%   +0.01%     
==========================================
  Files         103      104       +1     
  Lines        9412     9435      +23     
  Branches     2155     2159       +4     
==========================================
+ Hits         8962     8985      +23     
  Misses        273      273              
  Partials      177      177              

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

@chasepd
Copy link
Contributor Author

chasepd commented May 3, 2024

pre-commit.ci autofix

Copy link
Member

@pheuer pheuer left a comment

Choose a reason for hiding this comment

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

Very nice start! Here are a few minor corrections.

There is one larger bug: right now, this code still returns the ground state ionization energy even if the particle is an ion, e.g.

Particle('C +2').ionization_energy == Particle('C +0').ionization_energy
>True

while, according to the NIST tables, the ionization states above should be 47 eV and 11 eV respectively. I can see two ways of fixing this:

  1. Make this property only available for particles corresponding to neutral atoms

  2. Much more ambitious: implement this property for all of the ion charge states!

If you chose the second path, I would recommend the following:

  1. Download the data for every element in the NIST database as a CSV
  2. Write a python script that takes that data and puts it into a single json file that you can add to the particles/data folder. You could add different isotopes there too.
  3. In the attribute, determine the isotope, charge, and nucleus of the particle and return the appropriate value from your json file.

No pressure to go the second path if you don't want to, just adding this for neutral atoms would be a nice start! But thought I'd offer it as a suggestion since you seem to have handled this pretty easily :)

tests/particles/test_particle_class.py Outdated Show resolved Hide resolved
src/plasmapy/particles/particle_class.py Outdated Show resolved Hide resolved
changelog/2657.feature.rst Outdated Show resolved Hide resolved
changelog/2657.feature.rst Outdated Show resolved Hide resolved
changelog/2657.feature.rst Outdated Show resolved Hide resolved
chasepd and others added 2 commits May 3, 2024 14:39
Co-authored-by: Peter Heuer <pvheuer@gmail.com>
Co-authored-by: Peter Heuer <pvheuer@gmail.com>
Copy link
Member

@pheuer pheuer 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 great! Thanks for adding the downloader script!

One remaining bug I found: you have separate data for deuterium (H-2) and hydrogen (H-1), but it looks like with the current logic both of these get interpreted as 'Hydrogen' so you never actually get the value for Deuterium. It's only slightly different, but sine you have the data in there it would be good to have it return the right one!

You could maybe add one more test for for this exception (since in all the other cases, you do have a test that correctly shows that the different isotopes have equal ionization energies).

To be clear on the physics, technically all of the isotopes have different ionization energies, but the difference is just vanishingly small above He so it's not measurable.

Particle('H').ionization_energy == Particle('D').ionization_energy == Particle('H-2').ionization_energy
>True

Should return False

@chasepd
Copy link
Contributor Author

chasepd commented May 13, 2024

pre-commit.ci autofix

@chasepd chasepd requested a review from pheuer May 13, 2024 21:52
Copy link
Member

@pheuer pheuer left a comment

Choose a reason for hiding this comment

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

Looks great @chasepd , thanks so much for putting this together!

@pheuer pheuer merged commit 9b498fe into PlasmaPy:main May 14, 2024
15 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
docs PlasmaPy Docs at http://docs.plasmapy.org packaging Related to packaging or distribution testing
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants