def Lorentz_factor(V): r""" Return the Lorentz factor. Parameters ---------- V : ~astropy.units.Quantity The velocity in units convertible to meters per second. Returns ------- gamma : float or ~numpy.ndarray The Lorentz factor associated with the inputted velocities. Raises ------ TypeError The `V` is not a `~astropy.units.Quantity` and cannot be converted into a ~astropy.units.Quantity. ~astropy.units.UnitConversionError If the `V` is not in appropriate units. ValueError If the magnitude of `V` is faster than the speed of light. UserWarning If `V` is not a `~astropy.units.Quantity`, then a `UserWarning` will be raised and units of meters per second will be assumed. Notes ----- The Lorentz factor is a dimensionless number given by .. math:: \gamma = \frac{1}{\sqrt{1-\frac{V^2}{c^2}}} The Lorentz factor is approximately one for sub-relativistic velocities, and goes to infinity as the velocity approaches the speed of light. Examples -------- >>> from astropy import units as u >>> velocity = 1.4e8*u.m/u.s >>> Lorentz_factor(velocity) 1.130885603948959 >>> Lorentz_factor(299792458*u.m/u.s) inf """ utils._check_quantity(V, 'V', 'Lorentz_factor', u.m / u.s) if not np.all(np.abs(V) <= c): raise utils.RelativityError( "The Lorentz factor cannot be calculated for " "speeds faster than the speed of light. ") if V.size > 1: gamma = np.zeros_like(V.value) equals_c = np.abs(V) == c is_slow = ~equals_c gamma[is_slow] = ((1 - (V[is_slow] / c)**2)**-0.5).value gamma[equals_c] = np.inf else: if np.abs(V) == c: gamma = np.inf else: gamma = ((1 - (V / c)**2)**-0.5).value return gamma
def deBroglie_wavelength(V, particle): 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> """ utils._check_quantity(V, 'V', 'deBroglie_wavelength', u.m / u.s) V = np.abs(V) if np.any(V >= c): raise utils.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 = atomic.ion_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.to(u.m)
def Lorentz_factor(V: u.m / u.s): r""" Return the Lorentz factor. Parameters ---------- V : `~astropy.units.Quantity` The velocity in units convertible to meters per second. Returns ------- gamma : `float` or `~numpy.ndarray` The Lorentz factor associated with the inputted velocities. Raises ------ `TypeError` If ``V`` is not a `~astropy.units.Quantity` and cannot be converted into a `~astropy.units.Quantity`. `~astropy.units.UnitConversionError` If the ``V`` is not in appropriate units. `ValueError` 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 Lorentz factor is a dimensionless number given by .. math:: γ = \frac{1}{\sqrt{1-\frac{V^2}{c^2}}} The Lorentz factor is approximately one for sub-relativistic velocities, and :math:`γ → ∞` as the velocity approaches the speed of light. Examples -------- >>> from astropy import units as u >>> velocity = 1.4e8 * u.m / u.s >>> Lorentz_factor(velocity) 1.130885603948959 >>> Lorentz_factor(299792458 * u.m / u.s) inf """ if not np.all(np.abs(V) <= c): raise utils.RelativityError( "The Lorentz factor cannot be calculated for " "speeds faster than the speed of light. " ) if V.size > 1: γ = np.zeros_like(V.value) equals_c = np.abs(V) == c is_slow = ~equals_c γ[is_slow] = ((1 - (V[is_slow] / c) ** 2) ** -0.5).value γ[equals_c] = np.inf else: γ = np.inf if np.abs(V) == c else ((1 - (V / c) ** 2) ** -0.5).value return γ