def main(): options, args = parser.parse_args(sys.argv[1:]) if len(args) < 2: parser.print_help() sys.exit(45) serun=args[0] # to put into a fiducial coordinate system exposurenames=args[1:] # diff = options.diff nbin=int(options.nbin) imageformat=options.imageformat ptypes = options.ptypes ptypes = ptypes.split(',') nx=nbin ny=nbin stdout.write("Reading example wcs\n") example_wcs_byccd = du.get_exposure_wcs_example() for exposurename in exposurenames: stdout.write('-'*30 + "\n") doplot(serun, exposurename, example_wcs_byccd, imageformat=imageformat, nx=nx, ny=ny, ptypes=ptypes)
def run_from_dir(): options, args = parser.parse_args(sys.argv[1:]) if len(args) < 1: parser.print_help() sys.exit(45) exposurenames=args[:] dir=options.dir nbin=int(options.nbin) ptypes = options.ptypes ptypes = ptypes.split(',') screen = options.screen scale = options.scale dpi = options.dpi plotdir_base = path_join(dir, 'plots/psfcheck') if not os.path.exists(plotdir_base): os.makedirs(plotdir_base) dirs = {} allowed_types = \ ['starnobin','psfnobin','bothnobin','starbin','psfbin','bothbin'] for type in allowed_types: plotdir=path_join(plotdir_base, type) if not os.path.exists(plotdir): os.makedirs(plotdir) dirs[type] = plotdir stdout.write("Reading example wcs\n") ewcs = du.get_exposure_wcs_example() for exposurename in exposurenames: stdout.write('-'*30 + "\n") stdout.write('%s\n' % exposurename) data = read_exposure_data(dir,exposurename) # this is an index into the psf stars wpsf, = where(data['psf_flags'] == 0) if wpsf.size == 0: raise ValueError("No objects passed psf_flags") else: fields = ['e1','e2','e1interp','e2interp'] stats = du.stats_xy_byccd(data,fields, nx=nbin,ny=nbin, index=wpsf) for type in allowed_types: if type in ptypes: # read these from the main table if 'nobin' in type: sx=data['x'][wpsf] sy=data['y'][wpsf] se1=data['e1'][wpsf] se2=data['e2'][wpsf] se1i=data['e1interp'][wpsf] se2i=data['e2interp'][wpsf] sccd=data['ccd'][wpsf] sscale=scale else: sx=stats['mx'] sy=stats['my'] se1=stats['me1'] se2=stats['me2'] se1i=stats['me1interp'] se2i=stats['me2interp'] sccd=stats['ccd'] sscale=3*scale plotdir=dirs[type] psfile="%s-checkpsf-%s.eps" % (exposurename,type) psfile=path_join(plotdir, psfile) if 'star' in type: plt=doplot(sx, sy, se1,se2, sccd, ewcs, scale=sscale) elif 'psf' in type: plt=doplot(sx, sy, se1i,se2i, sccd, ewcs, scale=sscale) elif 'both' in type: plt=doplot(sx, sy, se1,se2, sccd, ewcs, scale=sscale) plt=doplot(sx, sy, se1i,se2i, sccd, ewcs, scale=sscale, color='red', plt=plt) # add the legend. Only easy way to do this is # to add fake ones off screen xx=numpy.array([-9999.9,-9999.0],dtype='f8') yy=numpy.array([-9999.9,-9999.0],dtype='f8') cstars = biggles.Curve(xx,yy, color='black',linewidth=2) cstars.label = 'stars' cpsf = biggles.Curve(xx,yy, color='red',linewidth=2) cpsf.label = 'psf' key = biggles.PlotKey(0.1,0.9,[cstars,cpsf]) plt.add(key) if screen: print 'showing in a window' plt.show() stdout.write("Writing eps file: %s\n" % psfile) plt.write_eps(psfile) stdout.write("Converting to png\n") esutil.misc.exec_process('converter -d %s %s' % (dpi,psfile))
def run_from_serun(): import columns options, args = parser.parse_args(sys.argv[1:]) serun=options.serun nbin=int(options.nbin) ptypes = options.ptypes ptypes = ptypes.split(',') screen = options.screen scale = float(options.scale) dpi = options.dpi magrange = options.magrange if magrange is not None: magrange = numpy.fromstring(magrange,sep=',') if magrange.size != 2: raise ValueError("magrange should have two elements") allowed_types = \ ['starnobin','psfnobin','bothnobin','starbin','psfbin','bothbin', 'allstarbin','allpsfbin','allbothbin'] # special case where we use all exposures if 'allstarbin' in ptypes or 'allpsfbin' in ptypes or 'allbothbin' in ptypes: exposurenames = ['all'] else: if len(args) < 1: parser.print_help() sys.exit(45) exposurenames=args[:] # we will use this example set of wcs to put things onto # a camera plane stdout.write("Reading example wcs\n") ewcs = du.get_exposure_wcs_example() collated_dir = deswl.files.wlse_collated_dir(serun) plotdir_base = path_join(collated_dir, 'plots/psfcheck') if not os.path.exists(plotdir_base): os.makedirs(plotdir_base) dirs = {} for type in allowed_types: plotdir=path_join(plotdir_base, type) if not os.path.exists(plotdir): os.makedirs(plotdir) dirs[type] = plotdir if options.coldir is not None: coldir=options.coldir else: coldir = deswl.files.coldir(serun) # open the column database stdout.write("Opening coldir: '%s'\n" % coldir) cols = columns.Columns(coldir) for exposurename in exposurenames: stdout.write('-'*30 + "\n") stdout.write('%s\n' % exposurename) # get index into main table for objects with this exposurename # note, this is equivalent to the uid column psf_uid, wpsf = read_psf_stars_by_exposurename(cols,exposurename) if psf_uid.size > 0: if magrange is not None: stdout.write("Limiting to mag range: %s" % magrange) imag = cols['imag'][psf_uid] w,=numpy.where( (imag > magrange[0]) & (imag < magrange[1]) ) if w.size == 0: raise ValueError("No objects in mag range: %s" % magrange) psf_uid = psf_uid[w] wpsf=wpsf[w] stdout.write("Found %s objects\n" % psf_uid.size) # ok, we now have all the indices we need to do our work # since psf_uid is an index back into the main table # and wpsf is row-by-row the corresponding index into the # psfstars table stdout.write("Reading x,y,ccd,psfe1,psfe2 from main table\n") x = cols['x'][psf_uid] y = cols['y'][psf_uid] ccd = cols['ccd'][psf_uid] e1interp = cols['interp_psf_e1'][psf_uid] e2interp = cols['interp_psf_e2'][psf_uid] # reading psfstars info stdout.write("Reading psf star e1,e2\n") psfstars_e1 = cols['psfstars']['e1'][wpsf] psfstars_e2 = cols['psfstars']['e2'][wpsf] stdout.write("Getting Stats\n") tdata={} tdata['x'] = x tdata['y'] = y tdata['ccd'] = ccd tdata['e1'] = psfstars_e1 tdata['e2'] = psfstars_e2 tdata['e1interp'] = e1interp tdata['e2interp'] = e2interp fields = [f for f in tdata.keys() if f != 'ccd'] stats = du.stats_xy_byccd(tdata,fields, nx=nbin,ny=nbin) for type in allowed_types: if type in ptypes: # read these from the main table if 'nobin' in type: sx=x sy=y se1=psfstars_e1 se2=psfstars_e2 se1i=e1interp se2i=e2interp sccd=ccd else: sx=stats['mx'] sy=stats['my'] se1=stats['me1'] se2=stats['me2'] se1i=stats['me1interp'] se2i=stats['me2interp'] sccd=stats['ccd'] plotdir=dirs[type] psfile="%s-checkpsf-%s.eps" % (exposurename,type) if magrange is not None: psfile=psfile.replace('.eps','-mag%0.1f-%0.1f.eps' % magrange) psfile=path_join(plotdir, psfile) if 'star' in type: plt=doplot(sx, sy, se1,se2, sccd, ewcs, scale=scale) elif 'psf' in type: plt=doplot(sx, sy, se1i,se2i, sccd, ewcs, scale=scale) elif 'both' in type: plt=doplot(sx, sy, se1,se2, sccd, ewcs, scale=scale) plt=doplot(sx, sy, se1i,se2i, sccd, ewcs, scale=scale, color='red', plt=plt) xx=numpy.array([-9999.9,-9999.0],dtype='f8') yy=numpy.array([-9999.9,-9999.0],dtype='f8') cstars = biggles.Curve(xx,yy, color='black',linewidth=2) cstars.label = 'stars' cpsf = biggles.Curve(xx,yy, color='red',linewidth=2) cpsf.label = 'psf' key = biggles.PlotKey(0.1,0.9,[cstars,cpsf]) plt.add(key) if screen: print 'showing in a window' plt.show() stdout.write("Writing eps file: %s\n" % psfile) plt.write_eps(psfile) stdout.write("Converting to png\n") esutil.misc.exec_process('converter -d %s %s' % (dpi,psfile))