autolens.Mask1D#

class Mask1D[source]#

Bases: Mask

A 1D mask, representing 1D data on a uniform line of pixels with equal spacing.

When applied to 1D data it extracts or masks the unmasked image pixels corresponding to mask entries that are False or 0).

The mask also defines the geometry of the 1D data structure it is paired to, for example how every pixel coordinate on the 1D line of data converts to physical units via the pixel_scales and origin parameters and a grid which is used for performing calculations.

Parameters:
  • mask (Union[ndarray, List]) – The ndarray of shape [total_pixels] containing the bool’s representing the mask, where False signifies an entry is unmasked and used in calculations.

  • pixel_scales (Union[Tuple[float], Tuple[float, float], float]) – The scaled units to pixel units conversion factor of each pixel.

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

Methods

all

all_false

Setup a 1D mask where all pixels are unmasked.

astype

copy

flip_hdu_for_ds9

from_fits

Loads the 1D mask from a .fits file.

from_primary_hdu

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

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

output_to_fits

Write the 1D mask to a .fits file.

reshape

sqrt

sum

with_new_array

Copy this object but give it a new array.

Attributes

array

derive_grid

derive_mask

dimensions

dtype

geometry

Return the 1D geometry of the mask, representing its uniform rectangular grid of (x) coordinates defined by its shape_native.

hdu_for_output

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

imag

is_all_false

Returns False if all pixels in a mask are False, else returns True.

is_all_true

Returns True if all pixels in a mask are True, else returns False.

mask

native

Returns the data structure in its native format which contains all unmaksed values to the native dimensions.

ndim

pixel_scale

For a mask with dimensions two or above check that are pixel scales are the same, and if so return this single value as a float.

pixel_scale_header

Returns the pixel scale of the mask as a header dictionary, which can be written to a .fits file.

pixel_scales

pixels_in_mask

The total number of unmasked pixels (values are False) in the mask.

real

shape

shape_native

shape_slim

The 1D shape of the mask, which is equivalent to the total number of unmasked pixels in the mask.

size

property native: Structure#

Returns the data structure in its native format which contains all unmaksed values to the native dimensions.

property geometry: Geometry1D#

Return the 1D geometry of the mask, representing its uniform rectangular grid of (x) coordinates defined by its shape_native.

classmethod all_false(shape_slim, pixel_scales, origin=(0.0,), invert=False)[source]#

Setup a 1D mask where all pixels are unmasked.

Parameters:
  • shape_slim – The (y,x) shape of the mask in units of pixels.

  • pixel_scales (Union[Tuple[float], Tuple[float, float], float]) – The scaled units to pixel units conversion factor of each pixel.

Return type:

Mask1D

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

Loads the 1D mask from a .fits file.

Parameters:
  • file_path (Union[Path, str]) – The full path of the fits file.

  • hdu (int) – The HDU number in the fits file containing the image image.

  • pixel_scales (Union[Tuple[float], Tuple[float, float], float]) – The scaled units to pixel units conversion factor of each pixel.

Return type:

Mask1D

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

Returns an Mask1D 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 Mask1D objects, including a description of the slim and native attribute used by the API, see the Mask1D 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.

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

Return type:

Mask1D

Examples

from astropy.io import fits
import autoarray as aa

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

array_1d = aa.Mask1D.from_primary_hdu(
    primary_hdu=primary_hdu,
)
property shape_slim: Tuple[int]#

The 1D shape of the mask, which is equivalent to the total number of unmasked pixels in the mask.

property hdu_for_output: PrimaryHDU#

The mask as a 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]#

Write the 1D mask to a .fits file.

Parameters:
  • file_path (Union[Path, str]) – The full path of the file that is output, including the file name and .fits extension.

  • overwrite (bool) – If True and a file already exists with the input file_path the .fits file is overwritten. If False, an error is raised.

Return type:

None

Examples

mask = Mask1D(mask=np.full(shape=(5,), fill_value=False)) mask.output_to_fits(file_path=’/path/to/file/filename.fits’, overwrite=True)