autolens.Grid1D#

class Grid1D[source]#

Bases: Structure

A grid of 1D (x) coordinates, which are paired to a uniform 1D mask of pixels. Each entry on the grid corresponds to the (x) coordinates at the centre of a pixel of an unmasked pixel.

A Grid1D is ordered such that pixels begin from the left (e.g. index [0]) of the corresponding mask and go right. The positive x-axis is to the right.

The grid can be stored in two formats:

  • slimmed: all masked entries are removed so the ndarray is shape [total_unmasked_coordinates, 2]

  • native: it retains the original shape of the grid so the ndarray is shape [total_unmasked_coordinates, 2].

__slim__

The Grid1D is an ndarray of shape [total_unmasked_coordinates].

The first element of the ndarray corresponds to the pixel index. For example:

  • grid[3] = the 4th unmasked pixel’s x-coordinate.

  • grid[6] = the 7th unmasked pixel’s x-coordinate.

Below is a visual illustration of a grid, where a total of 3 pixels are unmasked and are included in the grid.

<--- -ve  x  +ve -->

x x x O o x O x x x

This is an example mask.Mask1D, where:

x = `True` (Pixel is masked and excluded from the grid)
O = `False` (Pixel is not masked and included in the grid)

The mask pixel index’s will come out like this (and the direction of scaled coordinates is highlighted around the mask.

pixel_scales = 1.0"

<--- -ve  x  +ve -->

x x x 0 1 x 2 x x x

grid[0] = [-1.5]
grid[1] = [-0.5]
grid[2] = [1.5]

__native__

The Grid1D in its native format is stored as an ndarray of shape [total_x_coordinates], where masked entries have a value of 0.0.

All masked entries on the grid has (y,x) values of (0.0, 0.0).

For the following example mask:

x x x O O x O x x x

- grid[0] = 0.0 (it is masked, thus zero)
- grid[1] = 0.0 (it is masked, thus zero)
- grid[2] = 0.0 (it is masked, thus zero)
- grid[3] = -1.5
- grid[4] = -0.5
- grid[5] = 0.0 (it is masked, thus zero)
- grid[6] = 0.5

Grid1D Mapping

Every set of (x) coordinates in a pixel of the grid maps to an unmasked pixel in the mask. For a uniform grid, every x coordinate directly corresponds to the location of its paired unmasked pixel.

It is not a requirement that grid is uniform and that their coordinates align with the mask. The input grid could be an irregular set of x coordinates where the indexing signifies that the x coordinate originates or is paired with the mask’s pixels but has had its value change by some aspect of the calculation.

This is important for the child project PyAutoLens, where grids in the image-plane are ray-traced and deflected to perform lensing calculations. The grid indexing is used to map pixels between the image-plane and source-plane.

Parameters:
  • values (Union[ndarray, List]) – The (x,) coordinates of the grid, input as an ndarray of shape [total_unmasked_pixels] or [total_pixels] (native format).

  • mask (Mask1D) – The 1D mask associated with the grid, defining which pixels each grid coordinate is paired with.

  • store_native (bool) – If True, the ndarray is stored in its native format [total_pixels]. This avoids mapping large data arrays to and from the slim / native formats, which can be a computational bottleneck.

Methods

all

astype

copy

from_mask

Create a Grid1D (see Grid1D.__new__) from a mask, where only unmasked pixels are included in the grid (if the grid is represented in its native 1D masked values are 0.0).

grid_2d_radial_projected_from

Project the 1D grid of (y,x) coordinates to an irregular 2d grid of (y,x) coordinates.

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

no_mask

Create a Grid1D (see Grid1D.__new__) by inputting the grid coordinates in 1D.

reshape

sqrt

sum

trimmed_after_convolution_from

Trim the data structure back to its original shape after PSF convolution has been performed on a padded version of it.

uniform

Create a Grid1D (see Grid`D.__new__) as a uniform grid of (x) values given an input shape_native and pixel_scales of the grid.

uniform_from_zero

Create a Grid1D (see Grid`D.__new__) as a uniform grid of (x) values given an input shape_native and pixel_scales of the grid, where the first (x) coordinate of the grid is 0.0 and all other values ascend positively.

with_new_array

Copy this object but give it a new array.

Attributes

array

derive_grid

The DeriveGrid2D object of the mask, used to compute derived grids of (y,x) coordinates such as the edge grid, border grid, and full unmasked grid.

derive_indexes

The DeriveIndexes2D object of the mask, used to compute index arrays that map data between the slim (1D unmasked) and native (2D full-shape) representations.

derive_mask

The DeriveMask2D object of the mask, used to compute derived masks such as the edge mask, border mask, and blurring mask.

dtype

geometry

The geometry object of the mask associated with this structure, which defines coordinate conversions between pixel units and scaled units.

header_dict

The FITS header dictionary of the mask associated with this structure, containing pixel scale and origin entries.

imag

is_transformed

native

Return a Grid1D where the data is stored in its native representation, which is an ndarray of shape [total_x_pixels, 2].

ndim

origin

The (y,x) scaled units origin of the mask's coordinate system.

pixel_area

The area of a single pixel in scaled units squared (pixel_scales[0] * pixel_scales[1]).

pixel_scale

The pixel scale as a single float value.

pixel_scales

The (y,x) scaled units to pixel units conversion factors of every pixel, as a tuple of floats.

real

shape

shape_native

The shape of the data structure in its native representation (e.g. (total_y_pixels, total_x_pixels) for a 2D structure).

shape_slim

The 1D shape of the data structure in its slim representation, equal to the number of unmasked pixels.

size

slim

Return a Grid1D where the data is stored its slim representation, which is an ndarray of shape [total_unmasked_pixels, 2].

total_area

The total area of all unmasked pixels in scaled units squared (total_pixels * pixel_area).

total_pixels

The total number of unmasked pixels in the data structure (its slim length).

unmasked_grid

A grid of (y,x) coordinates of every pixel in the full mask shape (including masked pixels), using the mask's geometry to compute each pixel's scaled coordinate.

classmethod no_mask(values, pixel_scales, origin=(0.0,))[source]#

Create a Grid1D (see Grid1D.__new__) by inputting the grid coordinates in 1D.

Parameters:
  • values (Union[ndarray, List]) – The (x,) coordinates of the grid, input as an ndarray of shape [total_unmasked_pixels] or a list of values.

  • pixel_scales (Union[Tuple[float], Tuple[float, float], float]) – The (x,) arcsecond-to-pixel units conversion factor of every pixel. If this is input as a float, it is converted to a (float,) tuple.

  • origin (Tuple[float]) – The (x,) origin of the grid’s coordinate system.

Examples

import autoarray as aa

# Make Grid1D from input ndarray.

grid_1d = aa.Grid1D.no_mask(values=np.array([1.0, 2.0, 3.0, 4.0]), pixel_scales=1.0)

# Make Grid1D from input list.

grid_1d = aa.Grid1D.no_mask(values=[1.0, 2.0, 3.0, 4.0], pixel_scales=1.0)

# Print grid's slim (masked 1D data representation) and
# native (masked 1D data representation)

print(grid_1d.slim)
print(grid_1d.native)
classmethod from_mask(mask)[source]#

Create a Grid1D (see Grid1D.__new__) from a mask, where only unmasked pixels are included in the grid (if the grid is represented in its native 1D masked values are 0.0).

The mask’s pixel_scales, and origin properties are used to compute the grid (x) coordinates.

Parameters:

mask (Mask1D) – The mask whose masked pixels are used to setup the pixel grid.

classmethod uniform(shape_native, pixel_scales, origin=(0.0, 0.0))[source]#

Create a Grid1D (see Grid`D.__new__) as a uniform grid of (x) values given an input shape_native and pixel_scales of the grid.

Parameters:
  • shape_native (Tuple[int]) – The 1D shape of the uniform grid and the mask that it is paired with.

  • pixel_scales (Union[Tuple[float], Tuple[float, float], float]) – The (x) scaled units to pixel units conversion factor of every pixel. If this is input as a float, it is converted to a (float,) tuple.

  • origin (Tuple[float]) – The origin of the grid’s mask and coordinate system.

classmethod uniform_from_zero(shape_native, pixel_scales)[source]#

Create a Grid1D (see Grid`D.__new__) as a uniform grid of (x) values given an input shape_native and pixel_scales of the grid, where the first (x) coordinate of the grid is 0.0 and all other values ascend positively.

Parameters:
  • shape_native (Tuple[int]) – The 1D shape of the uniform grid and the mask that it is paired with.

  • pixel_scales (Union[Tuple[float], Tuple[float, float], float]) – The (x) scaled units to pixel units conversion factor of every pixel. If this is input as a float, it is converted to a (float,) tuple.

property slim: Grid1D#

Return a Grid1D where the data is stored its slim representation, which is an ndarray of shape [total_unmasked_pixels, 2].

If it is already stored in its slim representation the Grid1D is returned as it is. If not, it is mapped from native to slim and returned as a new Grid1D.

property native: Grid1D#

Return a Grid1D where the data is stored in its native representation, which is an ndarray of shape [total_x_pixels, 2].

If it is already stored in its native representation it is return as it is. If not, it is mapped from slim to native and returned as a new Grid1D.

grid_2d_radial_projected_from(angle=0.0)[source]#

Project the 1D grid of (y,x) coordinates to an irregular 2d grid of (y,x) coordinates. The projection works as follows:

1) Map the 1D (x) coordinates to 2D along the x-axis, such that the x value of every 2D coordinate is the corresponding (x) value in the 1D grid, and every y value is 0.0.

  1. Rotate this projected 2D grid clockwise by the input angle.

Parameters:

angle (float) – The angle with which the project 2D grid of coordinates is rotated clockwise.

Returns:

The projected and rotated 2D grid of (y,x) coordinates.

Return type:

Grid2DIrregular