code: def restrictCatalogToObservableSpaceMMD(self, catalog):
          
  
          # ADW: This creates a slope in color-magnitude space near the magnitude limit
          # i.e., if color=g-r then you can't have an object with g-r=1 and mag_r > mask_r-1
          # Depending on which is the detection band, this slope will appear at blue
          # or red colors. When it occurs at blue colors, it effects very few objects.
          # However, when occuring for red objects it can cut many objects. It is 
          # unclear that this is being correctly accounted for in the likelihood
  
          catalog.spatialBin(self.roi)
          sel_roi = (catalog.pixel_roi_index >= 0) # Objects outside ROI have pixel_roi_index of -1
          sel_mag_1 = catalog.mag_1 < self.mask_1.mask_roi_sparse[catalog.pixel_roi_index]
          sel_mag_2 = catalog.mag_2 < self.mask_2.mask_roi_sparse[catalog.pixel_roi_index]
  
          # and are located in the region of mag-mag space where background can be estimated
          sel_mmd = ugali.utils.binning.take2D(self.solid_angle_mmd,
                                               catalog.mag_2, catalog.mag_1,
                                               self.roi.bins_mag, self.roi.bins_mag) > 0.
  
          sel = np.all([sel_roi,sel_mag_1,sel_mag_2,sel_mmd], axis=0)
          return sel
docs: Retain only the catalog objects which fall within the observable (i.e., unmasked) space.
  
          Parameters:
          catalog: a Catalog object
          Returns:
          sel    : boolean selection array where True means the object would be observable (i.e., unmasked).
  
          ADW: Careful, this function is fragile! The selection here should
               be the same as isochrone.observableFraction space. However,
               for technical reasons it is faster to do the calculation with
               broadcasting there.