예제 #1
0
def deBroglie_wavelength(V: u.m / u.s, particle) -> u.m:
    r"""
    Return the de Broglie wavelength.

    The de Broglie wavelength (:math:`λ_{dB}`) of a particle is defined by

    .. math::

        λ_{dB} = \frac{h}{p} = \frac{h}{γ m V}

    where :math:`h` is the Planck constant, :math:`p` is the
    relativistic momentum of the particle, :math:`γ` is the
    Lorentz factor, :math:`m` is the mass of the particle, and
    :math:`V` is the velocity of the particle.

    **Aliases:** `lambdaDB_`

    Parameters
    ----------
    V : `~astropy.units.Quantity`
        Particle velocity in units convertible to meters per second.

    particle : `str`, `~plasmapy.particles.particle_class.Particle`, or `~astropy.units.Quantity`
        An instance of `~plasmapy.particles.particle_class.Particle`, or
        an equivalent representation (e.g., ``'e'``, ``'p'``, ``'D+'``, or
        ``'He-4 1+'``), for the particle of interest, or the particle
        mass in units convertible to kg.  If a
        `~plasmapy.particles.particle_class.Particle` instance is given, then the
        particle mass is retrieved from the object.

    Returns
    -------
    lambda_dB : `~astropy.units.Quantity`
        The de Broglie wavelength in units of meters.

    Raises
    ------
    `TypeError`
        If the velocity is not a `~astropy.units.Quantity` and cannot be
        converted into a `~astropy.units.Quantity`.

    `~astropy.units.UnitConversionError`
        If the velocity is not in appropriate units.

    `~plasmapy.utils.exceptions.RelativityError`
        If the magnitude of ``V`` is larger than the speed of light.

    Warns
    -----
    : `~astropy.units.UnitsWarning`
        If units are not provided, SI units are assumed.

    Examples
    --------
    >>> from astropy import units as u
    >>> velocity = 1.4e7 * u.m / u.s
    >>> deBroglie_wavelength(velocity, 'e')
    <Quantity 5.18997095e-11 m>
    >>> deBroglie_wavelength(V = 0 * u.m / u.s, particle = 'D+')
    <Quantity inf m>
    """

    V = np.abs(V)

    if np.any(V >= c):
        raise RelativityError(
            "Velocity input in deBroglie_wavelength cannot "
            "be greater than or equal to the speed of "
            "light."
        )

    if not isinstance(particle, u.Quantity):
        try:
            # TODO: Replace with more general routine!
            m = particles.particle_mass(particle)
        except InvalidParticleError:
            raise ValueError("Unable to find particle mass.")
    else:
        try:
            m = particle.to(u.kg)
        except u.UnitConversionError as e:
            raise u.UnitConversionError(
                "The second argument for deBroglie_wavelength must be either a "
                "representation of a particle or a"
                " Quantity with units of mass."
            ) from e

    if V.size > 1:

        lambda_dBr = np.ones(V.shape) * np.inf * u.m
        indices = V.value != 0
        lambda_dBr[indices] = h / (m * V[indices] * Lorentz_factor(V[indices]))

    elif V == 0 * u.m / u.s:
        lambda_dBr = np.inf * u.m
    else:
        lambda_dBr = h / (Lorentz_factor(V) * m * V)

    return lambda_dBr
예제 #2
0
파일: quantum.py 프로젝트: zhyhou/PlasmaPy
def deBroglie_wavelength(V: u.m / u.s, particle) -> u.m:
    r"""
    Calculates the de Broglie wavelength.

    Parameters
    ----------
    V : ~astropy.units.Quantity
        Particle velocity in units convertible to meters per second.

    particle : str or ~astropy.units.Quantity
        Representation of the particle species (e.g., `'e'`, `'p'`, `'D+'`,
        or `'He-4 1+'`, or the particle mass in units convertible to
        kilograms.

    Returns
    -------
    lambda_dB : ~astropy.units.Quantity
        The de Broglie wavelength in units of meters.

    Raises
    ------
    TypeError
        The velocity is not a `~astropy.units.Quantity` and cannot be
        converted into a ~astropy.units.Quantity.

    ~astropy.units.UnitConversionError
        If the velocity is not in appropriate units.

    ~plasmapy.utils.RelativityError
        If the magnitude of `V` is faster than the speed of light.

    Warns
    -----
    ~astropy.units.UnitsWarning
        If units are not provided, SI units are assumed

    Notes
    -----
    The de Broglie wavelength is given by

    .. math::

        \lambda_{dB} = \frac{h}{p} = \frac{h}{\gamma m V}

    where :math:`h` is the Planck constant, :math:`p` is the
    relativistic momentum of the particle, :math:`gamma` is the
    Lorentz factor, :math:`m` is the particle's mass, and :math:`V` is the
    particle's velocity.

    Examples
    --------
    >>> from astropy import units as u
    >>> velocity = 1.4e7 * u.m / u.s
    >>> deBroglie_wavelength(velocity, 'e')
    <Quantity 5.18997095e-11 m>
    >>> deBroglie_wavelength(V = 0 * u.m / u.s, particle = 'D+')
    <Quantity inf m>
    """

    V = np.abs(V)

    if np.any(V >= c):
        raise RelativityError("Velocity input in deBroglie_wavelength cannot "
                              "be greater than or equal to the speed of "
                              "light.")

    if not isinstance(particle, u.Quantity):
        try:
            # TODO: Replace with more general routine!
            m = particles.particle_mass(particle)
        except Exception:
            raise ValueError("Unable to find particle mass.")
    else:
        try:
            m = particle.to(u.kg)
        except Exception:
            raise u.UnitConversionError("The second argument for deBroglie"
                                        " wavelength must be either a "
                                        "representation of a particle or a"
                                        " Quantity with units of mass.")

    if V.size > 1:

        lambda_dBr = np.ones(V.shape) * np.inf * u.m
        indices = V.value != 0
        lambda_dBr[indices] = h / (m * V[indices] * Lorentz_factor(V[indices]))

    else:

        if V == 0 * u.m / u.s:
            lambda_dBr = np.inf * u.m
        else:
            lambda_dBr = h / (Lorentz_factor(V) * m * V)

    return lambda_dBr
예제 #3
0
def test_Lorentz_factor():
    r"""Test Lorentz_factor in relativity.py"""

    V = 123456789 * u.m / u.s
    assert np.isclose(Lorentz_factor(V), (1 / np.sqrt(1 - V**2 / c**2)).value)
    assert Lorentz_factor(-V) == Lorentz_factor(V)

    assert np.isclose(Lorentz_factor(0 * u.m / u.s), 1.0)
    assert Lorentz_factor(c) == np.inf

    V_arr = np.array([987532.0, 299792458]) * u.m / u.s
    gamma_arr = Lorentz_factor(V_arr)
    assert np.isclose(gamma_arr[0],
                      (1 / np.sqrt(1 - V_arr[0]**2 / c**2)).value)
    assert gamma_arr[1] == np.inf

    assert (Lorentz_factor(3 * u.m / u.s) *
            u.dimensionless_unscaled).unit == u.dimensionless_unscaled

    with pytest.raises(RelativityError):
        Lorentz_factor(1.0000000001 * c)

    with pytest.raises(ValueError), pytest.warns(u.UnitsWarning):
        Lorentz_factor(299792459)

    with pytest.warns(u.UnitsWarning):
        Lorentz_factor(2.2)

    with pytest.raises(u.UnitTypeError):
        Lorentz_factor(4 * u.kg)