autolens.Mask2D#

class Mask2D[source]#

Bases: Mask

A 2D mask, used for masking values which are associated with a a uniform rectangular grid of pixels.

When applied to 2D data with the same shape, values in the mask corresponding to False entries are unmasked and therefore used in subsequent calculations. .

The ``Mask2D`, has in-built functionality which:

  • Maps data structures between two data representations: slim` (all unmasked False values in a 1D ndarray) and native (all unmasked values in a 2D or 3D ndarray).

  • Has a Geometry2D object (defined by its (y,x) pixel scales, (y,x) origin and sub_size) which defines how coordinates are converted from pixel units to scaled units.

  • Associates Cartesian Grid2D objects of (y,x) coordinates with the data structure (e.g. a (y,x) grid of all unmasked pixels) via the DeriveGrid2D object.

  • This includes sub-grids, which perform calculations higher resolutions which are then binned up.

A detailed description of the 2D mask API is provided below.

SLIM DATA REPRESENTATION (sub-size=1)

Below is a visual illustration of a Mask2D, where a total of 10 pixels are unmasked (values are False):

x x x x x x x x x x
x x x x x x x x x x     This is an example ``Mask2D``, where:
x x x x x x x x x x
x x x x O O x x x x     x = `True` (Pixel is masked and excluded from the array)
x x x O O O O x x x     O = `False` (Pixel is not masked and included in the array)
x x x O O O O x x x
x x x x x x x x x x
x x x x x x x x x x
x x x x x x x x x x
x x x x x x x x x x

The mask pixel index’s are as follows (the positive / negative direction of the Grid2D objects associated with the mask are also shown on the y and x axes).

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

 x x x x x x x x x x  ^
 x x x x x x x x x x  I
 x x x x x x x x x x  I
 x x x x 0 1 x x x x +ve
 x x x 2 3 4 5 x x x  y
 x x x 6 7 8 9 x x x -ve
 x x x x x x x x x x  I
 x x x x x x x x x x  I
 x x x x x x x x x x \/
 x x x x x x x x x x

The Mask2D’s slim data representation is an ndarray of shape [total_unmasked_pixels].

For the Mask2D above the slim representation therefore contains 10 entries and two examples of these entries are:

mask[3] = the 4th unmasked pixel's value.
mask[6] = the 7th unmasked pixel's value.

A Cartesian grid of (y,x) coordinates, corresponding to all slim values (e.g. unmasked pixels) is given by mask.derive_grid.masked.slim.

NATIVE DATA REPRESENTATION (sub_size=1)

Masked data represented as an an ndarray of shape [total_y_values, total_x_values], where all masked entries have values of 0.0.

For the following mask:

x x x x x x x x x x
x x x x x x x x x x     This is an example ``Mask2D``, where:
x x x x x x x x x x
x x x x O O x x x x     x = `True` (Pixel is masked and excluded from the array)
x x x O O O O x x x     O = `False` (Pixel is not masked and included in the array)
x x x O O O O x x x
x x x x x x x x x x
x x x x x x x x x x
x x x x x x x x x x
x x x x x x x x x x

The mask has the following indexes:

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

 x x x x x x x x x x  ^
 x x x x x x x x x x  I
 x x x x x x x x x x  I
 x x x x 0 1 x x x x +ve
 x x x 2 3 4 5 x x x  y
 x x x 6 7 8 9 x x x -ve
 x x x x x x x x x x  I
 x x x x x x x x x x  I
 x x x x x x x x x x  \/
 x x x x x x x x x x

In the above array:

- mask[0,0] = True (it is masked)
- mask[0,0] = True (it is masked)
- mask[3,3] = True (it is masked)
- mask[3,3] = True (it is masked)
- mask[3,4] = False (not masked)
- mask[3,5] = False (not masked)
- mask[4,5] = False (not masked)

SLIM TO NATIVE MAPPING

The Mask2D has functionality which maps data between the slim and native data representations.

For the example mask above, the 1D ndarray given by mask.derive_indexes.slim_to_native is:

