ApertureMask#
- class photutils.aperture.ApertureMask(data, bbox)[source]#
Bases:
objectClass for an aperture mask.
- Parameters:
- dataarray_like
A 2D array representing the fractional overlap of an aperture on the pixel grid. This should be the full-sized (i.e., not truncated) array that is the direct output of one of the low-level
photutils.geometryfunctions.- bbox
photutils.aperture.BoundingBox The bounding box object defining the aperture minimal bounding box.
Attributes Summary
The shape of the mask data array.
Methods Summary
cutout(data[, fill_value, copy])Create a cutout from the input data over the mask bounding box, taking any edge effects into account.
get_overlap_slices(shape)Get slices for the overlapping part of the aperture mask and a 2D array.
get_values(data[, mask])Get the mask-weighted pixel values from the data as a 1D array.
multiply(data[, fill_value])Multiply the aperture mask with the input data, taking any edge effects into account.
to_image(shape[, dtype])Return an image of the mask in a 2D array of the given shape, taking any edge effects into account.
Attributes Documentation
- shape#
The shape of the mask data array.
Methods Documentation
- cutout(data, fill_value=0.0, copy=False)[source]#
Create a cutout from the input data over the mask bounding box, taking any edge effects into account.
- Parameters:
- dataarray_like
The 2D array from which to extract the cutout.
- fill_valuefloat, optional
The value used to fill pixels where the aperture mask does not overlap with the input
data. The default is 0. For a partial overlap, the cutout has the data type ofdata, sofill_valueis cast to that type. A nonfinitefill_valuegives a float cutout.- copybool, optional
If
Truethen the returned cutout array will always hold a copy of the inputdata. IfFalseand the mask is fully within the inputdata, then the returned cutout array will be a view into the inputdata. If the mask only partially overlaps the inputdata, the returned cutout array is always a copy (i.e., this keyword has no effect).
- Returns:
- result
ndarray,Quantity, orNone A 2D array cut out from the input
datarepresenting the same cutout region as the aperture mask. If there is a partial overlap of the aperture mask with the input data, pixels outside the data will be assigned tofill_value.Noneis returned if there is no overlap of the aperture with the inputdata.
- result
- get_overlap_slices(shape)[source]#
Get slices for the overlapping part of the aperture mask and a 2D array.
- Parameters:
- shape2-tuple of int
The shape of the 2D array.
- Returns:
- slices_largetuple of slices or
None A tuple of slice objects for each axis of the large array, such that
large_array[slices_large]extracts the region of the large array that overlaps with the small array.Noneis returned if there is no overlap of the bounding box with the given image shape.- slices_smalltuple of slices or
None A tuple of slice objects for each axis of the aperture mask array such that
small_array[slices_small]extracts the region that is inside the large array.Noneis returned if there is no overlap of the bounding box with the given image shape.
- slices_largetuple of slices or
- get_values(data, mask=None)[source]#
Get the mask-weighted pixel values from the data as a 1D array.
If the
ApertureMaskwas created withmethod='center'(where the mask weights are only 1 or 0), then the returned values will simply be pixel values extracted from the data.- Parameters:
- Returns:
- result
ndarrayorQuantity A 1D array of mask-weighted pixel values from the input
data. Only pixels with a nonzero mask weight that lie withindataare returned. If there is no overlap of the aperture with the inputdata, the result will be an empty array with shape (0,). Ifdatais aQuantity, the result is aQuantitywith the same units.
- result
- multiply(data, fill_value=0.0)[source]#
Multiply the aperture mask with the input data, taking any edge effects into account.
The result is a mask-weighted cutout from the data.
- Parameters:
- dataarray_like or
Quantity The 2D array to multiply with the aperture mask.
- fill_valuefloat, optional
The value assigned to pixels where the aperture mask does not overlap with the input
dataand to pixels within the bounding box where the mask weight is zero. Pixels outside of the inputdatathat have a nonzero mask weight are set tofill_valuemultiplied by the mask weight. The default is 0.
- dataarray_like or
- Returns:
- result
ndarray,Quantity, orNone A 2D mask-weighted cutout from the input
data. If there is a partial overlap of the aperture mask with the input data, pixels outside the data will be assigned tofill_valuebefore being multiplied with the mask.Noneis returned if there is no overlap of the aperture with the inputdata.
- result
- to_image(shape, dtype=<class 'float'>)[source]#
Return an image of the mask in a 2D array of the given shape, taking any edge effects into account.
- Parameters:
- shapetuple of int
The
(ny, nx)shape of the output array.- dtypedata-type, optional
The desired data type for the array. This should be a floating data type if the
ApertureMaskwas created with the “exact” or “subpixel” method, otherwise the fractional mask weights will be altered. An integer data type may be used if theApertureMaskwas created with the “center” method.
- Returns: