#!/bin/env python """write out the important header information from a block of fits files""" # known bug - crashed on verbose mode for some of the latest run's data. #from pyfits import getheader import pyfits import sys,os,glob oldstem = '' def lriscat(files, verbose, inputmode, inputtarg): global oldstem minfilenamelen = 20 maxfilenamelen = 12 for f in files: filename = f[f.rfind('/')+1:] if verbose <= 2: filename = filename[:filename.rfind('.fits')] if len(filename) > maxfilenamelen: maxfilenamelen= len(filename) if len(filename) < minfilenamelen: minfilenamelen= len(filename) filenamelen = maxfilenamelen if verbose == 0: filenamelen = max(minfilenamelen,9) if verbose == 0: print 'file'.ljust(filenamelen)+' obj/target exp air filt/gr slit PA other' if verbose == 1: print 'file'.ljust(filenamelen)+' ut targname object exp air ra dec filt/gr dic slit PA other' if verbose == 2: print 'file'.ljust(filenamelen)+' ut targname object exp air ra dec filt/gr dic slit PA other' if verbose == 3: print 'file'.ljust(filenamelen)+' ut targname object exp air ra dec filt grat/gris dic slit PA focus cwav win other' i = 0 for f in files: if f == '': continue i += 1 file = f[f.rfind('/')+1:] stem = f[:f.rfind('/')+1] if verbose <= 2: file = file[:file.rfind('.fits')] #h = getheader(f) u = pyfits.open(f) h = u[0].header u.close() s = '' cam = '' try: inst = h['INSTRUME'] if inst == 'LRISBLUE': cam = 'blue' if inst == 'LRIS': cam = 'red' except: if f.find('b') >= 0: cam = 'blue' if f.find('red') >= 0: cam = 'red' if cam == '': print 'Not an LRIS file.' continue try: u = str(h['UTC']) except: try: u = str(h['UT']) except: u = '????' try: rfilt = h['REDFILT'] except: rfilt = '?' try: bfilt = h['BLUFILT'] except: bfilt = '?' try: slit = h['SLITNAME'] except: slit = '????' try: targname = h['TARGNAME'] except: targname = '???' try: objname = h['OBJECT'] except: objname = '???' try: exptime = h['ELAPTIME'] except: try: exptime = h['EXPTIME'] except: exptime = '?' try: ra = h['RA'] dec = h['DEC'] except: ra = '?' dec = '?' try: grisname = h['GRISNAME'] except: grisname = '?' try: graname = h['GRANAME'] except: graname = '?' try: dichname = h['DICHNAME'] except: dichname = '?' try: airmass = h['AIRMASS'] except: airmass = '?' try: rotposn = h['ROTPOSN'] except: rotposn = '?' try: bluefocus = h['BLUFOCUS'] except: bluefocus = '?' try: redfocus = h['REDFOCUS'] except: redfocus = '?' try: cwave = h['WAVELEN'] except: cwave = '?' try: trapdoor = h['TRAPDOOR'] except: trapdoor = '?' Hg = Ne = Ar = Cd = Zn = hal = Kr = Xe = FeAr = De = 0 try: lamps = h['LAMPS'] Hg = int(lamps[0]) Ne = int(lamps[2]) Ar = int(lamps[4]) Cd = int(lamps[6]) Zn = int(lamps[8]) hal = int(lamps[10]) Kr = int(lamps[12]) Xe = int(lamps[14]) FeAr = int(lamps[16]) De = int(lamps[18]) except: try: if h['MERCURY'].strip() == 'on': Hg = 1 if h['NEON'].strip() == 'on': Ne = 1 if h['ARGON'].strip() == 'on': Ar = 1 if h['CADMIUM'].strip() == 'on': Cd = 1 if h['ZINC'].strip() == 'on': Zn = 1 if h['HALOGEN'].strip() =='on': hal = 1 if h['KRYPTON'].strip() =='on': Kr = 1 if h['XENON'].strip() =='on': Xe = 1 if h['FEARGON'].strip() =='on': FeAr = 1 if h['DEUTERI'].strip() =='on': De = 1 lamps = ''+str(Hg)+','+str(Ne)+','+str(Ar)+','+str(Cd)+','+str(Zn)+','+str(hal) except: lamps = '0000000000000' try: imlamp = h['FLIMAGIN'].strip() except: imlamp = '?' #not present in older images. try: speclamp = h['FLSPECTR'].strip() except: speclamp = '?' try: pane = h['PANE'] except: pane = '?' try: window = h['WINDOW'] except: window = '?' try: bin = h['BINNING'].strip() except: bin = '?' grname = '?' if cam == 'red': grname = graname if cam == 'blue': grname = grisname filt = '?' if cam == 'red': filt = rfilt if cam == 'blue': filt = bfilt mode = 'im' #default if grname.find('/') >= 0: mode = 'spec' if inputmode == 'i' and mode == 'spec': continue if inputmode == 's' and mode == 'im': continue s = s + file.ljust(maxfilenamelen) + ' ' if verbose >= 1: s = s + u.ljust(11) + ' ' #if (dec == '+45:00:00.0'): # Telescope Elevation = 45 degrees (see FACSUM). # Dome and Azimuth are 90 degrees apart (see FACSUM). try: azimuth = h['AZ'] elevation = h['EL'] domeazimuth = h['DOMEPOSN'] except: azimuth = 0 elevation = 0 domeazimuth = 0 domerelaz = domeazimuth - azimuth while domerelaz < -180.0: domerelaz += 360. while domerelaz >= 180.0: domerelaz -= 360. if abs(elevation-45)<0.1 and abs(abs(domerelaz)-90) < 0.2: view = 'flat' elif abs(domerelaz) > 1.0: # assume the dome opening angle is 2 degrees, but I don't actually know view = 'dome' else: view = 'sky' if inputtarg == 'a' and view != 'sky': continue if stem != oldstem: print stem oldstem = stem if verbose == 0: if view != 'sky': s = s + objname.ljust(15)[:15] + ' ' else: s = s + targname.ljust(15) + ' ' else: s = s + targname.ljust(15) + ' ' s = s + objname.ljust(20)[:20] + ' ' if exptime != '?': s = s + "%4d" % exptime + ' ' else: s = s + ' ? ' if airmass != '?': s = s + ("%.2f" % float(airmass)).ljust(5) + '' else: s = s + ("?").ljust(5) + '' if verbose > 0: s = s + ra.ljust(11) + ' ' s = s + dec.ljust(11) + ' ' if mode == 'im' or verbose >= 3: s = s + filt.ljust(6+3*(verbose<3)) + ' ' if mode == 'spec' or verbose >= 3: s = s + grname.ljust(9) + ' ' if verbose >= 1: s = s + dichname.ljust(3)[0:3] + ' ' if verbose <= 1: if slit.rfind('long') >= 0 or slit.rfind('pol') >= 0: if slit.rfind('lon') >= 0: slit = slit + '"' if slit.rfind('pol') >= 0: slit = slit + 'P' slit = slit[slit.rfind('_')+1:] slit = slit[:4] else: if slit == 'direct': slit = 'dir' s = s + slit.ljust(4)[:4] + ' ' if verbose >= 2: s = s + slit.ljust(8)[:8] + ' ' if rotposn != '?': pa = (float(rotposn) + 90.0) + 0.001 if pa < -90.0: pa = pa + 360 if pa >= 360.0: pa = pa - 360.0 s = s + ("%.2f" % pa).ljust(7) else: s = s + ("?").ljust(7) if verbose >= 3: if cam == 'blue': try: s = s + str(round(bluefocus,2)).ljust(8) + ' ' except: s = s + '?'.ljust(8) + ' ' s = s + '- ' + ' ' if cam == 'red': try: s = s + str(round(redfocus,2)).ljust(8) + ' ' except: s = s + '?'.ljust(8) + ' ' try: s = s + str(round(cwave,1)).ljust(6) + ' ' except: s = s + str(cwave).ljust(6) + ' ' binning = '?' if bin == '1,1' or bin == '1, 1': binning ='1x1' if bin == '1,2' or bin == '1, 2': binning ='1x2' if bin == '2,1' or bin == '2, 1': binning ='2x1' if bin == '2,2' or bin == '2, 2': binning ='2x2' if binning != '1x1': s = s +binning + ' ' windowing = '?' if window != '?': if cam == 'red': if window == '0,0,550,2048,1000': windowing = 'slit' if window == '0,0,0,550,1000': windowing = 'slit' if window == '0,0,0,2048,2048': windowing = 'full' if cam == 'blue': if window == '1,0,0,2048,4096': windowing = 'full' if window == '0,0,0,2048,4096': windowing = 'full' if pane != '?': if pane == '1500,0,1200,4096': windowing = 'slit' if pane == '400,625,3400,2500': windowing = 'img' if pane == '0,0,4096,4096': windowing = 'full' if verbose >=3 and cam=='red': if windowing=='?': s = s + pane + ' ' else: s = s + windowing.ljust(5) else: if mode == 'im' and windowing == 'slit': s = s + 'w-' + windowing + '! ' if mode == 'spec' and windowing == 'img': s = s + 'w-' + windowing + '! ' if windowing == 'full' and cam =='red' and window == '?': s = s + 'w-' + windowing + ' ' if windowing != 'full' and cam =='blue': s = s + 'w-' + windowing + ' ' try: dooropen = trapdoor[0] == 'o' if not(dooropen): s = s + 'closed' except: dooropen = -1 s = s + '??????' if Hg + Ne + Ar + Cd + Zn + hal + Kr + Xe + FeAr + De > 0: if (dooropen): s = s + 'open!!' s = s + ':' s = s + (Hg and 'Hg' or '') s = s + (Ne and 'Ne' or '') s = s + (Ar and 'Ar' or '') s = s + (Cd and 'Cd' or '') s = s + (Zn and 'Zn' or '') s = s + (hal and 'hal' or '') s = s + (Kr and 'Kr' or '') s = s + (Xe and 'Xe' or '') s = s + (FeAr and 'Fe' or '') s = s + (De and 'De' or '') s = s + ' ' else: if not(dooropen): s = s + ':dark' + ' ' #some sort of warning if dome lamps are on and on sky? or off in flatfield with td open? if (dooropen) and view != 'sky': s = s + view + ' ' print s ################### def help(): print "lriscat [files]" print " -c : curt (prints only basic info, fits in 80 char terminal)" #print " -v : verbose (prints dichroic, full slit name)" #print " -e : extra verbose (prints focus and central wavelength)" print " -v : verbose (prints focus and central wavelength)" print " -s : spectroscopy (hide imaging exposures)" print " -i : imaging (hide spectroscopy exposures)" print " -a : astronomical (hide dome exposures)" print " -h : help (show this information)" sys.exit() ################### def main(): argv = sys.argv verbose = 1 input = '' input2 = '' fileselector = ["l*.fits"] #default if (len(argv)>=2): for v in argv[1:]: if v == '-v': verbose = 3 #if v == '-v': verbose = 2 if v == '-c': verbose = 0 if v == '-i': input = 'i' if v == '-s': input = 's' if v == '-a': input2 = 'a' if v == '-h': help() if v[0] != '-': fileselector.append(v) if len(fileselector) > 1: fileselector = fileselector[1:] files = [] for fs in fileselector: files += glob.glob(fs) nbadfilenames = 0 for i in range(len(files)): f = files[i] #print f if f.find('.fit') < 0: if (len(argv)>=2): print f + ' is not a fits file.' files[i] = '' nbadfilenames = nbadfilenames + 1 if f.find('am') >= 0 or f.find('slit') >= 0: print f + ' is a cam file.' files[i] = '' nbadfilenames = nbadfilenames + 1 if len(files) - nbadfilenames <= 0: print 'Error: No valid .fits files specified.' return 1 lriscat(files,verbose,input,input2) ################### if __name__=='__main__': main()