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 (
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
Setup a 1D mask where all pixels are unmasked.
astype
- rtype:
AbstractNDArray
copy
flip_hdu_for_ds9
Loads the 1D mask from a .fits file.
Returns an
Mask1D
by from a PrimaryHDU object which has been loaded via astropy.fitsinstance_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
Write the 1D mask to a .fits file.
reshape
- rtype:
AbstractNDArray
sqrt
- rtype:
AbstractNDArray
sum
with_new_array
Copy this object but give it a new array.
Attributes
array
derive_grid
- rtype:
DeriveGrid1D
derive_mask
- rtype:
DeriveMask1D
dimensions
- rtype:
dtype
Return the 1D geometry of the mask, representing its uniform rectangular grid of (x) coordinates defined by its
shape_native
.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.
mask
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
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
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 native: Structure#
Returns the data structure in its native format which contains all unmaksed values to the native dimensions.
- Return type:
Structure
- 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.
- classmethod from_fits(file_path, pixel_scales, sub_size=1, hdu=0, origin=(0.0,))[source]#
Loads the 1D mask from a .fits file.
- 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.fitsThis 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 theslim
andnative
attribute used by the API, see theMask1D 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:
- 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.