slim_to_native[0] = [3,4]
slim_to_native[1] = [3,5]
slim_to_native[2] = [4,3]
slim_to_native[3] = [4,4]
slim_to_native[4] = [4,5]
slim_to_native[5] = [4,6]
slim_to_native[6] = [5,3]
slim_to_native[7] = [5,4]
slim_to_native[8] = [5,5]
slim_to_native[9] = [5,6]

SUB GRIDDING

If the Mask2D sub_size is > 1, its slim and native data representations have entries corresponding to the values at the centre of every sub-pixel of each unmasked pixel.

The sub-array indexes are ordered such that pixels begin from the first (top-left) sub-pixel in the first unmasked pixel. Indexes then go over the sub-pixels in each unmasked pixel, for every unmasked pixel.

Therefore, the shapes of the sub-array are as follows:

  • slim representation: an ndarray of shape [total_unmasked_pixels*sub_size**2].

  • native representation: an ndarray of shape [total_y_values*sub_size, total_x_values*sub_size].

Below is a visual illustration of a sub array. Indexing of each sub-pixel goes from the top-left corner. In contrast to the array above, our illustration below restricts the mask to just 2 pixels, to keep the illustration brief.

x x x x x x x x x x
x x x x x x x x x x     This is an example ``Mask2D``, where:
x x x x x x x x x x
x x x x x x x x x x     x = `True` (Pixel is masked and excluded from lens)
x 0 0 x x x x x x x     O = `False` (Pixel is not masked and included in lens)
x x x x x x x x x x
x x x x x x x x x x
x x x x x x x x x x
x x x x x x x x x x
x x x x x x x x x x

If sub_size=2, each unmasked pixel has 4 (2x2) sub-pixel values. For the example above, pixels 0 and 1 each have 4 values which map to slim representation as follows:

Pixel 0 - (2x2):

       slim[0] = value of first sub-pixel in pixel 0.
 0 1   slim[1] = value of first sub-pixel in pixel 1.
 2 3   slim[2] = value of first sub-pixel in pixel 2.
       slim[3] = value of first sub-pixel in pixel 3.

Pixel 1 - (2x2):

       slim[4] = value of first sub-pixel in pixel 0.
 4 5   slim[5] = value of first sub-pixel in pixel 1.
 6 7   slim[6] = value of first sub-pixel in pixel 2.
       slim[7] = value of first sub-pixel in pixel 3.

For the native data representation we get the following mappings:

Pixel 0 - (2x2):

       native[8, 2] = value of first sub-pixel in pixel 0.
 0 1   native[8, 3] = value of first sub-pixel in pixel 1.
 2 3   native[9, 2] = value of first sub-pixel in pixel 2.
       native[9, 3] = value of first sub-pixel in pixel 3.

Pixel 1 - (2x2):

       native[10, 4] = value of first sub-pixel in pixel 0.
 4 5   native[10, 5] = value of first sub-pixel in pixel 1.
 6 7   native[11, 4] = value of first sub-pixel in pixel 2.
       native[11, 5] = value of first sub-pixel in pixel 3.

Other entries (all masked sub-pixels are zero):

       native[0, 0] = 0.0 (it is masked, thus zero)
       native[15, 12] = 0.0 (it is masked, thus zero)

If we used a sub_size of 3, for pixel 0 we we would create a 3x3 sub-array:

        slim[0] = value of first sub-pixel in pixel 0.
        slim[1] = value of first sub-pixel in pixel 1.
        slim[2] = value of first sub-pixel in pixel 2.
0 1 2   slim[3] = value of first sub-pixel in pixel 3.
3 4 5   slim[4] = value of first sub-pixel in pixel 4.
6 7 8   slim[5] = value of first sub-pixel in pixel 5.
        slim[6] = value of first sub-pixel in pixel 6.
        slim[7] = value of first sub-pixel in pixel 7.
        slim[8] = value of first sub-pixel in pixel 8.
