CartesianGridο
- class plasmapy.plasma.grids.CartesianGrid( )[source]ο
Bases:
AbstractGrid
A uniformly spaced Cartesian grid.
Attributes Summary
First axis of the grid.
Second axis of the grid.
Third axis of the grid.
Grid step size along axis
ax0
.Grid step size along axis
ax1
.Grid step size along axis
ax2
.A single grid of vertex positions of shape (N0, N1, N2, 3).
A scalar estimate of the grid resolution, calculated as the the minima of [dax0, dax1, dax2].
Three grids of vertex positions (in each coordinate), each having shape (N0, N1, N2).
A boolean value reflecting whether or not the grid points are uniformly spaced.
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.
Shape of the grid.
3-element list containing unitless scale factors for converting the corresponding axis from its stored units to SI.
The unit for the entire grid.
Unit of dimension 1.
Unit of dimension 2.
Unit of dimension 3.
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.
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 fromp1
top2
intersects the grid, andFalse
otherwise.volume_averaged_interpolator
(pos,Β *args[,Β ...])Interpolate values on the grid using a volume-averaged scheme with no higher-order weighting.
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.
- 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, calculated as the the minima of [dax0, dax1, dax2].
- 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.
Methods Documentation
- add_quantities(**kwargs: Quantity) None ο
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.
- nearest_neighbor_interpolator( )[source]ο
Interpolate values on the grid using a nearest-neighbor scheme with no higher-order weighting.
- Parameters:
pos (
ndarray
orQuantity
array, shape (n,3)) β An array of positions in space, where the second dimension corresponds to the three dimensions of the grid. If anndarray
is provided, units will be assumed to match those of the grid.*args (
str
) β Strings that correspond to DataArrays in the datasetpersistent (
bool
) β IfTrue
, 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 toFalse
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 non-uniform grids, βon gridβ is defined as being bounded by grid points in all axes.
- classmethod 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.
- require_quantities(
- req_quantities: Iterable[str],
- replace_with_zeros: bool = False,
- warn_on_replace_with_zeros: bool = True,
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
ofstr
) β 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
) β IfTrue
, warn if a required quantity is replaced with an array of zeros. IfFalse
, no warning is shown.
- Raises:
- vector_intersects(p1, p2)[source]ο
True
if the vector fromp1
top2
intersects the grid, andFalse
otherwise.This is a standard ray-box intersection algorithm.
- volume_averaged_interpolator( )[source]ο
Interpolate values on the grid using a volume-averaged scheme with no higher-order weighting.
- Parameters:
pos (
ndarray
orQuantity
array, shape (n,3)) β An array of positions in space, where the second dimension corresponds to the three dimensions of the grid. If andarray
is provided, units will be assumed to match those of the grid.*args (
str
) β Strings that correspond to DataArrays in the datasetpersistent (
bool
) β IfTrue
, 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 toFalse
if the arguments list has changed since the last call.
Notes
This interpolator approximates the value of a quantity at a given interpolation point using a weighted sum of the values at the eight grid vertices that surround the point. The weighting factors are calculated by defining a volume \(dx Γ dy Γ dz\) (where \(dx\), \(dy\), and \(dz\) are the grid spacings in each direction) around each grid vertex and around the interpolation point. The contribution of each grid vertex is then weighted by the fraction of the volume surrounding the interpolation point that overlaps the volume surrounding that vertex. This effectively introduces a linear interpolation between grid vertices.
This implementation of this algorithm assumes that the grid is uniformly spaced and Cartesian.