Exemple #1
0
    def _get_multi_band_observations(self, mindex):
        """
        Get an ObsList object for the Coadd observations
        Get a MultiBandObsList object for the SE observations.
        """

        coadd_mb_obs_list = MultiBandObsList()
        mb_obs_list = MultiBandObsList()

        for band in self.iband:
            cobs_list, obs_list = self._get_band_observations(band, mindex)
            coadd_mb_obs_list.append(cobs_list)
            mb_obs_list.append(obs_list)

        meta_row = self._get_meta_row()
        meta_row["id"][0] = self.meds_list[0]["id"][mindex]
        meta_row["number"][0] = self.meds_list[0]["number"][mindex]
        meta_row["nimage_tot"][0, :] = numpy.array(
            [self.meds_list[b]["ncutout"][mindex] - 1 for b in xrange(self.conf["nband"])], dtype="i4"
        )
        meta = {"meta_data": meta_row, "meds_index": mindex, "id": self.meds_list[0]["id"][mindex], "obj_flags": 0}

        coadd_mb_obs_list.update_meta_data(meta)
        mb_obs_list.update_meta_data(meta)

        return coadd_mb_obs_list, mb_obs_list
Exemple #2
0
    def get_mb_obs_list(self, index):
        """
        raise MissingFit if any bands missing or no cutouts
        """
        mbo=MultiBandObsList()

        rev=self.rev_number

        ncut=self.h_number[index]
        print("    number:",index+1,"total cutouts:",ncut)

        i=index
        if rev[i] != rev[i+1]:
            w=rev[ rev[i]:rev[i+1] ]

            ed=self.epoch_data[w]

            for band in xrange(self.nband):
                obslist=self.get_band_obslist(index, band, ed)

                mbo.append( obslist )
        else:
            raise MissingFit("band missing")

        return mbo
Exemple #3
0
    def get_round_mbo(self, index, mbo, model):
        """
        get round observations, with simulated
        galaxy images
        """
        new_mbo = MultiBandObsList()

        bpars=zeros(6)

        n=Namer(model)
        pname=n(self.pname)
        pars=self.model_fits[pname][index].copy()

        if self['use_logpars']:
            pars[4:] = exp(pars[4:])

        for band in xrange(self.nband):
            bpars[0:5] = pars[0:5] 
            bpars[5] = pars[5+band]
            obslist=mbo[band]

            new_obslist = self.get_round_band_obslist(bpars,model,obslist)

            new_mbo.append( new_obslist )

        factor=ngmix.shape.get_round_factor(pars[2], pars[3])
        Tround = pars[4]*factor

        pars_round=pars.copy()
        pars_round[2]=0.0
        pars_round[3]=0.0
        pars_round[4]=Tround

        return new_mbo, pars_round
Exemple #4
0
    def _trim_images(self, mbo_input, censky):
        """
        cen in sky coords, relative to jacobian
        center
        """

        mbo = MultiBandObsList()
        for obslist in mbo_input:

            new_obslist=ObsList()
            for obs in obslist:

                j=obs.jacobian
                scale=j.get_scale()
                cenpix=array( j.get_cen() )

                new_cen = cenpix + censky/scale
                #print("cen0:",cenpix,"newcen:",new_cen)

                new_im=_trim_image(obs.image, new_cen)
                new_wt=_trim_image(obs.weight, new_cen)
                new_j = j.copy()
                new_j.set_cen(row=new_cen[0], col=new_cen[1])

                newobs = Observation(
                    new_im,
                    weight=new_wt,
                    jacobian=new_j,
                    psf=obs.psf,
                )

                new_obslist.append( newobs )
            mbo.append( new_obslist )

        return mbo
Exemple #5
0
    def _get_multi_band_observations(self, mindex):
        """
        Get an ObsList object for the Coadd observations
        Get a MultiBandObsList object for the SE observations.
        """

        coadd_mb_obs_list=MultiBandObsList()
        mb_obs_list=MultiBandObsList()

        for band in self.iband:
            cobs_list, obs_list = self._get_band_observations(band, mindex)
            coadd_mb_obs_list.append(cobs_list)
            mb_obs_list.append(obs_list)

        meta_row = self._get_meta_row()
        meta_row['id'][0] = self.meds_list[0]['id'][mindex]
        meta_row['number'][0] = self.meds_list[0]['number'][mindex]

        # to account for max_cutouts limit, we count the actual number
        #meta_row['nimage_tot'][0,:] = numpy.array([self.meds_list[b]['ncutout'][mindex]-1 for b in xrange(self.conf['nband'])],dtype='i4')
        meta_row['nimage_tot'][0,:] = numpy.array([len(mb_obs_list[b]) for b in xrange(self.conf['nband'])],dtype='i4')

        meta = {'meta_data':meta_row,'meds_index':mindex,'id':self.meds_list[0]['id'][mindex],'obj_flags':0}

        coadd_mb_obs_list.update_meta_data(meta)
        mb_obs_list.update_meta_data(meta)

        return coadd_mb_obs_list, mb_obs_list
Exemple #6
0
    def _check_flags(self, mbobs):
        flags = self['metacal'].get('bmask_flags', None)
        passed_flags = True
        _mbobs = None

        if flags is not None:
            _mbobs = MultiBandObsList()
            _mbobs.update_meta_data(mbobs.meta)
            for obslist in mbobs:
                _obslist = ObsList()
                _obslist.update_meta_data(obslist.meta)

                for obs in obslist:
                    msk = (obs.bmask & flags) != 0
                    if np.any(msk):
                        logger.info("   EDGE HIT")
                    else:
                        _obslist.append(obs)
                        passed_flags = True

                _mbobs.append(_obslist)

            # all bands have to have at least one obs
            for ol in _mbobs:
                if len(ol) == 0:
                    passed_flags = False

        return passed_flags, _mbobs
