예제 #1
0
    def plot(self, type, Rmin=0.0, show=True, yrange=None, dotitle=False, 
             reduce_plot_key=True):
        """
        Send Rmin to limit the plotted R values
        if too many s2 use reduce_plot_key=False
        """
        pfile = self.plotfile(self['run'],
                              self['objmodel'],
                              self['psfmodel'], 
                              type,
                              Rmin=Rmin,
                              yrange=yrange, 
                              dotitle=dotitle)

        if 'R_rg' in self.alldata[0].dtype.names:
            print("using R_rg")
            rname = 'R_rg'
        else:
            rname = 'R'
        #rname='R'
        keepdata = []
        for st in self.alldata:
            if numpy.median(st[rname]) > Rmin:
                keepdata.append(st)


        #keepdata = self.alldata
        ndata = len(keepdata)
        colors=pcolors.rainbow(ndata, 'hex')

        biggles.configure('PlotKey','key_vsep',1.0)
        plt = biggles.FramedPlot()
        plt.aspect_ratio=1
        plt.xlabel='object ellipticity'
        plt.ylabel=r'$\Delta \gamma/\gamma$'

        allplots=[]
        i=0
        for st in reversed(keepdata):
            # this s2 is the value we were aiming for, could be pretty
            # far off for some models
            """
            if 's2noweight' in st.dtype.names:
                s2 = st['s2noweight'][0]
            else:
                s2 = st['s2'][0]
            """
            s2 = numpy.median(st['s2admom'])
            #s2 = numpy.median(st['s2noweight'])
            #s2 = st['s2'][0]

            # this "etrue" is adaptive moments of pre-psf image
            s = st['etrue'].argsort()
            etrue = st['etrue'][s]

            if type == 'regauss':
                emeas = st['ecorr_rg'][s]
            elif type == 'am+':
                emeas = st['ecorr'][s]
            elif type == 'noweight':
                emeas = st['ecorr_uw'][s]
            else:
                raise ValueError("type should be 'regauss','am+', or 'noweight'")

            gamma_frac_rg = shear_fracdiff(etrue, emeas, deriv=1.0)

            Rmean = numpy.median( st[rname] )

            label = '%0.3f (%0.3f)' % (s2,Rmean)

            crg = biggles.Curve(etrue, gamma_frac_rg, color=colors[i])
            crg.label=label

            plt.add(crg)
            
            allplots.append(crg)
            i += 1

        if dotitle:
            title='obj: %s psf: %s run: %s' \
                    % (self['objmodel'],self['psfmodel'],self['run'])

            if 'forcegauss' in self.config:
                if self.config['forcegauss']:
                    title += ' forcegauss'
            plt.title=title


        fsize=1.5
        if not reduce_plot_key:
            key = biggles.PlotKey(0.9,0.9, allplots, halign='right', fontsize=fsize)
        else:
            # pick a few
            nplot=len(allplots)
            tplots = [allplots[0], 
                      allplots[nplot*1/4], 
                      allplots[nplot/2], 
                      allplots[nplot*3/4], 
                      allplots[-1]]
            key = biggles.PlotKey(0.9,0.9, tplots, halign='right', fontsize=fsize)

        plt.add(key)

        klabtext=r'$<\sigma^2_{psf}/\sigma^2_{gal}> (<R>)$'
        klab = biggles.PlotLabel(0.90,0.95,klabtext,
                                 fontsize=1.5,halign='right')
        plt.add(klab)


        plab='%s %s %s' % (type,self['objmodel'],self['psfmodel'])
        l = biggles.PlotLabel(0.1,0.9, plab, halign='left')
        plt.add(l)

        siglab=r'$\sigma_{PSF}: %.1f$ pix' % self['psf_sigma']
        if 's2n' in self.config:
            siglab+=r'$ S/N: %(s2n)d N_{trial}: %(ntrial)d$' % self.config
        elif 'ntrial' in self.config:
            siglab+=r'$  N_{trial}: %(ntrial)d$' % self.config
        sl = biggles.PlotLabel(0.075,0.1, siglab, halign='left',fontsize=2.5)
        plt.add(sl)

        if not reduce_plot_key:
            plt.xrange = [0,1.4]
        if yrange is not None:
            plt.yrange = yrange
        print("Writing plot file:",pfile)
        if show:
            plt.show()
        plt.write_eps(pfile)
        converter.convert(pfile,dpi=100,verbose=True)
