AbstractGrid

class plasmapy.plasma.grids.AbstractGrid(
*seeds: Sequence[Quantity],
num: int = 100,
**kwargs,
)[source]

Bases: ABC

Abstract grid represents a 3D grid of positions. The grid is stored as an ndarray, while the units associated with each dimension are stored separately.

There are two preferred methods to creating a grid object:

  1. Initializing the grid by providing three 3D Quantity arrays of positions along each axis (xpoints, ypoints, zpoints)

    AbstractGrid(xpoints, ypoints, zpoints)
    
  2. A new grid can also be created using a syntax similar to numpy.linspace by providing two three-element Quantity arrays of start and stop values and setting the num keyword to the number of points along each axis.

    AbstractGrid(
        start=[x0, y0, z0],
        stop=[x1, y1, z1],
        num=[Nx, Ny, Nz],
        **kwargs,
    )
    

    In this case, any additional keyword arguments **kwargs provided will be passed directly to linspace.

Attributes Summary

ax0

First axis of the grid.

ax1

Second axis of the grid.

ax2

Third axis of the grid.

dax0

Grid step size along axis ax0.

dax1

Grid step size along axis ax1.

dax2

Grid step size along axis ax2.

grid

A single grid of vertex positions of shape (N0, N1, N2, 3).

grids

Three grids of vertex positions (in each coordinate), each having shape (N0, N1, N2).

is_uniform

A boolean value reflecting whether or not the grid points are uniformly spaced.

pts0

Array of positions in dimension 1.

pts1

Array of positions in dimension 2.

pts2

Array of positions in dimension 3.

quantities

A list of the keys corresponding to the quantities currently defined on the grid.

shape

Shape of the grid.

si_scale_factors

3-element list containing unitless scale factors for converting the corresponding axis from its stored units to SI.

unit

The unit for the entire grid.

unit0

Unit of dimension 1.

unit1

Unit of dimension 2.

unit2

Unit of dimension 3.

units

A list of the units of each dimension.

Methods Summary

add_quantities(**kwargs)

Adds a quantity to the dataset as a new DataArray.

nearest_neighbor_interpolator(pos, *args[, ...])

Interpolate values on the grid using a nearest-neighbor scheme with no higher-order weighting.

on_grid(pos)

Given a list of positions, determines which are in the region bounded by the grid points.

recognized_quantities()

A dictionary of standard key names representing particular physical quantities.

require_quantities(req_quantities[, ...])

Check to make sure that a list of required quantities are present.

vector_intersects(p1, p2)

True if the vector from p1 to p2 intersects the grid, and False otherwise.

Attributes Documentation

ax0

First axis of the grid.

Only valid for uniform grids.

ax1

Second axis of the grid.

Only valid for uniform grids.

ax2

Third axis of the grid.

Only valid for uniform grids.

dax0

Grid step size along axis ax0.

Only valid for uniform grids.

dax1

Grid step size along axis ax1.

Only valid for uniform grids.

dax2

Grid step size along axis ax2.

Only valid for uniform grids.

grid

A single grid of vertex positions of shape (N0, N1, N2, 3).

Only defined for grids for which the unit property is defined.

grids

Three grids of vertex positions (in each coordinate), each having shape (N0, N1, N2).

is_uniform

A boolean value reflecting whether or not the grid points are uniformly spaced.

pts0

Array of positions in dimension 1.

pts1

Array of positions in dimension 2.

pts2

Array of positions in dimension 3.

quantities

A list of the keys corresponding to the quantities currently defined on the grid.

shape

Shape of the grid.

si_scale_factors

3-element list containing unitless scale factors for converting the corresponding axis from its stored units to SI.

unit

The unit for the entire grid. Only valid if all dimensions of the grid have the same units.

Raises:

ValueError – If all grid dimensions do not have identical units.

unit0

Unit of dimension 1.

unit1

Unit of dimension 2.

unit2

Unit of dimension 3.

units

A list of the units of each dimension.

Methods Documentation

add_quantities(**kwargs: Quantity) None[source]

Adds a quantity to the dataset as a new DataArray.

Parameters:

**kwargs (key, array pairs) – The key will be used as the dataset key, while the array holds the quantity.

abstract nearest_neighbor_interpolator(
pos: ndarray | Quantity,
*args,
persistent: bool = False,
)[source]

Interpolate values on the grid using a nearest-neighbor scheme with no higher-order weighting.

Parameters:
  • pos (ndarray or Quantity array, shape (n,3)) – An array of positions in space, where the second dimension corresponds to the three dimensions of the grid. If an ndarray is provided, units will be assumed to match those of the grid.

  • *args (str) – Strings that correspond to DataArrays in the dataset

  • persistent (bool) – If True, the interpolator will assume the grid and its contents have not changed since the last interpolation. This substantially speeds up the interpolation when many interpolations are performed on the same grid in a loop. persistent overrides to False if the arguments list has changed since the last call.

on_grid(pos)[source]

Given a list of positions, determines which are in the region bounded by the grid points.

For non-uniform grids, “on grid” is defined as being bounded by grid points in all axes.

Parameters:

pos (ndarray or Quantity array, shape (n,3)) – An array of positions in space, where the second dimension corresponds to the three dimensions of the grid.

classmethod recognized_quantities()[source]

A dictionary of standard key names representing particular physical quantities. Using these keys allows these quantities to be recognized automatically by other PlasmaPy functions. Each entry contains a tuple containing a description and the unit associated with the quantity.

require_quantities(
req_quantities: Iterable[str],
replace_with_zeros: bool = False,
warn_on_replace_with_zeros: bool = True,
)[source]

Check to make sure that a list of required quantities are present. Optionally, can create missing quantities and fill them with an array of zeros.

Parameters:
  • req_quantities (iterable of str) – A list of quantity keys that are required.

  • replace_with_zeros (bool, optional) – If true, missing quantities will be replaced with an array of zeros. If false, an exception will be raised instead. The default is False.

  • warn_on_replace_with_zeros (bool, default: True) – If True, warn if a required quantity is replaced with an array of zeros. If False, no warning is shown.

Raises:
  • KeyError – If replace_with_zeros is False and a required quantity is missing.

  • KeyError – If replace_with_zeros is True but the Quantity is not in the list of recognized quantities. In this case the units for the quantity are unknown, so an array of zeros cannot be constructed.

abstract vector_intersects(p1, p2)[source]

True if the vector from p1 to p2 intersects the grid, and False otherwise.

The definition of ‘intersects’ is determined by the implementation for each subclass.