def check_system(_telescope, img, Stdout=True): from snoopy2 import src try: import pyfits except: from astropy.io import fits as pyfits import re if pyfits.getheader(img).get('INSTRUME') == 'SOFI' or pyfits.getheader( img).get('INSTRUME') == 'NICS': _system = 1 else: aa = 'unknown' _header = src.read_parameter(_telescope, 0) if _header: _filter = src.filter(img, _header, _telescope) aa = src.filtername(_telescope, _filter, 0) if aa != 'unknown': if Stdout: print '##################################' print 'System optical: UBVRI' print '##################################' _system = 0 if aa == 'unknown': _header = src.read_parameter(_telescope, 1) if _header: _filter = src.filter(img, _header, _telescope) aa = src.filtername(_telescope, _filter, 1) if aa != 'unknown': if Stdout: print '##################################' print 'System infrared: JHK' print '##################################' _system = 1 if aa == 'unknown': _header = src.read_parameter(_telescope, 2) if _header: _filter = src.filter(img, _header, _telescope) aa = src.filtername(_telescope, _filter, 2) if aa != 'unknown': if Stdout: print '##################################' print 'System sloan: ugriz' print '##################################' _system = 2 if aa == 'unknown': if Stdout: print '##################################' print 'WARNING: FILTER not recognised in ' + str( img) + ' !!! ' print '##################################' _system = 99 # sys.exit() return _system
def check_tel(img, _aa, _system): from snoopy2 import src try: _header = src.read_parameter(_aa, _system) filter = src.filter(img, _header, _aa) instrument = src.instrument(img, _header, _aa) _airmass = src.airmass(img, _header, _aa) _exptime = src.exptime(img, _header, _aa) _date = src.date(img, _header, _aa) xdim = src.xdimen(img, _aa) ydim = src.ydimen(img, _aa) _object = src.objects(img, _header, _aa) _julday = src.JD(img, _header, _aa) _UT = src.UT(img, _header, _aa) print '#### Header check ......ok ' check = 1 except Exception as e: print e check = 0 return check
print '## ' print _telescope print '## ' _system = src.check_system(_telescope, img, Stdout=True) if _system not in [0, 1, 2]: _header = src.read_parameter(_telescope, 0) else: _header = src.read_parameter(_telescope, _system) _imagetype = src.imagetype(img, _header, _telescope) _object = src.objects(img, _header, _telescope) _JD = src.JD(img, _header, _telescope) _airmass = src.airmass(img, _header, _telescope) _filter = src.filter(img, _header, _telescope) _grism = src.grism(img, _header, _telescope) _exptime = src.exptime(img, _header, _telescope) _date = src.date(img, _header, _telescope) _gain = src.gain(img, _header, _telescope) _ron = src.ron(img, _header, _telescope) _lampid = src.lampid(img, _header, _telescope) _RA = src.RA(img, _header, _telescope) _DEC = src.DEC(img, _header, _telescope) _ccdmax = src.ccdmax(img, _header, _telescope) _ccdmin = src.ccdmin(img, _header, _telescope) _cenwav = src.cenwav(img, _header, _telescope) _slitw = src.slitw(img, _header, _telescope) _UT = src.UT(img, _header, _telescope) _xdimen = src.xdimen(img, _telescope) _ydimen = src.ydimen(img, _telescope)
def fwhm_computation(img, tmpfiltercoo, stars, system, interactive): from snoopy2 import src import snoopy2 import string, os from numpy import compress from numpy import array from numpy import average from numpy import mean from numpy import median from numpy import std from pyraf import iraf from numpy import log10 _telescope = src.telescope(img) _header = src.read_parameter(_telescope, system) _xdimen = src.xdimen(img, _telescope) _ydimen = src.ydimen(img, _telescope) _filter = src.filter(img, _header, _telescope) try: filter = src.filtername(_telescope, _filter, system) except: filter = _filter _exptime = src.exptime(img, _header, _telescope) iraf.delete("tmp.imex_output", verify='no') stars_pos = [] alllines = [] ff = open(tmpfiltercoo, 'r') for j in range(0, 3): exl = ff.readline() for j in range(len(stars)): alllines.append(ff.readline()) xx = string.split(alllines[-1])[0:2] os.system('echo ' + xx[0] + ' ' + xx[1] + '> tmp.two') pp = iraf.imexam(input=img, frame=1, logfile='', keeplog='no', imagecur='tmp.two', defkey='m', wcs='logical', use_disp='no', Stdout=1) if not 1. <= float(xx[0]) <= float(_xdimen) or not 1. <= float( xx[1]) <= float(_ydimen): stars_pos.append(0) elif string.split(pp[1])[-1] == string.split(pp[1])[-2]: stars_pos.append(0) else: stars_pos.append(1) ff.close() ff = open('tmp.' + img + 'good.coo', 'w') for i in range(len(stars_pos)): if stars_pos[i]: ff.write(alllines[i]) ff.close() for i in range(len(alllines)): if stars_pos[i]: ff = open('tmp.one', 'w') xx = string.split(alllines[i])[0:2] ff.write(xx[0] + ' ' + xx[1] + ' a') ff.close() try: iraf.imexam(input=img, frame=1, logfile='tmp.imex_output', keeplog='yes', imagecur='tmp.one', wcs='logical', use_disp='no') except: if not os.path.isfile('tmp.imex_output'): os.system("echo '# [1] " + str(img) + " - " + str(coordinatelist) + "' > tmp.imex_output") os.system( "echo '# COL LINE COORDINATES R MAG FLUX SKY PEAK E PA BETA ENCLOSED MOFFAT DIRECT' >> tmp.imex_output" ) os.system( "echo '999. 999. 999. 999. INDEF INDEF INDEF INDEF INDEF INDEF INDEF INDEF INDEF INDEF INDEF' >> tmp.imex_output" ) else: os.system( "echo '999. 999. 999. 999. INDEF INDEF INDEF INDEF INDEF INDEF INDEF INDEF INDEF INDEF INDEF' >> tmp.imex_output" ) _fwhm0 = iraf.fields('tmp.imex_output', '15', Stdout=1) _mag = iraf.fields('tmp.imex_output', '6', Stdout=1) _fwhm, _magime = [], [] j = 0 for i in range(len(stars)): if stars_pos[i]: try: _magime.append(float(_mag[j]) + 2.5 * log10(_exptime)) except: _magime.append(float(9999)) try: _fwhm.append(float(_fwhm0[j])) except: _fwhm.append(float(9999)) j = j + 1 else: _magime.append(float(9999)) _fwhm.append(float(9999)) fwhm_ave = compress((array(_fwhm) < 999), _fwhm) fwhm_ave1 = compress( (average(fwhm_ave) - 2 * std(fwhm_ave) < array(fwhm_ave)) & (array(fwhm_ave) < average(fwhm_ave) + std(fwhm_ave) * 2), array(fwhm_ave)) _fwhm_ave = mean( compress((average(fwhm_ave1) - 2 * std(fwhm_ave1) < array(fwhm_ave1)) & (array(fwhm_ave1) < average(fwhm_ave1) + std(fwhm_ave1) * 2), array(fwhm_ave1))) fwhm_ave22 = compress( (average(fwhm_ave) - 2 * std(fwhm_ave) < array(fwhm_ave)) & (array(fwhm_ave) < average(fwhm_ave) + std(fwhm_ave) * 2), array(fwhm_ave)) _fwhm_ave2 = median( compress( (average(fwhm_ave22) - 2 * std(fwhm_ave22) < array(fwhm_ave22)) & (array(fwhm_ave22) < average(fwhm_ave22) + std(fwhm_ave22) * 2), array(fwhm_ave22))) checkfwhm = 'yes' while checkfwhm == 'yes': print '################ FWHM(median) = ' + str(_fwhm_ave2) + ' ' print '################ FWHM(mean) = ' + str(_fwhm_ave) + ' ' if interactive: fwhm_ave = raw_input('################ FWHM = [' + str(_fwhm_ave2) + '] ? ') else: fwhm_ave = str(_fwhm_ave2) try: if not fwhm_ave: fwhm_ave = _fwhm_ave2 else: fwhm_ave = float(fwhm_ave) checkfwhm = 'no' except: print 'WARNING: FWHM not good !!!!' checkfwhm = 'yes' #fwhm[filter]=fwhm_ave iraf.hedit(img, 'qubafwhm', fwhm_ave, add='yes', update='yes', verify='no') return fwhm_ave, _magime, stars_pos, _fwhm