How to use plasmapy - 10 common examples

To help you get started, we’ve selected a few plasmapy examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github PlasmaPy / PlasmaPy / plasmapy / particles / nuclear.py View on Github external
input_err_msg = (
        "The inputs to nuclear_reaction_energy should be either "
        "a string representing a nuclear reaction (e.g., "
        "'D + T -> He-4 + n') or the keywords 'reactants' and "
        "'products' as lists with the nucleons or particles "
        "involved in the reaction (e.g., reactants=['D', 'T'] "
        "and products=['He-4', 'n']."
    )

    reaction_string_is_input = args and not kwargs and len(args) == 1

    reactants_products_are_inputs = kwargs and not args and len(kwargs) == 2

    if reaction_string_is_input == reactants_products_are_inputs:
        raise AtomicError(input_err_msg)

    if reaction_string_is_input:

        reaction = args[0]

        if not isinstance(reaction, str):
            raise TypeError(input_err_msg)
        elif "->" not in reaction:
            raise AtomicError(
                f"The reaction '{reaction}' is missing a '->'"
                " or '-->' between the reactants and products."
            )

        try:
            LHS_string, RHS_string = re.split("-+>", reaction)
            LHS_list = re.split(r" \+ ", LHS_string)
github PlasmaPy / PlasmaPy / plasmapy / particles / ionization_states.py View on Github external
    @validate_quantities(T_e={"equivalencies": u.temperature_energy()})
    def __init__(
        self,
        inputs: Union[Dict[str, np.ndarray], List, Tuple],
        *,
        T_e: u.K = np.nan * u.K,
        equilibrate: Optional[bool] = None,
        abundances: Optional[Dict[str, Real]] = None,
        log_abundances: Optional[Dict[str, Real]] = None,
        n: u.m ** -3 = np.nan * u.m ** -3,
        tol: Real = 1e-15,
        kappa: Real = np.inf,
    ):

        abundances_provided = abundances is not None or log_abundances is not None

        set_abundances = True
github PlasmaPy / PlasmaPy / plasmapy / diagnostics / langmuir.py View on Github external
@validate_quantities(
    probe_area={"can_be_negative": False, "can_be_inf": False, "can_be_nan": False}
)
def get_ion_density_OML(
    probe_characteristic: Characteristic,
    probe_area: u.m ** 2,
    gas,
    visualize=False,
    return_fit=False,
):
    r"""Implement the Orbital Motion Limit (OML) method of obtaining an
    estimate of the ion density.

    Parameters
    ----------
    probe_characteristic : ~plasmapy.diagnostics.langmuir.Characteristic
        The swept probe characteristic that is to be analyzed.
github PlasmaPy / PlasmaPy / plasmapy / formulary / collisions.py View on Github external
@validate_quantities(T={"equivalencies": u.temperature_energy()})
@particles.particle_input
def _boilerPlate(T: u.K, species: (particles.Particle, particles.Particle), V):
    """
    Some boiler plate code for checking if inputs to functions in
    collisions.py are good. Also obtains reduced in mass in a
    2 particle collision system along with thermal velocity.
    """
    masses = [p.mass for p in species]
    charges = [np.abs(p.charge) for p in species]

    # obtaining reduced mass of 2 particle collision system
    reduced_mass = particles.reduced_mass(*species)

    # getting thermal velocity of system if no velocity is given
    V = _replaceNanVwithThermalV(V, T, reduced_mass)
github PlasmaPy / PlasmaPy / plasmapy / formulary / parameters.py View on Github external
@validate_quantities(
    T={"can_be_negative": False, "equivalencies": u.temperature_energy()}
)
def kappa_thermal_speed(
    T: u.K, kappa, particle="e-", method="most_probable"
) -> u.m / u.s:
    r"""Return the most probable speed for a particle within a Kappa
    distribution.

    **Aliases:** `vth_kappa_`

    Parameters
    ----------
    T : ~astropy.units.Quantity
        The particle temperature in either kelvin or energy per particle

    kappa: float
github PlasmaPy / PlasmaPy / plasmapy / formulary / parameters.py View on Github external
@validate_quantities(
    Vperp={"can_be_nan": True},
    T_i={"can_be_nan": True, "equivalencies": u.temperature_energy()},
    validations_on_return={"equivalencies": u.dimensionless_angles()},
)
def gyroradius(
    B: u.T,
    particle="e-",
    *,
    Vperp: u.m / u.s = np.nan * u.m / u.s,
    T_i: u.K = np.nan * u.K,
) -> u.m:
    r"""Return the particle gyroradius.

    **Aliases:** `rc_`, `rhoc_`

    Parameters
github PlasmaPy / PlasmaPy / plasmapy / diagnostics / langmuir.py View on Github external
@validate_quantities(
    electron_saturation_current={
        "can_be_negative": True,
        "can_be_inf": False,
        "can_be_nan": False,
    },
    T_e={
        "can_be_negative": False,
        "can_be_inf": False,
        "can_be_nan": False,
        "equivalencies": u.temperature_energy(),
    },
    probe_area={"can_be_negative": False, "can_be_inf": False, "can_be_nan": False},
    validations_on_return={"can_be_negative": False},
)
def get_electron_density_LM(
    electron_saturation_current: u.A, T_e: u.eV, probe_area: u.m ** 2
github PlasmaPy / PlasmaPy / plasmapy / formulary / magnetostatics.py View on Github external
    @validate_quantities
    def __init__(self, direction, p0: u.m, current: u.A):
        self.direction = direction / np.linalg.norm(direction)
        self.p0 = p0.value
        self._p0_u = p0.unit
        self.current = current.value
        self._current_u = current.unit
github PlasmaPy / PlasmaPy / plasmapy / formulary / parameters.py View on Github external
@validate_quantities
def magnetic_pressure(B: u.T) -> u.Pa:
    r"""
    Calculate the magnetic pressure.

    **Aliases:** `pmag_`

    Parameters
    ----------
    B : ~astropy.units.Quantity
        The magnetic field in units convertible to tesla.

    Returns
    -------
    p_B : ~astropy.units.Quantity
        The magnetic pressure in units in pascals (newtons per square meter).
github PlasmaPy / PlasmaPy / plasmapy / formulary / parameters.py View on Github external
@validate_quantities(
    T_i={"can_be_negative": False, "equivalencies": u.temperature_energy()},
    T_e={"can_be_negative": False, "equivalencies": u.temperature_energy()},
    n_e={"can_be_negative": False, "none_shall_pass": True},
    k={"can_be_negative": False, "none_shall_pass": True},
)
def ion_sound_speed(
    T_e: u.K,
    T_i: u.K,
    n_e: u.m ** -3 = None,
    k: u.m ** -1 = None,
    gamma_e=1,
    gamma_i=3,
    ion="p+",
    z_mean=None,
) -> u.m / u.s:
    r"""