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
def get_fits(fra,fdec,fsource,fsize): sc=SkyCoord(fra*u.deg,fdec*u.deg,frame='icrs') s=sc.to_string(style='hmsdms',sep='',precision=2) name=fsource newsize=2.5*fsize/3600.0 lm=LofarMaps() print fra,fdec mosname=lm.find(fra,fdec) filename=os.environ['IMAGEDIR']+'/'+mosname hdu=extract_subim(filename,fra,fdec,newsize) if hdu is not None: hdu.writeto('cutouts/'+name+'.fits',overwrite=True) flag=0 else: print 'Cutout failed for '+str(fsource) flag=1 return flag
from download_image_files import LofarMaps scale = 3600.0 # scaling factor for region sizes def mogrify(filename): command = 'mogrify -quality 90 -trim ' + filename p = subprocess.Popen(command, shell=True) return p if __name__ == '__main__': t = Table.read('sources_2arcmin.fits') ot = Table.read('components_2arcmin.fits') lm = LofarMaps(stay_in_imagedir=False) for i in range(0, len(t)): r = t[i] print r lofarfile = os.environ['IMAGEDIR'] + '/' + lm.find(r['RA'], r['DEC']) sourcename = r['Source_Name'] # find components of this source cfilter = ot['Parent_Source'] == sourcename ctable = ot[cfilter] if len(ctable) == 0: raise RuntimeError('Source has no components!') cimage = sourcename + '_C.png' cpimage = sourcename + '_Cp.png'
else: if sourcename.startswith('ILTJ'): sourcelist = [sourcename] else: # maybe this is a file with a list of sources if not os.path.isfile(sourcename): raise RuntimeError('Cannot parse entity on command line') else: sourcelist = [l.rstrip() for l in open(sourcename).readlines()] sourcelist += s.zoomneeded sourcelist = list(set(sourcelist)) print('Processing', len(sourcelist), 'sources') # now download any images we need! wd = os.getcwd() # the zoom directory lm = LofarMaps(stay_in_imagedir=True) # now work in downloads dir os.chdir('downloads') for sourcename in sourcelist: record = sql.get_object(sourcename, create=True) ra = s.sd[sourcename]['RA'] dec = s.sd[sourcename]['DEC'] record['lofarfile'] = lm.find(ra, dec) sql.set_object(sourcename, record) # back to zoom dir os.chdir(wd)
import sys import os if __name__ == '__main__': t = Table.read(sys.argv[1]) if 'Dec' in t.colnames: t['Dec'].name = 'DEC' outfilename = sys.argv[1].replace('.fits', '-list.txt') if not (os.path.isfile(outfilename)): startpoint = 0 outfile = open(outfilename, 'w') else: startpoint = len(open(outfilename).readlines()) outfile = open(outfilename, 'a') lm = LofarMaps(stay_in_imagedir=True) # now work in downloads dir os.chdir('downloads') for r in t[startpoint:]: print r['Source_Name'] print r['RA'], r['DEC'] lofarname = lm.find(r['RA'], r['DEC']) legacyname = get_legacy(r['RA'], r['DEC'], bands='zrg') #wisename=get_wise(r['RA'],r['DEC'],1) #firstname=get_first(r['RA'],r['DEC']) print >> outfile, r[ 'Source_Name'], lofarname, legacyname #,wisename,firstname outfile.close()
if ssize<20.0: ssize=20.0 flag=get_fits(sra,sdec,ssource,ssize) # make output locations if needed if os.path.isdir(cutouts): continue else: os.mkdir('cutouts') if os.path.isdir(4rms): continue else: os.mkdir('4rms') cutout='cutouts/'+ssource+'.fits' lmd=LofarMaps() dname=os.environ['IMAGEDIR']+'/'+lmd.find(sra,sdec) if os.path.isfile(dname): lhdu=fits.open(dname) if flag==0: nlhdu=fits.open(cutout) # Write out npy arrays applying 4xrms and dyn range thresholds (cf Mingo+19) d=nlhdu[0].data peak=flux dyncut=50.0 ratio=peak/dyncut print peak,rms,ratio if rms<ratio: print "rms < ratio"
idname='ID' st=Table.read(sourcecat) gt=Table.read('edited_gaussians.fits') # has parent name and source name gt['ra']=np.where(gt['ra']>360,np.nan,gt['ra']) gt['dec']=np.where(gt['dec']>90,np.nan,gt['dec']) # now download any images we need! lofarfiles={} legacyfiles={} wisefiles={} w=WISE() if not os.path.isfile('blend-list.txt'): outfile=open('blend-list.txt','w') # now work in downloads dir wd=os.getcwd() # the zoom directory lm=LofarMaps(stay_in_imagedir=True) os.chdir('downloads') print('Making images') for r in t: sourcename=r['Source_Name'] ra=r['RA'] dec=r['Dec'] lofarfiles[sourcename]=os.environ['IMAGEDIR']+'/'+lm.find(ra,dec) legacyfiles[sourcename]=os.environ['IMAGEDIR']+'/downloads/'+get_legacy(ra,dec,bands='zrg') wisename=w.find_pos(ra,dec) if wisename is None: wisename=get_wise(ra,dec,1) wisefiles[sourcename]=os.environ['IMAGEDIR']+'/downloads/'+wisename print(sourcename,lofarfiles[sourcename],legacyfiles[sourcename],wisefiles[sourcename],file=outfile) outfile.close()
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)