casa
$Rev:20696$
|
00001 import os 00002 from taskinit import * 00003 00004 def conjugatevis(vis,spwlist=[],outputvis="",overwrite=False): 00005 """: 00006 Change the sign of the phases in all visibility columns 00007 00008 Keyword arguments: 00009 vis -- Name of input visibility file 00010 default: none; example='3C273XC1.ms' 00011 spwlist -- Select spectral window 00012 default: [] all spws will be conjugated; example: spw=[1,2] 00013 outputvis -- name of output visibility file 00014 default: 'conjugated_'+vis; example= 'conjugated.ms' 00015 overwrite -- Overwrite the outputvis if it exists 00016 default=False; example: overwrite=True 00017 00018 """ 00019 00020 #Python script 00021 try: 00022 casalog.origin('conjugatevis') 00023 myddlist = [] 00024 tb.open(vis+'/SPECTRAL_WINDOW') 00025 maxspw = tb.nrows()-1 00026 tb.close() 00027 if (type(spwlist)==type(1)): 00028 spwlist = [spwlist] 00029 elif(spwlist==None or spwlist==[] or spwlist==""): 00030 spwlist = [] 00031 casalog.post("Will conjugate visibilities for all spws.", 'INFO') 00032 if not spwlist==[]: 00033 try: 00034 tb.open(vis+'/DATA_DESCRIPTION') 00035 for k in spwlist: 00036 if (k<-1 or k>maxspw): 00037 raise Exception, "Error: max valid spw id is "+str(maxspw) 00038 raise 00039 else: 00040 for j in range(0,tb.nrows()): 00041 if(tb.getcell("SPECTRAL_WINDOW_ID",j)==k and not (j in myddlist)): 00042 myddlist = myddlist + [j] 00043 #end for k 00044 tb.close() 00045 casalog.post('DATA_DESC_IDs to process: '+str(myddlist), 'INFO') 00046 except: 00047 raise Exception, 'Error reading DATA_DESCRIPTION table' 00048 #endif 00049 outname = 'conjugatedvis_'+vis 00050 if not outputvis=="": 00051 if((type(outputvis)!=str) or (len(outputvis.split()) < 1)): 00052 raise Exception, 'parameter outputvis is invalid' 00053 outname = outputvis 00054 if not overwrite and os.path.exists(outname): 00055 raise Exception, 'outputvis '+outname+' exists and you did not permit overwrite' 00056 os.system('rm -rf '+outname) 00057 os.system('cp -R '+vis+' '+outname) 00058 tb.open(outname, nomodify=False) 00059 if tb.iswritable(): 00060 if(spwlist==None): 00061 for colname in [ 'DATA', 'CORRECTED_DATA', 'FLOAT_DATA' ]: 00062 if colname in tb.colnames(): 00063 casalog.post('Conjugating '+str(colname), 'INFO') 00064 for i in xrange(0,tb.nrows()): 00065 a = tb.getcell(colname, i) 00066 a = a.conjugate() 00067 tb.putcell(colname, i, a) 00068 else: 00069 for colname in [ 'DATA', 'CORRECTED_DATA', 'FLOAT_DATA' ]: 00070 if colname in tb.colnames(): 00071 casalog.post('Conjugating '+str(colname), 'INFO') 00072 for i in xrange(0,tb.nrows()): 00073 if(tb.getcell("DATA_DESC_ID",i) in myddlist): 00074 a = tb.getcell(colname, i) 00075 a = a.conjugate() 00076 tb.putcell(colname, i, a) 00077 #endif 00078 tb.flush() 00079 tb.close() 00080 casalog.post('Created '+str(outname), 'INFO') 00081 else: 00082 tb.close() 00083 casalog.post('Cannot write to output MS '+str(outname), 'WARN') 00084 00085 except Exception, instance: 00086 tb.close() 00087 print '*** Error ***', instance 00088 raise Exception, instance 00089 00090