-
Notifications
You must be signed in to change notification settings - Fork 307
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
Distribution function #141
Distribution function #141
Conversation
Hello @antoinelpp! Thanks for updating the PR. Cheers ! There are no PEP8 issues in this Pull Request. 🍻 Comment last updated on October 06, 2017 at 15:48 Hours UTC |
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.
Hey, thanks for this one! I like it. There are some minor improvements I could see being useful.
I can't find a good place to put comments on the Jupyter notebook, so I'll put them here:
- Check out astropy's quantity support for matplotlib
- There's some minor typos, but rather than pointing them out I'll just go through the changes before merging and try to fix as many as I can :)
assert np.isclose(v_vect[Maxwellian_1D(v_vect,T=T_e, part='e',V_drift = V_drift ).argmax()].value,V_drift.value) | ||
|
||
#integral of the distribution over v_vect | ||
integral = (Maxwellian_1D(v_vect,T= 30000*u.K, part='e')).sum()*dv |
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.
If we used scipy.integrate
here (I don't think adding scipy to requirements is an issue given we're working within the scientific Python stack), we'd also get an error estimate on the integral we could use for the next line!
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'n not so used to Scipy, I didn't knew we could do it ! I'll check it out.
from ..distribution import (Maxwellian_1D) | ||
|
||
T_e = 30000*u.K; | ||
V_drift = 10*u.m/u.s; |
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 haven't looked at the speed of this test, but if it's not too slow (it's an integral, it shouldn't be) this would be a perfect place to test a few parameter combinations via pytest fixtures. I'd be happy to add them!
plasmapy/physics/distribution.py
Outdated
The temperature in Kelvin | ||
|
||
part: string, optional | ||
Representation of the ion species (e.g., 'p' for protons, 'D+' |
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.
Could we rename this to particle
, and say Representation of the particle species
?
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.
Ok for the argument name !
plasmapy/physics/distribution.py
Outdated
|
||
else : | ||
try: | ||
m_s = ion_mass(ion) |
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 be possible to clean up a bit once #140 goes through :)
plasmapy/physics/distribution.py
Outdated
Representation of the ion species (e.g., 'p' for protons, 'D+' | ||
for deuterium, or 'He-4 +1' for singly ionized helium-4), | ||
which defaults to electrons. | ||
|
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.
We could probably use a latex (mathrm) representation of the formula. I can get that done for you.
Come to think of it, AFAIK SymPy can autogenerate those representations... #136 ? :D
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 so sure to understand this comment. I tried something tell me if this is what you think of.
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.
My apologies, I guess I wasn't clear at all here! I added a commit to show what I mean (the actual formula for the Maxwellian distribution) within the docstring.
plasmapy/physics/distribution.py
Outdated
from ..utils import _check_quantity, check_relativistic, check_quantity | ||
|
||
|
||
def Maxwellian_1D(v,T,part ="e", V_drift = 0* units.m/units.s): |
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.
Seems like a nice place for @astropy.units.quantity_input :D
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.
good point !
That's a weird test failure:
so you expect something on the order of 6m/s and get 6 * 10^-7 s/m ? This seems like some bug in the formula, I'll take a look. |
Okay, so I just noticed that this returns I also noticed I forgot to add |
No that's my mistake ! |
Sorry all for the PR spam, but I couldn't figure out how to run the tests without pushing... I tried to rebase it on Upstream, but the PR is now a mess... Shouldn't I do it ? Or I maybe I did it wrong... |
I wouldn't worry about rebasing for now. I think we can live with a lengthy history. We really need to look into this: run |
Ho ! |
No worries, glad it works for you :) I'll try to do a final review on this but I won't be able to do that by Friday, probably. If anyone wants to step in, I'd be much obliged! |
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.
You know, I checked and this did indeed turn out to be a lot of commits. The review screen on GitHub at least turned out weird and it looks like you're kind of duplicating changes from #140. That may be a glitch. However, could you please still try rebasing onto current master and squashing some of those smaller commits after all?
I'll go through the notebook as soon as time permits :)
@@ -26,3 +21,5 @@ | |||
from .relativity import Lorentz_factor | |||
|
|||
from .transport import Coulomb_logarithm | |||
|
|||
from .distribution import (Maxwellian_1D) |
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.
Why the ( ) parentheses here?
Quantity) | ||
|
||
from ..constants import (m_p, m_e, c, mu0, k_B, e, eps0, pi, e) | ||
from ..atomic import (ion_mass, charge_state) |
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.
Once again, ( ) ?
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've made a habit of using parentheses when doing long import
statements, as per PEP 328. At least to me, this makes it easier to read. It is at its most useful when import
statements span multiple lines.
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.
Oh right. I'm sorry, I forgot about this and I was checking this in a slight rush. Multilines, sure. Here, not particularly certain they're quite necessary!
plasmapy/physics/distribution.py
Outdated
|
||
# Get mass | ||
|
||
if particle == "e": |
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.
Another way to do this is to import _is_electron
from atomic
and use that here:
if _is_electron(particle):
m_s = m_e
This will catch when e-
or electron
is used to represent electrons as well.
Thank you for doing this!
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.
Good point !
I'm not fluant with the atomic package... I should take a better look into it.
@antoinelpp I took a closer look at the branch history and moanad, because something must have gone horribly wrong there. That tree was duplicated in some weird ways. I tried everything, but in the end the only thing that made sense was to fix some of that tangled mess via rebase - you can see the result of that here, but at the same time I may have messed up some of the chronological ordering of the changes. If you think we can let it go and let that previous messed up version rest under the sea, I made another version where it's all squashed into a single commit. Doing it that way means no worries about chronology for this PR. |
Hi @StanczakDominik !
My bad :( I sorry about it.
No no no, I'd like not to mess with the branch !
Ok that looks way better ! I can try to squash it myself (on my repo) in order to fix the other issues. Or I can remove this PR, clean my branch and do it again... What do you think ? Again sorry |
Hey don't worry about it! Git trees are literal straight-outta-Disney magic
from time to time.
I think the best way to do this would be to go on your branch and sort of
overwrite it with the state of my squash branch, then merge it.
I'll put on my wizard robe and hat and discover a git incantation to do
this. :)
…On Oct 6, 2017 10:09, "antoinelpp" ***@***.***> wrote:
Hi @StanczakDominik <https://github.com/stanczakdominik> !
I took a closer look at the branch history and moanad, because something
must have gone horribly wrong there.
My bad :( I sorry about it.
we can let it go and let that previous messed up version rest under the
sea,
No no no, I'd like not to mess with the branch !
I made another version where it's all squashed into a single commit.
Ok that looks way better ! I can try to squash it myself (on my repo) in
order to fix the other issues. Or I can remove this PR, clean my branch and
do it again... What do you think ?
Again sorry
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#141 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AKxDL_2sQ-R25FnyJ3Q05LBeCHMc5a1Kks5speA_gaJpZM4PtTgi>
.
|
I have used the power of Google and divined that (sorry for placeholders,
typing from phone)
`git remote add Dominik CLONE-URL-GOES-HERE`
`git checkout Distribution-fn` (branch name)
`git reset --hard Dominik/Distribution-fn-squash` or whatever the branch
name was
`git push -f`
should do it.
…On Oct 6, 2017 10:24, "Dominik Stańczak" ***@***.***> wrote:
Hey don't worry about it! Git trees are literal straight-outta-Disney
magic from time to time.
I think the best way to do this would be to go on your branch and sort of
overwrite it with the state of my squash branch, then merge it.
I'll put on my wizard robe and hat and discover a git incantation to do
this. :)
On Oct 6, 2017 10:09, "antoinelpp" ***@***.***> wrote:
> Hi @StanczakDominik <https://github.com/stanczakdominik> !
>
> I took a closer look at the branch history and moanad, because something
> must have gone horribly wrong there.
>
> My bad :( I sorry about it.
>
> we can let it go and let that previous messed up version rest under the
> sea,
>
> No no no, I'd like not to mess with the branch !
>
> I made another version where it's all squashed into a single commit.
>
> Ok that looks way better ! I can try to squash it myself (on my repo) in
> order to fix the other issues. Or I can remove this PR, clean my branch and
> do it again... What do you think ?
>
> Again sorry
>
> —
> You are receiving this because you were mentioned.
> Reply to this email directly, view it on GitHub
> <#141 (comment)>,
> or mute the thread
> <https://github.com/notifications/unsubscribe-auth/AKxDL_2sQ-R25FnyJ3Q05LBeCHMc5a1Kks5speA_gaJpZM4PtTgi>
> .
>
|
created distribution.py created test_distribution.py change `part` argument to `particle` and minor docstrings Added is_electron Update formula docstring
c78cfef
to
a6fbf18
Compare
Awesome, I'll just do a short stylistic pass on the example (TBD within two hours) and we're good to go :) |
751232d
to
854251b
Compare
All right, take a look at this and once it's done I'd say we can merge this one :) |
Thanks @StanczakDominik ! |
And I merged it, thanks a bunch for this one! |
First contribution for me !
To start with #101, I added a 1D Maxwellian distribution function calculation.
Please tell me if you like the interface, numbre of arguments and so on.
Needs to be done :