Parameters:
  • mask (Union[ndarray, List]) – The ndarray of shape [total_y_pixels, total_x_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 (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, float) structure.

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

Methods

all

all_false

Create a mask where all pixels are False and therefore unmasked.

astype

rtype:

AbstractNDArray

circular

Returns a Mask2D (see Mask2D.__new__) where all False entries are within a circle of input radius.

circular_annular

Returns a Mask2D (see Mask2D.__new__) where all False entries are within an annulus of input inner radius and outer radius.

circular_anti_annular

Returns a Mask2D (see Mask2D.__new__) where all False entries are within an inner circle and second outer circle, forming an inverse annulus.

copy

elliptical

Returns a Mask2D (see Mask2D.__new__) where all False entries are within an ellipse.

elliptical_annular

Returns a Mask2D (see Mask2D.__new__) where all False entries are within an elliptical annulus of input inner and outer scaled major-axis and centre.

flip_hdu_for_ds9

from_fits

Loads the image from a .fits file.

from_pixel_coordinates

Returns a Mask2D (see Mask2D.__new__) where all False entries are defined from an input list of list of pixel coordinates.

from_primary_hdu

Returns an Mask2D 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.

instance_unflatten

Unflatten a tuple of attributes (i.e.

invert

mask_new_sub_size_from

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

max

min

output_to_fits

Write the 2D Mask to a .fits file.

reshape

rtype:

AbstractNDArray

sqrt

rtype:

AbstractNDArray

sum

trimmed_array_from

Map a padded 1D array of values to its original 2D array, trimming all edge values.

unmasked_blurred_array_from

For a padded grid and psf, compute an unmasked blurred image from an unmasked unblurred image.

with_new_array

Copy this object but give it a new array.

Attributes

array

circular_radius

A property that is only computed once per instance and then replaces itself with an ordinary attribute.

derive_grid

rtype:

DeriveGrid2D

derive_indexes

rtype:

DeriveIndexes2D

derive_mask

rtype:

DeriveMask2D

dimensions

rtype:

int

dtype

geometry

Return the 2D geometry of the mask, representing its uniform rectangular grid of (y,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

rtype:

AbstractNDArray

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.

is_circular

Returns whether the mask is circular or not.

mask

mask_centre

rtype:

Tuple[float, float]

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

rtype:

AbstractNDArray

shape

shape_native

rtype:

Tuple[int, ...]

shape_native_masked_pixels

The (y,x) shape corresponding to the extent of unmasked pixels that go vertically and horizontally across the mask.

shape_slim

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

size

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

zoom_centre

rtype:

Tuple[float, float]

zoom_mask_unmasked

The scaled-grid of (y,x) coordinates of every pixel.

zoom_offset_pixels

rtype:

Tuple[float, float]

zoom_offset_scaled

rtype:

Tuple[float, float]

zoom_region

The zoomed rectangular region corresponding to the square encompassing all unmasked values.

zoom_shape_native

rtype:

Tuple[int, int]

property native: Structure#

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

Return type:

Structure

property geometry: Geometry2D#

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

Return type:

Geometry2D

classmethod all_false(shape_native, pixel_scales, sub_size=1, origin=(0.0, 0.0), invert=False)[source]#

Create a mask where all pixels are False and therefore unmasked.

Parameters:
  • shape_native (Tuple[int, int]) – The 2D shape of the mask that is created.

  • 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, float) structure.

  • 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 mask’s coordinate system.

  • invert (bool) – If True, the bool’s of the input mask are inverted, for example False’s become True and visa versa.

Return type:

Mask2D

classmethod circular(shape_native, radius, pixel_scales, sub_size=1, origin=(0.0, 0.0), centre=(0.0, 0.0), invert=False)[source]#

Returns a Mask2D (see Mask2D.__new__) where all False entries are within a circle of input radius.

The radius and centre are both input in scaled units.

Parameters:
  • shape_native (Tuple[int, int]) – The (y,x) shape of the mask in units of pixels.

  • radius (float) – The radius in scaled units of the circle within which pixels are False and unmasked.

  • 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, float) structure.

  • 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 mask’s coordinate system.

  • centre (Tuple[float, float]) – The (y,x) scaled units centre of the circle used to mask pixels.

  • invert (bool) – If True, the bool’s of the input mask are inverted, for example False’s become True and visa versa.

Return type:

Mask2D

classmethod circular_annular(shape_native, inner_radius, outer_radius, pixel_scales, sub_size=1, origin=(0.0, 0.0), centre=(0.0, 0.0), invert=False)[source]#

Returns a Mask2D (see Mask2D.__new__) where all False entries are within an annulus of input inner radius and outer radius.

The inner_radius, outer_radius and centre are all input in scaled units.

Parameters:
  • shape_native (Tuple[int, int]) – The (y,x) shape of the mask in units of pixels.

  • inner_radius (float) – The inner radius in scaled units of the annulus within which pixels are False and unmasked.

  • outer_radius (float) – The outer radius in scaled units of the annulus within which pixels are False and unmasked.

  • 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, float) structure.

  • 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 mask’s coordinate system.

  • centre (Tuple[float, float]) – The (y,x) scaled units centre of the annulus used to mask pixels.

  • invert (bool) – If True, the bool’s of the input mask are inverted, for example False’s become True and visa versa.

