### PlasmaPy Documentation Examples Source: https://docs.plasmapy.org/en/stable/_sources/notebooks/diagnostics/charged_particle_radiography_particle_tracing_wire_mesh.ipynb.txt How to run and understand the code examples provided in the PlasmaPy documentation. ```python # To run examples, ensure you have PlasmaPy and its dependencies installed. # Copy the code block from the documentation into a Python interpreter or script. # For example: # from plasmapy.formulary import plasma_frequency # from astropy import units as u # n_e = 1e19 * u.m**-3 # T_e = 1e6 * u.K # omega_p = plasma_frequency(n_e, T_e) # print(omega_p) ``` -------------------------------- ### Example Notebooks Source: https://docs.plasmapy.org/en/stable/api_static/plasmapy.particles.particle_class.html Links to example notebooks demonstrating the usage of PlasmaPy particles. ```APIDOC ## Example notebooks Using PlasmaPy Particles ``` -------------------------------- ### Install testing dependencies Source: https://docs.plasmapy.org/en/stable/contributing/testing_guide.html Install Nox and uv to manage and run the test suite. ```bash python -m pip install uv nox nox-uv ``` ```bash py -m pip install uv nox nox-uv ``` -------------------------------- ### Install documentation dependencies Source: https://docs.plasmapy.org/en/stable/_sources/contributing/doc_guide.rst.txt Install the necessary dependencies for building documentation and running tests from the repository root. ```bash pip install -e .[docs,tests] ``` -------------------------------- ### Example Parameter Definitions Source: https://docs.plasmapy.org/en/stable/_sources/contributing/doc_guide.rst.txt Common examples of parameter documentation for different data types. ```rst x : `float` Description of ``x``. y : `int` Description of ``y``. settings : `dict` of `str` to `int` Description of ``settings``. ``` -------------------------------- ### Install PlasmaPy with uv Source: https://docs.plasmapy.org/en/stable/_sources/install.rst.txt Install PlasmaPy into an activated uv-managed virtual environment. ```bash uv pip install plasmapy ``` -------------------------------- ### Install Documentation and Test Dependencies Source: https://docs.plasmapy.org/en/stable/contributing/doc_guide.html This command installs the necessary dependencies for building the documentation and running tests in an isolated virtual environment. It is recommended to run this from the top-level directory of the repository. ```bash pip install -e .[docs,tests] ``` -------------------------------- ### PlasmaPy Example Usage Source: https://docs.plasmapy.org/en/stable/_sources/notebooks/diagnostics/charged_particle_radiography_particle_tracing_wire_mesh.ipynb.txt A more integrated example showing multiple PlasmaPy functionalities. ```python import plasmapy as pp from astropy import units as u # Define plasma parameters n_e = 1e20 * u.m**-3 T_e = 5e6 * u.K B = 0.5 * u.T ion_species = 'He+' # Calculate key plasma properties omega_p = pp.formulary.plasma_frequency(n_e, T_e) lambda_D = pp.formulary.debye_length(n_e, T_e) v_A = pp.formulary.alfven_speed(B, n_e, ion_species=ion_species) print(f"Plasma Frequency: {omega_p:.2e}") print(f"Debye Length: {lambda_D:.2e}") print(f"Alfven Speed: {v_A:.2e}") ``` -------------------------------- ### Install Testing Dependencies (Windows) Source: https://docs.plasmapy.org/en/stable/_sources/contributing/testing_guide.rst.txt Installs uv, nox, and nox-uv using pip for Windows environments. ```powershell py -m pip install uv nox nox-uv ``` -------------------------------- ### Install pre-commit Source: https://docs.plasmapy.org/en/stable/_sources/contributing/getting_ready.rst.txt Install the pre-commit framework, which is used for running code quality checks and automated fixes. Execute this command in your terminal. ```bash uv tool install pre-commit ``` -------------------------------- ### Install Testing Dependencies (macOS/Linux/WSL) Source: https://docs.plasmapy.org/en/stable/_sources/contributing/testing_guide.rst.txt Installs uv, nox, and nox-uv using pip for macOS, Linux, or WSL environments. ```bash python -m pip install uv nox nox-uv ``` -------------------------------- ### Install PlasmaPy from Local Source Source: https://docs.plasmapy.org/en/stable/_sources/install.rst.txt After downloading or cloning the PlasmaPy source code, navigate to the directory and use this command to build and install it. This is typically done within the cloned repository's root directory. ```bash pip install . ``` -------------------------------- ### Example Notebook: Charged Particle Radiography Film Stacks Source: https://docs.plasmapy.org/en/stable/_sources/ad/diagnostics/charged_particle_radiography/detector_stacks.rst.txt An example notebook demonstrating the use of film stacks for charged particle radiography. ```APIDOC ## Example Notebook: Charged Particle Radiography Film Stacks ### Description This example notebook illustrates how to use film stacks for charged particle radiography. It covers setup, simulation, and analysis of radiography data using film stacks. ### Notebook Path /notebooks/diagnostics/charged_particle_radiography_film_stacks ### Usage Refer to the notebook for practical implementation details and code examples. ``` -------------------------------- ### FiniteStraightWire Initialization Source: https://docs.plasmapy.org/en/stable/_modules/plasmapy/formulary/magnetostatics.html Initializes a FiniteStraightWire object with specified start and end points and electric current. Raises a ValueError if the start and end points are the same. ```python def __init__( self, p1: u.Quantity[u.m], p2: u.Quantity[u.m], current: u.Quantity[u.A] ) -> None: self.p1 = p1.value self.p2 = p2.value self._p1_u = p1.unit self._p2_u = p2.unit if np.all(p1 == p2): raise ValueError("p1, p2 should not be the same point.") self.current = current.value self._current_u = current.unit ``` -------------------------------- ### Build Documentation with Make Source: https://docs.plasmapy.org/en/stable/_sources/contributing/doc_guide.rst.txt Use this command to build the documentation when make is installed. Navigate to the |docs|_ directory first. ```bash make html ``` -------------------------------- ### Getting Particle Charge Source: https://docs.plasmapy.org/en/stable/_sources/notebooks/diagnostics/charged_particle_radiography_particle_tracing_wire_mesh.ipynb.txt Example of retrieving the charge of a particle. ```python from plasmapy.particles import Particle from astropy import units as u particle = Particle(element='He', atomic_number=2, charge_state=1) charge = particle.charge print(f"Charge of {particle.element}: {charge:.2f}") ``` -------------------------------- ### Get Ionic Levels of Helium Source: https://docs.plasmapy.org/en/stable/api/plasmapy.particles.atomic.ionic_levels.html Use `ionic_levels` to get all ionic levels of an element starting from charge 0. Requires importing `ionic_levels` from `plasmapy.particles`. ```python from plasmapy.particles import ionic_levels >>> ionic_levels("He") ParticleList(['He 0+', 'He 1+', 'He 2+']) ``` -------------------------------- ### Importing necessary libraries Source: https://docs.plasmapy.org/en/stable/_sources/notebooks/formulary/iter.ipynb.txt Initial setup for plotting and plasma calculations. ```python %matplotlib inline import astropy.units as u import matplotlib.pyplot as plt import numpy as np from plasmapy import formulary ``` -------------------------------- ### Calculating Electron Mass in kg Source: https://docs.plasmapy.org/en/stable/_sources/notebooks/diagnostics/charged_particle_radiography_particle_tracing_wire_mesh.ipynb.txt Example of getting the electron mass in kilograms. ```python from plasmapy.constants import m_e_kg print(f"Electron mass (kg): {m_e_kg:.2e}") ``` -------------------------------- ### Get Most Abundant Ion Source: https://docs.plasmapy.org/en/stable/_sources/notebooks/particles/ace.ipynb.txt Access the most abundant ion for a given element. No setup or imports are explicitly shown. ```python He_states.Z_most_abundant ``` -------------------------------- ### Build documentation with make Source: https://docs.plasmapy.org/en/stable/contributing/doc_guide.html Useful for interactive building and rebuilding of documentation. ```bash make html ``` ```bash make clean ``` -------------------------------- ### Plot Langmuir Characteristic Source: https://docs.plasmapy.org/en/stable/api/plasmapy.diagnostics.langmuir.Characteristic.html Generates a plot of the I-V characteristic using Matplotlib. No additional setup is required if Matplotlib is installed. ```python characteristic.plot() ``` -------------------------------- ### ParticleTracker Initialization and Setup Source: https://docs.plasmapy.org/en/stable/api/plasmapy.simulation.particle_tracker.particle_tracker.ParticleTracker.html Demonstrates how to initialize the ParticleTracker with a grid, termination condition, and other simulation parameters. ```APIDOC ## ParticleTracker Initialization ### Description Initializes the ParticleTracker with a grid, termination condition, time step, and other simulation settings. ### Method Instantiation of the `ParticleTracker` class. ### Parameters - **grid** (CartesianGrid) - Required - The simulation grid. - **termination_condition** (TerminationCondition) - Required - The condition to stop the simulation. - **dt** (Quantity) - Optional - The time step for the simulation. Defaults to `1e-2 * u.s`. - **save_routine** (SaveRoutine) - Optional - Routine for saving simulation data. - **field_weighting** (str) - Optional - Method for field weighting. Defaults to "nearest neighbor". - **verbose** (bool) - Optional - Whether to display verbose output. Defaults to `False`. ### Request Example ```python from plasmapy.simulation import ParticleTracker from plasmapy.simulation.grid import CartesianGrid from plasmapy.simulation.termination_conditions import TimeElapsedTerminationCondition from plasmapy.simulation.save_routines import IntervalSaveRoutine import astropy.units as u grid = CartesianGrid(-1e6 * u.m, 1e6 * u.m, num=2) grid_shape = (2, 2, 2) Bz = np.full(grid_shape, 1) * u.T grid.add_quantities(B_z=Bz) termination_condition = TimeElapsedTerminationCondition(6.28 * u.s) save_routine = IntervalSaveRoutine(6.28 * u.s / 10) simulation = ParticleTracker( grid, termination_condition, dt=1e-2 * u.s, save_routine=save_routine, field_weighting="nearest neighbor", verbose=False, ) ``` ``` -------------------------------- ### Get RMS Ion Charge Source: https://docs.plasmapy.org/en/stable/_sources/notebooks/particles/ace.ipynb.txt Retrieve the root-mean-square (RMS) charge of ions for a given element. No setup or imports are explicitly shown. ```python He_states.Z_rms ``` -------------------------------- ### Clone PlasmaPy GitHub Repository Source: https://docs.plasmapy.org/en/stable/_sources/install.rst.txt Use this command to clone the PlasmaPy GitHub repository to get the most recent development version. Ensure you have Git installed. ```bash git clone https://github.com/PlasmaPy/PlasmaPy.git ``` -------------------------------- ### Import PlasmaPy and Plotting Libraries Source: https://docs.plasmapy.org/en/stable/notebooks/formulary/thermal_speed.html Imports necessary modules from astropy, matplotlib, numpy, and PlasmaPy for calculations and plotting. This setup is required for all subsequent examples. ```python %matplotlib inline import astropy.units as u import matplotlib.pyplot as plt import numpy as np from plasmapy.formulary import ( Maxwellian_speed_1D, Maxwellian_speed_2D, Maxwellian_speed_3D, ) from plasmapy.formulary.speeds import thermal_speed ``` -------------------------------- ### Initialize and Run Particle Tracker Source: https://docs.plasmapy.org/en/stable/api/plasmapy.simulation.particle_tracker.particle_tracker.ParticleTracker.html Sets up a Cartesian grid, defines simulation parameters, loads particles, and runs the simulation. Ensure 'example_particle' is defined elsewhere. ```python grid = CartesianGrid(-1e6 * u.m, 1e6 * u.m, num=2) grid_shape = (2, 2, 2) Bz = np.full(grid_shape, 1) * u.T grid.add_quantities(B_z=Bz) x = [[0, 0, 0]] * u.m v = [[1, 0, 0]] * u.m / u.s termination_condition = TimeElapsedTerminationCondition(6.28 * u.s) save_routine = IntervalSaveRoutine(6.28 * u.s / 10) simulation = ParticleTracker( grid, termination_condition, dt=1e-2 * u.s, save_routine=save_routine, field_weighting="nearest neighbor", verbose=False, ) simulation.load_particles(x, v, example_particle) simulation.run() print( simulation.save_routine.results["time"][-1], simulation.save_routine.results["x"][-1], ) ``` -------------------------------- ### Get Standard Atomic Weight of Element Source: https://docs.plasmapy.org/en/stable/_modules/plasmapy/particles/atomic.html Retrieve the standard atomic weight for a given element. Requires the element name or atomic symbol. Example uses 'H' and 'lead'. ```python >>> standard_atomic_weight("H") >>> standard_atomic_weight("lead") ``` -------------------------------- ### Import necessary libraries for Thomson scattering analysis Source: https://docs.plasmapy.org/en/stable/_sources/notebooks/diagnostics/thomson.ipynb.txt Imports astropy units, matplotlib for plotting, numpy for numerical operations, and the thomson module from plasmapy.diagnostics. This setup is required for all subsequent examples. ```python %matplotlib inline import astropy.units as u import matplotlib.pyplot as plt import numpy as np from plasmapy.diagnostics import thomson ``` -------------------------------- ### Getting Particle Name Source: https://docs.plasmapy.org/en/stable/_sources/notebooks/diagnostics/charged_particle_radiography_particle_tracing_wire_mesh.ipynb.txt Shows how to get the name of a particle. ```python from plasmapy.particles import Particle particle = Particle(element='He', atomic_number=2, charge_state=1) name = particle.name print(f"Particle name: {name}") ``` -------------------------------- ### Build Documentation with Nox Source: https://docs.plasmapy.org/en/stable/contributing/doc_guide.html This command uses Nox to build the documentation. It installs an isolated virtual environment with uv and generates the HTML output in 'docs/_build/html/'. This is the recommended method for building documentation. ```bash nox -s docs ``` -------------------------------- ### Initialize ParticleTracker with Example Parameters Source: https://docs.plasmapy.org/en/stable/_modules/plasmapy/simulation/particle_tracker/particle_tracker.html Demonstrates initializing ParticleTracker with a CartesianGrid, termination condition, save routine, and specific field weighting. Ensure all necessary imports are present. ```python from plasmapy.particles import Particle from plasmapy.plasma.grids import CartesianGrid from plasmapy.simulation.particle_tracker.particle_tracker import ( ParticleTracker, ) from plasmapy.simulation.particle_tracker.save_routines import ( IntervalSaveRoutine, ) from plasmapy.simulation.particle_tracker.termination_conditions import ( TimeElapsedTerminationCondition, ) import astropy.units as u import numpy as np example_particle = Particle("p+") grid = CartesianGrid(-1e6 * u.m, 1e6 * u.m, num=2) grid_shape = (2, 2, 2) Bz = np.full(grid_shape, 1) * u.T grid.add_quantities(B_z=Bz) x = [[0, 0, 0]] * u.m v = [[1, 0, 0]] * u.m / u.s termination_condition = TimeElapsedTerminationCondition(6.28 * u.s) save_routine = IntervalSaveRoutine(6.28 * u.s / 10) simulation = ParticleTracker( grid, termination_condition, dt=1e-2 * u.s, save_routine=save_routine, field_weighting="nearest neighbor", verbose=False, ) simulation.load_particles(x, v, example_particle) simulation.run() print( simulation.save_routine.results["time"][-1], simulation.save_routine.results["x"][-1], ) ``` -------------------------------- ### Downloader module imports and setup Source: https://docs.plasmapy.org/en/stable/_modules/plasmapy/utils/data/downloader.html Initializes the downloader module with necessary imports and environment checks for CI integration. ```python """ Contains functionality for downloading files from a URL. Intended for downloading files from |PlasmaPy's data repository|. """ import contextlib import json import os import time import warnings from pathlib import Path from urllib.parse import urljoin import requests __all__ = ["_API_CONNECTION_ESTABLISHED", "Downloader"] _API_CONNECTION_ESTABLISHED = False _IS_CI = "GH_TOKEN" in os.environ # TODO: use a config file variable to allow users to set a location ``` -------------------------------- ### Creating a Plasma Distribution Source: https://docs.plasmapy.org/en/stable/_sources/notebooks/diagnostics/charged_particle_radiography_particle_tracing_wire_mesh.ipynb.txt Example of creating a plasma distribution object. ```python from plasmapy.classes import PlasmaDistribution dist = PlasmaDistribution() print(dist) ``` -------------------------------- ### Importing Necessary Libraries Source: https://docs.plasmapy.org/en/stable/_sources/notebooks/formulary/thermal_bremsstrahlung.ipynb.txt Initializes the environment with required libraries for physical constants, units, plotting, and the thermal bremsstrahlung function. ```python %matplotlib inline import astropy.constants as const import astropy.units as u import matplotlib.pyplot as plt import numpy as np from plasmapy.formulary.radiation import thermal_bremsstrahlung ``` -------------------------------- ### Initialize CustomParticle Source: https://docs.plasmapy.org/en/stable/api/plasmapy.particles.particle_class.CustomParticle.html Demonstrates creating custom particles using mass, charge, and charge number parameters. ```python >>> import astropy.units as u >>> from plasmapy.particles import CustomParticle >>> custom_particle = CustomParticle( ... mass=1.2e-26 * u.kg, ... charge=9.2e-19 * u.C, ... ) >>> custom_particle.mass >>> custom_particle.charge >>> average_particle = CustomParticle( ... mass=1.5e-26 * u.kg, ... Z=-1.5, ... symbol="Ξ", ... ) >>> average_particle.mass >>> average_particle.charge >>> average_particle.symbol 'Ξ' ``` -------------------------------- ### Example of a type mismatch error Source: https://docs.plasmapy.org/en/stable/contributing/coding_guide.html An example function that triggers a mypy return-value error. ```python def return_object(x: int | str) -> int: # should be: -> int | str return x ``` ```text Incompatible return value type (got "int | str", expected "int") [return-value] ``` -------------------------------- ### Install PlasmaPy with Conda Source: https://docs.plasmapy.org/en/stable/_sources/install.rst.txt Install PlasmaPy from the conda-forge channel into an activated Conda environment. ```bash conda install -c conda-forge plasmapy ``` -------------------------------- ### Verify Git Installation Source: https://docs.plasmapy.org/en/stable/_sources/contributing/getting_ready.rst.txt Check if Git is installed on your system by running this command in your terminal. ```bash git --version ``` -------------------------------- ### Build documentation using Nox Source: https://docs.plasmapy.org/en/stable/_sources/contributing/doc_guide.rst.txt Build the documentation locally using Nox, which creates an isolated virtual environment. ```bash nox -s docs ``` ```bash nox -s docs -- -v ``` -------------------------------- ### Symbols Starting with X Source: https://docs.plasmapy.org/en/stable/genindex.html Documentation for symbols, functions, and classes in PlasmaPy starting with 'X'. ```APIDOC ## X ### `x` Attribute - **Description**: Represents the x-coordinate or a related quantity. - **Appears in**: `plasmapy.formulary.collisions.frequencies.SingleParticleCollisionFrequencies`, `plasmapy.plasma.sources.plasma3d.Plasma3D` ``` -------------------------------- ### Initialize Environment for Magnetostatics Source: https://docs.plasmapy.org/en/stable/_sources/notebooks/formulary/magnetostatics.ipynb.txt Sets up the necessary imports and matplotlib configuration for plotting magnetostatic fields. ```python %matplotlib inline import astropy.units as u import matplotlib.pyplot as plt import numpy as np from plasmapy.formulary import magnetostatics from plasmapy.plasma.sources import Plasma3D plt.rcParams["figure.figsize"] = [10.5, 10.5] ``` -------------------------------- ### Symbols Starting with W Source: https://docs.plasmapy.org/en/stable/genindex.html Documentation for symbols, functions, and classes in PlasmaPy starting with 'W'. ```APIDOC ## W ### `w0_()` - **Module**: `plasmapy.formulary` - **Submodule**: `plasmapy.formulary.laser` ### `waiting_times` Attribute - **Description**: Attribute related to waiting times in time series analysis. - **Appears in**: `plasmapy.analysis.time_series.conditional_averaging.ConditionalEvents` ### `wavenumber` Attribute - **Description**: Wavenumber of a wave. - **Appears in**: `plasmapy.simulation.abstractions.AbstractNormalizations` ### `wc_()` - **Module**: `plasmapy.formulary` - **Submodule**: `plasmapy.formulary.frequencies` ### `Wigner_Seitz_radius()` - **Module**: `plasmapy.formulary.quantum` ### `wikipedia` Role - **Description**: Represents a role related to Wikipedia. ### `Wire` Class - **Module**: `plasmapy.formulary.magnetostatics` ### `wlh_()` - **Module**: `plasmapy.formulary` - **Submodule**: `plasmapy.formulary.frequencies` ### `wp_()` - **Module**: `plasmapy.formulary` - **Submodule**: `plasmapy.formulary.frequencies` ### `wuh_()` - **Module**: `plasmapy.formulary` - **Submodule**: `plasmapy.formulary.frequencies` ``` -------------------------------- ### Symbols Starting with V Source: https://docs.plasmapy.org/en/stable/genindex.html Documentation for symbols, functions, and classes in PlasmaPy starting with 'V'. ```APIDOC ## V ### `v_over_c` Attribute - **Description**: Relativistic velocity as a fraction of the speed of light. - **Appears in**: `plasmapy.formulary.relativity.RelativisticBody` ### `va_()` - **Module**: `plasmapy.formulary` - **Submodule**: `plasmapy.formulary.speeds` ### `valid_categories` - **Module**: `plasmapy.particles.particle_class` ### `validate_class_attributes()` - **Module**: `plasmapy.utils.decorators.validators` ### `validate_quantities()` - **Module**: `plasmapy.utils.decorators.validators` ### `ValidateQuantities` Class - **Module**: `plasmapy.utils.decorators.validators` ### `validation_functions` Attribute - **Description**: Attribute related to validation functions. - **Appears in**: `plasmapy.utils.datatype_factory_base.BasicRegistrationFactory` ### `ValidationFunctionError` - **Type**: Exception ### `validations` Attribute - **Description**: Attribute related to validations. - **Appears in**: `plasmapy.utils.decorators.validators.ValidateQuantities` ### `variance` Attribute - **Description**: Variance calculation. - **Appears in**: `plasmapy.analysis.time_series.conditional_averaging.ConditionalEvents` ### `vd_()` - **Module**: `plasmapy.formulary` - **Submodule**: `plasmapy.formulary.drifts` ### `veb_()` - **Module**: `plasmapy.formulary` - **Submodule**: `plasmapy.formulary.drifts` ### `vector_intersects()` Method - **Description**: Method to check if a vector intersects with a grid. - **Appears in**: `plasmapy.plasma.grids.AbstractGrid`, `plasmapy.plasma.grids.CartesianGrid`, `plasmapy.plasma.grids.NonUniformCartesianGrid` ### `velocity` Attribute - **Description**: Velocity of a relativistic body or plasma component. - **Appears in**: `plasmapy.formulary.relativity.RelativisticBody`, `plasmapy.plasma.sources.plasma3d.Plasma3D`, `plasmapy.simulation.abstractions.AbstractNormalizations` ### `vf_err` Attribute - **Description**: Error related to VF (Velocity Field). - **Appears in**: `plasmapy.analysis.swept_langmuir.floating_potential.VFExtras` ### `vfd_()` - **Module**: `plasmapy.formulary` - **Submodule**: `plasmapy.formulary.drifts` ### `VFExtras` Class - **Module**: `plasmapy.analysis.swept_langmuir.floating_potential` ### `vmax` Attribute - **Description**: Maximum velocity. - **Appears in**: `plasmapy.diagnostics.charged_particle_radiography.synthetic_radiography.Tracker`, `plasmapy.simulation.particle_tracker.particle_tracker.ParticleTracker` ### `volume_averaged_interpolator()` Method - **Description**: Method to create a volume-averaged interpolator. - **Appears in**: `plasmapy.plasma.grids.CartesianGrid` ### `volumetric_heating_rate` Attribute - **Description**: Rate of volumetric heating. - **Appears in**: `plasmapy.simulation.abstractions.AbstractNormalizations` ### `volumetric_rate` Attribute - **Description**: General volumetric rate. - **Appears in**: `plasmapy.simulation.abstractions.AbstractNormalizations` ### `vth_()` - **Module**: `plasmapy.formulary` - **Submodule**: `plasmapy.formulary.speeds` ### `vth_kappa_()` - **Module**: `plasmapy.formulary` - **Submodule**: `plasmapy.formulary.speeds` ``` -------------------------------- ### Initialize Stack and Inspect Properties Source: https://docs.plasmapy.org/en/stable/notebooks/diagnostics/charged_particle_radiography_film_stacks.html Create a stack of layers and retrieve basic properties like layer count and total thickness. ```python Layer(100 * u.um, energy_axis, aluminum_stopping_power, active=False), *HDV2, Layer(100 * u.um, energy_axis, aluminum_stopping_power, active=False), *HDV2, Layer(100 * u.um, energy_axis, aluminum_stopping_power, active=False), *HDV2, Layer(100 * u.um, energy_axis, aluminum_stopping_power, active=False), *HDV2, Layer(500 * u.um, energy_axis, aluminum_stopping_power, active=False), *HDV2, Layer(500 * u.um, energy_axis, aluminum_stopping_power, active=False), *HDV2, Layer(1000 * u.um, energy_axis, aluminum_stopping_power, active=False), *HDV2, Layer(1000 * u.um, energy_axis, aluminum_stopping_power, active=False), *HDV2, Layer(2000 * u.um, energy_axis, aluminum_stopping_power, active=False), *HDV2, Layer(2000 * u.um, energy_axis, aluminum_stopping_power, active=False), *HDV2, Layer(2000 * u.um, energy_axis, aluminum_stopping_power, active=False), ] stack = Stack(layers) ``` ```python print(f"Number of layers: {stack.num_layers}") print(f"Number of active layers: {stack.num_active}") print(f"Total stack thickness: {stack.thickness:.2f}") ``` -------------------------------- ### Symbols Starting with U Source: https://docs.plasmapy.org/en/stable/genindex.html Documentation for symbols, functions, and classes in PlasmaPy starting with 'U'. ```APIDOC ## U ### `ub_()` - **Module**: `plasmapy.formulary` - **Submodule**: `plasmapy.formulary.misc` ### `UnexpectedParticleError` - **Type**: Exception ### `uniform_null_point_find()` - **Module**: `plasmapy.analysis.nullpoint` ### `unit` Attribute - **Description**: An attribute related to units. - **Appears in**: `plasmapy.plasma.grids.AbstractGrid`, `plasmapy.plasma.grids.CartesianGrid`, `plasmapy.plasma.grids.NonUniformCartesianGrid` ### `unit0` Attribute - **Description**: An attribute related to units. - **Appears in**: `plasmapy.plasma.grids.AbstractGrid`, `plasmapy.plasma.grids.CartesianGrid`, `plasmapy.plasma.grids.NonUniformCartesianGrid` ### `unit1` Attribute - **Description**: An attribute related to units. - **Appears in**: `plasmapy.plasma.grids.AbstractGrid`, `plasmapy.plasma.grids.CartesianGrid`, `plasmapy.plasma.grids.NonUniformCartesianGrid` ### `unit2` Attribute - **Description**: An attribute related to units. - **Appears in**: `plasmapy.plasma.grids.AbstractGrid`, `plasmapy.plasma.grids.CartesianGrid`, `plasmapy.plasma.grids.NonUniformCartesianGrid` ### `units` Attribute - **Description**: An attribute related to units. - **Appears in**: `plasmapy.plasma.grids.AbstractGrid`, `plasmapy.plasma.grids.CartesianGrid`, `plasmapy.plasma.grids.NonUniformCartesianGrid` ### `units_string` Attribute - **Description**: An attribute related to unit strings. - **Appears in**: `plasmapy.simulation.particle_tracker.termination_conditions.AbstractTerminationCondition`, `plasmapy.simulation.particle_tracker.termination_conditions.AllParticlesOffGridTerminationCondition`, `plasmapy.simulation.particle_tracker.termination_conditions.NoParticlesOnGridsTerminationCondition`, `plasmapy.simulation.particle_tracker.termination_conditions.TimeElapsedTerminationCondition` ### `unregister()` Method - **Description**: Method for unregistering. - **Appears in**: `plasmapy.plasma.plasma_factory.PlasmaFactory`, `plasmapy.utils.datatype_factory_base.BasicRegistrationFactory` ### `upper_hybrid_frequency()` - **Module**: `plasmapy.formulary.frequencies` ### `user` Role - **Description**: Represents a user role. ``` -------------------------------- ### Enter Repository Directory Source: https://docs.plasmapy.org/en/stable/contributing/getting_ready.html Navigate into the cloned PlasmaPy directory. ```bash cd PlasmaPy ``` -------------------------------- ### Numpydoc Example Function Source: https://docs.plasmapy.org/en/stable/contributing/doc_guide.html An example of a function with a numpydoc formatted docstring, including parameters, returns, raises, warns, see also, notes, and examples sections. This format is used for documenting Python functions. ```python import warnings import numpy as np def subtract(a, b, *, switch_order=False): r""" Compute the difference between two integers. Add ∼1–3 sentences here for an extended summary of what the function does. This extended summary is a good place to briefly define the quantity that is being returned. .. math:: f(a, b) = a - b Parameters ---------- a : `float` The number from which ``b`` will be subtracted. b : `float` The number being subtracted from ``a``. switch_order : `bool`, |keyword-only|, default: `True` If `True`, return :math:`a - b`. If `False`, then return :math:`b - a`. Returns ------- float The difference between ``a`` and ``b``. Raises ------ `ValueError` If ``a`` or ``b`` is `~numpy.inf`. Warns ----- `UserWarning` If ``a`` or ``b`` is `~numpy.nan`. See Also -------- add : Add two numbers. Notes ----- The "Notes" section provides extra information that cannot fit in the extended summary near the beginning of the docstring. This section should include a discussion of the physics behind a particular concept that should be understandable to someone who is taking their first plasma physics class. This section can include a derivation of the quantity being calculated or a description of a particular algorithm. Examples -------- Include a few example usages of the function here. Start with simple examples and then increase complexity when necessary. >>> from package.subpackage.module import subtract >>> subtract(9, 6) 3 Here is an example of a multi-line function call. >>> subtract( ... 9, 6, switch_order=True, ... ) -3 PlasmaPy's test suite will check that these commands provide the output that follows each function call. """ if np.isinf(a) or np.isinf(b): raise ValueError("Cannot perform subtraction operations involving infinity.") warnings.warn("The `subtract` function encountered a nan value.", UserWarning) return b - a if switch_order else a - b ``` -------------------------------- ### Initialize and use AlfvenWave Source: https://docs.plasmapy.org/en/stable/_modules/plasmapy/dispersion/analytical/mhd_waves_.html Demonstrates how to instantiate the AlfvenWave class and calculate wave properties like angular frequency and phase velocity. ```python >>> import astropy.units as u >>> from plasmapy.dispersion.analytical import AlfvenWave >>> alfven = AlfvenWave(1e-3 * u.T, 1e16 * u.m**-3, "p+") >>> alfven.angular_frequency(1e-5 * u.rad / u.m, 0 * u.deg) >>> alfven.phase_velocity(1e-5 * u.rad / u.m, 0 * u.deg) >>> alfven.alfven_speed ``` -------------------------------- ### PlasmaPy Installation Source: https://docs.plasmapy.org/en/stable/_sources/notebooks/diagnostics/charged_particle_radiography_particle_tracing_wire_mesh.ipynb.txt Instructions for installing PlasmaPy using pip. Ensure you have a compatible Python version. ```bash pip install plasmapy ``` -------------------------------- ### PlasmaPy Plotting Example (Conceptual) Source: https://docs.plasmapy.org/en/stable/_sources/notebooks/diagnostics/charged_particle_radiography_particle_tracing_wire_mesh.ipynb.txt Illustrative example of how plotting might be integrated, likely using Matplotlib. ```python import matplotlib.pyplot as plt import numpy as np x = np.linspace(0, 10, 100) y = np.sin(x) plt.figure() plt.plot(x, y) plt.xlabel("X-axis") plt.ylabel("Y-axis") plt.title("Sample Plot") plt.grid(True) plt.show() ``` -------------------------------- ### Initialize DimensionlessParticle Source: https://docs.plasmapy.org/en/stable/_modules/plasmapy/particles/particle_class.html Example of creating a dimensionless particle instance with mass, charge, and symbol. ```python >>> from plasmapy.particles import DimensionlessParticle >>> particle = DimensionlessParticle(mass=1.0, charge=-1.0, symbol="ξ") >>> particle.mass np.float64(1.0) >>> particle.charge np.float64(-1.0) >>> particle.symbol 'ξ' ``` -------------------------------- ### Mixed Particle List Example Source: https://docs.plasmapy.org/en/stable/_sources/glossary.rst.txt An example of a list containing both atom-like and non-atom-like particles, which is not considered atom-like. ```python ["He-4", "e-"] ``` -------------------------------- ### Initialize Environment for Fit Functions Source: https://docs.plasmapy.org/en/stable/notebooks/analysis/fit_functions.html Set up the plotting environment and import the necessary fit function modules. ```python %matplotlib inline import matplotlib.pyplot as plt import numpy as np from plasmapy.analysis import fit_functions as ffuncs plt.rcParams["figure.figsize"] = [10.5, 0.56 * 10.5] ``` -------------------------------- ### Create and Print InfiniteStraightWire Source: https://docs.plasmapy.org/en/stable/_sources/notebooks/formulary/magnetostatics.ipynb.txt Initializes an InfiniteStraightWire object with specified parameters and prints its representation. ```python iw = magnetostatics.InfiniteStraightWire( np.array([0, 1, 0]), np.array([0, 0, 0]) * u.m, 1 * u.A ) print(iw) ``` -------------------------------- ### Initialize Null Point Finder Environment Source: https://docs.plasmapy.org/en/stable/_sources/notebooks/analysis/nullpoint.ipynb.txt Sets up the plotting environment and imports necessary modules for null point analysis. ```python %matplotlib inline import matplotlib.pyplot as plt import numpy as np from plasmapy.analysis import nullpoint plt.rcParams["figure.figsize"] = [10.5, 0.56 * 10.5] ``` -------------------------------- ### Non-Atom-Like Particle Examples Source: https://docs.plasmapy.org/en/stable/_sources/glossary.rst.txt Examples of particle representations that are considered particle-like but not atom-like. These include neutral particles and antiparticles. ```python "neutron" ``` ```python "e-" ``` ```python ["e-", "e+"] ``` -------------------------------- ### POST /synthetic_radiography/init Source: https://docs.plasmapy.org/en/stable/_modules/plasmapy/diagnostics/charged_particle_radiography/synthetic_radiography.html Initializes the Synthetic Radiography simulation environment with grid, source, and detector configurations. ```APIDOC ## POST /synthetic_radiography/init ### Description Initializes the synthetic radiography simulation, defining the particle source, detector geometry, and simulation parameters. ### Parameters #### Request Body - **grids** (AbstractGrid | Iterable[AbstractGrid]) - Required - The grid(s) used for the simulation. - **source** (u.Quantity) - Required - Vector pointing to the particle source (Cartesian, cylindrical, or spherical). - **detector** (u.Quantity) - Required - Vector pointing to the center of the detector plane. - **dt** (u.Quantity) - Optional - Explicit time step in seconds. - **dt_range** (tuple) - Optional - Range for adaptive time step clamping. - **field_weighting** (str) - Optional - Algorithm for field assignment ('volume averaged' or 'nearest neighbor'). - **detector_hdir** (numpy.ndarray) - Optional - Horizontal unit vector for the detector plane. - **detector_vdir** (numpy.ndarray) - Optional - Vertical unit vector for the detector plane. - **output_directory** (pathlib.Path) - Optional - Directory for saving output files. - **output_basename** (str) - Optional - Base name for output files. - **fraction_exited_threshold** (float) - Optional - Fraction of particles exiting the grid to terminate simulation. - **verbose** (bool) - Optional - Enable standard output logging. ``` -------------------------------- ### Particle Representation Examples Source: https://docs.plasmapy.org/en/stable/_sources/glossary.rst.txt Examples of how particles can be represented as strings or integers. These representations are used to instantiate Particle objects. ```python "p+" ``` ```python "He-4" ``` ```python "deuterium" ``` ```python "O 0+" ``` ```python Particle("Fe-56 16+)" ``` ```python ["He-4 1+", "He-4 2+"] ``` ```python 26 ``` -------------------------------- ### Install and manage PlasmaPy with Conda Source: https://docs.plasmapy.org/en/stable/install.html Commands for installing, creating environments, and updating PlasmaPy using the conda-forge channel. ```bash conda install -c conda-forge plasmapy ``` ```bash conda create -n env_name -c conda-forge plasmapy ``` ```bash conda activate env_name ``` ```bash conda update plasmapy ``` -------------------------------- ### Initialize Downloader Class Source: https://docs.plasmapy.org/en/stable/_modules/plasmapy/utils/data/downloader.html Initializes the Downloader class, setting up the download directory, validation preferences, and API token. It also handles the creation or reading of the local SHA blob file. ```python def __init__( self, directory: Path | None = None, validate: bool = True, api_token: str | None = None, ) -> None: if directory is None: # No test coverage for default directory, since pytest always # saves into a temporary directory self._download_directory = ( Path.home() / ".plasmapy" / "downloads" ) # coverage: ignore else: self._download_directory = Path(directory) # If currently operating in a CI environment and no token was specified, # take the token from the CI environment variables if _IS_CI and api_token is None: api_token = api_token if api_token is not None else os.getenv("GH_TOKEN") self._validate = validate self._api_token = api_token # Flag to record whether the blob file has been updated from the repo # by this instantiation of the class. Once the file has been updated # once, we won't update it again to limit API calls. self._updated_blob_file_from_repo = False self._download_directory.mkdir(parents=True, exist_ok=True) # Path to the local SHA blob file self._blob_file = Path(self._download_directory, self._blob_file_name) # Create the SHA blob file if it doesn't already exist if not self._blob_file.is_file(): self._blob_dict = {} self._write_blobfile() # Otherwise, read the SHA blob file else: self._read_blobfile() ``` -------------------------------- ### Install PlasmaPy with pip Source: https://docs.plasmapy.org/en/stable/install.html Use these commands to install the latest PlasmaPy release from PyPI into a Python 3.12+ environment. ```bash python -m pip install plasmapy ``` ```bash py -3.14 -m pip install plasmapy ``` -------------------------------- ### Install PlasmaPy test dependencies Source: https://docs.plasmapy.org/en/stable/_sources/contributing/testing_guide.rst.txt Installs the necessary packages for running tests locally, including Nox and pytest. ```bash pip install -e .[tests] ``` -------------------------------- ### Import necessary libraries Source: https://docs.plasmapy.org/en/stable/_sources/notebooks/formulary/ExB_drift.ipynb.txt Initializes the environment with required scientific computing and PlasmaPy modules. ```python %matplotlib inline import math import astropy.units as u import matplotlib.pyplot as plt import numpy as np from plasmapy import formulary, particles ```