ndcube icon indicating copy to clipboard operation
ndcube copied to clipboard

MaskCollection Class

Open DanRyanIrish opened this issue 5 years ago • 1 comments

Description

Currently, the NDCube.mask implementation is simply a boolean array. However I there may be many components to a mask and in some cases users may want to keep them separate, e.g. parts of the CCD not illuminated, dusk in the optical path, cosmic rays hits, and also feature masks, e.g. active region, of flare.

Is there currently a class out there, e.g. MaskCollection, that can store all these components and return a master mask which is a combination of them all a a subset of them. If not, implementing one might not be so hard.

Proposed implementation

  • MaskCollection inherits from dict.
  • Mask components are stored as boolean arrays or Mask objects where:
    • Mask.mask is a boolean array
    • Mask.meta is a dictionary-like including a description/info entry giving more info on what the mask represents.
  • MaskCollection.mask_and(masks) is a method returning a logical AND combination of masks which is a list of key values of masks within the collection.
  • MaskCollection.mask_or(masks): same as MaskCollection.mask_and(masks) except that a logical OR combination is returned.
  • MaskCollection.mask is a property returning a combined mask using the conditions defined in MaskCollection._mask_defaults.
  • MaskCollection._mask_defaults: a **kwargs-like dictionary defining how the MaskCollection.mask is computed.
    • MaskCollection._mask_defaults.masks: list of key names of masks to be combined.
    • MaskCollection._mask_defaults.func(): The function via which the masks are to be combined.
      • Must take MaskCollection._mask_defaults.masks as the input.
      • Can be as simple as self.mask_or() or a complicated combination combining different masks differently.
      • Default is self.mask_or
  • MaskCollection.set_mask_defaults(masks=None, func=None): a method allowing users to set the defaults in MaskCollection._mask_defaults.

Additional context

DanRyanIrish avatar Apr 07 '20 13:04 DanRyanIrish

@mwcraig, given your comment on astropy issue 11176 perhaps this feature might be of interest to nddata. Let me know if you have any thoughts.

DanRyanIrish avatar Jan 27 '21 14:01 DanRyanIrish