Return type:

Mask2D

classmethod circular_anti_annular(shape_native, inner_radius, outer_radius, outer_radius_2, pixel_scales, sub_size=1, origin=(0.0, 0.0), centre=(0.0, 0.0), invert=False)[source]#

Returns a Mask2D (see Mask2D.__new__) where all False entries are within an inner circle and second outer circle, forming an inverse annulus.

The inner_radius, outer_radius, outer_radius_2 and centre are all input in scaled units.

Parameters:
  • shape_native (Tuple[int, int]) – The (y,x) shape of the mask in units of pixels.

  • inner_radius (float) – The inner radius in scaled units of the annulus within which pixels are False and unmasked.

  • outer_radius (float) – The first outer radius in scaled units of the annulus within which pixels are True and masked.

  • outer_radius_2 (float) – The second outer radius in scaled units of the annulus within which pixels are False and unmasked and outside of which all entries are True and masked.

  • 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, float) structure.

  • 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 mask’s coordinate system.

  • centre (Tuple[float, float]) – The (y,x) scaled units centre of the anti-annulus used to mask pixels.

  • invert (bool) – If True, the bool’s of the input mask are inverted, for example False’s become True and visa versa.

Return type:

Mask2D

classmethod elliptical(shape_native, major_axis_radius, axis_ratio, angle, pixel_scales, sub_size=1, origin=(0.0, 0.0), centre=(0.0, 0.0), invert=False)[source]#

Returns a Mask2D (see Mask2D.__new__) where all False entries are within an ellipse.

The major_axis_radius, and centre are all input in scaled units.

Parameters:
  • shape_native (Tuple[int, int]) – The (y,x) shape of the mask in units of pixels.

  • major_axis_radius (float) – The major-axis in scaled units of the ellipse within which pixels are unmasked.

  • axis_ratio (float) – The axis-ratio of the ellipse within which pixels are unmasked.

  • angle (float) –

    The rotation angle of the ellipse within which pixels are unmasked, (counter-clockwise from the positive

    x-axis).

  • 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, float) structure.

  • 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 mask’s coordinate system.

  • centre (Tuple[float, float]) – The (y,x) scaled units centred of the ellipse used to mask pixels.

  • invert (bool) – If True, the bool’s of the input mask are inverted, for example False’s become True and visa versa.

Return type:

Mask2D

classmethod elliptical_annular(shape_native, inner_major_axis_radius, inner_axis_ratio, inner_phi, outer_major_axis_radius, outer_axis_ratio, outer_phi, pixel_scales, sub_size=1, origin=(0.0, 0.0), centre=(0.0, 0.0), invert=False)[source]#

Returns a Mask2D (see Mask2D.__new__) where all False entries are within an elliptical annulus of input inner and outer scaled major-axis and centre.

The outer_major_axis_radius, inner_major_axis_radius and centre are all input in scaled units.

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

  • int) – 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.

  • inner_major_axis_radius (float) – The major-axis in scaled units of the inner ellipse within which pixels are masked.

  • inner_axis_ratio (float) – The axis-ratio of the inner ellipse within which pixels are masked.

  • inner_phi (float) – The rotation angle of the inner ellipse within which pixels are masked, (counter-clockwise from the positive x-axis).

  • outer_major_axis_radius (float) – The major-axis in scaled units of the outer ellipse within which pixels are unmasked.

  • outer_axis_ratio (float) – The axis-ratio of the outer ellipse within which pixels are unmasked.

  • outer_phi (float) – The rotation angle of the outer ellipse within which pixels are unmasked, (counter-clockwise from the positive x-axis).

  • 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 mask’s coordinate system.

  • centre (Tuple[float, float]) – The (y,x) scaled units centre of the elliptical annuli used to mask pixels.

  • invert (bool) – If True, the bool’s of the input mask are inverted, for example False’s become True and visa versa.

