AbstractGrid¶

class
plasmapy.plasma.grids.
AbstractGrid
(*seeds, num=100, **kwargs)¶ Bases:
abc.ABC
Abstract grid represents a 3D grid of positions. The grid is stored as an np.ndarray, while the units associated with each dimension are stored separately.
Attributes Summary
First axis of the grid, only valid for uniform grids
Second axis of the grid, only valid for uniform grids
Third axis of the grid, only valid for uniform grids
Grid step size along axis
ax0
, only valid for uniform grids.Grid step size along axis
ax1
, only valid for uniform grids.Grid step size along axis
ax2
, only valid for uniform grids.A single grid of vertex positions of shape (N0, N1, N2, 3)
A scalar estimate of the grid resolution.
Three grids of vertex positions (in each coordinate), each having shape (N0, N1, N2)
A nearestneighbor interpolator that returns the nearest grid index to a position.
Array of positions in dimension 1
Array of positions in dimension 2
Array of positions in dimension 3
A list of the keys corresponding to the quantities currently defined on the grid.
A dictionary of standard key names representing particular physical quantities.
Shape of the grid
The unit for the entire grid.
Unit of dimension 1
Unit of dimension 2
Unit of dimension 3
Returns a list of the units of each dimension
Methods Summary
add_quantities
(**kwargs)Adds a quantity to the dataset as a new DataArray
interpolate_indices
(pos)Interpolate the nearest grid indices to a position using a nearestneighbor interpolator
nearest_neighbor_interpolator
(pos, *args[, …])Interpolate values on the grid using a nearestneighbor scheme with no higherorder weighting.
on_grid
(pos)Given a list of positions, determines which are in the region bounded by the grid points.
vector_intersects
(p1, p2)Returns True if the vector from p1 to p2 intersects the grid.
volume_averaged_interpolator
(pos, *args[, …])Interpolate values on the grid using a volumeaveraged scheme with no higherorder weighting.
Attributes Documentation

ax0
¶ First axis of the grid, only valid for uniform grids
 Raises
ValueError – If grid is nonuniform.

ax1
¶ Second axis of the grid, only valid for uniform grids
 Raises
ValueError – If grid is nonuniform.

ax2
¶ Third axis of the grid, only valid for uniform grids
 Raises
ValueError – If grid is nonuniform.

dax0
¶ Grid step size along axis
ax0
, only valid for uniform grids. Raises
ValueError – If grid is nonuniform.

dax1
¶ Grid step size along axis
ax1
, only valid for uniform grids. Raises
ValueError – If grid is nonuniform.

dax2
¶ Grid step size along axis
ax2
, only valid for uniform grids. Raises
ValueError – If grid is nonuniform.

grid
¶ A single grid of vertex positions of shape (N0, N1, N2, 3)
Only defined for grids for which the
unit
property is defined.

grid_resolution
¶ A scalar estimate of the grid resolution.
For uniform grids, this is the minima of [dax0, dax1, dax2].
For nonuniform grids, it is the closest spacing between any two points.

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

interpolator
¶ A nearestneighbor interpolator that returns the nearest grid index to a position.

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.

recognized_quantities
¶ 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.

shape
¶ Shape of the grid

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
¶ Returns a list of the units of each dimension
Methods Documentation

add_quantities
(**kwargs)¶ Adds a quantity to the dataset as a new DataArray
 Parameters
key – The key will be used as the dataset key, while the array holds the quantity.
pairs as keyword arguments (array) – The key will be used as the dataset key, while the array holds the quantity.
 Returns
 Return type
None.

interpolate_indices
(pos: Union[numpy.ndarray, astropy.units.quantity.Quantity])¶ Interpolate the nearest grid indices to a position using a nearestneighbor interpolator
 Parameters
pos (np.ndarray or u.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 np.ndarray is provided, units will be assumed to match those of the grid.
 Returns
i – An array of indices corresponding to the positions such that i[n,:] = ix,iy,iz such that grid[ix,iy,iz,:] ~ pos[n,:]
 Return type
np.ndarray, shape (n,3)

nearest_neighbor_interpolator
(pos: Union[numpy.ndarray, astropy.units.quantity.Quantity], *args, persistent=False)¶ Interpolate values on the grid using a nearestneighbor scheme with no higherorder weighting.
 Parameters
pos (np.ndarray or u.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 np.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)¶ Given a list of positions, determines which are in the region bounded by the grid points.
For nonuniform grids, “on grid” is defined as being bounded by grid points in all axes.
 Parameters
pos (np.ndarray or u.Quantity array, shape (n,3)) – An array of positions in space, where the second dimension corresponds to the three dimensions of the grid.

vector_intersects
(p1, p2)¶ Returns True if the vector from p1 to p2 intersects the grid. Otherwise, returns false. This is a standard raybox intersection algorithm.

volume_averaged_interpolator
(pos: Union[numpy.ndarray, astropy.units.quantity.Quantity], *args, persistent=False)¶ Interpolate values on the grid using a volumeaveraged scheme with no higherorder weighting.
 Parameters
pos (np.ndarray or u.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 np.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.
