autocti.Mask2D#
- class autocti.Mask2D(mask: Union[ndarray, List], pixel_scales: Union[Tuple[float], Tuple[float, float], float], sub_size: int = 1, origin: Tuple[float, float] = (0.0, 0.0), invert: bool = False, *args, **kwargs)[source]#
Bases:
Mask2D
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 1Dndarray
) andnative
(all unmasked values in a 2D or 3Dndarray
).Has a
Geometry2D
object (defined by its (y,x)pixel scales
, (y,x)origin
andsub_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 theDeriveGrid2D
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 areFalse
):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
’sslim
data representation is anndarray
of shape [total_unmasked_pixels].For the
Mask2D
above theslim
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 bymask.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 theslim
andnative
data representations.For the example mask above, the 1D
ndarray
given bymask.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, itsslim
andnative
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: anndarray
of shape [total_unmasked_pixels*sub_size**2].native
representation: anndarray
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 toslim
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 – 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 – 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 – The (y,x) scaled units origin of the mask’s coordinate system.
Methods
all
Returns True if all elements evaluate to True.
Create a mask where all pixels are False and therefore 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.
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.
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.
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.
fill
Fill the array with a scalar value.
flatten
Return a copy of the array collapsed into one dimension.
Returns the mask used for CTI Calibration, which is all False unless specific regions are input for masking.
Loads the image from a .fits file.
from_masked_regions
from_pixel_coordinates
Returns a Mask2D (see Mask2D.__new__) where all False entries are defined from an input list of list of pixel coordinates.
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)
Create a Mask2D (see Mask2D.__new__) by inputting the array values in 2D, for example:
mask_new_sub_size_from
Returns the mask on the same scaled coordinate system but with a sub-grid of an inputsub_size.
masked_fpr_and_eper_from
masked_parallel_eper_from
masked_parallel_fpr_from
masked_serial_eper_from
masked_serial_fpr_from
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 2D 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.
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.
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
derive_indexes
A property that is only computed once per instance and then replaces itself with an ordinary attribute.
derive_mask
dimensions
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 2D geometry of the mask, representing its uniform rectangular grid of (y,x) coordinates defined by its
shape_native
.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.
mask_centre
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_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
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
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
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
zoom_mask_unmasked
The scaled-grid of (y,x) coordinates of every pixel.
zoom_offset_pixels
zoom_offset_scaled
zoom_region
The zoomed rectangular region corresponding to the square encompassing all unmasked values.
zoom_shape_native
- classmethod manual(mask, pixel_scales, origin=(0.0, 0.0), invert=False)[source]#
Create a Mask2D (see Mask2D.__new__) by inputting the array values in 2D, for example:
- mask=np.array([[False, False],
[True, False]])
- mask=[[False, False],
[True, False]]
- Parameters:
mask – The bool values of the mask input as an ndarray of shape [total_y_pixels, total_x_pixels ]or a list of lists.
pixel_scales – 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 ((float, float)) – The (y,x) scaled units origin of the mask’s coordinate system.
invert – If True, the
bool
’s of the inputmask
are inverted, for example False’s become True and visa versa.
- classmethod all_false(shape_native, pixel_scales, origin=(0.0, 0.0), invert=False)[source]#
Create a mask where all pixels are False and therefore unmasked.
- Parameters:
mask – The bool values of the mask input as an ndarray of shape [total_y_pixels, total_x_pixels ]or a list of lists.
pixel_scales – 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 ((float, float)) – The (y,x) scaled units origin of the mask’s coordinate system.
invert – If True, the
bool
’s of the inputmask
are inverted, for example False’s become True and visa versa.
- classmethod from_cosmic_ray_map_buffed(cosmic_ray_map, settings=<autocti.mask.mask_2d.SettingsMask2D object>)[source]#
Returns the mask used for CTI Calibration, which is all False unless specific regions are input for masking.
- Parameters:
cosmic_ray_map (array_2d.Array2D) – 2D arrays flagging where cosmic rays on the image.
cosmic_ray_parallel_buffer – The number of pixels from each ray pixels are masked in the parallel direction.
cosmic_ray_serial_buffer – The number of pixels from each ray pixels are masked in the serial direction.
cosmic_ray_diagonal_buffer – The number of pixels from each ray pixels are masked in the digonal up from the parallel + serial direction.
- classmethod from_fits(file_path, pixel_scales, hdu=0, origin=(0.0, 0.0), resized_mask_shape=None)[source]#
Loads the image from a .fits file.
- Parameters:
file_path – The full path of the fits file.
hdu – The HDU number in the fits file containing the image image.
(float (pixel_scales or) – The arc-second to pixel conversion factor of each pixel.
float) – The arc-second to pixel conversion factor of each pixel.