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.
Methods
all
astype
- rtype:
AbstractNDArray
copy
Returns the distance of every (y,x) coordinate in this Coordinate instance 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..
flip_hdu_for_ds9
Returns a Grid2DIrregular object from a .json file, which stores the coordinates as a list of list of tuples.
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.
Create a Grid2DIrregular object from a 2D NumPy array of values of shape [total_coordinates, 2], which are structured following this Grid2DIrregular instance.
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 this instance of the Grid2DIrregular object to a .json file as a list of list of tuples.
reshape
- rtype:
AbstractNDArray
sqrt
- rtype:
AbstractNDArray
Returns the squared distance of every (y,x) coordinate in this Coordinate instance from an input coordinate.
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:
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
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:
with_new_array
Copy this object but give it a new array.
Attributes
array
dtype
For 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.
imag
- rtype:
AbstractNDArray
Return the coordinates in a list.
Returns the data structure in its native format which contains all unmaksed values to the native dimensions.
ndim
real
- rtype:
AbstractNDArray
The (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.
shape
size
slim
- rtype:
sub_shape_slim
- rtype:
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:
- classmethod from_yx_1d(y, x)[source]#
Create Grid2DIrregular from a list of y and x values.
- Return type:
- 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:
- 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:
- 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:
- 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.
- 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:
- 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:
- 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.
- 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.
- 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.- Return type:
- 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.