Grid¶
-
class
hcipy.field.
Grid
(coords, weights=None)¶ Bases:
object
A set of points on some coordinate system.
- Parameters
- coordsCoords
The actual definition of the coordinate values.
- weightsarray_like or None
The interval size, area, volume or hypervolume of each point, depending on the number of dimensions. If this is None (default), the weights will be attempted to be calculated on the fly when needed.
- Attributes
- coords
The coordinate values for each dimension.
Attributes Summary
The spacing between points in regularly-spaced grid.
The number of elements in each dimension for a separated grid.
True if the grid is regularly-spaced, False otherwise.
True if the grid is separated, False otherwise.
True if the grid is unstructured, False otherwise.
The number of dimensions.
A list of points of this grid.
The tuple (delta, dims, zero) for a regularly-spaced grid.
A list of coordinates for each dimension in a separated grid.
The shape of a reshaped
numpy.ndarray
using this grid.The number of points in this grid.
The interval size, area, volume or hypervolume of each point, depending on the number of dimensions.
The zero point of a regularly-spaced grid.
Methods Summary
as_
(self, system)Convert the grid to the new coordinate system system.
closest_to
(self, p)Get the index of the point closest to point p.
copy
(self)Create a copy.
empty
(self[, tensor_shape, dtype])Create an empty Field from this Grid.
from_dict
(tree)Make a Grid from a dictionary, previously created by to_dict().
is_
(self, system)Check if the coordinate system is system.
ones
(self[, tensor_shape, dtype])Create a field of ones from this Grid.
reverse
(self)Reverse the order of the points in-place.
reversed
(self)Make a copy of the grid with the order of the points reversed.
rotate
(self, angle[, axis])Rotate the grid in-place.
rotated
(self, angle[, axis])A rotated copy of this grid.
scale
(self, scale)Scale the grid in-place.
scaled
(self, scale)A scaled copy of this grid.
shift
(self, shift)Shift the grid in-place.
shifted
(self, shift)A shifted copy of this grid.
subset
(self, criterium)Construct a subset of the current sampling, based on criterium.
to_dict
(self)Convert the object to a dictionary for serialization.
zeros
(self[, tensor_shape, dtype])Create a field of zeros from this Grid.
Attributes Documentation
-
delta
¶ The spacing between points in regularly-spaced grid.
- Raises
- ValueError
If the grid is not regular.
-
dims
¶ The number of elements in each dimension for a separated grid.
- Raises
- ValueError
If the grid is not separated.
-
is_regular
¶ True if the grid is regularly-spaced, False otherwise.
-
is_separated
¶ True if the grid is separated, False otherwise.
-
is_unstructured
¶ True if the grid is unstructured, False otherwise.
-
ndim
¶ The number of dimensions.
-
points
¶ A list of points of this grid.
This can be used for easier iteration:
for p in grid.points: print(p)
-
regular_coords
¶ The tuple (delta, dims, zero) for a regularly-spaced grid.
- Raises
- ValueError
If the grid is not regular.
-
separated_coords
¶ A list of coordinates for each dimension in a separated grid.
- Raises
- ValueError
If the grid is not separated.
-
shape
¶ The shape of a reshaped
numpy.ndarray
using this grid.- Raises
- ValueError
If the grid is not separated.
-
size
¶ The number of points in this grid.
-
weights
¶ The interval size, area, volume or hypervolume of each point, depending on the number of dimensions.
The weights are attempted to be calculated on the fly if not set. If this fails, a warning is emitted and all points will be given an equal weight of one.
-
zero
¶ The zero point of a regularly-spaced grid.
- Raises
- ValueError
If the grid is not regular.
Methods Documentation
-
as_
(self, system)¶ Convert the grid to the new coordinate system system.
If the grid is already in the right coordinate system, this function doesn’t do anything.
- Parameters
- systemstr
The name of the coordinate system to check for.
- Returns
- Grid
A new
Grid
in the required coordinate system.
- Raises
- ValueError
If the conversion to the coordinate system system isn’t known.
-
closest_to
(self, p)¶ Get the index of the point closest to point p.
Point p is assumed to have the same coordinate system as the grid itself.
- Parameters
- parray_like
The point at which to search for.
- Returns
- int
The index of the closest point.
-
copy
(self)¶ Create a copy.
-
empty
(self, tensor_shape=None, dtype=None)¶ Create an empty Field from this Grid.
- Parameters
- tensor_shapearray_like or None
The shape of the tensors in the to be created field. If this is None, a scalar field will be created.
- dtypedata-type
The numpy data-type with which to create the field.
- Returns
- Field
A empty field.
-
classmethod
from_dict
(tree)¶ Make a Grid from a dictionary, previously created by to_dict().
- Parameters
- treedictionary
The dictionary from which to make a new Grid object.
- Returns
- Grid
The created object.
- Raises
- ValueError
If the dictionary is not formatted correctly.
-
is_
(self, system)¶ Check if the coordinate system is system.
- Parameters
- systemstr
The name of the coordinate system to check for.
- Returns
- bool
If the coordinate system of the grid is equal to system.
-
ones
(self, tensor_shape=None, dtype=None)¶ Create a field of ones from this Grid.
- Parameters
- tensor_shapearray_like or None
The shape of the tensors in the to be created field. If this is None, a scalar field will be created.
- dtypedata-type
The numpy data-type with which to create the field.
- Returns
- Field
A ones field.
-
reverse
(self)¶ Reverse the order of the points in-place.
- Returns
- Grid
Itself to allow for chaining these transformations.
-
reversed
(self)¶ Make a copy of the grid with the order of the points reversed.
- Returns
- Grid
The reversed grid.
-
rotate
(self, angle, axis=None)¶ Rotate the grid in-place.
- Parameters
- anglescalar
The angle in radians.
- axisndarray or None
The axis of rotation. For two-dimensional grids, it is ignored. For three-dimensional grids it is required.
- Returns
- Grid
Itself to allow for chaining these transformations.
-
rotated
(self, angle, axis=None)¶ A rotated copy of this grid.
- Parameters
- anglescalar
The angle in radians.
- axisndarray or None
The axis of rotation. For two-dimensional grids, it is ignored. For three-dimensional grids it is required.
- Returns
- Grid
The rotated grid.
-
scale
(self, scale)¶ Scale the grid in-place.
- Parameters
- scalearray_like
The factor with which to scale the grid.
- Returns
- Grid
Itself to allow for chaining these transformations.
-
scaled
(self, scale)¶ A scaled copy of this grid.
- Parameters
- scalearray_like
The factor with which to scale the grid.
- Returns
- Grid
The scaled grid.
-
shift
(self, shift)¶ Shift the grid in-place.
- Parameters
- shiftarray_like
The amount with which to shift the grid.
- Returns
- Grid
Itself to allow for chaining these transformations.
-
shifted
(self, shift)¶ A shifted copy of this grid.
- Parameters
- shiftarray_like
The amount with which to shift the grid.
- Returns
- Grid
The scaled grid.
-
subset
(self, criterium)¶ Construct a subset of the current sampling, based on criterium.
- Parameters
- criteriumfunction or array_like
The criterium used to select points. A function will be evaluated for every point. Otherwise, this must be a boolean array of integer array, used for slicing the points.
- Returns
- Grid
A new grid with UnstructuredCoords that includes only the points for which the criterium was true.
-
to_dict
(self)¶ Convert the object to a dictionary for serialization.
- Returns
- dictionary
The created dictionary.
-
zeros
(self, tensor_shape=None, dtype=None)¶ Create a field of zeros from this Grid.
- Parameters
- tensor_shapearray_like or None
The shape of the tensors in the to be created field. If this is None, a scalar field will be created.
- dtypedata-type
The numpy data-type with which to create the field.
- Returns
- Field
A zeros field.