casa  $Rev:20696$
 All Classes Namespaces Files Functions Variables
test_virtualconcat.py
Go to the documentation of this file.
00001 #############################################################################
00002 # $Id:$
00003 # Test Name:                                                                #
00004 #    Unit Test Script for the virtualconcat task
00005 #    
00006 #                                                                           #
00007 #############################################################################
00008 import os
00009 import sys
00010 import shutil
00011 import glob
00012 import time
00013 from __main__ import default
00014 from tasks import *
00015 from taskinit import *
00016 import unittest
00017 
00018 myname = 'test_virtualconcat'
00019 
00020 # name of the resulting MS
00021 msname = 'concatenated.ms'
00022 
00023 testmms=False
00024 
00025 def checktable(thename, theexpectation, multims=False):
00026     global msname, myname
00027     if multims:        
00028         tb.open(msname+"/SUBMSS/"+thename)
00029     else:
00030         tb.open(msname+"/"+thename)
00031     if thename == "":
00032         thename = "MAIN"
00033     for mycell in theexpectation:
00034         print myname, ": comparing ", mycell
00035         value = tb.getcell(mycell[0], mycell[1])
00036         # see if value is array
00037         try:
00038             isarray = value.__len__
00039         except:
00040             # it's not an array
00041             # zero tolerance?
00042             if mycell[3] == 0:
00043                 in_agreement = (value == mycell[2])
00044             else:
00045                 in_agreement = ( abs(value - mycell[2]) < mycell[3]) 
00046         else:
00047             # it's an array
00048             # zero tolerance?
00049             if mycell[3] == 0:
00050                 in_agreement =  (value == mycell[2]).all() 
00051             else:
00052                 try:
00053                     in_agreement = (abs(value - mycell[2]) < mycell[3]).all()
00054                 except:
00055                     in_agreement = False
00056         if not in_agreement:
00057             print myname, ":  Error in MS subtable", thename, ":"
00058             print "     column ", mycell[0], " row ", mycell[1], " contains ", value
00059             print "     expected value is ", mycell[2]
00060             tb.close()
00061             return False
00062     tb.close()
00063     print myname, ": table ", thename, " as expected."
00064     return True
00065 
00066 
00067 ###########################
00068 # beginning of actual test 
00069 
00070 class test_virtualconcat(unittest.TestCase):
00071     
00072     def setUp(self):
00073         global testmms
00074         res = None
00075 
00076         datapath=os.environ.get('CASAPATH').split()[0]+'/data/regression/unittest/concat/input/'
00077         # Pick up alternative data directory to run tests on MMSs
00078         testmms = False
00079         if os.environ.has_key('TEST_DATADIR'):   
00080             testmms = True
00081             print "\nTesting on MMSs ...\n"
00082             DATADIR = str(os.environ.get('TEST_DATADIR'))
00083             if os.path.isdir(DATADIR):
00084                 datapath = DATADIR+'/concat/input/'
00085 
00086         cpath = os.path.abspath(os.curdir)
00087         filespresent = sorted(glob.glob("*.ms"))
00088         os.chdir(datapath)
00089         for mymsname in sorted(glob.glob("*.ms")):
00090             if not mymsname in filespresent:
00091                 print "Copying ", mymsname
00092                 shutil.copytree(mymsname, cpath+'/'+mymsname, True)
00093         os.chdir(cpath)
00094 
00095         default(virtualconcat)
00096         
00097     def tearDown(self):
00098         shutil.rmtree(msname,ignore_errors=True)
00099 
00100     def test1(self):
00101         '''Virtualconcat 1: 4 parts, same sources but different spws'''
00102         retValue = {'success': True, 'msgs': "", 'error_msgs': '' }    
00103         
00104         self.res = virtualconcat(vis=['part1.ms','part2.ms','part3.ms','part4.ms'],concatvis=msname)
00105         self.assertEqual(self.res,None)
00106 
00107         print myname, ": Now checking output MS ", msname
00108         try:
00109             ms.open(msname)
00110         except:
00111             ms.close()
00112             print myname, ": Error  Cannot open MS table", tablename
00113             retValue['success']=False
00114             retValue['error_msgs']=retValue['error_msgs']+'Cannot open MS table '+tablename
00115         else:
00116             ms.close()
00117             if 'test1.ms' in glob.glob("*.ms"):
00118                 shutil.rmtree('test1.ms',ignore_errors=True)
00119             shutil.copytree(msname,'test1.ms', True)
00120             print myname, ": OK. Checking tables in detail ..."
00121             retValue['success']=True
00122 
00123             # check source table
00124             name = "SOURCE"
00125             #             col name, row number, expected value, tolerance
00126             expected = [
00127                 ['SOURCE_ID',           55, 13, 0],
00128                 ['SPECTRAL_WINDOW_ID',  55, 3, 0]
00129                 ]
00130             results = checktable(name, expected)
00131             if not results:
00132                 retValue['success']=False
00133                 retValue['error_msgs']=retValue['error_msgs']+'Check of table '+name+' failed'
00134             # check spw table
00135             name = "SPECTRAL_WINDOW"
00136             #             col name, row number, expected value, tolerance
00137             expected = [
00138                 ['NUM_CHAN',           3, 128, 0]
00139                 ]
00140             results = checktable(name, expected)
00141             if not results:
00142                 retValue['success']=False
00143                 retValue['error_msgs']=retValue['error_msgs']+'Check of table '+name+' failed'
00144 
00145         self.assertTrue(retValue['success'])
00146 
00147 
00148     def test2(self):
00149         '''Virtualconcat 2: 3 parts, different sources, different spws, visweightscale=[3.,2.,1.], keepcopy=True'''
00150         retValue = {'success': True, 'msgs': "", 'error_msgs': '' }
00151         self.res = virtualconcat(vis=['part1.ms','part2-mod.ms','part3.ms'],concatvis=msname, visweightscale=[3.,2.,1.], keepcopy=True)
00152         self.assertEqual(self.res,None)
00153         
00154         print myname, ": Now checking output MS ", msname
00155         try:
00156             ms.open(msname)
00157         except:
00158             ms.close()
00159             print myname, ": Error  Cannot open MS table", tablename
00160             retValue['success']=False
00161             retValue['error_msgs']=retValue['error_msgs']+'Cannot open MS table '+tablename
00162         else:
00163             ms.close()
00164             if 'test2.ms' in glob.glob("*.ms"):
00165                 shutil.rmtree('test2.ms',ignore_errors=True)
00166             shutil.copytree(msname,'test2.ms', True)
00167             print myname, ": OK. Checking tables in detail ..."
00168             retValue['success']=True
00169 
00170             # check source table
00171             name = "SOURCE"
00172             #             col name, row number, expected value, tolerance
00173             expected = [
00174                 ['SOURCE_ID',           41, 13, 0],
00175                 ['SPECTRAL_WINDOW_ID',  41, 2, 0]
00176                 ]
00177             results = checktable(name, expected)
00178             if not results:
00179                 retValue['success']=False
00180                 retValue['error_msgs']=retValue['error_msgs']+'Check of table '+name+' failed'
00181             # check spw table
00182             name = "SPECTRAL_WINDOW"
00183             #             col name, row number, expected value, tolerance
00184             expected = [
00185                 ['NUM_CHAN',           2, 128, 0]
00186                 ]
00187             results = checktable(name, expected)
00188             if not results:
00189                 retValue['success']=False
00190                 retValue['error_msgs']=retValue['error_msgs']+'Check of table '+name+' failed'
00191 
00192             # collecting parameters for subsequent test of MAIN table
00193             msnrows = []
00194             oldweightbeg = []
00195             oldweightend = []
00196             ii = 0
00197             for myms in ['part1.ms','part2-mod.ms','part3.ms']:
00198                 tb.open(myms)
00199                 msnrows.append(tb.nrows())
00200                 oldweightbeg.append(tb.getcell('WEIGHT',0))
00201                 oldweightend.append(tb.getcell('WEIGHT',tb.nrows()-1))
00202                 tb.close()
00203 
00204 
00205             name = "" # i.e. Main
00206             #             col name, row number, expected value, tolerance
00207             expected = [
00208                     ['WEIGHT', 0, 3.*oldweightbeg[0], 1E-6], # scaling uses float precision
00209                     ['WEIGHT', msnrows[0]-1, 3.*oldweightend[0], 1E-6],
00210                     ['WEIGHT', msnrows[0], 2.*oldweightbeg[1], 1E-6],
00211                     ['WEIGHT', msnrows[0]+msnrows[1]-1, 2.*oldweightend[1], 1E-6],
00212                     ['WEIGHT', msnrows[0]+msnrows[1], oldweightbeg[2], 1E-6],
00213                     ['WEIGHT', msnrows[0]+msnrows[1]+msnrows[2]-1, oldweightend[2], 1E-6]
00214                 ]
00215 
00216             results = checktable(name, expected)
00217             if not results:
00218                 retValue['success']=False
00219                 retValue['error_msgs']=retValue['error_msgs']+'Check of table '+name+' failed'
00220 
00221         self.assertTrue(retValue['success'])
00222 
00223 
00224     def test3(self):
00225         '''Virtualconcat 3: 3 parts, different sources, same spws'''
00226         retValue = {'success': True, 'msgs': "", 'error_msgs': '' }    
00227         self.res = virtualconcat(vis=['part1.ms','part2-mod2.ms','part3.ms'],concatvis=msname)
00228         self.assertEqual(self.res,None)
00229 
00230         print myname, ": Now checking output MS ", msname
00231         try:
00232             ms.open(msname)
00233         except:
00234             ms.close()
00235             print myname, ": Error  Cannot open MS table", tablename
00236             retValue['success']=False
00237             retValue['error_msgs']=retValue['error_msgs']+'Cannot open MS table '+tablename
00238         else:
00239             ms.close()
00240             if 'test3.ms' in glob.glob("*.ms"):
00241                 shutil.rmtree('test3.ms',ignore_errors=True)
00242             shutil.copytree(msname,'test3.ms', True)
00243             print myname, ": OK. Checking tables in detail ..."
00244             retValue['success']=True
00245 
00246             # check source table
00247             name = "SOURCE"
00248             #             col name, row number, expected value, tolerance
00249             expected = [
00250                 ['SOURCE_ID',           28, 13, 0],
00251                 ['SPECTRAL_WINDOW_ID',  28, 1, 0]
00252                 ]
00253             results = checktable(name, expected)
00254             if not results:
00255                 retValue['success']=False
00256                 retValue['error_msgs']=retValue['error_msgs']+'Check of table '+name+' failed'
00257             # check spw table
00258             name = "SPECTRAL_WINDOW"
00259             #             col name, row number, expected value, tolerance
00260             expected = [
00261                 ['NUM_CHAN',           1, 128, 0]
00262                 ]
00263             results = checktable(name, expected)
00264             if not results:
00265                 retValue['success']=False
00266                 retValue['error_msgs']=retValue['error_msgs']+'Check of table '+name+' failed'
00267 
00268         self.assertTrue(retValue['success'])
00269 
00270 
00271     def test4(self):
00272         '''Virtualconcat 4: five MSs with identical sources but different time/intervals on them (CSV-268)'''
00273         retValue = {'success': True, 'msgs': "", 'error_msgs': '' }
00274         
00275         self.res = virtualconcat(vis = ['shortpart1.ms', 'shortpart2.ms', 'shortpart3.ms', 'shortpart4.ms', 'shortpart5.ms'],
00276                           concatvis = msname)
00277         self.assertEqual(self.res,None)
00278 
00279         print myname, ": Now checking output ..."
00280         try:
00281             ms.open(msname)
00282         except:
00283             ms.close()
00284             print myname, ": Error  Cannot open MS table", tablename
00285             retValue['success']=False
00286             retValue['error_msgs']=retValue['error_msgs']+'Cannot open MS table '+tablename
00287         else:
00288             ms.close()
00289             if 'test4.ms' in glob.glob("*.ms"):
00290                 shutil.rmtree('test4.ms',ignore_errors=True)
00291             shutil.copytree(msname,'test4.ms', True)
00292             print myname, ": OK. Checking tables in detail ..."
00293             retValue['success']=True
00294         
00295     
00296             # check source table
00297             name = "SOURCE"
00298             #             col name, row number, expected value, tolerance
00299             expected = [
00300                 ['SOURCE_ID',           0, 0, 0],
00301                 ['SPECTRAL_WINDOW_ID',  0, 0, 0]
00302                 ]
00303             results = checktable(name, expected)
00304             if not results:
00305                 retValue['success']=False
00306                 retValue['error_msgs']=retValue['error_msgs']+'Check of table '+name+' failed'
00307             expected = [
00308                 ['SOURCE_ID',           7, 0, 0],
00309                 ['SPECTRAL_WINDOW_ID',  7, 7, 0]
00310                 ]
00311             results = checktable(name, expected)
00312             if not results:
00313                 retValue['success']=False
00314                 retValue['error_msgs']=retValue['error_msgs']+'Check of table '+name+' failed'
00315             expected = [
00316                 ['SOURCE_ID',           8, 1, 0],
00317                 ['SPECTRAL_WINDOW_ID',  8, 0, 0]
00318                 ]
00319             results = checktable(name, expected)
00320             if not results:
00321                 retValue['success']=False
00322                 retValue['error_msgs']=retValue['error_msgs']+'Check of table '+name+' failed'
00323             expected = [
00324                 ['SOURCE_ID',           15, 1, 0],
00325                 ['SPECTRAL_WINDOW_ID',  15, 7, 0]
00326                 ]
00327             results = checktable(name, expected)
00328             if not results:
00329                 retValue['success']=False
00330                 retValue['error_msgs']=retValue['error_msgs']+'Check of table '+name+' failed'
00331             expected = [
00332                 ['SOURCE_ID',           16, 0, 100000],
00333                 ['SPECTRAL_WINDOW_ID',  16, 0, 100000]
00334                 ]
00335             print "The following should fail: SOURCE row 16 should not exist"
00336             try:
00337                 results = checktable(name, expected)
00338             except:
00339                 print "Expected error."
00340                 results = False
00341             if results: 
00342                 retValue['success']=False
00343                 retValue['error_msgs']='SOURCE row 16 should not existCheck of table '+name+' failed'
00344             # check spw table
00345             name = "SPECTRAL_WINDOW"
00346             #             col name, row number, expected value, tolerance
00347             expected = [
00348                 ['NUM_CHAN',           8, 4, 0]
00349                 ]
00350             results = checktable(name, expected)
00351             if not results:
00352                 retValue['success']=False
00353                 retValue['error_msgs']=retValue['error_msgs']+'Check of table '+name+' failed'
00354     
00355                 
00356         self.assertTrue(retValue['success'])
00357         
00358     def test5(self):
00359         '''Virtualconcat 5: two MSs with different state table (CAS-2601)'''
00360         retValue = {'success': True, 'msgs': "", 'error_msgs': '' }
00361         
00362         self.res = virtualconcat(vis = ['A2256LC2_4.5s-1.ms','A2256LC2_4.5s-2.ms'],
00363                           concatvis = msname)
00364         self.assertEqual(self.res,None)
00365 
00366         print myname, ": Now checking output ..."
00367         try:
00368             ms.open(msname)
00369         except:
00370             print myname, ": Error  Cannot open MS table", tablename
00371             retValue['success']=False
00372             retValue['error_msgs']=retValue['error_msgs']+'Cannot open MS table '+tablename
00373         else:
00374             ms.close()
00375             if 'test5.ms' in glob.glob("*.ms"):
00376                 shutil.rmtree('test5.ms',ignore_errors=True)
00377             shutil.copytree(msname,'test5.ms', True)
00378             print myname, ": OK. Checking tables in detail ..."
00379             retValue['success']=True        
00380     
00381             # check state table
00382             name = "STATE"
00383             #             col name, row number, expected value, tolerance
00384             expected = [
00385                 ['CAL',  0, 0, 0],
00386                 ['SIG',  0, 1, 0],
00387                 ['SUB_SCAN',  2, 1, 0]
00388                 ]
00389             results = checktable(name, expected)
00390             if not results:
00391                 retValue['success']=False
00392                 retValue['error_msgs']=retValue['error_msgs']+'Check of table '+name+' failed'
00393                 retValue['error_msgs']=retValue['error_msgs']+'Check of table '+name+' failed'
00394                 
00395         self.assertTrue(retValue['success'])
00396 
00397     def test6(self):
00398         '''Virtualconcat 6: two MSs with different state table and feed table'''
00399         retValue = {'success': True, 'msgs': "", 'error_msgs': '' }
00400         
00401         self.res = virtualconcat(vis = ['A2256LC2_4.5s-1.ms','A2256LC2_4.5s-2b.ms'],
00402                           concatvis = msname)
00403         self.assertEqual(self.res,None)
00404 
00405         print myname, ": Now checking output ..."
00406         try:
00407             ms.open(msname)
00408         except:
00409             ms.close()
00410             print myname, ": Error  Cannot open MS table", tablename
00411             retValue['success']=False
00412             retValue['error_msgs']=retValue['error_msgs']+'Cannot open MS table '+tablename
00413         else:
00414             ms.close()
00415             if 'test6.ms' in glob.glob("*.ms"):
00416                 shutil.rmtree('test6.ms',ignore_errors=True)
00417             shutil.copytree(msname,'test6.ms', True)
00418             print myname, ": OK. Checking tables in detail ..."
00419             retValue['success']=True        
00420     
00421             # check FEED table
00422             name = "FEED"
00423             #             col name, row number, expected value, tolerance
00424             expected = [
00425                 ['SPECTRAL_WINDOW_ID',  53, 1, 0],
00426                 ['SPECTRAL_WINDOW_ID',  54, 2, 0],
00427                 ['SPECTRAL_WINDOW_ID',  107, 3, 0],
00428                 ['RECEPTOR_ANGLE',  54, [-1,0], 0]
00429                 ]
00430             results = checktable(name, expected)
00431             if not results:
00432                 retValue['success']=False
00433                 retValue['error_msgs']=retValue['error_msgs']+'Check of table '+name+' failed'
00434                 retValue['error_msgs']=retValue['error_msgs']+'Check of table '+name+' failed'
00435                 
00436         self.assertTrue(retValue['success'])
00437 
00438     def test7(self):
00439         '''Virtualconcat 7: two MSs with different antenna table such that baseline label reversal becomes necessary'''
00440         retValue = {'success': True, 'msgs': "", 'error_msgs': '' }
00441         
00442         self.res = virtualconcat(vis = ['sim7.ms','sim8.ms'],
00443                           concatvis = msname)
00444         self.assertEqual(self.res,None)
00445 
00446         print myname, ": Now checking output ..."
00447         try:
00448             ms.open(msname)
00449         except:
00450             ms.close()
00451             print myname, ": Error  Cannot open MS table", tablename
00452             retValue['success']=False
00453             retValue['error_msgs']=retValue['error_msgs']+'Cannot open MS table '+tablename
00454         else:
00455             ms.close()
00456             if 'test7.ms' in glob.glob("*.ms"):
00457                 shutil.rmtree('test7.ms',ignore_errors=True)
00458             shutil.copytree(msname,'test7.ms', True)
00459             print myname, ": OK. Checking tables in detail ..."
00460             retValue['success']=True        
00461     
00462             # check Main table
00463             tb.open('test7.ms')
00464             ant1 = tb.getcol('ANTENNA1')
00465             ant2 = tb.getcol('ANTENNA2')
00466             tb.close()
00467             result = True
00468             print myname, ": OK. Checking baseline labels ..."
00469             for i in xrange(0,len(ant1)):
00470                 if(ant1[i]>ant2[i]):
00471                     print "Found incorrectly ordered baseline label in row ", i, ": ", ant1, " ", ant2
00472                     result = False
00473                     break
00474 
00475             if not result:
00476                 retValue['success']=False
00477                 retValue['error_msgs']=retValue['error_msgs']+'Check of table '+name+' failed'
00478                 retValue['error_msgs']=retValue['error_msgs']+'Check of table '+name+' failed'
00479                 
00480         self.assertTrue(retValue['success'])
00481 
00482     def test8(self):
00483         '''Virtualconcat 8: two MSs with different antenna tables, copypointing=False'''
00484         retValue = {'success': True, 'msgs': "", 'error_msgs': '' }
00485         
00486         self.res = virtualconcat(vis = ['sim7.ms','sim8.ms'],
00487                           concatvis = msname, copypointing=False)
00488         self.assertEqual(self.res,None)
00489 
00490         print myname, ": Now checking output ..."
00491         try:
00492             ms.open(msname)
00493         except:
00494             ms.close()
00495             print myname, ": Error  Cannot open MS table", tablename
00496             retValue['success']=False
00497             retValue['error_msgs']=retValue['error_msgs']+'Cannot open MS table '+tablename
00498         else:
00499             ms.close()
00500             if 'test8.ms' in glob.glob("*.ms"):
00501                 shutil.rmtree('test8.ms',ignore_errors=True)
00502             shutil.copytree(msname,'test8.ms', True)
00503             print myname, ": OK. Checking tables in detail ..."
00504             retValue['success']=True        
00505     
00506             # check Main table
00507             tb.open('test8.ms')
00508             ant1 = tb.getcol('ANTENNA1')
00509             ant2 = tb.getcol('ANTENNA2')
00510             tb.close()
00511             result = True
00512             print myname, ": OK. Checking baseline labels ..."
00513             for i in xrange(0,len(ant1)):
00514                 if(ant1[i]>ant2[i]):
00515                     print "Found incorrectly ordered baseline label in row ", i, ": ", ant1, " ", ant2
00516                     result = False
00517                     break
00518                 
00519             if result:
00520                 print myname, ": OK. Checking pointing table ..."
00521 
00522             tb.open('test8.ms/POINTING')
00523             pointingrows = tb.nrows()
00524             tb.close()
00525             if pointingrows>0:
00526                 print "Pointing table should be empty!"
00527                 result = False
00528 
00529             if not result:
00530                 retValue['success']=False
00531                 retValue['error_msgs']=retValue['error_msgs']+'Check of tables main and/or pointing failed'
00532                 
00533         self.assertTrue(retValue['success'])
00534 
00535 
00536 
00537     def test9(self):
00538         '''Virtualconcat 9: 3 parts, different sources, same spws, different scratch columns: no, yes, no'''
00539         global testmms
00540         retValue = {'success': True, 'msgs': "", 'error_msgs': '' }
00541 
00542         shutil.rmtree('part2-mod2-wscratch.ms',ignore_errors=True)
00543         shutil.copytree('part2-mod2.ms', 'part2-mod2-wscratch.ms', True)
00544         print 'creating scratch columns in part2-mod2-wscratch.ms'
00545         if testmms:
00546             ms.open('part2-mod2-wscratch.ms')
00547             mses = ms.getreferencedtables()
00548             ms.close()
00549             mses.sort()
00550             for mname in mses:
00551                 cb.open(mname)
00552                 cb.close()
00553         else:
00554             cb.open('part2-mod2-wscratch.ms') # calibrator-open creates scratch columns
00555             cb.close()
00556 
00557         self.res = virtualconcat(vis=['part1.ms','part2-mod2-wscratch.ms','part3.ms'],concatvis=msname)
00558         self.assertEqual(self.res,None)
00559 
00560         print myname, ": Now checking output ..."
00561         try:
00562             ms.open(msname)
00563         except:
00564             ms.close()
00565             print myname, ": Error  Cannot open MS table", tablename
00566             retValue['success']=False
00567             retValue['error_msgs']=retValue['error_msgs']+'Cannot open MS table '+tablename
00568         else:
00569             ms.close()
00570             if 'test9.ms' in glob.glob("*.ms"):
00571                 shutil.rmtree('test9.ms',ignore_errors=True)
00572             shutil.copytree(msname,'test9.ms', True)
00573             print myname, ": OK. Checking tables in detail ..."
00574             retValue['success']=True
00575 
00576             # check source table
00577             name = "SOURCE"
00578             #             col name, row number, expected value, tolerance
00579             expected = [
00580                 ['SOURCE_ID',           28, 13, 0],
00581                 ['SPECTRAL_WINDOW_ID',  28, 1, 0]
00582                 ]
00583             results = checktable(name, expected)
00584             if not results:
00585                 retValue['success']=False
00586                 retValue['error_msgs']=retValue['error_msgs']+'Check of table '+name+' failed'
00587             # check spw table
00588             name = "SPECTRAL_WINDOW"
00589             #             col name, row number, expected value, tolerance
00590             expected = [
00591                 ['NUM_CHAN',           1, 128, 0]
00592                 ]
00593             results = checktable(name, expected)
00594             if not results:
00595                 retValue['success']=False
00596                 retValue['error_msgs']=retValue['error_msgs']+'Check of table '+name+' failed'
00597 
00598         self.assertTrue(retValue['success'])
00599         
00600     def test10(self):
00601         '''Virtualconcat 10: 3 parts, different sources, same spws, different scratch columns: yes, no, no'''
00602         global testmms
00603         retValue = {'success': True, 'msgs': "", 'error_msgs': '' }
00604 
00605         shutil.rmtree('part1-wscratch.ms',ignore_errors=True)
00606         shutil.copytree('part1.ms', 'part1-wscratch.ms', True)
00607         print 'creating scratch columns in part1-wscratch.ms'
00608         if testmms:
00609             ms.open('part1-wscratch.ms')
00610             mses = ms.getreferencedtables()
00611             ms.close()
00612             mses.sort()
00613             for mname in mses:
00614                 cb.open(mname)
00615                 cb.close()
00616         else:
00617             cb.open('part1-wscratch.ms') # calibrator-open creates scratch columns
00618             cb.close()
00619 
00620         self.res = virtualconcat(vis=['part1-wscratch.ms','part2-mod2.ms','part3.ms'],concatvis=msname)
00621         self.assertEqual(self.res,None)
00622 
00623         print myname, ": Now checking output ..."
00624         try:
00625             ms.open(msname)
00626         except:
00627             ms.close()
00628             print myname, ": Error  Cannot open MS table", tablename
00629             retValue['success']=False
00630             retValue['error_msgs']=retValue['error_msgs']+'Cannot open MS table '+tablename
00631         else:
00632             ms.close()
00633             if 'test10.ms' in glob.glob("*.ms"):
00634                 shutil.rmtree('test10.ms',ignore_errors=True)
00635             shutil.copytree(msname,'test10.ms', True)
00636             print myname, ": OK. Checking tables in detail ..."
00637             retValue['success']=True
00638 
00639             # check source table
00640             name = "SOURCE"
00641             #             col name, row number, expected value, tolerance
00642             expected = [
00643                 ['SOURCE_ID',           28, 13, 0],
00644                 ['SPECTRAL_WINDOW_ID',  28, 1, 0]
00645                 ]
00646             results = checktable(name, expected)
00647             if not results:
00648                 retValue['success']=False
00649                 retValue['error_msgs']=retValue['error_msgs']+'Check of table '+name+' failed'
00650             # check spw table
00651             name = "SPECTRAL_WINDOW"
00652             #             col name, row number, expected value, tolerance
00653             expected = [
00654                 ['NUM_CHAN',           1, 128, 0]
00655                 ]
00656             results = checktable(name, expected)
00657             if not results:
00658                 retValue['success']=False
00659                 retValue['error_msgs']=retValue['error_msgs']+'Check of table '+name+' failed'
00660 
00661         self.assertTrue(retValue['success'])
00662 
00663     def test11(self):
00664         '''Virtualconcat 11: comparison to concat'''
00665         global testmms
00666         retValue = {'success': True, 'msgs': "", 'error_msgs': '' }
00667 
00668         if testmms:
00669             print "Skipping this test as concat will not work with an MMS."
00670         else:
00671             shutil.rmtree('allparts.ms', ignore_errors=True)
00672             shutil.rmtree('allparts.mms', ignore_errors=True)
00673             os.system('rm -f ms.txt mms.txt')
00674         
00675             thebeginning = time.time()
00676             concat(vis=['part1.ms','part2.ms','part3.ms','part4.ms'], concatvis='allparts.ms')
00677             theend = time.time()
00678             print "duration using concat (s) = ", theend-thebeginning
00679 
00680             thebeginning = time.time()
00681             virtualconcat(vis=['part1.ms','part2.ms','part3.ms','part4.ms'], concatvis='allparts.mms')
00682             theend = time.time()
00683             print "duration using virtualconcat (s) =", theend-thebeginning
00684         
00685             listobs(vis='allparts.ms', listfile='ms.txt')
00686             shutil.rmtree('allparts.ms')
00687             shutil.move('allparts.mms', 'allparts.ms') # to get same file name
00688             listobs(vis='allparts.ms', listfile='mms.txt')
00689             os.system('diff ms.txt mms.txt > diff.txt')
00690             os.system('cat diff.txt')
00691             retValue['success'] = (os.path.getsize('diff.txt') == 0)
00692 
00693         self.assertTrue(retValue['success'])
00694 
00695     def test12(self):
00696         '''Virtualconcat 12: two MSs with different antenna tables, copypointing=True (default)'''
00697         retValue = {'success': True, 'msgs': "", 'error_msgs': '' }
00698         
00699         self.res = virtualconcat(vis = ['sim7.ms','sim8.ms'],
00700                           concatvis = msname, copypointing=True)
00701         self.assertEqual(self.res,None)
00702 
00703         print myname, ": Now checking output ..."
00704         try:
00705             ms.open(msname)
00706         except:
00707             ms.close()
00708             print myname, ": Error  Cannot open MS table", tablename
00709             retValue['success']=False
00710             retValue['error_msgs']=retValue['error_msgs']+'Cannot open MS table '+tablename
00711         else:
00712             ms.close()
00713             if 'test12.ms' in glob.glob("*.ms"):
00714                 shutil.rmtree('test12.ms',ignore_errors=True)
00715             shutil.copytree(msname,'test12.ms', True)
00716             print myname, ": OK. Checking tables in detail ..."
00717             retValue['success']=True        
00718 
00719             result = True
00720             tb.open('test12.ms/POINTING')
00721             pointingrows = tb.nrows()
00722             tb.close()
00723             if pointingrows==0:
00724                 result = False
00725 
00726             if not result:
00727                 retValue['success']=False
00728                 retValue['error_msgs']=retValue['error_msgs']+'Check of pointing table failed'
00729                 
00730         self.assertTrue(retValue['success'])
00731 
00732 
00733 class virtualconcat_cleanup(unittest.TestCase):           
00734     def setUp(self):
00735         pass
00736     
00737     def tearDown(self):
00738         os.system('rm -rf *.ms')
00739 
00740     def testrun(self):
00741         '''Virtualconcat: Cleanup'''
00742         pass
00743     
00744 def suite():
00745     return [test_virtualconcat,virtualconcat_cleanup]        
00746