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

Implement NIST STAR Data #2555

Merged
merged 29 commits into from
May 30, 2024
Merged

Conversation

JaydenR2305
Copy link
Member

Implements the ability to calculate stopping power for alpha particles and protons in a specified material using the NIST ASTAR and PSTAR databases, respectively. The data for this pull request can be found here

Resolves #2517

@JaydenR2305 JaydenR2305 requested review from namurphy and a team as code owners March 4, 2024 00:47
Copy link

github-actions bot commented Mar 4, 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:

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 plasmapy.particles Related to the plasmapy.particles subpackage plasmapy.utils Related to the plasmapy.utils subpackage labels Mar 4, 2024
@JaydenR2305
Copy link
Member Author

@namurphy I wasn't quite sure where to put this function.. Where do you think it should go?

@JaydenR2305 JaydenR2305 marked this pull request as draft March 4, 2024 00:49
@JaydenR2305
Copy link
Member Author

JaydenR2305 commented Mar 9, 2024

image
Just to ensure that the pulled hdf5 file has accurate data, here is data I pulled directly from the PSTAR website (blue) plotted with data from the hdf5 file (orange). This particular plot is for the total stopping power of hydrogen

@github-actions github-actions bot added the docs PlasmaPy Docs at http://docs.plasmapy.org label Mar 9, 2024
@JaydenR2305 JaydenR2305 marked this pull request as ready for review March 10, 2024 02:17
Jayden Roberts and others added 2 commits May 28, 2024 11:01
…st_star_functionality

# Conflicts:
#	plasmapy/utils/data/downloader.py
@github-actions github-actions bot added CI Related to continuous integration static type checking python Pull requests that update Python code feature For new functionality, excluding breaking changes labels May 28, 2024
@JaydenR2305
Copy link
Member Author

@pheuer Do you know what's causing these ReadTimeout errors??

@pheuer
Copy link
Member

pheuer commented May 28, 2024

@pheuer Do you know what's causing these ReadTimeout errors??

Hm, does the test pass locally? The file/url it is trying to reach is definitely valid?

One thing you might want to do to limit test time/number of API queries is to use an unvalidated downloader in the tests (except for maybe one, that confirms the file is accessible). See example of how I did that here:

def in_ci() -> bool:

But, that shouldn't explain the read timeout, since even in the unvalidated mode downloader still has to download from the raw github URL...

@JaydenR2305
Copy link
Member Author

JaydenR2305 commented May 28, 2024

One thing you might want to do to limit test time/number of API queries is to use an unvalidated downloader in the tests (except for maybe one, that confirms the file is accessible).

Does this mean we would take a Downloader instance as an optional parameter for stopping_power ?

@pheuer
Copy link
Member

pheuer commented May 28, 2024

Does this mean we would take a Downloader instance as an optional parameter for stopping_power ?

Or you could add a switch inside stopping_power that automatically uses the unvalidated downloader if CI is detected?

It might be best practice to just say that any function that internally uses Downloader should allow an instance to be passed as an optional argument, just for this kind of thing, though?

@JaydenR2305
Copy link
Member Author

JaydenR2305 commented May 28, 2024

@pheuer What are your thoughts on implicitly setting the API token if it is detected that the code is being run in a CI environment? That is, if an API key is not explicitly passed during instantiation then os.environ["GH_TOKEN"] would be used.

This way we don't need to complicate things by introducing optional keywords for Downloader objects and remembering that we have to pass one in every time we write tests involving the downloader

@pheuer
Copy link
Member

pheuer commented May 28, 2024

@pheuer What are your thoughts on implicitly setting the API token if it is detected that the code is being run in a CI environment? That is, if an API key is not explicitly passed during instantiation then os.environ["GH_TOKEN"] would be used.

This way we don't need to complicate things by introducing optional keywords for Downloader objects and remembering that we have to pass one in every time we write tests involving the downloader

Hm, that's a good idea for now! It's not exactly equivalent to unvalidated (still makes queries to find the file I think) but that's ok.

Make sure you include a comment in the test explaining what you're doing.

Copy link

codecov bot commented May 28, 2024

Codecov Report

Attention: Patch coverage is 94.44444% with 2 lines in your changes are missing coverage. Please review.

Project coverage is 95.21%. Comparing base (534b8e9) to head (2455f67).
Report is 4 commits behind head on main.

Current head 2455f67 differs from pull request most recent head bef6384

Please upload reports for the commit bef6384 to get more accurate results.

Files Patch % Lines
src/plasmapy/particles/atomic.py 93.75% 1 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2555      +/-   ##
==========================================
- Coverage   95.25%   95.21%   -0.04%     
==========================================
  Files         104      104              
  Lines        9435     9435              
  Branches     2159     2167       +8     
==========================================
- Hits         8987     8984       -3     
- Misses        272      273       +1     
- Partials      176      178       +2     

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

@JaydenR2305
Copy link
Member Author

How should I add coverage for these lines?

return (
baseline_energies_data * u.MeV,
relevant_stopping_data * u.MeV * u.cm**2 / u.g,
)

The returned result can have some ~100 entries.

@JaydenR2305
Copy link
Member Author

also why does this have partial coverage? It looks like the code under the elseif statement is being executed fine?

https://app.codecov.io/gh/PlasmaPy/PlasmaPy/pull/2555/blob/src/plasmapy/particles/atomic.py#L595

@pheuer
Copy link
Member

pheuer commented May 29, 2024

How should I add coverage for these lines?

return (
baseline_energies_data * u.MeV,
relevant_stopping_data * u.MeV * u.cm**2 / u.g,
)

The returned result can have some ~100 entries.

It looks like this isn't being hit just because all the test cases supply energies? You could include one separate test that doesn't supply an energies vector, then just confirm that you get the tuple out?

also why does this have partial coverage? It looks like the code under the elseif statement is being executed fine?

https://app.codecov.io/gh/PlasmaPy/PlasmaPy/pull/2555/blob/src/plasmapy/particles/atomic.py#L595

I've no idea about this, weird...

material_data["electronic_stopping_power"]
+ material_data["nuclear_stopping_power"]
)
elif component == "electronic":
Copy link
Member

Choose a reason for hiding this comment

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

These two branches aren't getting hit: I would add one more test/test case that asks for the electronic and then the nuclear stopping power

@JaydenR2305
Copy link
Member Author

@JaydenR2305
Copy link
Member Author

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.

Looks good!

@pheuer pheuer merged commit ecced02 into PlasmaPy:main May 30, 2024
16 checks passed
@JaydenR2305 JaydenR2305 deleted the add_nist_star_functionality branch May 30, 2024 16:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CI Related to continuous integration docs PlasmaPy Docs at http://docs.plasmapy.org feature For new functionality, excluding breaking changes plasmapy.particles Related to the plasmapy.particles subpackage plasmapy.utils Related to the plasmapy.utils subpackage python Pull requests that update Python code static type checking testing
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Implement NIST STAR (Stopping Power & Ranging) calculations in PlasmaPy
4 participants