autolens.Array1D#

class Array1D[source]#

Bases: Structure

Methods

all

astype

rtype:

AbstractNDArray

copy

flip_hdu_for_ds9

from_fits

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

from_primary_hdu

Returns an Array1D by from a PrimaryHDU object which has been loaded via astropy.fits

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.

instance_unflatten

Unflatten a tuple of attributes (i.e.

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().

output_to_fits

Output the array to a .fits file.

reshape

rtype:

AbstractNDArray

sqrt

rtype:

AbstractNDArray

structure_2d_from

rtype:

Structure

structure_2d_list_from

rtype:

List[Structure]

sum

trimmed_after_convolution_from

rtype:

Structure

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

rtype:

DeriveGrid2D

derive_indexes

rtype:

DeriveIndexes2D

derive_mask

rtype:

DeriveMask2D

dtype

geometry

grid_radial

rtype:

Grid1D

hdu_for_output

The array as an HDU object, which can be output to a .fits file.

imag

rtype:

AbstractNDArray

native

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

ndim

origin

rtype:

Tuple[int, ...]

pixel_area

pixel_scale

rtype:

float

pixel_scale_header

rtype:

Dict

pixel_scales

rtype:

Tuple[float, ...]

readout_offsets

rtype:

Tuple[float]

real

rtype:

AbstractNDArray

shape

shape_native

rtype:

Tuple[int, ...]

shape_slim

rtype:

int

size

slim

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

sub_shape_native

rtype:

Tuple[int, ...]

sub_shape_slim

rtype:

int

sub_size

rtype:

int

total_area

total_pixels

rtype:

int

unmasked_grid

rtype:

Union[Grid1D, Grid2D]

classmethod no_mask(values, pixel_scales, sub_size=1, 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*sub_size] 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).

  • sub_size (int) – The size of each unmasked pixels sub-grid.

  • 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 Array2D 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)
Return type:

Array1D

classmethod full(fill_value, shape_native, pixel_scales, sub_size=1, 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 (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.

  • sub_size (int) – The size (sub_size) of each unmasked pixels sub-array.

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

Return type:

Array1D

classmethod zeros(shape_native, pixel_scales, sub_size=1, 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 (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.

  • sub_size (int) – The size (sub_size) of each unmasked pixels sub-array.

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

Return type:

Array1D

classmethod ones(shape_native, pixel_scales, sub_size=1, 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 (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.

  • sub_size (int) – The size (sub_size) of each unmasked pixels sub-array.

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

Return type:

Array1D

classmethod from_fits(file_path, pixel_scales, hdu=0, sub_size=1, 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.

  • sub_size (int) – The sub-size of each unmasked pixels sub-array.

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

Return type:

Array1D

classmethod from_primary_hdu(primary_hdu, sub_size=1, origin=(0.0, 0.0))[source]#

Returns an Array1D by from a PrimaryHDU object which has been loaded via astropy.fits

This assumes that the header of the PrimaryHDU contains an entry named PIXSCALE which gives the pixel-scale of the array.

For a full description of Array1D objects, including a description of the slim and native attribute used by the API, see the Array1D class API documentation.

Parameters:
  • primary_hdu (PrimaryHDU) – The PrimaryHDU object which has already been loaded from a .fits file via astropy.fits and contains the array data and the pixel-scale in the header with an entry named PIXSCALE.

  • sub_size (int) – The size (sub_size x sub_size) of each unmasked pixels sub-array.

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

Examples

from astropy.io import fits
import autoarray as aa

# Make Array1D with sub_size 1.

primary_hdu = fits.open("path/to/file.fits")

array_1d = aa.Array1D.from_primary_hdu(
    primary_hdu=primary_hdu,
    sub_size=1
)
import autoarray as aa

# Make Array1D with sub_size 2.
# (It is uncommon that a sub-gridded array would be loaded from
# a .fits, but the API support its).

 primary_hdu = fits.open("path/to/file.fits")

array_1d = aa.Array1D.from_primary_hdu(
    primary_hdu=primary_hdu,
    sub_size=2
)
Return type:

Array1D

property slim: Array1D#

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

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.

Return type:

Array1D

property native: Array1D#

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

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.

Return type:

Array1D

property hdu_for_output: PrimaryHDU#

The array as an HDU object, which can be output to a .fits file.

The header of the HDU is used to store the pixel_scale of the array, which is used by the Array1D.from_hdu.

This method is used in other projects (E.g. PyAutoGalaxy, PyAutoLens) to conveniently output the array to .fits files.

Return type:

The HDU containing the data and its header which can then be written to .fits.

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

Output the array to a .fits file.

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

  • overwrite (bool) – If a file already exists at the path, if overwrite=True it is overwritten else an error is raised.