def save_fits(ra, dec, name=None, size=0.25): if name is None: sc = SkyCoord(ra * u.deg, dec * u.deg, frame='icrs') s = sc.to_string(style='hmsdms', sep='', precision=2) name = (str('ILTJ' + s).replace(' ', '')[:-1]) lm = LofarMaps() filename = os.environ['IMAGEDIR'] + '/' + lm.find(ra, dec) hdu = extract_subim(filename, ra, dec, size) outname = name + '.fits' hdu.writeto(outname, clobber=True) return outname
name = r['Source_Name'] if os.path.isfile(name + '.txt'): print name, 'already has a blend file' continue id = r['Source_id'] # unique in this field! rgt = gt[gt['Source_id'] == id] print 'Contains', len(rgt), 'Gaussians' mlt = rgt[~np.isnan(rgt['lr_ra_fin'])] mlt['ra'] = mlt['lr_ra_fin'] mlt['dec'] = mlt['lr_dec_fin'] title = name + ' (%s)' % display_mode ra, dec, size = find_bbox(rgt, scale=scale) size *= 1.5 size /= 3600.0 print 'Lofarfile is', lofarfile lhdu = extract_subim(lofarfile, ra, dec, size * 2) try: peak == r['Peak_flux'] / 1000.0 except: peak = None pwg = gals[(np.abs(gals['ra'] - ra) < size) & (np.abs(gals['dec'] - dec) < size)] ora = r['lr_ra_fin'] odec = r['lr_dec_fin'] ga = GaussAssoc(rgt, ora, odec) stop = False while not (stop): if display_mode == 'Spitzer': ohdu = extract_subim(spitzerfile, ra, dec, size)
size/=3600.0 initfactor=2.0 scalefactor=initfactor overlaygals=True while True: print 'Scale factor is',scalefactor if overlaygals: pwg=gals[(np.abs(gals['ra']-ra)<size*scalefactor/np.cos(dec*np.pi/180.0)) & (np.abs(gals['dec']-dec)<size*3)] else: pwg=None ots=ot[separation(ra,dec,ot['RA'],ot['DEC'])<(size*scalefactor)] #pshdu=extract_subim(imagedir+'/downloads/'+psmaps[i],ra,dec,size*2,hduid=1) print 'Lofarfile is',lofarfile lhdu=extract_subim(lofarfile,ra,dec,size*scalefactor) if mode=='spitzer': whdu=extract_subim(spitzerfile,ra,dec,size*scalefactor) else: whdu=extract_subim(ibandfile,ra,dec,size*scalefactor) try: peak==r['Peak_flux']/1000.0 except: peak=None try: f=show_overlay(lhdu,whdu,ra,dec,size*scalefactor/initfactor,coords_color='red',coords_ra=s.sd[sourcename]['RA'],coords_dec=s.sd[sourcename]['DEC'],coords_lw=3,lw=2,no_labels=True,marker_ra=marker_ra,marker_dec=marker_dec,marker_lw=3,marker_color='cyan',title=title,block=False,interactive=False,drlimit=8000,peak=peak,plotpos=[(pwg,'+')]) except Exception as e: print '*** Error making image ***' print e raw_input()
import sys import os from subim import extract_subim from download_image_files import LofarMaps from astropy.coordinates import SkyCoord import astropy.units as u if len(sys.argv)==3: ra=float(sys.argv[1]) dec=float(sys.argv[2]) sc=SkyCoord(ra*u.deg,dec*u.deg,frame='icrs') s=sc.to_string(style='hmsdms',sep='',precision=2) name=(str('ILTJ'+s).replace(' ','')[:-1]) elif len(sys.argv)==2: s=sys.argv[1][4:] coord=s[0:2]+':'+s[2:4]+':'+s[4:9]+' '+s[9:12]+':'+s[12:14]+':'+s[14:] sc = SkyCoord(coord,unit=(u.hourangle,u.deg)) ra=sc.ra.value dec=sc.dec.value print 'Parsed coordinates to ra=%f, dec=%f' % (ra,dec) name=sys.argv[1] else: print 'Call me with the name of a source or RA, Dec in degrees' lm=LofarMaps() filename=os.environ['IMAGEDIR']+'/'+lm.find(ra,dec) hdu=extract_subim(filename,ra,dec,0.25) hdu.writeto(name+'.fits',clobber=True)
size/=3600.0 seps=separation(ra,dec,ot['RA'],ot['DEC']) ots=ot[seps<size*2] print ra,dec print ots['RA','DEC'] cols=[] for nr in ots: if nr['Source_Name']==r['Source_Name']: # this is our target cols.append('red') else: cols.append('green') lhdu=extract_subim(lofarfile,ra,dec,size) rhdu=extract_subim(rbandfile,ra,dec,size) khdu=extract_subim(kbandfile,ra,dec,size) #shdu=extract_subim(s45bandfile,ra,dec,size) try: peak==r['Peak_flux'] except: peak=None print ots,cols show_overlay(lhdu,rhdu,ra,dec,size,firsthdu=None,overlay_cat=ots,overlay_scale=scale,coords_color='red',coords_ra=r['RA'],coords_dec=r['DEC'],coords_lw=3,lw=2,save_name=rimage,no_labels=True,marker_ra=marker_ra,marker_dec=marker_dec,marker_lw=3,marker_color='cyan',title=title,ellipse_color=cols,peak=peak,noisethresh=1) show_overlay(lhdu,khdu,ra,dec,size,firsthdu=None,overlay_cat=ots,overlay_scale=scale,coords_color='red',coords_ra=r['RA'],coords_dec=r['DEC'],coords_lw=3,lw=2,save_name=kimage,no_labels=True,marker_ra=marker_ra,marker_dec=marker_dec,marker_lw=3,marker_color='cyan',title=title,ellipse_color=cols,peak=peak) #show_overlay(lhdu,shdu,ra,dec,size,firsthdu=None,overlay_cat=ots,overlay_scale=scale,coords_color='red',coords_ra=r['RA'],coords_dec=r['DEC'],coords_lw=3,lw=2,save_name=simage,no_labels=True,marker_ra=marker_ra,marker_dec=marker_dec,marker_lw=3,marker_color='cyan',title=title,ellipse_color=cols,peak=peak)