Beispiel #1
0
    def combine_scinv(self):
        from glob import glob

        outfile=self.combined_file()
        stdout.write("Will write to file: %s\n" % outfile)

        dir=self.output_dir()
        pattern = self.scinv_file_pattern()
        pattern=path_join(dir, pattern)
        flist = glob(pattern)

        datalist = []
        idmin = 0
        for f in flist:
            print f

            tdata = esutil.io.read(f)
            data = numpy_util.add_fields(tdata, [('zid','i4')])
            data['zid'] = idmin + numpy.arange(data.size)
            idmin += data.size

            print data['zid'].min(), data['zid'].max()
            datalist.append(data)

        hdr = esutil.sfile.read_header(flist[0])
        print 'combining data'
        data = numpy_util.combine_arrlist(datalist)

        print 'writing file: %s' % outfile
        esutil.sfile.write(data, outfile, header=hdr)
Beispiel #2
0
    def match(self, tilename):
        """
        match and write the output file
        """
        from esutil import numpy_util as nu

        scat_data = read_orig_scat(self.scat_name, tilename)

        print("matching")
        mdg, msc = nu.match(scat_data["coadd_objects_id"], self.ids)
        print("    matched: %d/%d" % (mdg.size, scat_data.size))

        if mdg.size == 0:
            print("    skipping")
            return

        scat_data = scat_data[mdg]
        add_dt = [("scinv_flags", "i4"), ("scinv", "f8", self.nz)]
        newdata = nu.add_fields(scat_data, add_dt)
        newdata["scinv"] = self.data["scinv"][msc, :]
        newdata["scinv_flags"] = self.data["flags"][msc]

        self._write_data(newdata, tilename)