예제 #2
0
    def plot_with_alt(self, alt, Rmin=0.0, show=True, yrange=None, dotitle=False):
        '''
        Plot the regauss with another for comparison, e.g. noweight or AM+
        '''
        pfile = self.plotfile(self['run'],
                              self['objmodel'],
                              self['psfmodel'], 
                              'regauss-'+alt,
                              alt=alt, Rmin=Rmin, yrange=yrange,
                              dotitle=dotitle)

        keepdata = []
        for st in self.alldata:
            if numpy.median(st['R']) > Rmin:
                keepdata.append(st)


        #keepdata = self.alldata
        ndata = len(keepdata)
        colors=pcolors.rainbow(ndata, 'hex')

        allplots=[]
        i=0
        for st in keepdata:
            # this s2 is the value we were aiming for, could be pretty
            # far off for some models
            if 's2noweight' in st.dtype.names:
                s2 = st['s2noweight'][0]
            else:
                s2 = st['s2'][0]

            # this "etrue" is adaptive moments of pre-psf image
            s = st['etrue'].argsort()
            etrue = st['etrue'][s]

            # the top plot will be the regular analytic correction or the
            # unweighted correction. 
            if alt == 'noweight':
                gamma_frac_alt = shear_fracdiff(etrue, st['ecorr_uw'][s])
            elif alt == 'am+':
                gamma_frac_alt = shear_fracdiff(etrue, st['ecorr'][s])
            else:
                raise ValueError("alt should be am+ or noweight")

            gamma_frac_rg = shear_fracdiff(etrue, st['ecorr_rg'][s])

            Rmean = numpy.median( st['R'] )

            if Rmean >= Rmin:
                pdict={}
                label = 's2: %0.3f R: %0.3f' % (s2,Rmean)

                calt = biggles.Curve(etrue, gamma_frac_alt, color=colors[i])
                calt.label = label 
                pdict['calt'] = calt

                crg = biggles.Curve(etrue, gamma_frac_rg, color=colors[i])
                crg.label=label
                pdict['crg'] = crg
                
                allplots.append(pdict)
                i += 1

        conv=self.config.get('sim_conv', 'analytic')
        if dotitle:
            title='obj: %s psf: %s run: %s' \
                    % (self['objmodel'],self['psfmodel'],self['run'])

            if 'forcegauss' in self.config:
                if self.config['forcegauss']:
                    title += ' forcegauss'
        else:
            title=None

        arr=biggles.FramedArray(2,1, title=title)
        arr.xlabel='object ellipticity'
        arr.ylabel=r'$\Delta \gamma/\gamma$'


        allc1 = []
        allc2 = []
        i=0
        for p in allplots:
            arr[0,0].add( p['calt'] )
            arr[1,0].add( p['crg'] )
            if i < (ndata//2):
                allc1.append(p['calt'])
            else:
                allc2.append(p['calt'])
            i+=1

        fsize=2
        key1 = biggles.PlotKey(0.95,0.9, allc1, halign='right', fontsize=fsize)
        arr[0,0].add(key1)
        key2 = biggles.PlotKey(0.95,0.9, allc2, halign='right', fontsize=fsize)
        arr[1,0].add(key2)

        if alt == 'noweight':
            l1 = biggles.PlotLabel(0.1,0.9,'UnWeighted', halign='left')
        else:
            l1 = biggles.PlotLabel(0.1,0.9,'AM+', halign='left')
        l2 = biggles.PlotLabel(0.1,0.9,'ReGauss',  halign='left')
        arr[0,0].add(l1)
        arr[1,0].add(l2)

        arr.uniform_limits = 1

        arr.xrange = [0,1.2]
        if yrange is not None:
            arr.yrange = yrange
        print("Writing plot file:",pfile)
        arr.write_eps(pfile)
        if show:
            arr.show()