code: def create_mask(self):
          
          ntags = len(self._drawn_tags)
  
          if ntags == 0:
              return
  
          old_image = self.fitsimage.get_image()
  
          if old_image is None:
              return
  
          mask = None
          obj_kinds = set()
  
          # Create mask
          for tag in self._drawn_tags:
              obj = self.canvas.get_object_by_tag(tag)
  
              try:
                  cur_mask = old_image.get_shape_mask(obj)
              except Exception as e:
                  self.logger.error('Cannot create mask: {0}'.format(str(e)))
                  continue
  
              if mask is not None:
                  mask |= cur_mask
              else:
                  mask = cur_mask
  
              obj_kinds.add(obj.kind)
  
          # Might be useful to inherit header from displayed image (e.g., WCS)
          # but the displayed image should not be modified.
          # Bool needs to be converted to int so FITS writer would not crash.
          image = dp.make_image(mask.astype('int16'), old_image, {},
                                pfx=self._mask_prefix)
          imname = image.get('name')
  
          # Insert new image
          self.fv.gui_call(self.fv.add_image, imname, image, chname=self.chname)
  
          # Add description to ChangeHistory
          s = 'Mask created from {0} drawings ({1})'.format(
              ntags, ','.join(sorted(obj_kinds)))
          info = dict(time_modified=datetime.utcnow(), reason_modified=s)
          self.fv.update_image_info(image, info)
          self.logger.info(s)
docs: Create boolean mask from drawing.
  
          All areas enclosed by all the shapes drawn will be set to 1 (True)
          in the mask. Otherwise, the values will be set to 0 (False).
          The mask will be inserted as a new image buffer, like ``Mosaic``.