Core package utilities (plasmapy.utils)

Introduction

PlasmaPy.utils is where we store functionality that helps us write (what we try to think of as) clean, readable and informative code. This means:

  • the many kinds of warnings and exceptions you may (hopefully not!) encounter while working with PlasmaPy, such as plasmapy.utils.RelativityWarning or plasmapy.utils.PhysicsError.
  • decorators we use for reusable physical quantity computation and checking, such as plasmapy.utils.check_quantity and plasmapy.utils.check_relativistic
  • Some helper utilities for importing and testing packages such as plasmapy.utils.call_string

Reference/API

plasmapy.utils.checks Module

Functions

check_quantity(validations) Raise an exception if an annotated argument in a decorated function is an Quantity with incorrect units and valid numerical values, or assume inputs are SI Quantities.
check_relativistic([func, betafrac]) Warns or raises an exception when the output of the decorated function is greater than betafrac times the speed of light.

plasmapy.utils.exceptions Module

Exceptions and warnings specific to PlasmaPy.

Classes

AtomicError An exception for errors in the atomic subpackage.
AtomicWarning The base warning for the atomic subpackage.
ChargeError An exception for incorrect or missing charge information.
CouplingWarning A warning for functions that rely on a particular coupling regime to be valid.
InvalidElementError An exception for when an argument is a valid particle is not a valid element.
InvalidIonError An exception for when an argument is a valid particle but not a valid ion.
InvalidIsotopeError An exception for when an argument is a valid particle but not a valid isotope.
InvalidParticleError An exception for when a particle is invalid.
MissingAtomicDataError An exception for missing atomic or particle data.
MissingAtomicDataWarning Warning for use when atomic or particle data is missing.
PhysicsError The base exception for physics-related errors.
PhysicsWarning The base warning for physics related warnings.
PlasmaPyError Base class of PlasmaPy custom errors.
PlasmaPyWarning Base class of PlasmaPy custom warnings.
RelativityError An exception for speeds greater than the speed of light.
RelativityWarning A warning for when relativistic velocities are being used in or are returned by non-relativistic functionality.
UnexpectedParticleError An exception for when a particle is not of the expected category.

Class Inheritance Diagram

Inheritance diagram of plasmapy.utils.exceptions.AtomicError, plasmapy.utils.exceptions.AtomicWarning, plasmapy.utils.exceptions.ChargeError, plasmapy.utils.exceptions.CouplingWarning, plasmapy.utils.exceptions.InvalidElementError, plasmapy.utils.exceptions.InvalidIonError, plasmapy.utils.exceptions.InvalidIsotopeError, plasmapy.utils.exceptions.InvalidParticleError, plasmapy.utils.exceptions.MissingAtomicDataError, plasmapy.utils.exceptions.MissingAtomicDataWarning, plasmapy.utils.exceptions.PhysicsError, plasmapy.utils.exceptions.PhysicsWarning, plasmapy.utils.exceptions.PlasmaPyError, plasmapy.utils.exceptions.PlasmaPyWarning, plasmapy.utils.exceptions.RelativityError, plasmapy.utils.exceptions.RelativityWarning, plasmapy.utils.exceptions.UnexpectedParticleError

plasmapy.utils.pytest_helpers Module

Test helper utilities.

Functions

call_string(f, args, kwargs[, color, …]) Return a string with the equivalent call of a function.
run_test(func, args, kwargs, …) Test that a function or class returns the expected result, raises the expected exception, or issues an expected warning for the supplied positional and keyword arguments.
run_test_equivalent_calls(*test_inputs, …) Test that different functions/inputs return equivalent results.

Classes

InconsistentTypeError Exception for when the type of the actual result differs from the type of the expected result.
IncorrectResultError Exception for when the actual result differs from the expected result by more than the allowed tolerance.
InvalidTestError Exception for when the inputs to a test are not valid.
MissingExceptionError Exception for when an expected exception is not raised.
MissingWarningError Exception for when a warning is expected to be issued, but isn’t.
RunTestError Base exception for test failures.
UnexpectedExceptionError Exception for when an exception is expected, but a different exception is raised instead.
UnexpectedResultError Exception for when the actual result differs from the expected result.

Class Inheritance Diagram

Inheritance diagram of plasmapy.utils.pytest_helpers.InconsistentTypeError, plasmapy.utils.pytest_helpers.IncorrectResultError, plasmapy.utils.pytest_helpers.InvalidTestError, plasmapy.utils.pytest_helpers.MissingExceptionError, plasmapy.utils.pytest_helpers.MissingWarningError, plasmapy.utils.pytest_helpers.RunTestError, plasmapy.utils.pytest_helpers.UnexpectedExceptionError, plasmapy.utils.pytest_helpers.UnexpectedResultError