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

Generalize ion sound speed #700

Merged
merged 12 commits into from
Oct 20, 2019
Merged

Generalize ion sound speed #700

merged 12 commits into from
Oct 20, 2019

Conversation

tvarnish
Copy link
Contributor

Closes #316. Generalizes ion_sound_speed to work for any case, not just for the limit when (k * lambda_D) ** 2 is small. Additional term from Chapter 5.1, Froula, Glenzer, Luhmann and Sheffield "Plasma Scattering of Electromagnetic Radiation".

Docstring updated to remove note about the non-dispersive limit. Updated docstring examples, and included a new example with a large value for (k * lambda_D) ** 2.

Updated tests for ion_sound_speed, and added additional tests for the (general) large limit. Updated the assert_can_handle_nparray pytest helper method to work for the additional parameter, k,
added to ion_sound_speed.

Addresses issue #316. Generalizes ion_sound_speed to work for any
case, not just for the limit when (k * lambda_D) ** 2 is small.
Additional term from Chapter 5.1, Froula, Glenzer, Luhmann and
Sheffield "Plasma Scattering of Electromagnetic Radiation".

Docstring updated to remove note about non-dispersive limit. Updated
docstring examples, and included new example with a large value for
(k * lambda_D) ** 2.

Updated tests for ion_sound_speed, and added additional tests for
the (general) large limit. Updated the assert_can_handle_nparray
pytest helper method to work for the additional parameter, "k",
added to the ion_sound_speed function.
@pep8speaks
Copy link

pep8speaks commented Oct 16, 2019

Hello @tvarnish! Thanks for updating your pull request.

Line 240:1: W293 blank line contains whitespace
Line 242:76: W291 trailing whitespace
Line 243:57: W291 trailing whitespace
Line 244:75: W291 trailing whitespace
Line 246:1: W293 blank line contains whitespace
Line 248:73: W291 trailing whitespace
Line 249:71: W291 trailing whitespace
Line 250:79: W291 trailing whitespace
Line 296:67: W291 trailing whitespace
Line 306:1: W293 blank line contains whitespace
Line 308:67: W291 trailing whitespace
Line 323:76: W291 trailing whitespace
Line 325:1: W293 blank line contains whitespace
Line 326:73: W291 trailing whitespace
Line 327:70: W291 trailing whitespace
Line 353:1: W293 blank line contains whitespace
Line 367:1: W293 blank line contains whitespace

Line 193:1: W293 blank line contains whitespace
Line 195:74: W291 trailing whitespace
Line 198:1: W293 blank line contains whitespace
Line 200:74: W291 trailing whitespace
Line 212:58: W291 trailing whitespace
Line 216:51: W291 trailing whitespace
Line 218:1: W293 blank line contains whitespace
Line 221:1: W293 blank line contains whitespace
Line 254:1: W293 blank line contains whitespace
Line 257:1: W293 blank line contains whitespace
Line 290:71: W291 trailing whitespace

Comment last updated at 2019-10-20 09:53:16 UTC

@tvarnish
Copy link
Contributor Author

(I haven't added a changelog entry to the PR yet as I wasn't sure what type to use.)

@codecov
Copy link

codecov bot commented Oct 16, 2019

Codecov Report

Merging #700 into master will decrease coverage by 0.03%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #700      +/-   ##
==========================================
- Coverage   95.05%   95.02%   -0.04%     
==========================================
  Files          57       57              
  Lines        4711     4722      +11     
==========================================
+ Hits         4478     4487       +9     
- Misses        233      235       +2
Impacted Files Coverage Δ
plasmapy/formulary/parameters.py 98.9% <100%> (-1.1%) ⬇️
plasmapy/utils/pytest_helpers/pytest_helpers.py 93.38% <100%> (+0.07%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update b10c41d...43d1d82. Read the comment docs.

@StanczakDominik
Copy link
Member

(I haven't added a changelog entry to the PR yet as I wasn't sure what type to use.)

It's definitely a feature :)

Copy link
Member

@StanczakDominik StanczakDominik 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, I've got a question though!

@StanczakDominik
Copy link
Member

I just merged #692 in, so this PR will also need to merge those changes, since the location for parameters changed to plasmapy/formulary/parameters.py. Apologies for the trouble!

Specify default values for k and n_e such that if values are
not specified by the user, assume the non-dispersive limit for
ion_sound_speed.
@tvarnish
Copy link
Contributor Author

@StanczakDominik I'm still getting the hang of using GitHub, so I just wanted to check (before I break anything): how should I go about merging that PR into this one? Should I pull the changes into my local master, then merge that with my local branch?

@StanczakDominik
Copy link
Member

Precisely! I would thus go:

git commit  # your current changes if any
git checkout master
git pull           # assuming you have `master` set up to track PlasmaPy/PlasmaPy#master, not tvarnish/PlasmaPy#master
git checkout generalize_ion_sound_speed
git merge master

@tvarnish
Copy link
Contributor Author

Great! I think that's worked.

@StanczakDominik
Copy link
Member

You'll still need to push the merge commit, though! :)

Copy link
Member

@rocco8773 rocco8773 left a comment

Choose a reason for hiding this comment

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

I'd set default values to None and handle None accordingly in the code. Plus, a None default values is more explicit to what is actually happening...the user did not specify a value.

I did not add it in the code review, but you could also issue a UserWarning of some kind if the user only passes in k or n_e, and not both.

Change default values of k and n_e to None, and add checks to ensure
the user has given both values. Assume non-dispersive limit if user
has only given one of k or n_e. Add tests to check that a UserWarning
is thrown if only one of k or n_e has been given.
@tvarnish
Copy link
Contributor Author

Thanks for the feedback @rocco8773! Using None for the default values was a much simpler solution that anything I was considering. I've also put in a UserWarning if only one of k or n_e is specified, as you suggested. You (and/or @StanczakDominik) might want to take a look at that message to check it's not too long and gets the point across clearly.

@StanczakDominik
Copy link
Member

Thanks @rocco8773 for handling this! I wasn't able to look at it yesterday :(

Copy link
Member

@StanczakDominik StanczakDominik left a comment

Choose a reason for hiding this comment

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

Mostly LGTM, except for a mix-up between warnings and exceptions in the code (see comments)!

We could also think about reverting a few of the test changes, so we still get a few tests for the default case.

@StanczakDominik
Copy link
Member

And the warning message is awesome! :)

