i1,i2 = numpy.max([0,i1]),numpy.min([hdr['NAXIS1'],i2]) j1,j2 = numpy.max([0,j1]),numpy.min([hdr['NAXIS2'],j2]) # and find corresponding cutout pixels: imin,imax = iw/2 - (i0 - i1),iw/2 + (i2 - i0) jmin,jmax = iw/2 - (j0 - j1),iw/2 + (j2 - j0) if vb: print "Input image pixel ranges:",[i1,i2],[j1,j2] if vb: print "Non-zero part of cutout:",[imin,imax],[jmin,jmax] # Make cutout, centred on iw/2: cutout = numpy.zeros([iw,iw]) cutout[jmin:jmax,imin:imax] = hdulist[k].data[j1:j2,i1:i2] # Subtract background: if backsub: image = hdulist[k].data stats = proto.imagestats(image,clip=3) back = stats['median'] if vb: print "Subtracting constant background:",back index = numpy.where(cutout > 0) cutout[index] -= back # Almost ready to write out - first adjust hdr: x0 = float(iw/2 + x0-i0 + 1) y0 = float(iw/2 + y0-j0 + 1) if vb: print "Switching to one-indexing," if vb: print "Cutout central pixel:",x0,y0 # BUG: this is only accurate to ~0.5 pixels with SDSS cutouts, due to # more complex astrometric transformation? # Hogg: should really only change CRPIX and keep old CRVAL...
bluefile = args[2] if vb: print " " print "Making RGB png image from the following input files:" print " ",redfile,greenfile,bluefile print "Output files will be prefixed with",name else : print USAGE return # -------------------------------------------------------------------- # Measure image stats: hdulist = pyfits.open(redfile) redimage = hdulist[0].data redstats = proto.imagestats(redimage) hdulist.close() hdulist = pyfits.open(greenfile) greenimage = hdulist[0].data greenstats = proto.imagestats(greenimage) hdulist.close() hdulist = pyfits.open(bluefile) blueimage = hdulist[0].data bluestats = proto.imagestats(blueimage) hdulist.close() # Plot from a*sigma to b*sigma, using each channel's sigma a = -3 b = 200 vmin_r,vmax_r=a*redstats['stdev'], b*redstats['stdev'], vmin_g,vmax_g=a*greenstats['stdev'],b*greenstats['stdev'],