Exemple #7
0
def _strip_coadd(mbobs):
    _mbobs = MultiBandObsList()
    _mbobs.update_meta_data(mbobs.meta)
    for ol in mbobs:
        _ol = ObsList()
        _ol.update_meta_data(ol.meta)
        for i in range(1, len(ol)):
            _ol.append(ol[i])
        _mbobs.append(_ol)
    return _mbobs
Exemple #8
0
def _strip_zero_flux(mbobs):
    _mbobs = MultiBandObsList()
    _mbobs.update_meta_data(mbobs.meta)
    for ol in mbobs:
        _ol = ObsList()
        _ol.update_meta_data(ol.meta)
        for i in range(len(ol)):
            if np.sum(ol[i].image) > 0:
                _ol.append(ol[i])
        _mbobs.append(_ol)
    return _mbobs
Exemple #9
0
 def _get_good_mb_obs_list(self, mb_obs_list):
     new_mb_obs_list = MultiBandObsList()
     for obs_list in mb_obs_list:
         new_obs_list = ObsList()
         for obs in obs_list:
             if obs.meta['flags'] == 0:
                 new_obs_list.append(obs)
         new_mb_obs_list.append(new_obs_list)
     new_mb_obs_list.update_meta_data(mb_obs_list.meta)
     new_mb_obs_list.update_meta_data({'old_mb_obs_list': mb_obs_list})
     return new_mb_obs_list
Exemple #10
0
def mbobs():
    mbobs = MultiBandObsList()
    for i in range(3):
        ol = ObsList()
        for j in range(4):
            o = Observation(image=np.ones((32, 32)) * (j + 1),
                            weight=np.ones((32, 32)) * (j + 1),
                            jacobian=ngmix.DiagonalJacobian(scale=0.25,
                                                            row=0,
                                                            col=0))
            ol.append(o)
        mbobs.append(ol)
    return mbobs
Exemple #11
0
    def _make_mbobs(im, cen):
        dx = cen[0] - int(cen[0] + 0.5)
        dy = cen[1] - int(cen[1] + 0.5)
        xlow = int(int(cen[0] + 0.5) - nstamp_cen)
        ylow = int(int(cen[1] + 0.5) - nstamp_cen)
        _im = im[ylow:ylow + nstamp, xlow:xlow + nstamp]
        jac = DiagonalJacobian(
            scale=wcs.scale,
            x=nstamp_cen + dx,
            y=nstamp_cen + dy,
        )

        obs = Observation(image=_im,
                          jacobian=jac,
                          psf=psf_obs,
                          weight=np.ones_like(_im),
                          noise=rng.normal(size=_im.shape) * noise)
        mbobs = MultiBandObsList()
        obsl = ObsList()
        obsl.append(obs)
        mbobs.append(obsl)
        return mbobs
Exemple #12
0
def get_model_obs(
    *, rng, model,
    noise=0.0,
    psf_model='turb',
    psf_noise=1.0e-6,
    set_psf_gmix=False,
    set_templates=False,
    set_psf_templates=False,
    nepoch=None, nband=None,
    star=False,
):

    if nband is not None:
        do_mbobs = True
        if nepoch is None:
            nepoch = 1
    else:
        do_mbobs = False
        nband = 1

    if nepoch is not None:
        do_obslist = True
    else:
        do_obslist = False
        nepoch = 1

    if star:
        T = 0.0
    else:
        T = 0.27

    g1 = 0.1
    g2 = 0.05
    flux = 100.0
    off = 0.5

    # not offset from the jacobian center
    pars = [0.0, 0.0, g1, g2, T] + [flux]*nband
    gm = GMixModel(pars[0:6], model)

    mbobs = MultiBandObsList()
    for iband in range(nband):
        obslist = ObsList()
        for i in range(nepoch):

            off1_pix, off2_pix = rng.uniform(low=-off, high=off, size=2)
            dims = [32, 32]
            jcen = (np.array(dims) - 1.0) / 2.0
            jacob = DiagonalJacobian(
                scale=PIXEL_SCALE,
                row=jcen[0] + off1_pix,
                col=jcen[1] + off2_pix,
            )

            psf_ret = get_psf_obs(rng=rng, model=psf_model, noise=psf_noise)
            if set_psf_gmix:
                psf_ret['obs'].set_gmix(psf_ret['gmix'])

            if set_psf_templates:
                psf_ret['obs'].template = psf_ret['gmix'].make_image(
                    dims,
                    jacobian=jacob,
                )

            gmconv = gm.convolve(psf_ret['gmix'])

            im0 = gmconv.make_image(dims, jacobian=jacob)

            im = im0 + rng.normal(size=im0.shape, scale=noise)
            if noise == 0.0:
                weight = im*0 + 1.0/1.0e-12
            else:
                weight = im*0 + 1.0/noise**2

            obs = Observation(
                im,
                weight=weight,
                jacobian=jacob,
                psf=psf_ret['obs'],
            )

            if set_templates:
                obs.template = im0

            obslist.append(obs)

        mbobs.append(obslist)

    ret = {
        'gmix': gm,
        'pars': pars,
        'psf_data': psf_ret,
    }

    if do_mbobs:
        ret['obs'] = mbobs
    else:
        obslist = mbobs[0]
        if not do_obslist:
            obs = obslist[0]
            ret['obs'] = obs
        else:
            ret['obs'] = obslist

    return ret