def show_residual(self, ci, psfmix, objmix=None): """ Show plots of the input compared with the fit gaussian mixtures. """ psfmodel = gmix_image.gmix2image(psfmix,ci.psf.shape, counts=ci.psf.sum()) images.compare_images(ci.psf,psfmodel, label1='psf',label2='gmix') if objmix is not None: skysig=None if ci['skysig'] > 0: skysig=ci['skysig'] model0 = gmix_image.gmix2image(objmix,ci.image0.shape, counts=ci.image0.sum()) model = gmix_image.gmix2image(objmix,ci.image.shape, psf=psfmix, counts=ci.image.sum()) images.compare_images(ci.image0,model0, label1='object0',label2='gmix', skysig=skysig) images.compare_images(ci.image,model, label1='object+psf',label2='gmix', skysig=skysig) stop
def make_images(self): import gmix_image self.psf = gmix_image.gmix2image(self.psf_gmix,self['dims'], nsub=self.nsub) self.image = gmix_image.gmix2image(self.obj_gmix,self['dims'], nsub=self.nsub) #self.image0 = gmix_image.gmix2image(self.obj0_gmix,self['dims'], # nsub=self.nsub) self.image0=None
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
def test(): import images dguess=[{'p':0.58,'row':15.,'col':15.,'irr':1.3,'irc':-0.05,'icc':1.16}, {'p':0.19,'row':15.,'col':15.,'irr':7.7,'irc':-0.23,'icc':6.8}] im=gmix_image.gmix2image(dguess, [31,31]) print 'counts:',im.sum() images.multiview(im)
def show(self): import images if hasattr(self.gm,'popt'): pars=self.gm.popt else: pars=self.gm.get_pars() model=gmix2image(pars,self.psf.shape, coellip=True) #print((model-self.psf).max()) #images.multiview(self.psf) #images.multiview(model) #model *= self['counts']/model.sum() images.compare_images(self.psf, model)
def process_image(self, image, ngauss, cen, cov, psf=None, coellip=False, cocenter=False, show=False): im=image.copy() # need no zero pixels and sky value im_min = im.min() if im_min <= 0: im -= im_min sky=0.001*im.max() im += sky else: sky = im_min # In the iteration, we can sometimes run into negative determinants. # we will retry a few times with different random offsets in that case flags = GMIXEM_ERROR_NEGATIVE_DET ntry=0 while flags == GMIXEM_ERROR_NEGATIVE_DET and ntry < self['max_retry']: guess = self.get_guess(ngauss, cen, cov) gm = gmix_image.GMixEM(im,guess, sky=sky, maxiter=self['gmix_maxiter'], tol=self['gmix_tol'], coellip=coellip, cocenter=cocenter, psf=psf, verbose=self['verbose']) flags = gm.flags #stderr.write("gmix niter: %d\n" % gm.numiter) ntry += 1 #stderr.write("ntry: %d " % ntry) out={'gmix': gm.pars, 'flags': gm.flags, 'numiter':gm.numiter, 'fdiff':gm.fdiff, 'ntry':ntry} if flags == 0 and show: print 'psf' pprint(psf) print 'gmix' pprint(out['gmix']) imrec=gmix_image.gmix2image(out['gmix'], image.shape, psf=psf,counts=image.sum()) images.compare_images(image,imrec, label1='image',label2='%d gauss' % ngauss) return out
def test_measure_image_width(fwhm=20.0, smooth=0.1, nsub=20, type='erf'): import gmix_image print 'testing type:',type sigma=fwhm/2.3548 dim=2*5*sigma if (dim % 2)==0: dim+=1 dims=[dim]*2 cen=[(dim-1)//2]*2 gm=gmix_image.GMix([1.0, cen[0], cen[1], sigma**2, 0.0, sigma**2]) im=gmix_image.gmix2image(gm, dims) if type=='erf': widths = measure_image_width(im, 0.5, smooth=smooth) else: widths = measure_image_width_interp(im, 0.5, nsub=nsub) print 'true:',fwhm print 'meas:',widths print 'meas/true-1:',widths/fwhm-1