casa  $Rev:20696$
 All Classes Namespaces Files Functions Variables
task_testconcat.py
Go to the documentation of this file.
00001 import os
00002 import shutil
00003 import stat
00004 from taskinit import *
00005 
00006 def testconcat(vislist,testconcatvis,freqtol,dirtol,copypointing):
00007         """
00008         The list of data sets given in the vis argument are concatenated into an output
00009         data set in concatvis without copying the bulk data of the main table.
00010         This is useful for obtaining the information in the merged subtables without
00011         actually performing a time-consuming concatenation disk.
00012 
00013         Keyword arguments:
00014         vis -- Name of input visibility files for which the subtables are to be combined
00015         default: none; example: vis = 'mydata.ms',
00016         example: vis=['src2.ms','ngc5921.ms','ngc315.ms']
00017         
00018         testconcatvis -- Name of MS that will contain the concatenated subtables
00019         default: none; example: testconcatvis='test.ms'
00020         
00021         freqtol -- Frequency shift tolerance for considering data to be in the same
00022         spwid.  The number of channels must also be the same.
00023         default: ''  do not combine unless frequencies are equal
00024         example: freqtol='10MHz' will not combine spwid unless they are
00025         within 10 MHz.
00026         Note: This option is useful to conbine spectral windows with very slight
00027         frequency differences caused by Doppler tracking, for example.
00028         
00029         dirtol -- Direction shift tolerance for considering data as the same field
00030         default: '' means always combine.
00031         example: dirtol='1.arcsec' will not combine data for a field unless
00032         their phase center differ by less than 1 arcsec.  If the field names
00033         are different in the input data sets, the name in the output data
00034         set will be the first relevant data set in the list.
00035 
00036         copypointing -- copy all rows of the pointing table
00037         default: True
00038         """
00039 
00040         ###
00041         #Python script
00042         try:
00043                 casalog.origin('testconcat')
00044                 t = tbtool()
00045                 m = mstool()
00046                 #break the reference between vis and vislist as we modify vis
00047                 if(type(vislist)==str):
00048                         vis=[vislist]
00049                 else:
00050                         vis=list(vislist)
00051                 if((type(testconcatvis)!=str) or (len(testconcatvis.split()) < 1)):
00052                         raise Exception, 'parameter testconcatvis is invalid'
00053                 if(vis.count(testconcatvis) > 0):
00054                         vis.remove(testconcatvis)
00055 
00056                 if(os.path.exists(testconcatvis)):
00057                         raise Exception, 'Visibility data set '+testconcatvis+' exists. Will not overwrite.'
00058                 else:
00059                         if(len(vis) >0): 
00060                                 casalog.post('copying structure of '+vis[0]+' to '+testconcatvis , 'INFO')
00061                                 # Copy procedure which does not copy the bulk data of the main table
00062                                 t.open(vis[0])
00063                                 tmptb = t.copy(newtablename=testconcatvis, deep=True, valuecopy=True, norows=True) # copy only table structure
00064                                 tmptb.close()
00065                                 t.close()
00066                                 # copy content of subtables
00067                                 thesubtables = os.walk(vis[0]).next()[1]
00068                                 for subt in thesubtables:
00069                                         if not (subt[0]=='.'):
00070                                                 tb.open(vis[0]+'/'+subt)
00071                                                 no_rows = False
00072                                                 if (subt=='POINTING' and not copypointing):
00073                                                         casalog.post('*** copypointing==False: resulting MS will have empty POINTING table', 'INFO')
00074                                                         no_rows = True
00075                                                 tmptb = tb.copy(testconcatvis+'/'+subt, deep=False, valuecopy=True, norows=no_rows)
00076                                                 tmptb.close()
00077                                                 tb.close()
00078                                 vis.remove(vis[0])
00079                 # determine handling switch value
00080                 handlingswitch = 1
00081                 if not copypointing:
00082                         handlingswitch = 3
00083         
00084                 m.open(testconcatvis,False) # nomodify=False to enable writing
00085         
00086                 for elvis in vis : 
00087                         casalog.post('concatenating subtables from '+elvis+' into '+testconcatvis , 'INFO')
00088 
00089                         m.concatenate(msfile=elvis,freqtol=freqtol,dirtol=dirtol,handling=handlingswitch)
00090 
00091                         m.writehistory(message='taskname=testconcat',origin='testconcat')
00092                         m.writehistory(message='vis         = "'+str(testconcatvis)+'"',origin='testconcat')
00093                         m.writehistory(message='concatvis   = "'+str(elvis)+'"',origin='testconcat')
00094                         m.writehistory(message='freqtol     = "'+str(freqtol)+'"',origin='testconcat')
00095                         m.writehistory(message='dirtol      = "'+str(dirtol)+'"',origin='testconcat')
00096                         m.writehistory(message='copypointing = "'+str(copypointing)+'"',origin='concat')
00097 
00098                 m.close()
00099 
00100         except Exception, instance:
00101                 print '*** Error ***',instance
00102                 raise Exception, instance
00103