autolens.Array1D#

class Array1D[source]#

Bases: Structure

A uniform 1D array of values, paired with a 1D mask of pixels.

Each entry of an Array1D corresponds to a value at the centre of a pixel in its corresponding Mask1D. It is ordered such that pixels begin from the left of the corresponding mask and go right.

Like Array2D, the Array1D supports slim (1D, unmasked only) and native (1D, full length) data representations.

Parameters:
  • values (Union[ndarray, List]) – The values of the array, input in the slim or native format.

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

  • header (Optional[Header]) – Optional metadata header associated with the array (e.g. from a FITS file).

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

  • xp – The array module to use (default numpy; pass jax.numpy for JAX support).

Methods

all

astype

copy

from_fits

Create an Array1D (see Array1D.__new__) by loading the array values from a .fits file.

full

Create an Array1D (see Array1D.__new__) where all values are filled with an input fill value, analogous to the method np.full().

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 Array1D (see Array1D.__new__) by inputting the array values in 1D

ones

Create an Array1D (see Array1D.__new__) where all values are filled with ones, analogous to the method np.ones().

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.

with_new_array

Copy this object but give it a new array.

zeros

Create an Array1D (see Array1D.__new__) where all values are filled with zeros, analogous to the method np.zeros().

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.

grid_radial

header_dict

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

imag

is_transformed

native

Return an Array1D where the data is stored in its native representation, which is an ndarray of shape [total_pixels].

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.

readout_offsets

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 an Array1D where the data is stored its slim representation, which is an ndarray of shape [total_unmasked_pixels].

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,), header=None)[source]#

Create a Array1D (see Array1D.__new__) by inputting the array values in 1D

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

  • pixel_scales (Union[Tuple[float], Tuple[float, float], float]) – The scaled units to pixel units conversion factor of the array data coordinates (e.g. the x-axis).

  • origin (Tuple[float]) – The origin of the 1D array’s mask.

Examples

import autoarray as aa

# Make Array1D from input np.ndarray.

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

# Make Array1D from input list.

array_1d = aa.Array1D.no_mask(values=[1.0, 2.0, 3.0, 4.0], pixel_scales=1.0)

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

print(array_1d.slim)
print(array_1d.native)
classmethod full(fill_value, shape_native, pixel_scales, origin=(0.0,), header=None)[source]#

Create an Array1D (see Array1D.__new__) where all values are filled with an input fill value, analogous to the method np.full().

From 1D input the method cannot determine the 1D shape of the array and its mask, thus the shape_native must be input into this method. The mask is setup as a unmasked Mask1D of size shape_native.

Parameters:
  • fill_value (float) – The value all array elements are filled with.

  • shape_native (Union[int, Tuple[int]]) – The 1D shape of the mask the array is paired with.

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

  • origin (Tuple[float]) – The (x) scaled units origin of the mask’s coordinate system.

classmethod zeros(shape_native, pixel_scales, origin=(0.0,), header=None)[source]#

Create an Array1D (see Array1D.__new__) where all values are filled with zeros, analogous to the method np.zeros().

From 1D input the method cannot determine the 1D shape of the array and its mask, thus the shape_native must be input into this method. The mask is setup as a unmasked Mask1D of size shape_native.

Parameters:
  • shape_native (Union[int, Tuple[int]]) – The 1D shape of the mask the array is paired with.

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

  • origin (Tuple[float]) – The (x) scaled units origin of the mask’s coordinate system.

classmethod ones(shape_native, pixel_scales, origin=(0.0,), header=None)[source]#

Create an Array1D (see Array1D.__new__) where all values are filled with ones, analogous to the method np.ones().

From 1D input the method cannot determine the 1D shape of the array and its mask, thus the shape_native must be input into this method. The mask is setup as a unmasked Mask1D of size shape_native.

Parameters:
  • shape_native (Union[int, Tuple[int]]) – The 1D shape of the mask the array is paired with.

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

  • origin (Tuple[float]) – The (x) scaled units origin of the mask’s coordinate system.

classmethod from_fits(file_path, pixel_scales, hdu=0, origin=(0.0, 0.0))[source]#

Create an Array1D (see Array1D.__new__) by loading the array values from a .fits file.

Parameters:
  • file_path (Union[Path, str]) – The path the file is loaded from, including the filename and the .fits extension, e.g. ‘/path/to/filename.fits’

  • hdu (int) – The Header-Data Unit of the .fits file the array data is loaded from.

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

  • origin (Tuple[float]) – The (x,) scaled units origin of the coordinate system.

property slim: Array1D#

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

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

property native: Array1D#

Return an Array1D where the data is stored in its native representation, which is an ndarray of shape [total_pixels].

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

property readout_offsets: Tuple[float]#
property grid_radial: Grid1D#