def maskMoon(fits, mask, moonMask): header = getHeader(fits) moonAz = iraf.real(header['MOONAZ']) moonEl = iraf.real(header['MOONEL']) if (moonEl > 0): moonX, moonY = getCoords(moonEl, moonAz) addToMask(mask, moonMask, moonX, moonY, 200) else: os.system("cp "+mask+" "+moonMask)
def closer_than(ra1, dec1, ra2, dec2, tol=5): '''Returns 1 if ra2,dec2 is closer than tol arc-sec from ra1,dec1 and 0 otherwise. ra? is assumed to be in hours, dec? in degrees.''' ra1 = iraf.real(ra1) dec1 = iraf.real(dec1) ra2 = iraf.real(ra2) dec2 = iraf.real(dec2) dist = math.sqrt(((ra1 - ra2) * 15.0)**2 + (dec1 - dec2)**2) * 3600.0 if dist < tol: return 1 else: return 0
def readasci(ascifile): f = open(ascifile, 'r') ss = f.readlines() f.close() ra, dec, mag, dmag = [], [], [], [] for line in ss: if line[0] != '#': ra.append(iraf.real(line.split()[0])) dec.append(iraf.real(line.split()[1])) mag.append(line.split()[2]) dmag.append(line.split()[3]) else: if 'ra' in line: _filter = line.split()[2] return ra, dec, mag, dmag, _filter
def getmag(asci): obs = {} obs['fts'] = {} for _file in asci: ras, decs, mags, dmags, _filter = readasci(_file) # _filter=_file.split('-')[1] # _ut=_file.split('-')[2] try: _ut = _file.split('-')[1] + '_' + _file.split('-')[2] + '_' + _file.split('-')[3] except: _ut = _file.split('_')[2] + '_' + _file.split('_')[3] + '_' + _file.split('_')[4] if _ut not in obs['fts'].keys(): obs['fts'][_ut] = {} if _filter not in obs['fts'][_ut].keys(): obs['fts'][_ut][_filter] = {} if 'ra' not in obs['fts'][_ut][_filter].keys(): obs['fts'][_ut][_filter]['ra'] = [] if 'dec' not in obs['fts'][_ut][_filter].keys(): obs['fts'][_ut][_filter]['dec'] = [] if 'mag' not in obs['fts'][_ut][_filter].keys(): obs['fts'][_ut][_filter]['mag'] = [] if 'merr' not in obs['fts'][_ut][_filter].keys(): obs['fts'][_ut][_filter]['merr'] = [] obs['fts'][_ut][_filter]['ra'] = obs['fts'][_ut][_filter]['ra'] + list(ras) obs['fts'][_ut][_filter]['dec'] = obs['fts'][_ut][_filter]['dec'] + list(decs) obs['fts'][_ut][_filter]['mag'] = obs['fts'][_ut][_filter]['mag'] + list(np.array(mags, float)) obs['fts'][_ut][_filter]['merr'] = obs['fts'][_ut][_filter]['merr'] + list(np.array(dmags, float)) ra, dec = [], [] for t in obs.keys(): for d in obs[t].keys(): for f in obs[t][d].keys(): for i in range(len(obs[t][d][f]['ra'])): _ra = obs[t][d][f]['ra'][i] _dec = obs[t][d][f]['dec'][i] ra.append(iraf.real(_ra)) dec.append(iraf.real(_dec)) ra, dec = np.array(ra), np.array(dec) from pylab import ion, plot ion() plot(ra, dec, '.r') raw_input('go on') ii, idstar = 0, np.zeros(len(ra), dtype=int) # match stars coordinates for i in range(len(ra)): if idstar[i] == 0: scal = np.pi / 180. dist = np.arccos(np.sin(dec * scal) * np.sin(dec[i] * scal) + np.cos(dec * scal) * np.cos(dec[i] * scal) * np.cos((ra - ra[i]) * scal)) * ((180 / np.pi)) #dist = sqrt(((ra-ra[i])*cos(dec[i]*pi/180.))**2+(dec-dec[i])**2) imatch = np.where(dist * 3600. < 3.5) ii += 1 idstar[imatch] = ii refstar = np.unique(idstar) print ' Found ', len(refstar), ' different stars' j = 0 for t in obs.keys(): # assign star names for d in obs[t].keys(): for f in obs[t][d].keys(): obs[t][d][f]['idstar'] = [] for i in range(len(obs[t][d][f]['ra'])): obs[t][d][f]['idstar'].append(idstar[j]) j += 1 MAGST, star = {}, {} for t in obs.keys(): MAGST[t], star[t] = {}, {} for r in refstar: star[t][r] = {} MAGST[t][r] = {} # compute calibrate mag for d in obs[t].keys(): star[t][r][d] = {} MAGST[t][r][d] = {} mag, _ra, _dec = {}, {}, {} for f in obs[t][d].keys(): for i in range(len(obs[t][d][f]['mag'])): if r == obs[t][d][f]['idstar'][i]: MAGST[t][r][d][f] = obs[t][d][f]['mag'][i] star[t][r][d][f] = {'dec': obs[t][d][f]['dec'][i], 'ra': obs[t][d][f]['ra'][i]} return MAGST, star, ra, dec
def getmag(asci): obs = {} obs['fts'] = {} for _file in asci: ras, decs, mags, dmags, _filter = readasci(_file) # _filter=_file.split('-')[1] # _ut=_file.split('-')[2] try: _ut = _file.split('-')[1] + '_' + _file.split( '-')[2] + '_' + _file.split('-')[3] except: _ut = _file.split('_')[2] + '_' + _file.split( '_')[3] + '_' + _file.split('_')[4] if _ut not in obs['fts'].keys(): obs['fts'][_ut] = {} if _filter not in obs['fts'][_ut].keys(): obs['fts'][_ut][_filter] = {} if 'ra' not in obs['fts'][_ut][_filter].keys(): obs['fts'][_ut][_filter]['ra'] = [] if 'dec' not in obs['fts'][_ut][_filter].keys(): obs['fts'][_ut][_filter]['dec'] = [] if 'mag' not in obs['fts'][_ut][_filter].keys(): obs['fts'][_ut][_filter]['mag'] = [] if 'merr' not in obs['fts'][_ut][_filter].keys(): obs['fts'][_ut][_filter]['merr'] = [] obs['fts'][_ut][_filter]['ra'] = obs['fts'][_ut][_filter]['ra'] + list( ras) obs['fts'][_ut][_filter][ 'dec'] = obs['fts'][_ut][_filter]['dec'] + list(decs) obs['fts'][_ut][_filter][ 'mag'] = obs['fts'][_ut][_filter]['mag'] + list( np.array(mags, float)) obs['fts'][_ut][_filter][ 'merr'] = obs['fts'][_ut][_filter]['merr'] + list( np.array(dmags, float)) ra, dec = [], [] for t in obs.keys(): for d in obs[t].keys(): for f in obs[t][d].keys(): for i in range(len(obs[t][d][f]['ra'])): _ra = obs[t][d][f]['ra'][i] _dec = obs[t][d][f]['dec'][i] ra.append(iraf.real(_ra)) dec.append(iraf.real(_dec)) ra, dec = np.array(ra), np.array(dec) from pylab import ion, plot ion() plot(ra, dec, '.r') raw_input('go on') ii, idstar = 0, np.zeros(len(ra), dtype=int) # match stars coordinates for i in range(len(ra)): if idstar[i] == 0: scal = np.pi / 180. dist = np.arccos( np.sin(dec * scal) * np.sin(dec[i] * scal) + np.cos(dec * scal) * np.cos(dec[i] * scal) * np.cos( (ra - ra[i]) * scal)) * ((180 / np.pi)) #dist = sqrt(((ra-ra[i])*cos(dec[i]*pi/180.))**2+(dec-dec[i])**2) imatch = np.where(dist * 3600. < 3.5) ii += 1 idstar[imatch] = ii refstar = np.unique(idstar) print ' Found ', len(refstar), ' different stars' j = 0 for t in obs.keys(): # assign star names for d in obs[t].keys(): for f in obs[t][d].keys(): obs[t][d][f]['idstar'] = [] for i in range(len(obs[t][d][f]['ra'])): obs[t][d][f]['idstar'].append(idstar[j]) j += 1 MAGST, star = {}, {} for t in obs.keys(): MAGST[t], star[t] = {}, {} for r in refstar: star[t][r] = {} MAGST[t][r] = {} # compute calibrate mag for d in obs[t].keys(): star[t][r][d] = {} MAGST[t][r][d] = {} mag, _ra, _dec = {}, {}, {} for f in obs[t][d].keys(): for i in range(len(obs[t][d][f]['mag'])): if r == obs[t][d][f]['idstar'][i]: MAGST[t][r][d][f] = obs[t][d][f]['mag'][i] star[t][r][d][f] = { 'dec': obs[t][d][f]['dec'][i], 'ra': obs[t][d][f]['ra'][i] } return MAGST, star, ra, dec
########## GET FIELD COORDINATES RA, DEC = 0, 0 try: coord = iraf.hselect(img, 'RA,DEC', 'yes', Stdout=1) RA = float(string.split(coord[0], '\t')[0]) DEC = float(string.split(coord[0], '\t')[1]) except: print "RA,DEC not found" ra = iraf.clDms(RA) dec = iraf.clDms(DEC) answ = raw_input('>> RA,Dec [' + str(ra) + ' ' + str(dec) + '] ? ') if len(answ) > 0: ra, dec = string.split(answ) RA = iraf.real(ra) DEC = iraf.real(dec) iraf.printf("RA=%h DEC=%m\n ", RA, DEC) ff = open('tmp.reg', 'w') ff.write(ra + ' ' + dec + ' ' + '10 10') ff.close() iraf.agetim('tmp.reg', 'tmpdss', imsurve='dss1@cadc', wcsedit='yes') iraf.display('tmpdss', 2) answ = raw_input('>> Change cuts (y/n) ? [n]') if len(answ) > 0: while string.lower(answ) == 'y': z1, z2 = string.split(raw_input('z1 z2 ? ')) iraf.display('tmpdss', 2, z1=z1, z2=z2, zscale='no', zrange='no') answ = raw_input('>> Change cuts (y/n) ? [n]')