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 – The irregular grid of (y,x) coordinates.
Methods
all
Returns True if all elements evaluate to True.
any
Returns True if any of the elements of a evaluate to True.
argmax
Return indices of the maximum values along the given axis.
argmin
Return indices of the minimum values along the given axis.
argpartition
Returns the indices that would partition this array.
argsort
Returns the indices that would sort this array.
astype
Copy of the array, cast to a specified type.
byteswap
Swap the bytes of the array elements
choose
Use an index array to construct a new array from a set of choices.
clip
Return an array whose values are limited to
[min, max]
.compress
Return selected slices of this array along given axis.
conj
Complex-conjugate all elements.
conjugate
Return the complex conjugate, element-wise.
copy
Return a copy of the array.
cumprod
Return the cumulative product of the elements along the given axis.
cumsum
Return the cumulative sum of the elements along the given axis.
diagonal
Return specified diagonals.
Returns the distance of every (y,x) coordinate in this Coordinate instance from an input coordinate.
dot
dump
Dump a pickle of the array to the specified file.
dumps
Returns the pickle of the array as a string.
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..
fill
Fill the array with a scalar value.
flatten
Return a copy of the array collapsed into one dimension.
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.
getfield
Returns a field of the given array as a certain type.
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.
item
Copy an element of an array to a standard Python scalar and return it.
itemset
Insert scalar into an array (scalar is cast to array's dtype, if possible)
max
Return the maximum along a given axis.
mean
Returns the average of the array elements along given axis.
min
Return the minimum along a given axis.
newbyteorder
Return the array with the same data viewed with a different byte order.
nonzero
Return the indices of the elements that are non-zero.
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.
partition
Rearranges the elements in the array in such a way that the value of the element in kth position is in the position it would be in a sorted array.
prod
Return the product of the array elements over the given axis
ptp
Peak to peak (maximum - minimum) value along a given axis.
put
Set
a.flat[n] = values[n]
for all n in indices.ravel
Return a flattened array.
repeat
Repeat elements of an array.
reshape
Returns an array containing the same data with a new shape.
resize
Change shape and size of array in-place.
round
Return a with each element rounded to the given number of decimals.
searchsorted
Find indices where elements of v should be inserted in a to maintain order.
setfield
Put a value into a specified place in a field defined by a data-type.
setflags
Set array flags WRITEABLE, ALIGNED, WRITEBACKIFCOPY, respectively.
sort
Sort an array in-place.
Returns the squared distance of every (y,x) coordinate in this Coordinate instance from an input coordinate.
squeeze
Remove axes of length one from a.
std
Returns the standard deviation of the array elements along given axis.
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
Return the sum of the array elements over the given axis.
swapaxes
Return a view of the array with axis1 and axis2 interchanged.
take
Return an array formed from the elements of a at the given indices.
tobytes
Construct Python bytes containing the raw data bytes in the array.
tofile
Write array to a file as text or binary (default).
tolist
Return the array as an
a.ndim
-levels deep nested list of Python scalars.tostring
A compatibility alias for tobytes, with exactly the same behavior.
trace
Return the sum along diagonals of the array.
transpose
Returns a view of the array with axes transposed.
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
var
Returns the variance of the array elements, along given axis.
view
New view of array with the same data.
Attributes
T
The transposed array.
base
Base object if memory is from some other object.
ctypes
An object to simplify the interaction of the array with the ctypes module.
data
Python buffer object pointing to the start of the array's data.
dtype
Data-type of the array's elements.
flags
Information about the memory layout of the array.
flat
A 1-D iterator over the array.
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
The imaginary part of the array.
Return the coordinates in a list.
itemsize
Length of one array element in bytes.
Returns the data structure in its native format which contains all unmaksed values to the native dimensions.
nbytes
Total bytes consumed by the elements of the array.
ndim
Number of array dimensions.
real
The real part of the array.
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
Tuple of array dimensions.
size
Number of elements in the array.
slim
- rtype
strides
Tuple of bytes to step in each dimension when traversing an array.
- 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.