Example #1
0
    def _get_meds_weight(self, meds, mindex, icut):
        """
        Get a weight map from the input MEDS file
        """
        maxfrac=self.conf['max_zero_weight_frac']
        skip=False

        wt_raw = meds.get_cutout(mindex, icut, type='weight')
        if self.conf['region'] == 'mof':
            wt=wt_raw.copy()
            wt_us = meds.get_cweight_cutout_nearest(mindex, icut)
        elif self.conf['region'] == "cweight-nearest":
            wt = meds.get_cweight_cutout_nearest(mindex, icut)
            wt_us = None
        elif self.conf['region'] == 'seg_and_sky':
            wt=meds.get_cweight_cutout(mindex, icut)
            wt_us = None
        elif self.conf['region'] == 'weight':
            wt=wt_raw.copy()
            wt_us = None
        else:
            raise ValueError("no support for region type %s" % self.conf['region'])

        wt = self._clip_weight(wt)
        wt_raw = self._clip_weight(wt_raw)
        if wt_us is not None:
            wt_us = self._clip_weight(wt_us)

        try:
            seg = meds.interpolate_coadd_seg(mindex, icut)
        except:
            seg = meds.get_cutout(mindex, icut, type='seg')


        '''
        if self.conf['symmetrize_weight']:
            raise RuntimeError("this is bogus!  Need to zero the map not add")
            wt     = wt     + numpy.rot90(wt)
            wt_raw = wt_raw + numpy.rot90(wt_raw)

            if wt_us is not None:
                wt_us  = wt_us  + numpy.rot90(wt_us)
        '''

        # check raw weight map for zero pixels
        wzero=numpy.where(wt_raw == 0.0)

        notok=self._badfrac_too_high(
            icut, wzero[0].size, wt_raw.shape, maxfrac, 'zero weight'
        )
        if notok:
            skip=True

        return wt,wt_us,wt_raw,seg, skip
Example #2
0
    def _get_meds_weight(self, band, meds, mindex, icut, bmask):
        """
        Get a weight map from the input MEDS file
        """

        conf = self.conf

        maxfrac = conf['max_zero_weight_frac']
        skip = False

        wt_raw = meds.get_cutout(mindex, icut, type='weight')
        if conf['region'] == 'mof':
            wt = wt_raw.copy()
            wt_us = meds.get_uberseg(mindex, icut)
        elif conf['region'] in ["cweight-nearest", "uberseg"]:
            wt = meds.get_uberseg(mindex, icut)
            wt_us = None
        elif conf['region'] == 'seg_and_sky':
            wt = meds.get_cweight_cutout(mindex, icut)
            wt_us = None
        elif conf['region'] == 'weight':
            wt = wt_raw.copy()
            wt_us = None
        else:
            raise ValueError("no support for region type %s" % conf['region'])

        if conf['extra_mask_flags'] is not None:
            self._zero_weights_for_flagged_pixels(wt, wt_us, bmask)

        try:
            seg = meds.interpolate_coadd_seg(mindex, icut)
        except:
            seg = meds.get_cutout(mindex, icut, type='seg')

        # note this happens *after* we zero according to bmask flags
        # see above extra_mask_flags

        if conf['symmetrize_weight']:
            self._symmetrize_weight_images(wt_raw, wt, wt_us)

        # check raw (possibly symmetrized) weight map for zero pixels
        wzero = numpy.where(wt_raw == 0.0)

        notok = self._badfrac_too_high(band, icut, wzero[0].size, wt_raw.shape,
                                       maxfrac, 'zero weight')
        if notok:
            skip = True

        return wt, wt_us, wt_raw, seg, skip
Example #3
0
    def _get_meds_weight(self, meds, mindex, icut):
        """
        Get a weight map from the input MEDS file
        """

        if self.conf["region"] == "mof":
            wt = meds.get_cutout(mindex, icut, type="weight")
            wt_us = meds.get_cweight_cutout_nearest(mindex, icut)
        elif self.conf["region"] == "cweight-nearest":
            wt = meds.get_cweight_cutout_nearest(mindex, icut)
            wt_us = None
        elif self.conf["region"] == "seg_and_sky":
            wt = meds.get_cweight_cutout(mindex, icut)
            wt_us = None
        elif self.conf["region"] == "weight":
            wt = meds.get_cutout(mindex, icut, type="weight")
            wt_us = None
        else:
            raise ValueError("no support for region type %s" % self.conf["region"])

        wt = wt.astype("f8", copy=False)
        w = numpy.where(wt < self.conf["min_weight"])
        if w[0].size > 0:
            wt[w] = 0.0

        if wt_us is not None:
            wt_us = wt_us.astype("f8", copy=False)
            w = numpy.where(wt_us < self.conf["min_weight"])
            if w[0].size > 0:
                wt_us[w] = 0.0

        try:
            seg = meds.interpolate_coadd_seg(mindex, icut)
        except:
            seg = meds.get_cutout(mindex, icut, type="seg")

        return wt, wt_us, seg