autogalaxy.Grid2DIrregular#
- class Grid2DIrregular[source]#
Bases:
AbstractNDArrayAn irregular grid of (y,x) coordinates.
The Grid2DIrregular stores the (y,x) irregular grid of coordinates as 2D NumPy array of shape [total_coordinates, 2].
Calculations should use the NumPy array structure wherever possible for efficient calculations.
The coordinates input to this function can have any of the following forms (they will be converted to the 1D NumPy array structure and can be converted back using the object’s properties):
[(y0,x0), (y1,x1)] [[y0,x0], [y1,x1]]
If your grid lies on a 2D uniform grid of data the Grid2D data structure should be used.
- Parameters:
values (
Union[ndarray,List]) – The irregular grid of (y,x) coordinates.
Methods
allastypecopyReturns the distance of every (y,x) coordinate in this
Grid2DIrregularinstance from an input coordinate.The extent of the grid in scaled units returned as a list [x_min, x_max, y_min, y_max], where all values are buffed such that their extent is further than the grid's extent..
Create Grid2DIrregular from a list of coordinates in pixel units and a mask which allows these coordinates to be converted to scaled units.
Create Grid2DIrregular from a list of y and x values.
Returns a new Grid2DIrregular from this grid coordinates, where the (y,x) coordinates of this grid have a grid of (y,x) values, termed the deflection grid, subtracted from them to determine the new grid of (y,x) values.
From an input grid, find the closest coordinates of this instance of the Grid2DIrregular to each coordinate on the input grid and return each closest coordinate as a new Grid2DIrregular.
instance_flattenFlatten an instance of an autoarray class into a tuple of its attributes (i.e.. a pytree).
instance_unflattenUnflatten a tuple of attributes (i.e. a pytree) into an instance of an autoarray class.
invertmaxminreshapesqrtReturns the squared distance of every (y,x) coordinate in this
Grid2DIrregularinstance from an input coordinate.Return a new Grid2DIrregular where the (y, x) coordinates of this grid have an offset subtracted and are then rotated counter-clockwise by
angle(in degrees) about the offset point.Return a new Grid2DIrregular with
offsetsubtracted from every (y, x) coordinate.sumwith_new_arrayCopy this object but give it a new array.
Attributes
arraydtypeFor every (y,x) coordinate on the Grid2DIrregular returns the furthest radial distance of each coordinate to any other coordinate on the grid.
The (y,x) 2D shape of the irregular grid in scaled units, computed by taking the minimum and maximum values of (y,x) coordinates on the grid.
imagReturn the coordinates in a list.
is_transformedReturns the grid in its
nativerepresentation.ndimrealThe (y,x) maximum values of the grid in scaled units, buffed such that their extent is further than the grid's extent.
The (y,x) minimum values of the grid in scaled units, buffed such that their extent is further than the grid's extent.
shapesizeReturns the grid in its
slimrepresentation.The raw underlying ndarray of (y,x) coordinate pairs, with shape [total_coordinates, 2].
- classmethod from_pixels_and_mask(pixels, mask)[source]#
Create Grid2DIrregular from a list of coordinates in pixel units and a mask which allows these coordinates to be converted to scaled units.
- property values#
The raw underlying ndarray of (y,x) coordinate pairs, with shape [total_coordinates, 2].
- property geometry#
The (y,x) 2D shape of the irregular grid in scaled units, computed by taking the minimum and maximum values of (y,x) coordinates on the grid.
- property slim: Grid2DIrregular#
Returns the grid in its
slimrepresentation. For an irregular grid there is no 2D native format, so this returns the grid as-is.
- property native: Grid2DIrregular#
Returns the grid in its
nativerepresentation. For an irregular grid there is no 2D native format, so this returns the grid as-is.
- property scaled_minima: Tuple#
The (y,x) minimum values of the grid in scaled units, buffed such that their extent is further than the grid’s extent.
- property scaled_maxima: Tuple#
The (y,x) maximum values of the grid in scaled units, buffed such that their extent is further than the grid’s extent.
- extent_with_buffer_from(buffer=1e-08)[source]#
The extent of the grid in scaled units returned as a list [x_min, x_max, y_min, y_max], where all values are buffed such that their extent is further than the grid’s extent..
This follows the format of the extent input parameter in the matplotlib method imshow (and other methods) and is used for visualization in the plot module.
- grid_2d_via_deflection_grid_from(deflection_grid)[source]#
Returns a new Grid2DIrregular from this grid coordinates, where the (y,x) coordinates of this grid have a grid of (y,x) values, termed the deflection grid, subtracted from them to determine the new grid of (y,x) values.
This is to perform grid ray-tracing.
- Parameters:
deflection_grid (
ndarray) – The grid of (y,x) coordinates which is subtracted from this grid.
- squared_distances_to_coordinate_from(coordinate=(0.0, 0.0))[source]#
Returns the squared distance of every (y,x) coordinate in this
Grid2DIrregularinstance from an input coordinate.
- distances_to_coordinate_from(coordinate=(0.0, 0.0))[source]#
Returns the distance of every (y,x) coordinate in this
Grid2DIrregularinstance from an input coordinate.
- property furthest_distances_to_other_coordinates: ArrayIrregular#
For every (y,x) coordinate on the Grid2DIrregular returns the furthest radial distance of each coordinate to any other coordinate on the grid.
For example, for the following grid:
values=[(0.0, 0.0), (0.0, 1.0), (0.0, 3.0)]
The returned further distances are:
[3.0, 2.0, 3.0]
- Returns:
The further distances of every coordinate to every other coordinate on the irregular grid.
- Return type:
- grid_of_closest_from(grid_pair)[source]#
From an input grid, find the closest coordinates of this instance of the Grid2DIrregular to each coordinate on the input grid and return each closest coordinate as a new Grid2DIrregular.
- Parameters:
grid_pair (
Grid2DIrregular) – The grid of coordinates the closest coordinate of each (y,x) location is paired with.- Returns:
The grid of coordinates corresponding to the closest coordinate of each coordinate of this instance of
the Grid2DIrregular to the input grid.
- subtracted_from(offset, xp=<module 'numpy' from '/home/docs/checkouts/readthedocs.org/user_builds/pyautogalaxy/envs/latest/lib/python3.11/site-packages/numpy/__init__.py'>)[source]#
Return a new Grid2DIrregular with
offsetsubtracted from every (y, x) coordinate.
- subtracted_and_rotated_from(offset, angle, xp=<module 'numpy' from '/home/docs/checkouts/readthedocs.org/user_builds/pyautogalaxy/envs/latest/lib/python3.11/site-packages/numpy/__init__.py'>)[source]#
Return a new Grid2DIrregular where the (y, x) coordinates of this grid have an offset subtracted and are then rotated counter-clockwise by
angle(in degrees) about the offset point.Order matches
Grid2D.subtracted_and_rotated_from: shift, then rotate.- Parameters:
offset – The (y, x) offset subtracted from every grid coordinate before rotation.
angle (
float) – The rotation angle in degrees. Positive values rotate counter-clockwise.