Fix warning when only given one of (k, n_e). Change Userwarning
to PhysicsWarning.
Copy link
Member

@rocco8773 rocco8773 left a comment

Choose a reason for hiding this comment

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

I think this is my last suggestion. Everything else looks in order. Good job!

Comment on lines 374 to 378
if n_e is None or k is None:
klD2 = 0.0
else:
lambda_D = Debye_length(T_e, n_e)
klD2 = (k * lambda_D) ** 2
Copy link
Member

Choose a reason for hiding this comment

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

As the above comment suggests, place warning in this if-else statement

if n_e is None or k is None:
    klD2 = 0.0

    if n_e is None and k is None:
        warnings.warn("say stuff")
else:
    lambda_D = Debye_length(T_e, n_e)
    klD2 = (k * lambda_D) ** 2

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Do you think the warning should just go within the first if statement (rather than being within the nested if statement)? That way, the function would warn the user whenever the non-dispersive limit is assumed.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Or... do you think it would make sense to only call the warning when one of k or n_e is given, so scripts that are dependant on PlasmaPy and were previously happy to use the non-dispersive limit don't cause warnings to be shown?

Copy link
Member

Choose a reason for hiding this comment

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

Good point. I think the n_e=None and k=None case should not throw a warning since it is the default state. @StanczakDominik correct me if you think otherwise. In that case, I would restructure it like...

klD2 = 0.0
if (n_e is None) ^ (k is None):
    warnings.warn("say stuff")
elif n_e is not None and k is not None:
    lambda_D = Deby_length(T_e, n_e)
    klD2 = (k * lambda_D) ** 2

The parenthesis are needed in this case since the xor operator ^ only acts on booleans. The parenthesis force the conditionals into booleans before the xor operation is poerformed.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Neat! I never knew there was an XOR operator in python. I see what you’re saying about the default case. That makes sense.

Copy link
Member

Choose a reason for hiding this comment

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

Yeah, defaults should probably not throw warnings! I haven't (consciously) seen XOR in Python yet either. I like the proposed way of doing things :)

Copy link
Member

@StanczakDominik StanczakDominik left a comment

Choose a reason for hiding this comment

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

Aaaaand that's lovely! Let's just wait for the tests to pass and that's a merge in my eyes! :)

Thanks @tvarnish !

@StanczakDominik
Copy link
Member

And thanks @rocco8773 for the very helpful advice!

@tvarnish
Copy link
Contributor Author

Brilliant! I'm pleased I could help. :) Thank you @StanczakDominik and @rocco8773 for your really helpful code reviews and advice!

@StanczakDominik StanczakDominik merged commit db8ad77 into PlasmaPy:master Oct 20, 2019
@tvarnish
Copy link
Contributor Author

@StanczakDominik I think the docs/about/credits.rst file might have broken... I saw there was a conflict so just went to check it had been properly resolved, and it seems the contents of someone's email has been inserted into the contributor list!

StanczakDominik pushed a commit that referenced this pull request Oct 20, 2019
* Generalize ion_sound_speed function

Addresses issue #316. Generalizes ion_sound_speed to work for any
case, not just for the limit when (k * lambda_D) ** 2 is small.
Additional term from Chapter 5.1, Froula, Glenzer, Luhmann and
Sheffield "Plasma Scattering of Electromagnetic Radiation".

Docstring updated to remove note about non-dispersive limit. Updated
docstring examples, and included new example with a large value for
(k * lambda_D) ** 2.

Updated tests for ion_sound_speed, and added additional tests for
the (general) large limit. Updated the assert_can_handle_nparray
pytest helper method to work for the additional parameter, "k",
added to the ion_sound_speed function.

* Update contributors list

* Fix ion_sound_speed docstring examples

* Remove duplicate parameters in examples

* Add changelog entry (#700)

* Change k and n_e to optional parameters

Specify default values for k and n_e such that if values are
not specified by the user, assume the non-dispersive limit for
ion_sound_speed.

* Fix default values for k and n_e

Change default values of k and n_e to None, and add checks to ensure
the user has given both values. Assume non-dispersive limit if user
has only given one of k or n_e. Add tests to check that a UserWarning
is thrown if only one of k or n_e has been given.

* Revert some tests back to default values (k, n_e)

* Change UserWarning to PhysicsWarning

Fix warning when only given one of (k, n_e). Change Userwarning
to PhysicsWarning.

* Restructure PhysicsWarning (for k and n_e)
@StanczakDominik
Copy link
Member

StanczakDominik commented Oct 20, 2019

Insert expletive here. Curse the middle click on Linux!

Thanks a ton for pointing that out; I've cleaned it up on the master branch. Phew.

And yeah, that was all me. 😆

@rocco8773 rocco8773 added the plasmapy.formulary Related to the plasmapy.formulary subpackage label Jul 9, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
plasmapy.formulary Related to the plasmapy.formulary subpackage
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Generalize ion_sound_speed
4 participants