def doplot(serun, exposurename, example_wcs_byccd, nx=3,ny=3,diff=False,
           imageformat='png', ptypes=['unbinned','comparebinned']):

    stdout.write("serun: %s\n" % serun)
    stdout.write("exposurename: %s\n" % exposurename)
    stdout.write("\tReading checkpsf data\n")

    alldata = []
    allstats = []

    for ccd in range(1,62+1):

        try:
            data = deswl.files.wlse_read(exposurename,ccd,'checkpsf',
                                         serun=serun)

            fields=['e1','e2','e1interp','e2interp']
            stats = du.stats_xy(data, fields, nx=nx, ny=ny, typ='median')

            ccd_wcs = example_wcs_byccd[ccd]
            fx,fy = ccd_wcs.image2sky(data['x'], data['y'])
            mfx,mfy = ccd_wcs.image2sky(stats['mx'],stats['my'])

            newdata = numpy_util.add_fields(data, [('fx','f4'),('fy','f4')])
            newdata['fx'] = fx - 337.3
            newdata['fy'] = fy + 15.0

            fadd=[('mfx','f4'),('mfy','f4'),('me1diff','f4'),('me2diff','f4')]
            newstats = numpy_util.add_fields(stats,fadd)
            newstats['mfx'] = mfx - 337.3
            newstats['mfy'] = mfy + 15.0
            newstats['me1diff'] = newstats['me1interp']-newstats['me1']
            newstats['me2diff'] = newstats['me2interp']-newstats['me2']

            alldata.append(newdata)
            allstats.append(newstats)

        except:
            stdout.write("Failed ccd=%s\n" % ccd)
            print sys.exc_info()

    data = numpy_util.combine_arrlist(alldata)
    stats = numpy_util.combine_arrlist(allstats)

    stdout.write("\tPlotting whiskers\n")
    plt = du.setuplot('Agg')
    plt.clf()

    nplots = len(ptypes)
    xsize=8*nplots
    fig=plt.figure(figsize=(xsize,7))

    iplot = 1

    u, v = polar2whisker(data['e1'], data['e2'])
    uinterp, vinterp = polar2whisker(data['e1interp'], data['e2interp'])
    mu, mv = polar2whisker(stats['me1'],stats['me2'])
    muinterp, mvinterp = polar2whisker(stats['me1interp'],stats['me2interp'])
    mudiff, mvdiff = polar2whisker(stats['me1diff'],stats['me2diff'])



    # example size to plot
    psize=0.01

    if 'unbinned' in ptypes or 'compareunbinned' in ptypes:
        stdout.write("\t\tDoing plot type 'unbinned'\n")
        ax = fig.add_subplot(1,nplots,iplot)
        iplot += 1

        # plot individual stars
        scale=3.
        whiskers(ax, data['fx'], data['fy'], u, v, scale=scale,
                 linewidth=0.25)

        # a measure of scale
        xtext=-1.2
        ax.text(xtext, 0.9, str(psize), verticalalignment='center')
        whiskers(ax, xtext+0.18, 0.9, psize, 0.0, color='blue', scale=scale)

        if 'compareunbinned' in ptypes:
            stdout.write("\t\tOverplotting 'compareunbinned'\n")
            whiskers(ax, data['fx'], data['fy'], uinterp, vinterp, 
                     scale=scale, color='red', linewidth=0.25)
            
            # add a legend

            ypos = 1.1
            ystep = 0.07
            xtext = -1.1

            ax.text(xtext, ypos-ystep, "data", verticalalignment='center')
            whiskers(ax, xtext+0.23, ypos-ystep, psize, 0.0, 
                     color='black', scale=scale)
            ax.text(xtext, ypos-2*ystep, "interp", verticalalignment='center')
            whiskers(ax, xtext+0.23, ypos-2*ystep, psize, 0.0, 
                     color='red', scale=scale)


        ax.set_xlim(-1.3,1.3)
        ax.set_ylim(-1.3,1.3)
        set_minor_ticks(ax)

    if 'comparebinned' in ptypes:
        # comparison plot for the binned data
        ax = fig.add_subplot(1,nplots,iplot)
        iplot += 1

        scale=10.
        whiskers(ax, stats['mfx'], stats['mfy'], mu, mv, scale=scale)
        whiskers(ax, stats['mfx'], stats['mfy'], muinterp, mvinterp, 
                 scale=scale, color='red')

        # legend
        ypos = 1.1
        ystep = 0.07
        xtext = -1.1

        ax.text(xtext, ypos, str(psize), verticalalignment='center')
        whiskers(ax, xtext+0.23, ypos, psize, 0.0, color='blue', scale=scale)

        ax.text(xtext, ypos-ystep, "data", verticalalignment='center')
        whiskers(ax, xtext+0.23, ypos-ystep, psize, 0.0, 
                 color='black', scale=scale)
        ax.text(xtext, ypos-2*ystep, "interp", verticalalignment='center')
        whiskers(ax, xtext+0.23, ypos-2*ystep, psize, 0.0, 
                 color='red', scale=scale)

        ax.set_xlim(-1.3,1.3)
        ax.set_ylim(-1.3,1.3)
        set_minor_ticks(ax)

    if 'diffbinned' in ptypes:
        # comparison plot for the binned data
        ax = fig.add_subplot(1,nplots,iplot)
        iplot += 1

        scale=50.
        psize=0.001
        whiskers(ax, stats['mfx'], stats['mfy'], mudiff, mvdiff, scale=scale)

        ax.text(xtext, ypos, str(psize), verticalalignment='center')
        whiskers(ax, xtext+0.23, ypos, psize, 0.0, color='blue', scale=scale)

        ax.set_xlim(-1.3,1.3)
        ax.set_ylim(-1.3,1.3)
        set_minor_ticks(ax)


    outdir='/home/users/esheldon/www/tmp/plots'
    outdir=os.path.join(outdir, serun)
    if not os.path.exists(outdir):
        os.makedirs(outdir)

    ptypes_string = '-'.join(ptypes)
    outfile = "%s-checkpsf-%s.%s" % (exposurename,ptypes_string, imageformat)
    outfile=os.path.join(outdir,outfile)
    stdout.write("\tWriting plot file: %s\n" % outfile)
    plt.savefig(outfile, bbox_inches='tight', pad_inches=0.1)