Core package utilities (plasmapy.utils)

Introduction

The utils subpackage contains functionality that is needed across multiple subpackages or does not fit nicely in any other subpackage. Functionality contained in utils includes:

Reference/API

plasmapy.utils.decorators Package

A module to contain various decorators used to build readable and useful code.

Functions

angular_freq_to_hz(fn)

A decorator that adds to a function the ability to convert the function’s return from angular frequency (rad/s) to frequency (Hz).

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.

check_values([func, checks_on_return])

A decorator to ‘check’ – limit/control – the values of input and return arguments to a function or method.

check_units([func, checks_on_return])

A decorator to ‘check’ – limit/control – the units of input and return arguments to a function or method.

modify_docstring([func, prepend, append])

A decorator which programmatically prepends and/or appends the docstring of the decorated method/function.

preserve_signature(f)

A decorator for decorators, which preserves the signature of the function being wrapped.

validate_quantities([func, …])

A decorator to ‘validate’ – control and convert – the units and values of input and return arguments to a function or method.

Classes

CheckBase([checks_on_return])

Base class for ‘Check’ decorator classes.

CheckUnits(checks_on_return, …)

A decorator class to ‘check’ – limit/control – the units of input and return arguments to a function or method.

CheckValues(checks_on_return, bool]] = None, …)

A decorator class to ‘check’ – limit/control – the values of input and return arguments to a function or method.

ValidateQuantities([validations_on_return])

A decorator class to ‘validate’ – control and convert – the units and values of input and return arguments to a function or method.

Class Inheritance Diagram

Inheritance diagram of plasmapy.utils.decorators.checks.CheckBase, plasmapy.utils.decorators.checks.CheckUnits, plasmapy.utils.decorators.checks.CheckValues, plasmapy.utils.decorators.validators.ValidateQuantities

plasmapy.utils.exceptions Module

Exceptions and warnings specific to PlasmaPy.

Classes

PlasmaPyError

Base class of PlasmaPy custom errors.

PhysicsError

The base exception for physics-related errors.

InvalidRomanNumeralError

An exception to be raised when the input is not a valid Roman numeral.

OutOfRangeError

An exception to be raised for integers that outside of the range that can be converted to Roman numerals.

RelativityError

An exception for speeds greater than the speed of light.

RomanError

A base exception for errors from roman.

PlasmaPyWarning

Base class of PlasmaPy custom warnings.

CouplingWarning

A warning for functions that rely on a particular coupling regime to be valid.

PhysicsWarning

The base warning for warnings related to non-physical situations.

RelativityWarning

A warning for when relativistic velocities are being used in or are returned by non-relativistic functionality.

Class Inheritance Diagram

Inheritance diagram of plasmapy.utils.exceptions.PlasmaPyError, plasmapy.utils.exceptions.PhysicsError, plasmapy.utils.exceptions.InvalidRomanNumeralError, plasmapy.utils.exceptions.OutOfRangeError, plasmapy.utils.exceptions.RelativityError, plasmapy.utils.exceptions.RomanError, plasmapy.utils.exceptions.PlasmaPyWarning, plasmapy.utils.exceptions.CouplingWarning, plasmapy.utils.exceptions.PhysicsWarning, plasmapy.utils.exceptions.RelativityWarning

plasmapy.utils.code_repr Module

Tools for formatting strings, including for error messages.

Functions

call_string(f[, args, kwargs, max_items])

Approximate a call of a function or class with positional and keyword arguments.

attribute_call_string(cls, attr[, …])

Approximate the command to instantiate a class, and access an attribute of the resulting class instance.

method_call_string(cls, method, *[, …])

Approximate the command to instantiate a class, and then call a method in the resulting class instance.

plasmapy.utils.pytest_helpers Package

Functions

assert_can_handle_nparray(function_to_test)

Test for ability to handle numpy array quantities.

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.