示例#1
0
    def make_psf_stats(self):
        """
        Either generate moments from inputs or read an SDSS PSF
        """
        psfmodel = self['psfmodel']
        if isinstance(psfmodel, (str,unicode)):
            # generate a random orientation
            theta = 360.0*numpy.random.random()
            Irr, Irc, Icc = admom.ellip2mom(self['Tpsf'], e=self['psf_ellip'], theta=theta)
            self['Irr_psf'] = Irr
            self['Irc_psf'] = Irc
            self['Icc_psf'] = Icc
            self.psf = None
        else:
            # this is a psf generator.  We assume the psf has the center at
            # the image middle, is normalized
            psf = psfmodel.next()
            cen = [(psf.shape[0]-1)/2., (psf.shape[1]-1)/2.]
            out = admom.admom(psf, cen[0], cen[1])

            if out['whyflag'] != 0:
                raise RuntimeError("failure measuring psf admom")
            self.psf=psf
            self['Irr_psf'] = out['Irr']
            self['Irc_psf'] = out['Irc']
            self['Icc_psf'] = out['Icc']
            self['Tpsf'] = out['Irr'] + out['Icc']
示例#2
0
    def make_object_stats(self):
        """
        Generate moments for object from the inputs before convolution
        """

        Tobj = self['Tpsf']/self['s2']

        theta = 360.0*numpy.random.random()
        Irr, Irc, Icc = admom.ellip2mom(Tobj, e=self['obj_ellip'], theta=theta)
        self['Irr'] = Irr
        self['Irc'] = Irc
        self['Icc'] = Icc
示例#3
0
文件: regauss.py 项目: esheldon/admom
def test_regauss(gal_model='gauss',
                 gal_T=16.0,
                 gal_e1=0.0,
                 gal_e2=0.0,
                 psf_T=4.0,
                 psf_e1=0.0,
                 psf_e2=0.0,
                 show=True):

    from pprint import pprint
    import fimage
    import scipy.signal

    nsigma=5

    psf_sigma=numpy.sqrt(psf_T/2.)
    psf_imsize = int( round(2*nsigma*psf_sigma) )
    if (psf_imsize % 2) == 0:
        psf_imsize+=1

    psf_dims=[psf_imsize]*2
    psf_cen=[(psf_imsize-1)/2.]*2
    psf_moms = admom.ellip2mom(psf_T,e1=psf_e1,e2=psf_e2)
    psf = fimage.model_image('gauss', 
                             psf_dims,
                             psf_cen,
                             psf_moms,
                             nsub=16)

    gal_moms = admom.ellip2mom(gal_T,e1=gal_e1,e2=gal_e2)


    # for the image size, make it big enough to easily fit
    # the *convolved* galaxy
    gal_convolved_sigma = admom.mom2sigma(gal_T+psf_T)
    gal_imsize = int( round(2*nsigma*gal_convolved_sigma) )
    if gal_imsize < psf_imsize:
        gal_imsize = psf_imsize

    gal_cen  = [ (gal_imsize-1)/2. ]*2
    gal_dims = [int(gal_imsize)]*2

    gal = fimage.model_image(gal_model,
                             gal_dims,
                             gal_cen,
                             gal_moms,
                             nsub=16)

    levels=7

    # now convolve with the PSF
    imconv = scipy.signal.fftconvolve(gal, psf, mode='same')

    if show:
        import images
        images.multiview(psf, levels=levels)
        images.multiview(gal, levels=levels)
        images.multiview(imconv, levels=levels)

    rg = ReGauss(imconv, gal_cen[0], gal_cen[1], psf, guess=gal_T/2, guess_psf=psf_T/2)

    rg.do_admom()
    print("admom stats")
    pprint(rg['imstats'])
    rg.do_psf_admom()
    print("psf admom stats")
    pprint(rg['psfstats'])
    rg.do_basic_corr()
    print("admom corrected stats")
    pprint(rg['corrstats'])
    rg.do_regauss()
    print("rg stats")
    pprint(rg['rgstats'])
    rg.do_rg_corr()
    print("rg corrected stats")
    pprint(rg['rgcorrstats'])