Skip to content

Commit

Permalink
removed useless test, now in units.quantity_input
Browse files Browse the repository at this point in the history
  • Loading branch information
Antoine T committed Oct 4, 2017
1 parent 5e9d773 commit c78cfef
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 20 deletions.
19 changes: 9 additions & 10 deletions plasmapy/physics/distribution.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
"""Functions to deal with distribution : generate, fit, calculate"""


from astropy import units

from astropy.units import (UnitConversionError, UnitsError, quantity_input,
Expand All @@ -13,8 +12,11 @@

from ..utils import _check_quantity, check_relativistic, check_quantity


@units.quantity_input
def Maxwellian_1D(v: units.m/units.s, T: units.K, particle="e", V_drift=0*units.m/units.s):
def Maxwellian_1D(v: units.m/units.s,
T: units.K, particle="e",
V_drift=0*units.m/units.s):
r"""Return the probability at the velocity `v` in m/s
to find a particle `particle` in a plasma of temperature `T`
following the Maxwellian distribution function
Expand Down Expand Up @@ -54,7 +56,7 @@ def Maxwellian_1D(v: units.m/units.s, T: units.K, particle="e", V_drift=0*units.
Notes
-----
In one dimension, the Maxwellian distribution function for a particle of
mass m, velocity v, a drift velocity V and with temperature T is as follows:
mass m, velocity v, a drift velocity V and with temperature T is:
.. math::
f = \sqrt{\frac{m}{2 \pi T}} \exp(-\frac{m}{2 T} (v-V)^2)
Expand All @@ -64,20 +66,17 @@ def Maxwellian_1D(v: units.m/units.s, T: units.K, particle="e", V_drift=0*units.
-------
>>> from plasmapy.physics import Maxwellian_1D
>>> from astropy import units as u
>>> Maxwellian_1D(v=1*u.m/u.s, T= 30000*u.K, particle='e',V_drift=0*u.m/u.s)
>>> v=1*u.m/u.s
>>> Maxwellian_1D(v=v, T= 30000*u.K, particle='e',V_drift=0*u.m/u.s)
<Quantity 5.916329687405701e-07 s / m>
"""


#pass to Kelvin
# pass to Kelvin

if T.unit.is_equivalent(units.K):
T = T.to(units.K, equivalencies=units.temperature_energy())

else:
raise UnitConversionError("The temperatures unit should be in Kelvin ")

#Get mass
# Get mass

if particle == "e":
m_s = m_e
Expand Down
20 changes: 10 additions & 10 deletions plasmapy/physics/tests/test_distribution.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,29 +16,29 @@
stop = - start
dv = 10000 * u.m/u.s

v_vect = np.arange(start, stop, dtype='float64')* dv
v_vect = np.arange(start, stop, dtype='float64') * dv


def test_Maxwellian_1D():
"""test the 1D maxwellian distribution function"""


max_index = Maxwellian_1D(v_vect, T=T_e, particle='e', V_drift=0*u.m/u.s).argmax()
max_index = Maxwellian_1D(v_vect, T=T_e, particle='e', V_drift=0*u.m/u.s
).argmax()
assert np.isclose(v_vect[max_index].value, 0.0)

max_index = Maxwellian_1D(v_vect, T=T_e, particle='e', V_drift=V_drift).argmax()
max_index = Maxwellian_1D(v_vect, T=T_e, particle='e', V_drift=V_drift
).argmax()
assert np.isclose(v_vect[max_index].value, V_drift.value)

#integral of the distribution over v_vect
integral = (Maxwellian_1D(v_vect,T=30000*u.K, particle='e')).sum()*dv
# integral of the distribution over v_vect
integral = (Maxwellian_1D(v_vect, T=30000*u.K, particle='e')).sum()*dv
assert np.isclose(integral, 1.0)

std = np.sqrt((Maxwellian_1D(v_vect, T=T_e, particle='e')*v_vect**2*dv).sum())
std = (Maxwellian_1D(v_vect, T=T_e, particle='e')*v_vect**2*dv).sum()
std = np.sqrt(std)
T_distri = (std**2/k_B*m_e).to(u.K)

assert np.isclose(T_distri.value, T_e.value)

with pytest.raises(u.UnitConversionError):
Maxwellian_1D(1*u.m/u.s, T=1*u.V, particle='e')

with pytest.raises(ValueError):
Maxwellian_1D(1*u.m/u.s, T=1*u.K, particle='XXX')

0 comments on commit c78cfef

Please sign in to comment.