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

rtype:

AbstractNDArray

copy

distances_to_coordinate_from

Returns the distance of every (y,x) coordinate in this Coordinate 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..

flip_hdu_for_ds9

from_json

Returns a Grid2DIrregular object from a .json file, which stores the coordinates as a list of list of tuples.

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_from

Create a Grid2DIrregular object from a 2D NumPy array of values of shape [total_coordinates, 2], which are structured following this Grid2DIrregular instance.

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.

instance_unflatten

Unflatten a tuple of attributes (i.e.

invert

max

min

output_to_fits

Output the grid to a .fits file.

output_to_json

Output this instance of the Grid2DIrregular object to a .json file as a list of list of tuples.

reshape

rtype:

AbstractNDArray

sqrt

rtype:

AbstractNDArray

squared_distances_to_coordinate_from

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

structure_2d_from

Convert a result from a non autoarray structure to an aa.ArrayIrregular or aa.Grid2DIrregular structure, where the conversion depends on type(result) as follows:

structure_2d_list_from

Convert a result from a list of non autoarray structures to a list of aa.ArrayIrregular or aa.Grid2DIrregular structures, where the conversion depends on type(result) as follows:

sum

values_from

Create a ArrayIrregular object from a 1D NumPy array of values of shape [total_coordinates], which are structured following this Grid2DIrregular instance.

values_via_value_from

rtype:

ArrayIrregular

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

rtype:

AbstractNDArray

in_list

Return the coordinates in a list.

native

Returns the data structure in its native format which contains all unmaksed values to the native dimensions.

ndim

real

rtype:

AbstractNDArray

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

rtype:

Grid2DIrregular

sub_shape_slim

rtype:

int

values

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 native: Grid2DIrregular#

Returns the data structure in its native format which contains all unmaksed values to the native dimensions.

Return type:

Grid2DIrregular

classmethod from_yx_1d(y, x)[source]#

Create Grid2DIrregular from a list of y and x values.

Return type:

Grid2DIrregular

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.

Return type:

Grid2DIrregular

property in_list: List#

Return the coordinates in a list.

Return type:

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.

Return type:

Tuple

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.

Return type:

Tuple

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.

Return type:

List[float]

values_from(array_slim)[source]#

Create a ArrayIrregular object from a 1D NumPy array of values of shape [total_coordinates], which are structured following this Grid2DIrregular instance.

Return type:

ArrayIrregular

grid_from(grid_slim)[source]#

Create a Grid2DIrregular object from a 2D NumPy array of values of shape [total_coordinates, 2], which are structured following this Grid2DIrregular instance.

Return type:

Union[Grid2DIrregular, Grid2DIrregularTransformed]

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.

Return type:

Grid2DIrregular

structure_2d_from(result)[source]#

Convert a result from a non autoarray structure to an aa.ArrayIrregular or aa.Grid2DIrregular structure, where the conversion depends on type(result) as follows:

  • 1D np.ndarray -> aa.ArrayIrregular

  • 2D np.ndarray -> aa.Grid2DIrregular

  • [1D np.ndarray] -> [aa.ArrayIrregular]

  • [2D np.ndarray] -> [aa.Grid2DIrregular]

This function is used by the grid_2d_to_structure decorator to convert the output result of a function to an autoarray structure when a Grid2DIrregular instance is passed to the decorated function.

Parameters:

result (Union[ndarray, List]) – The input result (e.g. of a decorated function) that is converted to a PyAutoArray structure.

Return type:

Union[ArrayIrregular, Grid2DIrregular, Grid2DIrregularTransformed, List]

structure_2d_list_from(result_list)[source]#

Convert a result from a list of non autoarray structures to a list of aa.ArrayIrregular or aa.Grid2DIrregular structures, where the conversion depends on type(result) as follows:

- [1D np.ndarray] -> [aa.ArrayIrregular]
- [2D np.ndarray] -> [aa.Grid2DIrregular]

This function is used by the grid_like_list_to_structure_list decorator to convert the output result of a function to a list of autoarray structure when a Grid2DIrregular instance is passed to the decorated function.

Parameters:

result_list (List) – The input result (e.g. of a decorated function) that is converted to a PyAutoArray structure.

Return type:

List[Union[ArrayIrregular, Grid2DIrregular, Grid2DIrregularTransformed]]

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

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

Parameters:

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

Return type:

ArrayIrregular

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

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

Parameters:

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

Return type:

ArrayIrregular

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.

Return type:

Grid2DIrregular

Returns:

  • The grid of coordinates corresponding to the closest coordinate of each coordinate of this instance of

  • the Grid2DIrregular to the input grid.

classmethod from_json(file_path)[source]#

Returns a Grid2DIrregular object from a .json file, which stores the coordinates as a list of list of tuples.

Parameters:

file_path (Union[Path, str]) – The path to the coordinates .dat file containing the coordinates (e.g. ‘/path/to/coordinates.dat’)

Return type:

Grid2DIrregular

output_to_json(file_path, overwrite=False)[source]#

Output this instance of the Grid2DIrregular object to a .json file as a list of list of tuples.

Parameters:
  • file_path (Union[Path, str]) – The path to the coordinates .dat file containing the coordinates (e.g. ‘/path/to/coordinates.dat’)

  • overwrite (bool) – If there is as exsiting file it will be overwritten if this is True.