autogalaxy.Grid2DIrregular#

class Grid2DIrregular[source]#

Bases: AbstractNDArray

An 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

all

astype

copy

distances_to_coordinate_from

Returns the distance of every (y,x) coordinate in this Grid2DIrregular instance from an input coordinate.

extent_with_buffer_from

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

from_pixels_and_mask

Create Grid2DIrregular from a list of coordinates in pixel units and a mask which allows these coordinates to be converted to scaled units.

from_yx_1d

Create Grid2DIrregular from a list of y and x values.

grid_2d_via_deflection_grid_from

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.

grid_of_closest_from

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_flatten

Flatten an instance of an autoarray class into a tuple of its attributes (i.e.. a pytree).

instance_unflatten

Unflatten a tuple of attributes (i.e. a pytree) into an instance of an autoarray class.

invert

max

min

reshape

sqrt

squared_distances_to_coordinate_from

Returns the squared distance of every (y,x) coordinate in this Grid2DIrregular instance from an input coordinate.

subtracted_and_rotated_from

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.

subtracted_from

Return a new Grid2DIrregular with offset subtracted from every (y, x) coordinate.

sum

with_new_array

Copy this object but give it a new array.

Attributes

array

dtype

furthest_distances_to_other_coordinates

For every (y,x) coordinate on the Grid2DIrregular returns the furthest radial distance of each coordinate to any other coordinate on the grid.

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.

imag

in_list

Return the coordinates in a list.

is_transformed

native

Returns the grid in its native representation.

ndim

real

scaled_maxima

The (y,x) maximum values of the grid in scaled units, buffed such that their extent is further than the grid's extent.

scaled_minima

The (y,x) minimum values of the grid in scaled units, buffed such that their extent is further than the grid's extent.

shape

size

slim

Returns the grid in its slim representation.

values

The raw underlying ndarray of (y,x) coordinate pairs, with shape [total_coordinates, 2].

classmethod from_yx_1d(y, x)[source]#

Create Grid2DIrregular from a list of y and x values.

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 slim representation. 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 native representation. For an irregular grid there is no 2D native format, so this returns the grid as-is.

property in_list: List#

Return the coordinates in a list.

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 Grid2DIrregular instance from an input coordinate.

Parameters:

coordinate (Tuple[float, float]) – The (y,x) coordinate from which the squared distance of every Coordinate is computed.

distances_to_coordinate_from(coordinate=(0.0, 0.0))[source]#

Returns the distance of every (y,x) coordinate in this Grid2DIrregular instance from an input coordinate.

Parameters:

coordinate (Tuple[float, float]) – The (y,x) coordinate from which the distance of every coordinate is computed.

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:

ArrayIrregular

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 offset subtracted 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.