Exemplo n.º 1
0
    def get_normalized_model(self):
        """
        For jacobian models

        Fit for a flux then run the ydiff on it
        """
        from gmix_image.gmix_fit import GMixFitMultiPSFFlux
        from . import _render

        if self.jacobian is None:
            raise ValueError("only works for jacobian")

        imlist = [self.image0]
        wtlist = [self.image0 * 0 + self.ivar]
        jacoblist = [self.jacobian]
        gmix_list = [self.get_gmix()]

        gm = GMixFitMultiPSFFlux(imlist, wtlist, jacoblist, gmix_list)

        res = gm.get_result()

        gmix = self.get_gmix()

        gmix.set_psum(res["F"])

        model = gmix_image.gmix2image(gmix, self.image0.shape, jacob=self.jacobian)
        return model
Exemplo n.º 2
0
    def _fit_psf_flux(self, dindex, sdata):
        if self.debug:
            print >>stderr,'\tfitting psf flux'

        cen_prior=None
        if self.use_cenprior:
            cen_prior=CenPrior([0.0]*2, [self.cen_width]*2)

        gm=GMixFitMultiPSFFlux(sdata['imlist'],
                               sdata['wtlist'],
                               sdata['jacob_list'],
                               sdata['psf_gmix_list'],
                               cen_prior=cen_prior,
                               lm_max_try=self.obj_ntry)
        res=gm.get_result()
        self.data['psf_flags'][dindex] = res['flags']
        self.data['psf_iter'][dindex] = res['numiter']
        self.data['psf_tries'][dindex] = res['ntry']

        if res['flags']==0:
            self.data['psf_pars'][dindex,:]=res['pars']
            self.data['psf_pars_cov'][dindex,:,:] = res['pcov']

            flux=res['pars'][2]
            flux_err=sqrt(res['pcov'][2,2])
            self.data['psf_flux'][dindex] = flux
            self.data['psf_flux_err'][dindex] = flux_err
            self.data['psf_flux_s2n'][dindex] = flux/flux_err

            print >>stderr,'    psf_flux: %g +/- %g' % (flux,flux_err)

            n=get_model_names('psf')
            for sn in _stat_names:
                self.data[n[sn]][dindex] = res[sn]

            if self.debug:
                fmt='\t\t%s: %g +/- %g'
                print >>stderr,fmt % ('psf_flux',flux,flux_err)