Ejemplo n.º 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
Ejemplo n.º 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
Ejemplo n.º 3
0
 def _get_meds_image(self, meds, mindex, icut):
     """
     Get an image cutout from the input MEDS file
     """
     im = meds.get_cutout(mindex, icut)
     im = im.astype("f8", copy=False)
     return im
Ejemplo n.º 4
0
    def _get_meds_noise(self, meds, mindex, icut):
        if 'noise_cutouts' in meds._fits:
            nimage = meds.get_cutout(mindex, icut, type='noise')
        else:
            nimage = None

        return nimage
Ejemplo n.º 5
0
    def _get_meds_bmask(self, meds, mindex, icut):
        """
        Get an image cutout from the input MEDS file
        """
        maxfrac=self.conf['max_bmask_frac']
        skip=False

        if 'bmask_cutouts' in meds._fits:
            bmask=meds.get_cutout(mindex, icut, type='bmask')
            bmask=numpy.array(bmask, dtype='i4', copy=False)

            if self.conf['symmetrize_bmask']:
                if bmask.shape[0] == bmask.shape[1]:
                    borig=bmask.copy()
                    rotmask=numpy.rot90(bmask)
                    bmask |= rotmask
                else:
                    raise RuntimeError("cannot symmetrize non-square bmask")

            w=numpy.where(bmask != 0)

            notok=self._badfrac_too_high(
                icut, w[0].size, bmask.shape, maxfrac, 'bmask'
            )
            if notok:
                skip=True
                return None,skip

            if 'bmask_skip_flags' in self.conf:
                w=numpy.where( (bmask & self.conf['bmask_skip_flags']) != 0)
                if w[0].size > 0:
                    print("    skipping cutout",icut,
                          "because mask bits set:",
                          self.conf['bmask_skip_flags'])
                    skip=True
                    return None,skip

            if 'central_bmask_radius' in self.conf:
                rad=self.conf['central_bmask_radius']
                if rad is not None:
                    row0 = meds['cutout_row'][mindex,icut]
                    col0 = meds['cutout_col'][mindex,icut]

                    row_start = _clip_pixel(row0-rad, bmask.shape[0])
                    row_end   = _clip_pixel(row0+rad, bmask.shape[0])
                    col_start = _clip_pixel(col0-rad, bmask.shape[1])
                    col_end   = _clip_pixel(col0+rad, bmask.shape[1])

                    bmask_sub = bmask[row_start:row_end,
                                      col_start:col_end]
                    wcen=numpy.where(bmask_sub != 0)
                    if wcen[0].size > 0:
                        print("    skipping cutout",icut,"due center masked")
                        skip=True
                        return None,skip

        else:
            bmask=None

        return bmask, skip
Ejemplo n.º 6
0
    def _get_meds_image(self, meds, mindex, icut):
        """
        Get an image cutout from the input MEDS file
        """
        try:
            self.imname = os.path.basename(meds.get_source_path(mindex, icut))
        except IndexError:
            self.imname = ''

        return meds.get_cutout(mindex, icut)
Ejemplo n.º 7
0
    def _get_meds_image(self, meds, mindex, icut):
        """
        Get an image cutout from the input MEDS file
        """
        try:
            self.imname= os.path.basename(meds.get_source_path(mindex,icut))
        except IndexError:
            self.imname=''

        return meds.get_cutout(mindex, icut)
Ejemplo n.º 8
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