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 sub-grid which is used for performing calculations via super-sampling.

Parameters
  • mask – 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 – The scaled units to pixel units conversion factor of each pixel.

  • origin – The x origin of the mask’s coordinate system in scaled units.

Methods

all

Returns True if all elements evaluate to True.

all_false

Setup a 1D mask where all pixels are unmasked.

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.

dot

dump

Dump a pickle of the array to the specified file.

dumps

Returns the pickle of the array as a string.

fill

Fill the array with a scalar value.

flatten

Return a copy of the array collapsed into one dimension.

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

getfield

Returns a field of the given array as a certain type.

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)

mask_new_sub_size_from

Returns the mask on the same scaled coordinate system but with a sub-grid of an inputsub_size.

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

Write the 1D mask to a .fits file.

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.

squeeze

Remove axes of length one from a.

std

Returns the standard deviation of the array elements along given axis.

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.

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.

derive_grid

rtype

DeriveGrid1D

derive_mask

rtype

DeriveMask1D

dimensions

rtype

int

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.

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

The imaginary part of the array.

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.

itemsize

Length of one array element in bytes.

native

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.

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

The real part of the array.

shape

Tuple of array dimensions.

shape_native

rtype

Tuple[int]

shape_slim

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

size

Number of elements in the array.

strides

Tuple of bytes to step in each dimension when traversing an array.

sub_fraction

The fraction of the area of a pixel every sub-pixel contains.

sub_length

The total number of sub-pixels in a give pixel,

sub_pixels_in_mask

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

sub_shape_native

rtype

Tuple[int]

sub_shape_slim

The 1D shape of the mask's sub-grid, which is equivalent to the total number of unmasked pixels in the mask.

property geometry: Geometry1D#

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

Return type

Geometry1D

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

  • 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 Mask1D with sub_size 1.

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

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

# Make Mask1D 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.Mask1D.from_primary_hdu(
    primary_hdu=primary_hdu,
    sub_size=2
)
Return type

Mask1D

property shape_slim: Tuple[int]#

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

Return type

Tuple[int]

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)