casa  $Rev:20696$
 All Classes Namespaces Files Functions Variables
cl2skycat.py
Go to the documentation of this file.
00001 import casa as c
00002 import numpy as np
00003 def cl2skycat(componentlist='', skycat=''):
00004     """
00005     Converts a componentlist dictionary or componnent list file on disk
00006     to  a skycatalog to overlay on image in the viewer
00007     
00008     """
00009     qa=c.quanta
00010     cl=c.casac.componentlist()
00011     if(type(componentlist)==str):
00012         cl.open(componentlist)
00013     elif(type(componentlist)==dict):
00014         cl.purge()
00015         cl.fromrecord(componentlist)
00016     if(cl.length()==0):
00017             print "no components found"
00018             return
00019 
00020     des={}
00021     des['Type']={'valueType':'string'}
00022     des['Long']={'valueType':'double'}
00023     des['Lat']={'valueType':'double'}
00024     des['COMP_ID']={'valueType':'string'}
00025     des['RA']={'valueType':'string'}
00026     des['DEC']={'valueType':'string'}
00027     des['FluxValue']={'valueType':'double'}
00028     c.table.create(tablename=skycat, tabledesc=des, nrow=cl.length())
00029     eltype=[]
00030     nam=[]
00031     RA=[]
00032     DEC=[]
00033     lati=np.zeros((cl.length(),))
00034     longi=np.zeros((cl.length(),))
00035     fluxval=np.zeros((cl.length(),))
00036     for k in range(cl.length()):
00037         longi[k]=qa.convert(cl.getrefdir(k)['m0'],'deg')['value']
00038         lati[k]=qa.convert(cl.getrefdir(k)['m1'],'deg')['value']
00039         fluxval[k]=cl.getfluxvalue(k)[0]
00040         RA.append(qa.time(cl.getrefdir(k)['m0'], prec=10))
00041         DEC.append(qa.angle(cl.getrefdir(k)['m1'], prec=10))
00042         eltype.append(cl.getrefdir(k)['refer'])
00043         nam.append(str(k))
00044     c.table.putcol('Type', eltype)
00045     c.table.putcol('RA', RA)
00046     c.table.putcol('DEC', DEC)
00047     c.table.putcol('COMP_ID', nam)
00048     c.table.putcol('Long', longi)
00049     c.table.putcol('Lat', lati)
00050     c.table.putcol('FluxValue', fluxval)
00051     c.table.putcolkeyword(columnname='Long', keyword='UNIT', value='deg')
00052     c.table.putcolkeyword(columnname='Lat', keyword='UNIT', value='deg')                     
00053     c.table.putinfo({'type':'Skycatalog'})
00054     c.table.done()