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 numpy convention 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_size which masks an annulus with a given inner_radius and outer_radius.

Return type:

ndarray

hsr4hci.masking.get_circle_mask(mask_size, radius, center=None)[source]#

Create a circle mask.

Attention

This function uses the numpy convention 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_size which is False everywhere, except in a circular region of given radius around the specified center.

Return type:

ndarray

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 astropy convention 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.Quantity that 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:

ndarray

hsr4hci.masking.get_partial_roi_mask(roi_mask, roi_split, n_roi_splits)[source]#

Take a roi_mask and return a mask that selects only a subset of the ROI that is specified by the number of n_roi_splits and the index roi_split. This function is useful for processing data in parallel, for example on a cluster.

Parameters:
  • roi_mask (ndarray) โ€“ A 2D numpy array containing a binary mask.

  • roi_split (int) โ€“ The index of the split for which to return the mask.

  • n_roi_splits (int) โ€“ The (total) number of splits into which the ROI should be divided.

Returns:

A 2D numpy array containing a mask that selects a subset of the original ROI mask, as specified above.

Return type:

ndarray

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 numpy convention for coordinates!

Parameters:

mask (ndarray) โ€“ A numpy array containing only boolean values (or values that can be interpreted as such).

Returns:

A sorted list of all positions (x, y) for which we have mask[x, y] == True.

Return type:

List[Tuple[int, int]]

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_position around the position, and another circular region with radius radius_opposite centered on (-x, -y), where the center of the frame is taken as the origin of the coordinate system.

Attention

This function uses the astropy convention 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.Quantity that can be converted to pixels) of the circular region around the position that is used to select potential predictors.

  • radius_opposite (Quantity) โ€“ The radius (an astropy.units.Quantity that can be converted to pixels) of the circular region around the opposite position, that is, the position that we get if we mirror position across 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:

ndarray

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 astropy convention 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 the get_predictor_mask() function.

  • radius_opposite (Quantity) โ€“ The radius (an astropy.units.Quantity that can be converted to pixels) of the circular region around the opposite position, that is, the position that we get if we mirror position across the center of the frame.

  • radius_excluded (Quantity) โ€“ The radius (an astropy.units.Quantity that 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:

ndarray

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 numpy convention 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.Quantity that can be converted to pixels).

  • outer_radius (Quantity) โ€“ Outer radius of the region of interest (as an astropy.units.Quantity that can be converted to pixels).

Returns:

A 2D numpy array of size mask_size which masks the pixels within the specified region of interest.

Return type:

ndarray

hsr4hci.masking.mask_frame_around_position(frame, position, radius=5)[source]#

Create a circular mask with the given radius at the given position and set the frame outside this mask to zero. This is sometimes required for the Gaussian2D-based photometry methods to prevent the Gaussian to try and fit some part of the data that is far from the target position.

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 frame on which we can perform photometry based on fitting a 2D Gaussian to the data.

Return type:

ndarray

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 to minimum_size and maximum_size.

Return type:

ndarray