Exemple #1
0
    def __init__(self, s2, objmodel, obj_ellip, psfmodel,
                 psf_ellip=0.0, Tratio_psf=None, fluxfrac1=None, 
                 psf_fwhm=10.0,  # in pixels.  4'' seeing in SDSS is this big
                 verbose=False):

        self.verbose=verbose
        self['s2'] = s2
        self['objmodel'] = objmodel
        self['obj_ellip'] = obj_ellip
        self['psfmodel'] = psfmodel
        
        if isinstance(psfmodel, (str,unicode)):
            self['psf_ellip'] = psf_ellip
            self['Tratio_psf'] = Tratio_psf
            self['fluxfrac1'] = fluxfrac1
            self['psf_fwhm'] = psf_fwhm
            self['Tpsf'] = admom.fwhm2mom(psf_fwhm)
        else:
            self['psf_ellip'] = None
            self['Tratio_psf'] = None
            self['fluxfrac1'] = None
            self['psf_fwhm'] = None
            self['Tpsf'] = None

        self['Irr_psf'] = None
        self['Irc_psf'] = None
        self['Icc_psf'] = None

        self.randomize()
Exemple #2
0
    def regauss_obj(self, obj, filter):
        import admom
        from sdsspy.atlas.atlas import NoAtlasImageError

        run = obj['run']
        camcol = obj['camcol']
        field = obj['field']
        id = obj['id']

        c = sdsspy.FILTERNUM[filter]


        self.cache_psf(run, camcol, field)

        try:
            self.cache_atlas(run, camcol, field, id)
        except NoAtlasImageError:
            # we can safely ignore such errors, but we return
            # nothing
            return None

        im = numpy.array( self.atls['images'][c], dtype='f8')
        im -= self.atls['SOFT_BIAS']


        rowc=obj['rowc'][c]
        colc=obj['colc'][c]
        row=rowc - self.atls['row0'][c] - 0.5
        col=colc - self.atls['col0'][c] - 0.5

        sigsky = self.psfield['skysig'][0,c]
        psf = self.psfKLs[c].rec(rowc, colc, trim=True)

        # sometimes we get very negative pixels, not sure why
        #im=im.clip(-3*sigsky, im.max())

        guess_psf=admom.fwhm2mom( obj['psf_fwhm'][c], pixscale=0.4)/2.
        guess = guess_psf
        if 'm_rr_cc' in obj.dtype.names:
            if obj['m_rr_cc'][c] > guess_psf:
                guess=obj['m_rr_cc'][c]/2

        rg = admom.ReGauss(im, row, col, psf, 
                           sigsky=sigsky, guess=guess, guess_psf=guess_psf,
                           verbose=self.verbose)
        rg.do_all() 

        # keep these things in case we want to call show()
        self.rg=rg
        self.im=im
        self.psf=psf

        return rg
Exemple #3
0
    def _measure_psf(self, obj):
        fnum = self["fnum"]
        rowc = obj["rowc"][fnum]
        colc = obj["colc"][fnum]

        psf_im = self.psf_kl[fnum].rec(rowc, colc, trim=True)
        psf_im = psf_im.astype("f8")

        guess_psf = admom.fwhm2mom(obj["psf_fwhm"][fnum], pixscale=0.4) / 2.0

        psf_res = self._fit_psf(psf_im, guess_psf, 1.0)

        return psf_res
Exemple #4
0
def admom_atlas(type, run, camcol, field, id, filter, 
                objs=None,
                show=False, showmin=0, **keys):
    """
    Objs must be for this camcol!
    """
    import admom
    import sdsspy

    c = sdsspy.FILTERNUM[filter]

    if objs is None:
        sc=SweepCache()
        obj = sc.readobj(type, run, camcol, field, id)
    else:
        w=where1( (objs['field'] == field) & (objs['id'] == id) )
        if w.size == 0:
            raise ValueError("Object not found objs: "
                             "%06i-%i-%04i" % (run,camcol,id))
        obj = objs[w[0]]

    atls = sdsspy.read('fpAtlas',run,camcol,field,id, trim=True)
    im = numpy.array( atls['images'][c], dtype='f8') - atls['SOFT_BIAS']

    psfield = sdsspy.read('psField', run, camcol, field, lower=True)

    rowc=obj['rowc'][c]
    colc=obj['colc'][c]

    row=rowc - atls['row0'][c] - 0.5
    col=colc - atls['col0'][c] - 0.5

    sigsky = psfield['skysig'][0,c]
    Tguess_psf=admom.fwhm2mom( obj['psf_fwhm'][c], pixscale=0.4)
    if obj['m_rr_cc'][c] > Tguess_psf:
        Tguess=obj['m_rr_cc'][c]
    else:
        Tguess=Tguess_psf

    out = admom.admom(im,
                      row, 
                      col, 
                      sky=0.0,
                      sigsky=sigsky,
                      Tguess=Tguess)

    if show:
        import fimage
        import biggles
        plt=images.view(im, min=showmin, show=False, **keys)

        if out['whyflag'] == 0:
            levels=7

            wrow = out['wrow']
            wcol = out['wcol']

            model = fimage.model_image('gauss',
                                       im.shape,
                                       [wrow,wcol],
                                       [out['Irr'],out['Irc'],out['Icc']],
                                       counts=im.sum())


            cmod = biggles.Contours(model.transpose(), color='grey')
            cmod.levels = levels
            plt.add(cmod)
        plt.show()

    return out