masking#
Methods for creating and working with (binary) masks.
- hsr4hci.masking.get_annulus_mask(mask_size, inner_radius, outer_radius, center=None)[source]#
Create an annulus-shaped mask.
Attention
This function uses the
numpyconvention for coordinates!- Parameters:
mask_size (Tuple[int, int]) โ A tuple (width, height) containing the size of the mask (in pixels) to be created. Should match the size of the array which is masked.
inner_radius (float) โ Inner radius (in pixels) of the annulus mask.
outer_radius (float) โ Outer radius (in pixels) of the annulus mask.
center (Optional[Tuple[float, float]]) โ A tuple (x, y) containing the center of the annulus. If None is given, the annulus will be centered within the mask (this is the default).
- Returns:
A 2D numpy array of size
mask_sizewhich masks an annulus with a giveninner_radiusandouter_radius.- Return type:
- hsr4hci.masking.get_circle_mask(mask_size, radius, center=None)[source]#
Create a circle mask.
Attention
This function uses the
numpyconvention for coordinates!- Parameters:
mask_size (Tuple[int, int]) โ A tuple (x_size, y_size) containing the size of the mask (in pixels) to be created.
radius (float) โ Radius of the disk (in pixels).
center (Optional[Tuple[float, float]]) โ A tuple (x, y) containing the center of the circle. If None is given, the circle will be centered within the mask (this is the default).
- Returns:
A numpy array of the given
mask_sizewhich is False everywhere, except in a circular region of given radius around the specifiedcenter.- Return type:
- hsr4hci.masking.get_exclusion_mask(mask_size, position, radius_excluded)[source]#
Get a mask of the pixels that we must not use as predictors for the given target pixel at
position.For simplicity, the exclusion region is a disk where we exclude everything inside a given radius around the
position.Attention
This function uses the
astropyconvention for coordinates!- Parameters:
mask_size (Tuple[int, int]) โ A tuple (x_size, y_size) containing the size of the mask (in pixels) to be created.
position (Tuple[float, float]) โ The position (in astropy = matplotlib coordinates) for which to compute the exclusion mask.
radius_excluded (Quantity) โ The radius (an
astropy.units.Quantitythat can be converted to pixels) around position inside which pixels are excluded from being used as a predictor.
- Returns:
A 2D numpy array containing the (binary) exclusion mask for the pixel at the given
position.- Return type:
- hsr4hci.masking.get_partial_roi_mask(roi_mask, roi_split, n_roi_splits)[source]#
Take a
roi_maskand return a mask that selects only a subset of the ROI that is specified by the number ofn_roi_splitsand the indexroi_split. This function is useful for processing data in parallel, for example on a cluster.- Parameters:
- Returns:
A 2D numpy array containing a mask that selects a subset of the original ROI mask, as specified above.
- Return type:
- hsr4hci.masking.get_positions_from_mask(mask)[source]#
Convert a numpy mask into a list of positions selected by that mask.
Attention
The returned positions follow the
numpyconvention for coordinates!
- hsr4hci.masking.get_predictor_mask(mask_size, position, radius_position, radius_opposite)[source]#
Create a mask that selects the potential predictors for a position.
For a given position (x, y), this mask selects all pixels in a circular region with radius
radius_positionaround the position, and another circular region with radiusradius_oppositecentered on (-x, -y), where the center of the frame is taken as the origin of the coordinate system.Attention
This function uses the
astropyconvention for coordinates!- Parameters:
mask_size (Tuple[int, int]) โ A tuple (x_size, y_size) that specifies the size of the mask to be created in pixels.
position (Tuple[int, int]) โ A tuple (x, y) specifying the position / pixel for which this mask is created. The position is specified in astropy / matplotlib coordinates, not numpy coordinates!
radius_position (Quantity) โ The radius (an
astropy.units.Quantitythat can be converted to pixels) of the circular region around thepositionthat is used to select potential predictors.radius_opposite (Quantity) โ The radius (an
astropy.units.Quantitythat can be converted to pixels) of the circular region around the oppositeposition, that is, the position that we get if we mirrorpositionacross the center of the frame.
- Returns:
A 2D numpy array containing a mask that contains all potential predictors for the pixel at the given
position, that is, including the pixels that we must not use because they are not causally independent.- Return type:
- hsr4hci.masking.get_predictor_pixel_selection_mask(mask_size, position, radius_position, radius_opposite, radius_excluded)[source]#
Get the mask that selects the predictor pixels for a given position.
Attention
This function uses the
astropyconvention for coordinates!- Parameters:
mask_size (Tuple[int, int]) โ A tuple (x_size, y_size) that specifies the size of the mask to be created in pixels.
position (Tuple[int, int]) โ A tuple (x, y) specifying the position for which this mask is created, i.e., the mask selects the pixels that are used as predictors for (x, y).
radius_position (Quantity) โ The radius (as an astropy.units.Quantity that can be converted to pixels) of the circular region around the
position(and the mirrored position) that is used in theget_predictor_mask()function.radius_opposite (Quantity) โ The radius (an
astropy.units.Quantitythat can be converted to pixels) of the circular region around the oppositeposition, that is, the position that we get if we mirrorpositionacross the center of the frame.radius_excluded (Quantity) โ The radius (an
astropy.units.Quantitythat can be converted to pixels) around position inside which pixels are excluded from being used as a predictor.
- Returns:
A 2D numpy array containing a mask that selects the pixels to be used as predictors for the pixel at the given
position.- Return type:
- hsr4hci.masking.get_roi_mask(mask_size, inner_radius, outer_radius)[source]#
Get a numpy array masking the pixels within the region of interest.
Attention
This function uses the
numpyconvention for coordinates!- Parameters:
mask_size (Tuple[int, int]) โ A tuple (x_size, y_size) containing the spatial size of the input stack.
inner_radius (Quantity) โ Inner radius of the region of interest (as an
astropy.units.Quantitythat can be converted to pixels).outer_radius (Quantity) โ Outer radius of the region of interest (as an
astropy.units.Quantitythat can be converted to pixels).
- Returns:
A 2D numpy array of size
mask_sizewhich masks the pixels within the specified region of interest.- Return type:
- hsr4hci.masking.mask_frame_around_position(frame, position, radius=5)[source]#
Create a circular mask with the given
radiusat the given position and set the frame outside this mask to zero. This is sometimes required for theGaussian2D-based photometry methods to prevent the Gaussian to try and fit some part of the data that is far from the targetposition.- Parameters:
frame (ndarray) โ A 2D numpy array of shape (x_size, y_size) containing the data on which to run the aperture photometry.
position (Tuple[float, float]) โ A tuple (x, y) specifying the position at which to estimate the flux. The position should be in astropy / photutils coordinates.
radius (float) โ The radius of the mask; this should approximately match the size of a planet signal.
- Returns:
A masked version of the given
frameon which we can perform photometry based on fitting a 2D Gaussian to the data.- Return type:
- hsr4hci.masking.remove_connected_components(mask, minimum_size=None, maximum_size=None)[source]#
Remove connected components from a binary mask based on their size.
- Parameters:
mask (ndarray) โ Binary 2D numpy array from which to remove components.
minimum_size (Optional[int]) โ Components with less pixels than this number will be removed from
mask. Set to None to not remove small components.maximum_size (Optional[int]) โ Components with more pixels than this number will be removed from
mask. Set to None to not remove large components.
- Returns:
The original
mask, with connected components removed according tominimum_sizeandmaximum_size.- Return type: