-
Notifications
You must be signed in to change notification settings - Fork 340
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
Starting an attempt to remove default particle assumptions #911
Starting an attempt to remove default particle assumptions #911
Conversation
@arichar6 Thanks for taking this on! Issue #453 was created before I started working on def Alfven_speed(B, density, ion, z_mean=None):
... or def Alfven_speed(B, density, *, ion, z_mean=None):
... The latter keeps Additionally, we should add a proper annotation def Alfven_speed(B: u.T, density: [u.m ** -3, u.kg / u.m ** 3], *, ion: Union[str, Particle], z_mean=None):
... |
Thanks for the feedback! I'll remove the |
Also added type annotations for the particles. Still need to fix the tests.
I still have to fix the tests that now fail. But the defaults should be fixed now, and type annotations added. |
As I was working on the tests, I realized that one change might introduce a backwards-incompatibility. An alternative would be to change the order of the arguments to the function, but that seems worse somehow. Thoughts? ** edit ** |
Codecov Report
@@ Coverage Diff @@
## master #911 +/- ##
==========================================
- Coverage 96.21% 96.21% -0.01%
==========================================
Files 60 60
Lines 5417 5416 -1
==========================================
- Hits 5212 5211 -1
Misses 205 205
Continue to review full report at Codecov.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for working on this! Most of my suggestions are related to annotations for particle inputs, in particular that the annotation will need to be Particle
for when we eventually implement the @particle_input
decorator to this file (#341). Otherwise, all of the changes look great. Thank you again!
Many of the suggested changes are related to the @particle_input
decorator which still needs to implemented in the formulary
Otherwise, all of the changes look great.
Co-authored-by: Nick Murphy <[email protected]>
Co-authored-by: Nick Murphy <[email protected]>
Co-authored-by: Nick Murphy <[email protected]>
Co-authored-by: Nick Murphy <[email protected]>
Co-authored-by: Nick Murphy <[email protected]>
Co-authored-by: Nick Murphy <[email protected]>
Co-authored-by: Nick Murphy <[email protected]>
One more question. Now that we are using |
@arichar6 It appears the documentation build errors are due to the jupyter notebooks not being updated, specifically |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is looking good! I only have a few minor changes plus the update of the jupyter notebook.
The rest of the plasmapy.formulary
needs this treatment too, but I'm ok keeping that to a separate/followup PR.
plasmapy/formulary/parameters.py
Outdated
*, | ||
ion: Particle, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should look like....
def ion_sound_speed(
T_e: u.K,
T_i: u.K,
ion: Particle,
n_e: u.m ** -3 = None,
k: u.m ** -1 = None,
gamma_e=1,
gamma_i=3,
z_mean=None,
) -> u.m / u.s:
*
, overly simplified, indicates the end to the positional arguments, so keyword-only arguments should not be defined before it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So you are ok with changing the order of the arguments in this function call? I was using the *
entry so that I could keep the order of arguments the same, but have ion
(with no default) come after the other arguments which do have defaults.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Keywords have no order associated with them, so doing this does not change the order at all. It does make ion
a required argument that is either positional or keyword. So, the suggested makes the interface behave like...
ion_sound_speed(2*u.eV, 3*u.eV, "He+")
# or
ion_sound_speed(2*u.eV, 3*u.eV, ion="He+")
All the other arguments are keyword-only, so they can be specified in any order.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure why you say that all other arguments are keyword-only. I just tried, and you can specify an electron density and k by just giving them as the next arguments. No keywords needed.
>>> ion_sound_speed(2*u.eV, 3*u.eV, "He+", 1 * u.m**-3, 1 * u.m ** -1)
<Quantity 1.54899987 m / s>
Co-authored-by: Erik Everson <[email protected]>
…char6/PlasmaPy into 453-remove-default-particles
Any insights into why the codecov test is failing now? I'm don't really quite know what it is check for, exactly. |
Looks like line 339 in |
I might be wrong, but it looks like line 339 in elif np.any(np.isnan(V)):
if np.isscalar(V.value) and np.isscalar(T.value):
V = parameters.thermal_speed(T, "e-", mass=m)
elif np.isscalar(V.value):
V = parameters.thermal_speed(T, "e-", mass=m) I just tried this, and if |
Hm...that's a good question. That's a bit strange so it would be worth looking into it further. It does seem outside of the intended scope of this pull request, so my suggestion would be to create a brief issue on it so that we can address it in a different pull request. I'm not a fan of long extensive |
To follow up: there are a few other things in |
Co-authored-by: Erik Everson <[email protected]>
…char6/PlasmaPy into 453-remove-default-particles
Ok. I think this PR is finally done. While this does not complete the changes required for #453, it does complete the changes needed in |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me! Thanks making these improvement.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you again for doing this! It looks good to me so I think it's ready to merge.
This is my attempt to remove default values from functions that take a particle as input in
formulary/parameters.py
.This is described in issue #453.