00001 import casa as c 00002 import numpy as np 00003 def field2skycat(msname='', skycat=''): 00004 """ 00005 Converts field table in ms to skycatalog 00006 allow overlay on image in the viewer 00007 """ 00008 enumTypes =['J2000','JMEAN','JTRUE','APP','B1950', 00009 'B1950_VLA','BMEAN','BTRUE','GALACTIC','HADEC','AZEL','AZELSW', 00010 'AZELGEO','AZELSWGEO','JNAT','ECLIPTIC','MECLIPTIC','TECLIPTIC','SUPERGAL', 00011 'ITRF','TOPO','ICRS'] 00012 00013 qa=c.quanta 00014 c.table.open(msname+'/FIELD') 00015 dir=c.table.getcol('PHASE_DIR') 00016 nam=c.table.getcol('NAME') 00017 nfield=c.table.nrows() 00018 eltype=[] 00019 if(c.table.getcolkeyword('PHASE_DIR', 'MEASINFO').has_key('VarRefCol')): 00020 typeid=c.table.getcol(c.table.getcolkeyword('PHASE_DIR', 'MEASINFO')['VarRefCol']) 00021 for k in range(nfield): 00022 eltype.append(enumTypes[typeid[k]]) 00023 else: 00024 eltype=[c.table.getcolkeyword('PHASE_DIR', 'MEASINFO')['Ref']]*nfield 00025 unitra=c.table.getcolkeyword('PHASE_DIR', 'QuantumUnits')[0] 00026 unitdec=c.table.getcolkeyword('PHASE_DIR', 'QuantumUnits')[1] 00027 c.table.done() 00028 des={} 00029 des['Type']={'valueType':'string'} 00030 des['Long']={'valueType':'double'} 00031 des['Lat']={'valueType':'double'} 00032 des['FIELD_NAME']={'valueType':'string'} 00033 des['FIELD_ID']={'valueType':'string'} 00034 des['RA']={'valueType':'string'} 00035 des['DEC']={'valueType':'string'} 00036 c.table.create(tablename=skycat, tabledesc=des, nrow=nfield) 00037 c.table.putcol('Type', eltype) 00038 lati=np.zeros((nfield,)) 00039 longi=np.zeros((nfield,)) 00040 RA=[] 00041 DEC=[] 00042 fid=[] 00043 for k in range(nfield): 00044 longi[k]=qa.convert(qa.quantity(dir[0,0,k], unitra),'deg')['value'] 00045 lati[k]=qa.convert(qa.quantity(dir[1,0,k], unitdec), 'deg')['value'] 00046 RA.append(qa.time(qa.quantity(dir[0,0,k], unitra), prec=10)) 00047 DEC.append(qa.angle(qa.quantity(dir[1,0,0], unitdec), prec=10)) 00048 fid.append(str(k)) 00049 c.table.putcol('RA', RA) 00050 c.table.putcol('DEC', DEC) 00051 c.table.putcol('FIELD_NAME', nam) 00052 c.table.putcol('FIELD_ID', fid) 00053 c.table.putcol('Long', longi) 00054 c.table.putcol('Lat', lati) 00055 c.table.putcolkeyword(columnname='Long', keyword='UNIT', value='deg') 00056 c.table.putcolkeyword(columnname='Lat', keyword='UNIT', value='deg') 00057 c.table.putinfo({'type':'Skycatalog'}) 00058 c.table.done()