PlasmaPy Plasma


One of the core classes in PlasmaPy is Plasma. In order to make it easy to work with 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.plasma.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.plasma.plasma_factory.PlasmaFactory(default_widget_type=None, additional_validation_functions=None, 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.plasma.sources are a set of GenericPlasma subclasses which 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.


BasePlasma Registration class for GenericPlasma and declares some abstract methods for data common in different kinds of plasmas.
GenericPlasma(**kwargs) A Generic Plasma class.

Class Inheritance Diagram

Inheritance diagram of plasmapy.plasma.plasma_base.BasePlasma, plasmapy.plasma.plasma_base.GenericPlasma

Plasma Subclasses

The Plasma3D class is a basic structure to contain spatial information about a plasma. To initialize a Plasma3D system, first create an instance of the Plasma3D class and then set the Plasma3D.density, Plasma3D.momentum, Plasma3D.pressure and the Plasma3D.magnetic_field.

This feature is currently under development.

The PlasmaBlob class is a basic structure to contain just plasma parameter information about a plasma with no associated spatial or temporal scales. To initialize a PlasmaBlob system, call it with arguments: electron temperature PlasmaBlob.T_e, and electron density PlasmaBlob.n_e. You may also optionally define the ionization, PlasmaBlob.Z, and relevant plasma particle, PlasmaBlob.particle.

This feature is currently under development.


HDF5Reader(hdf5, **kwargs)
Plasma3D(domain_x, domain_y, domain_z, **kwargs) Core class for describing and calculating plasma parameters with spatial dimensions.
PlasmaBlob(T_e, n_e[, Z, particle]) Class for describing and calculating plasma parameters without spatial/temporal description.

Class Inheritance Diagram

Inheritance diagram of plasmapy.plasma.sources.openpmd_hdf5.HDF5Reader, plasmapy.plasma.sources.plasma3d.Plasma3D, plasmapy.plasma.sources.plasmablob.PlasmaBlob

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.plasma
import astropy.units as u

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

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

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

        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.plasma

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