#!/usr/bin/env python """Simple script to do subimages of a larger FITS""" from readcmd import ReadCmd import sys spec = """in = ??? # Input filename region = ??? # Region to clip, as xmin:xmax,ymin:ymax out = ??? # Output filename wcs = True # Compute new WCS for output image?""" arg = ReadCmd(spec,head=__doc__) inFile = arg.getstr('in',exist=True) region = arg.getliststr('region',length=2) outFile = arg.getstr('out',exist=False) wcsFlag = arg.getbool('wcs') keys = arg.getkeys(comment='IMSUB.PY:',format=80,time=True).strip().split('\n') import pyfits,pywcs from numpy import where,nan # open FITS image and read header if inFile == '-': fp = sys.stdin else: fp = pyfits.open(inFile) header = fp[0].header # read and interpret region keyword tmp1 = region[0].split(':')
header['CD2_2'] = scale angle = 180./pi*angle else: try: angle = float(header[rot]) # try to extract value from FITS header del(header[rot]) except KeyError: arg.error("No header keyword '%s' found for rotation angle!" %rot) except ValueError: arg.error("Cannot read rotation angle '%s'!" %header[rot]) return angle arg = ReadCmd(spec) inFile = arg.getstr('in',exist=True,type='file') outFile = arg.getstr('out',exist=False) expand = arg.getbool('expand') tmpext = arg.getstr('ext') rot = arg.getstr('rot') hist = arg.getkeys(comment='IMROTATE.PY:',format=72,time=True).strip().split('\n') import nlcastro import pyfits import scipy.interpolate from numpy import nan,isnan,pi,arctan2,cos,sin,meshgrid,arange,ceil,floor from numpy import amin,amax,where,isfinite,zeros,around ext = nlcastro.findExt(inFile,tmpext) header = pyfits.getheader(inFile,ext=ext) if header['naxis'] != 2: arg.error('Can only rotate 2-d images!')
#!/usr/bin/env python from readcmd import ReadCmd import nlclib spec = """# Convert image to table of pixels or wcs in = ??? # Input image ext = 1 # Extension name/number wcs = False # Set to true to output RA/DEC instead of pixels out = ??? # Output file (can be - for stdout)""" arg = ReadCmd(spec) infile = arg.getstr("in",exist=True) ext = arg.getstr("ext") wcsFlag = arg.getbool("wcs") outFile = arg.getstr("out",exist=False) # try to convert extension to an integer try: blah = int(ext) - 1 ext = blah except ValueError: pass import pyfits,pywcs from numpy import arange,meshgrid,savetxt,column_stack fp = pyfits.open(infile) #,ignore_missing_end=True) data = fp[ext].data header = fp[ext].header fp.close()