PlasmaPy Plasma

Overview

One of core classes in PlasmaPy is Plasma. In order to make it easy to work mwith different plasma data in PlasmaPy, the Plasma object provides a number of methods for commonly existing plasmas in nature.

All Plasma objects are created using the Plasma factory Plasma.

A number of plasma data structures are supported by subclassing this base object. See Plasma Subclasses to see a list of all of them.

Creating Plasma Objects

Plasma objects are constructed using the special factory class Plasma:

>>> x = plasmapy.classes.Plasma(T_e=T_e,
...                             n_e=n_e,
...                             Z=Z,
...                             particle=particle)  

The result of a call to Plasma will be either a GenericPlasma object, or a subclass of GenericPlasma which deals with a specific type of data, e.g. PlasmaBlob or Plasma3D (see Plasma Subclasses to see a list of all of them).

class plasmapy.classes.plasma_factory.PlasmaFactory(default_widget_type=None, additional_validation_functions=[], registry=None)

Plasma factory class. Used to create a variety of Plasma objects. Valid plasma structures are specified by registering them with the factory.

Using Plasma Objects

Once a Plasma object has been created using Plasma it will be a instance or a subclass of the GenericPlasma class. The documentation of GenericPlasma lists the attributes and methods that are available on all Plasma objects.

Plasma Classes

Defined in plasmapy.classes.sources are a set of GenericPlasma subclassesmwhich convert the keyword arguments data to the standard GenericPlasma interface. These subclasses also provide a method, which describes to the Plasma factory which the data match its plasma data structure.

Classes

BasePlasma Registration class for GenericPlasma and declares some abstract methods for data common in different kinds of plasmas.
GenericPlasma(**kwargs) A Generic Plasma class.
Species(plasma[, particle_type, …]) Object representing a species of particles: ions, electrons, or simply a group of particles with a particular initial velocity distribution.

Class Inheritance Diagram

Inheritance diagram of plasmapy.classes.plasma_base.BasePlasma, plasmapy.classes.plasma_base.GenericPlasma, plasmapy.classes.species.Species

Writing a new Plasma subclass

Any subclass of GenericPlasma which defines a method named is_datasource_for will automatically be registered with the Plasma factory. The is_datasource_for method describes the form of the data for which the GenericPlasma subclass is valid. For example, it might check the number and types of keyword arguments. This makes it straightforward to define your own GenericPlasma subclass for a new data structure or a custom data source like simulated data. These classes only have to be imported for this to work, as demonstrated by the following example.

import plasmapy.classes
import astropy.units as u

class FuturePlasma(plasmapy.classes.GenericPlasma):
    def __init__(self, **kwargs):

        super(FuturePlasma, self).__init__(**kwargs)

    # Specify a classmethod that determines if the input data matches
    # this new subclass
    @classmethod
    def is_datasource_for(cls, **kwargs):
        """
        Determines if any of keyword arguments have a dimensionless value.
        """
        for _, value in kwargs.items():
            try:
                if value.unit == u.dimensionless_unscaled:
                    return True
            except AttributeError:
                pass

        return False

This class will now be available through the Plasma factory as long as this class has been defined, i.e. imported into the current session.

If you do not want to create a method named is_datasource_for you can manually register your class and matching method using the following method.

import plasmapy.classes

plasmapy.classes.Plasma.register(FuturePlasma, FuturePlasma.some_matching_method)