Return type:

Mask2D

classmethod from_pixel_coordinates(shape_native, pixel_coordinates, pixel_scales, sub_size=1, origin=(0.0, 0.0), buffer=0, invert=False)[source]#

Returns a Mask2D (see Mask2D.__new__) where all False entries are defined from an input list of list of pixel coordinates.

These may be buffed via an input buffer, whereby all entries in all 8 neighboring directions by this amount.

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

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

  • pixel_coordinates ([[int, int]]) – The input lists of 2D pixel coordinates where False entries are created.

  • pixel_scales – The scaled units to pixel units conversion factor of each pixel.

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

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

  • buffer – All input pixel_coordinates are buffed with False entries in all 8 neighboring directions by this amount.

  • invert – If True, the bool’s of the input mask are inverted, for example False’s become True and visa versa.

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

Loads the image 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.

  • (float (pixel_scales or) – The scaled units to pixel units conversion factor of each pixel.

  • float) – The scaled units to pixel units conversion factor of each pixel.

  • 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 mask’s coordinate system.

Return type:

Mask2D

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

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

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

array_2d = aa.Mask2D.from_primary_hdu(
    primary_hdu=primary_hdu,
    sub_size=1
)
import autoarray as aa

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

Mask2D

trimmed_array_from(padded_array, image_shape)[source]#

Map a padded 1D array of values to its original 2D array, trimming all edge values.

Parameters:

padded_array – A 1D array of values which were computed using a padded grid

Return type:

Array2D

unmasked_blurred_array_from(padded_array, psf, image_shape)[source]#

For a padded grid and psf, compute an unmasked blurred image from an unmasked unblurred image.

This relies on using the lens dataset’s padded-grid, which is a grid of (y,x) coordinates which extends over the entire image as opposed to just the masked region.

Parameters:
  • psf (aa.Kernel2D) – The PSF of the image used for convolution.

  • unmasked_image_1d – The 1D unmasked image which is blurred.

Return type:

Array2D

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 Array2D.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 2D Mask to a .fits file.

Before outputting a NumPy array, the array may be flipped upside-down using np.flipud depending on the project config files. This is for Astronomy projects so that structures appear the same orientation as .fits files loaded in DS9.

Parameters:
  • file_path – The full path of the file that is output, including the file name and .fits extension.

  • overwrite – 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 = Mask2D(mask=np.full(shape=(5,5), fill_value=False)) mask.output_to_fits(file_path=’/path/to/file/filename.fits’, overwrite=True)

property shape_native_masked_pixels: Tuple[int, int]#

The (y,x) shape corresponding to the extent of unmasked pixels that go vertically and horizontally across the mask.

For example, if a mask is primarily surrounded by True entries, and there are 15 False entries going vertically and 12 False entries going horizontally in the central regions of the mask, then shape_masked_pixels=(15,12).

Return type:

Tuple[int, int]

property zoom_region: List[int]#

The zoomed rectangular region corresponding to the square encompassing all unmasked values. This zoomed extraction region is a squuare, even if the mask is rectangular.

This is used to zoom in on the region of an image that is used in an analysis for visualization.

Return type:

List[int]

property zoom_mask_unmasked: Mask2D#

The scaled-grid of (y,x) coordinates of every pixel.

This is defined from the top-left corner, such that the first pixel at location [0, 0] will have a negative x value y value in scaled units.

Return type:

Mask2D

property is_circular: bool#

Returns whether the mask is circular or not.

This is performed by taking the central row and column of the mask (based on the mask centre) and counting the number of unmasked pixels. If the number of unmasked pixels is the same, the mask is circular.

This function does not support rectangular masks and an exception will be raised if the pixel scales in each direction are different.

Return type:

bool