00001
00002
00003
00004
00005
00006
00007
00008 import os
00009 import sys
00010 import shutil
00011 import glob
00012 from __main__ import default
00013 from tasks import *
00014 from taskinit import *
00015 import unittest
00016
00017 myname = 'test_testconcat'
00018
00019
00020 msname = 'testconcatenated.ms'
00021
00022 def checktable(thename, theexpectation):
00023 global msname, myname
00024 mytb = tbtool()
00025 mytb.open(msname+"/"+thename)
00026 for mycell in theexpectation:
00027 print myname, ": comparing ", mycell
00028 value = mytb.getcell(mycell[0], mycell[1])
00029
00030 try:
00031 isarray = value.__len__
00032 except:
00033
00034
00035 if mycell[3] == 0:
00036 in_agreement = (value == mycell[2])
00037 else:
00038 in_agreement = ( abs(value - mycell[2]) < mycell[3])
00039 else:
00040
00041
00042 if mycell[3] == 0:
00043 in_agreement = (value == mycell[2]).all()
00044 else:
00045 try:
00046 in_agreement = (abs(value - mycell[2]) < mycell[3]).all()
00047 except:
00048 in_agreement = False
00049 if not in_agreement:
00050 print myname, ": Error in MS subtable", thename, ":"
00051 print " column ", mycell[0], " row ", mycell[1], " contains ", value
00052 print " expected value is ", mycell[2]
00053 mytb.close()
00054 return False
00055 mytb.close()
00056 print myname, ": table ", thename, " as expected."
00057 return True
00058
00059
00060
00061
00062
00063 class test_testconcat(unittest.TestCase):
00064
00065 def setUp(self):
00066 res = None
00067
00068 datapath=os.environ.get('CASAPATH').split()[0]+'/data/regression/unittest/concat/input/'
00069 cpath = os.path.abspath(os.curdir)
00070 filespresent = sorted(glob.glob("*.ms"))
00071 os.chdir(datapath)
00072 for mymsname in sorted(glob.glob("*.ms")):
00073 if not mymsname in filespresent:
00074 print "Copying ", mymsname
00075 shutil.copytree(mymsname, cpath+'/'+mymsname)
00076 os.chdir(cpath)
00077
00078 default(testconcat)
00079
00080 def tearDown(self):
00081 shutil.rmtree(msname,ignore_errors=True)
00082
00083 def test1(self):
00084 '''Testconcat 1: 4 parts, same sources but different spws'''
00085 retValue = {'success': True, 'msgs': "", 'error_msgs': '' }
00086
00087 self.res = testconcat(vis=['part1.ms','part2.ms','part3.ms','part4.ms'],testconcatvis=msname)
00088 self.assertEqual(self.res,None)
00089
00090 print myname, ": Success! Now checking output ..."
00091 mscomponents = set(["table.dat",
00092 "table.f0",
00093 "table.f1",
00094 "table.f2",
00095 "table.f3",
00096 "table.f4",
00097 "table.f5",
00098 "table.f6",
00099 "table.f7",
00100 "table.f8",
00101 "ANTENNA/table.dat",
00102 "DATA_DESCRIPTION/table.dat",
00103 "FEED/table.dat",
00104 "FIELD/table.dat",
00105 "FLAG_CMD/table.dat",
00106 "HISTORY/table.dat",
00107 "OBSERVATION/table.dat",
00108 "POINTING/table.dat",
00109 "POLARIZATION/table.dat",
00110 "PROCESSOR/table.dat",
00111 "SOURCE/table.dat",
00112 "SPECTRAL_WINDOW/table.dat",
00113 "STATE/table.dat",
00114 "ANTENNA/table.f0",
00115 "DATA_DESCRIPTION/table.f0",
00116 "FEED/table.f0",
00117 "FIELD/table.f0",
00118 "FLAG_CMD/table.f0",
00119 "HISTORY/table.f0",
00120 "OBSERVATION/table.f0",
00121 "POINTING/table.f0",
00122 "POLARIZATION/table.f0",
00123 "PROCESSOR/table.f0",
00124 "SOURCE/table.f0",
00125 "SPECTRAL_WINDOW/table.f0",
00126 "STATE/table.f0"
00127 ])
00128 for name in mscomponents:
00129 if not os.access(msname+"/"+name, os.F_OK):
00130 print myname, ": Error ", msname+"/"+name, "doesn't exist ..."
00131 retValue['success']=False
00132 retValue['error_msgs']=retValue['error_msgs']+msname+'/'+name+' does not exist'
00133 else:
00134 print myname, ": ", name, "present."
00135 print myname, ": pseudo-MS exists. All tables present."
00136 if 'test1.ms' in glob.glob("*.ms"):
00137 shutil.rmtree('test1.ms',ignore_errors=True)
00138 shutil.copytree(msname,'test1.ms')
00139 print myname, ": OK. Checking tables in detail ..."
00140 retValue['success']=True
00141
00142
00143 name = "SOURCE"
00144
00145 expected = [
00146 ['SOURCE_ID', 55, 13, 0],
00147 ['SPECTRAL_WINDOW_ID', 55, 3, 0]
00148 ]
00149 results = checktable(name, expected)
00150 if not results:
00151 retValue['success']=False
00152 retValue['error_msgs']=retValue['error_msgs']+'Check of table '+name+' failed'
00153
00154 name = "SPECTRAL_WINDOW"
00155
00156 expected = [
00157 ['NUM_CHAN', 3, 128, 0]
00158 ]
00159 results = checktable(name, expected)
00160 if not results:
00161 retValue['success']=False
00162 retValue['error_msgs']=retValue['error_msgs']+'Check of table '+name+' failed'
00163
00164
00165 def test2(self):
00166 '''Testconcat 2: 3 parts, different sources, different spws '''
00167 retValue = {'success': True, 'msgs': "", 'error_msgs': '' }
00168 self.res = testconcat(vis=['part1.ms','part2-mod.ms','part3.ms'],testconcatvis=msname)
00169 self.assertEqual(self.res,None)
00170
00171 print myname, ": Success! Now checking output ..."
00172 mscomponents = set(["table.dat",
00173 "table.f0",
00174 "table.f1",
00175 "table.f2",
00176 "table.f3",
00177 "table.f4",
00178 "table.f5",
00179 "table.f6",
00180 "table.f7",
00181 "table.f8",
00182 "ANTENNA/table.dat",
00183 "DATA_DESCRIPTION/table.dat",
00184 "FEED/table.dat",
00185 "FIELD/table.dat",
00186 "FLAG_CMD/table.dat",
00187 "HISTORY/table.dat",
00188 "OBSERVATION/table.dat",
00189 "POINTING/table.dat",
00190 "POLARIZATION/table.dat",
00191 "PROCESSOR/table.dat",
00192 "SOURCE/table.dat",
00193 "SPECTRAL_WINDOW/table.dat",
00194 "STATE/table.dat",
00195 "ANTENNA/table.f0",
00196 "DATA_DESCRIPTION/table.f0",
00197 "FEED/table.f0",
00198 "FIELD/table.f0",
00199 "FLAG_CMD/table.f0",
00200 "HISTORY/table.f0",
00201 "OBSERVATION/table.f0",
00202 "POINTING/table.f0",
00203 "POLARIZATION/table.f0",
00204 "PROCESSOR/table.f0",
00205 "SOURCE/table.f0",
00206 "SPECTRAL_WINDOW/table.f0",
00207 "STATE/table.f0"
00208 ])
00209 for name in mscomponents:
00210 if not os.access(msname+"/"+name, os.F_OK):
00211 print myname, ": Error ", msname+"/"+name, "doesn't exist ..."
00212 retValue['success']=False
00213 retValue['error_msgs']=retValue['error_msgs']+msname+'/'+name+' does not exist'
00214 else:
00215 print myname, ": ", name, "present."
00216 print myname, ": MS exists. All tables present."
00217
00218 if 'test2.ms' in glob.glob("*.ms"):
00219 shutil.rmtree('test2.ms',ignore_errors=True)
00220 shutil.copytree(msname,'test2.ms')
00221 print myname, ": OK. Checking tables in detail ..."
00222 retValue['success']=True
00223
00224
00225 name = "SOURCE"
00226
00227 expected = [
00228 ['SOURCE_ID', 41, 13, 0],
00229 ['SPECTRAL_WINDOW_ID', 41, 2, 0]
00230 ]
00231 results = checktable(name, expected)
00232 if not results:
00233 retValue['success']=False
00234 retValue['error_msgs']=retValue['error_msgs']+'Check of table '+name+' failed'
00235
00236 name = "SPECTRAL_WINDOW"
00237
00238 expected = [
00239 ['NUM_CHAN', 2, 128, 0]
00240 ]
00241 results = checktable(name, expected)
00242 if not results:
00243 retValue['success']=False
00244 retValue['error_msgs']=retValue['error_msgs']+'Check of table '+name+' failed'
00245
00246
00247 def test3(self):
00248 '''Testconcat 3: 3 parts, different sources, same spws'''
00249 retValue = {'success': True, 'msgs': "", 'error_msgs': '' }
00250 self.res = testconcat(vis=['part1.ms','part2-mod2.ms','part3.ms'],testconcatvis=msname)
00251 self.assertEqual(self.res,None)
00252
00253 print myname, ": Success! Now checking output ..."
00254 mscomponents = set(["table.dat",
00255 "table.f0",
00256 "table.f1",
00257 "table.f2",
00258 "table.f3",
00259 "table.f4",
00260 "table.f5",
00261 "table.f6",
00262 "table.f7",
00263 "table.f8",
00264 "ANTENNA/table.dat",
00265 "DATA_DESCRIPTION/table.dat",
00266 "FEED/table.dat",
00267 "FIELD/table.dat",
00268 "FLAG_CMD/table.dat",
00269 "HISTORY/table.dat",
00270 "OBSERVATION/table.dat",
00271 "POINTING/table.dat",
00272 "POLARIZATION/table.dat",
00273 "PROCESSOR/table.dat",
00274 "SOURCE/table.dat",
00275 "SPECTRAL_WINDOW/table.dat",
00276 "STATE/table.dat",
00277 "ANTENNA/table.f0",
00278 "DATA_DESCRIPTION/table.f0",
00279 "FEED/table.f0",
00280 "FIELD/table.f0",
00281 "FLAG_CMD/table.f0",
00282 "HISTORY/table.f0",
00283 "OBSERVATION/table.f0",
00284 "POINTING/table.f0",
00285 "POLARIZATION/table.f0",
00286 "PROCESSOR/table.f0",
00287 "SOURCE/table.f0",
00288 "SPECTRAL_WINDOW/table.f0",
00289 "STATE/table.f0"
00290 ])
00291 for name in mscomponents:
00292 if not os.access(msname+"/"+name, os.F_OK):
00293 print myname, ": Error ", msname+"/"+name, "doesn't exist ..."
00294 retValue['success']=False
00295 retValue['error_msgs']=retValue['error_msgs']+msname+'/'+name+' does not exist'
00296 else:
00297 print myname, ": ", name, "present."
00298 print myname, ": MS exists. All tables present."
00299
00300 if 'test3.ms' in glob.glob("*.ms"):
00301 shutil.rmtree('test3.ms',ignore_errors=True)
00302 shutil.copytree(msname,'test3.ms')
00303 print myname, ": OK. Checking tables in detail ..."
00304 retValue['success']=True
00305
00306
00307 name = "SOURCE"
00308
00309 expected = [
00310 ['SOURCE_ID', 28, 13, 0],
00311 ['SPECTRAL_WINDOW_ID', 28, 1, 0]
00312 ]
00313 results = checktable(name, expected)
00314 if not results:
00315 retValue['success']=False
00316 retValue['error_msgs']=retValue['error_msgs']+'Check of table '+name+' failed'
00317
00318 name = "SPECTRAL_WINDOW"
00319
00320 expected = [
00321 ['NUM_CHAN', 1, 128, 0]
00322 ]
00323 results = checktable(name, expected)
00324 if not results:
00325 retValue['success']=False
00326 retValue['error_msgs']=retValue['error_msgs']+'Check of table '+name+' failed'
00327
00328
00329 def test4(self):
00330 '''Testconcat 4: five MSs with identical sources but different time/intervals on them (CSV-268)'''
00331 retValue = {'success': True, 'msgs': "", 'error_msgs': '' }
00332
00333 self.res = testconcat(vis = ['shortpart1.ms', 'shortpart2.ms', 'shortpart3.ms', 'shortpart4.ms', 'shortpart5.ms'],
00334 testconcatvis = msname, copypointing=False)
00335 self.assertEqual(self.res,None)
00336
00337 print myname, ": Success! Now checking output ..."
00338 mscomponents = set(["table.dat",
00339 "table.f0",
00340 "table.f1",
00341 "table.f2",
00342 "table.f3",
00343 "table.f4",
00344 "table.f5",
00345 "table.f6",
00346 "table.f7",
00347 "table.f8",
00348 "ANTENNA/table.dat",
00349 "DATA_DESCRIPTION/table.dat",
00350 "FEED/table.dat",
00351 "FIELD/table.dat",
00352 "FLAG_CMD/table.dat",
00353 "HISTORY/table.dat",
00354 "OBSERVATION/table.dat",
00355 "POINTING/table.dat",
00356 "POLARIZATION/table.dat",
00357 "PROCESSOR/table.dat",
00358 "SOURCE/table.dat",
00359 "SPECTRAL_WINDOW/table.dat",
00360 "STATE/table.dat",
00361 "ANTENNA/table.f0",
00362 "DATA_DESCRIPTION/table.f0",
00363 "FEED/table.f0",
00364 "FIELD/table.f0",
00365 "FLAG_CMD/table.f0",
00366 "HISTORY/table.f0",
00367 "OBSERVATION/table.f0",
00368 "POINTING/table.f0",
00369 "POLARIZATION/table.f0",
00370 "PROCESSOR/table.f0",
00371 "SOURCE/table.f0",
00372 "SPECTRAL_WINDOW/table.f0",
00373 "STATE/table.f0"
00374 ])
00375 for name in mscomponents:
00376 if not os.access(msname+"/"+name, os.F_OK):
00377 print myname, ": Error ", msname+"/"+name, "doesn't exist ..."
00378 retValue['success']=False
00379 retValue['error_msgs']=retValue['error_msgs']+msname+'/'+name+' does not exist'
00380 else:
00381 print myname, ": ", name, "present."
00382 print myname, ": MS exists. All tables present."
00383
00384 if 'test4.ms' in glob.glob("*.ms"):
00385 shutil.rmtree('test4.ms',ignore_errors=True)
00386 shutil.copytree(msname,'test4.ms')
00387 print myname, ": OK. Checking tables in detail ..."
00388 retValue['success']=True
00389
00390
00391
00392 name = "SOURCE"
00393
00394 expected = [
00395 ['SOURCE_ID', 0, 0, 0],
00396 ['SPECTRAL_WINDOW_ID', 0, 0, 0]
00397 ]
00398 results = checktable(name, expected)
00399 if not results:
00400 retValue['success']=False
00401 retValue['error_msgs']=retValue['error_msgs']+'Check of table '+name+' failed'
00402 expected = [
00403 ['SOURCE_ID', 7, 0, 0],
00404 ['SPECTRAL_WINDOW_ID', 7, 7, 0]
00405 ]
00406 results = checktable(name, expected)
00407 if not results:
00408 retValue['success']=False
00409 retValue['error_msgs']=retValue['error_msgs']+'Check of table '+name+' failed'
00410 expected = [
00411 ['SOURCE_ID', 8, 1, 0],
00412 ['SPECTRAL_WINDOW_ID', 8, 0, 0]
00413 ]
00414 results = checktable(name, expected)
00415 if not results:
00416 retValue['success']=False
00417 retValue['error_msgs']=retValue['error_msgs']+'Check of table '+name+' failed'
00418 expected = [
00419 ['SOURCE_ID', 15, 1, 0],
00420 ['SPECTRAL_WINDOW_ID', 15, 7, 0]
00421 ]
00422 results = checktable(name, expected)
00423 if not results:
00424 retValue['success']=False
00425 retValue['error_msgs']=retValue['error_msgs']+'Check of table '+name+' failed'
00426 expected = [
00427 ['SOURCE_ID', 16, 0, 100000],
00428 ['SPECTRAL_WINDOW_ID', 16, 0, 100000]
00429 ]
00430 print "The following should fail: SOURCE row 16 should not exist"
00431 try:
00432 results = checktable(name, expected)
00433 except:
00434 print "Expected error."
00435 results = False
00436 if results:
00437 retValue['success']=False
00438 retValue['error_msgs']='SOURCE row 16 should not existCheck of table '+name+' failed'
00439
00440 name = "SPECTRAL_WINDOW"
00441
00442 expected = [
00443 ['NUM_CHAN', 8, 4, 0]
00444 ]
00445 results = checktable(name, expected)
00446 if not results:
00447 retValue['success']=False
00448 retValue['error_msgs']=retValue['error_msgs']+'Check of table '+name+' failed'
00449
00450
00451 self.assertTrue(retValue['success'])
00452
00453 def test5(self):
00454 '''Testconcat 5: two MSs with different state table (CAS-2601)'''
00455 retValue = {'success': True, 'msgs': "", 'error_msgs': '' }
00456
00457 self.res = testconcat(vis = ['A2256LC2_4.5s-1.ms','A2256LC2_4.5s-2.ms'],
00458 testconcatvis = msname)
00459 self.assertEqual(self.res,None)
00460
00461 print myname, ": Success! Now checking output ..."
00462 mscomponents = set(["table.dat",
00463 "table.f0",
00464 "table.f1",
00465 "table.f2",
00466 "table.f3",
00467 "table.f4",
00468 "table.f5",
00469 "table.f6",
00470 "table.f7",
00471 "table.f8",
00472 "ANTENNA/table.dat",
00473 "DATA_DESCRIPTION/table.dat",
00474 "FEED/table.dat",
00475 "FIELD/table.dat",
00476 "FLAG_CMD/table.dat",
00477 "HISTORY/table.dat",
00478 "OBSERVATION/table.dat",
00479 "POINTING/table.dat",
00480 "POLARIZATION/table.dat",
00481 "PROCESSOR/table.dat",
00482 "SOURCE/table.dat",
00483 "SPECTRAL_WINDOW/table.dat",
00484 "STATE/table.dat",
00485 "ANTENNA/table.f0",
00486 "DATA_DESCRIPTION/table.f0",
00487 "FEED/table.f0",
00488 "FIELD/table.f0",
00489 "FLAG_CMD/table.f0",
00490 "HISTORY/table.f0",
00491 "OBSERVATION/table.f0",
00492 "POINTING/table.f0",
00493 "POLARIZATION/table.f0",
00494 "PROCESSOR/table.f0",
00495 "SOURCE/table.f0",
00496 "SPECTRAL_WINDOW/table.f0",
00497 "STATE/table.f0"
00498 ])
00499 for name in mscomponents:
00500 if not os.access(msname+"/"+name, os.F_OK):
00501 print myname, ": Error ", msname+"/"+name, "doesn't exist ..."
00502 retValue['success']=False
00503 retValue['error_msgs']=retValue['error_msgs']+msname+'/'+name+' does not exist'
00504 else:
00505 print myname, ": ", name, "present."
00506 print myname, ": MS exists. All tables present."
00507
00508 if 'test5.ms' in glob.glob("*.ms"):
00509 shutil.rmtree('test5.ms',ignore_errors=True)
00510 shutil.copytree(msname,'test5.ms')
00511 print myname, ": OK. Checking tables in detail ..."
00512 retValue['success']=True
00513
00514
00515 name = "STATE"
00516
00517 expected = [
00518 ['CAL', 0, 0, 0],
00519 ['SIG', 0, 1, 0],
00520 ['SUB_SCAN', 2, 1, 0]
00521 ]
00522 results = checktable(name, expected)
00523 if not results:
00524 retValue['success']=False
00525 retValue['error_msgs']=retValue['error_msgs']+'Check of table '+name+' failed'
00526 retValue['error_msgs']=retValue['error_msgs']+'Check of table '+name+' failed'
00527
00528 self.assertTrue(retValue['success'])
00529
00530 class testconcat_cleanup(unittest.TestCase):
00531 def setUp(self):
00532 pass
00533
00534 def tearDown(self):
00535 os.system('rm -rf *.ms')
00536
00537 def testrun(self):
00538 '''Testconcat: Cleanup'''
00539 pass
00540
00541 def suite():
00542 return [test_testconcat,testconcat_cleanup]
00543