casa  $Rev:20696$
 All Classes Namespaces Files Functions Variables
test_wvrgcal.py
Go to the documentation of this file.
00001 # unit test for the wvrgcal task
00002 
00003 import os
00004 import shutil
00005 import numpy as np
00006 
00007 from __main__ import default
00008 from tasks import *
00009 from taskinit import *
00010 import unittest
00011 import testhelper as th
00012 
00013 class wvrgcal_test(unittest.TestCase):
00014 
00015     vis_f = 'multisource_unittest.ms'
00016     vis_g = 'wvrgcal4quasar_10s.ms'
00017     ref = ['multisource_unittest_reference.wvr',
00018            'multisource_unittest_reference-newformat.wvr',
00019            'wvrgcalctest.W',
00020            'wvrgcalctest_toffset.W',
00021            'wvrgcalctest_segsource.W',
00022            'wvrgcalctest_wvrflag1.W',
00023            'wvrgcalctest_wvrflag2.W',
00024            'wvrgcalctest_reverse.W',
00025            'wvrgcalctest_reversespw.W',
00026            'wvrgcalctest_smooth.W',
00027            'wvrgcalctest_scale.W',
00028            'wvrgcalctest_tie1.W',
00029            'wvrgcalctest_tie2.W',
00030            'wvrgcalctest_sourceflag1.W',
00031            'wvrgcalctest_sourceflag2.W',
00032            'wvrgcalctest_statsource.W',
00033            'wvrgcalctest_nsol.W',
00034            'wvrgcalctest_disperse.W']
00035 
00036 ## 2   'wvrgcalctest.W': '',
00037 ## 3   'wvrgcalctest_toffset.W': '--toffset -1', ........................ test3
00038 ## 4   'wvrgcalctest_segsource.W': '--segsource',
00039 ## 5   'wvrgcalctest_wvrflag1.W': '--wvrflag DV03',
00040 ## 6   'wvrgcalctest_wvrflag2.W': '--wvrflag DV03 --wvrflag PM02',
00041 ## 7   'wvrgcalctest_reverse.W': '--reverse', 
00042 ## 8   'wvrgcalctest_reversespw.W': '--reversespw 1', ................... test4
00043 ## 9   'wvrgcalctest_smooth.W':'--smooth 3', ............................ test5
00044 ## 10   'wvrgcalctest_scale.W':'--scale 0.8', ............................ test6
00045 ## 11   'wvrgcalctest_tie1.W':'--segsource --tie 0,1,2', ................. test7
00046 ## 12   'wvrgcalctest_tie2.W':'--segsource --tie 0,3 --tie 1,2', ......... test8
00047 ## 13   'wvrgcalctest_sourceflag1.W':'--sourceflag 0455-462 --segsource',
00048 ## 14   'wvrgcalctest_sourceflag2.W':'--sourceflag 0455-462 --sourceflag 0132-169 --segsource', ...test9
00049 ## 15   'wvrgcalctest_statsource.W':'--statsource 0455-462', ..............test10
00050 ## 16   'wvrgcalctest_nsol.W':'--nsol 5' ..................................test11
00051 ## 17   'wvrgcalctest_disperse.W':'--disperse', .......................... test12
00052 
00053 
00054     out = 'mycaltable.wvr'
00055     rval = False
00056     
00057     def setUp(self):    
00058         self.rval = False
00059 
00060         if(not os.path.exists(self.vis_f)):
00061             os.system('cp -R '+os.environ['CASAPATH'].split()[0]+'/data/regression/unittest/wvrgcal/input/multisource_unittest.ms .')
00062         if(not os.path.exists(self.vis_g)):
00063             os.system('cp -R '+os.environ['CASAPATH'].split()[0]+'/data/regression/unittest/wvrgcal/input/wvrgcal4quasar_10s.ms .')
00064         for i in range(0,len(self.ref)):
00065             if(not os.path.exists(self.ref[i])):
00066                 os.system('cp -R '+os.environ['CASAPATH'].split()[0]+'/data/regression/unittest/wvrgcal/input/'+self.ref[i]+' .')
00067 
00068         default(wvrgcal)
00069 
00070     def tearDown(self):
00071         os.system('rm -rf myinput.ms')
00072         os.system('rm -rf ' + self.out)
00073         for i in range(0,len(self.ref)):
00074             os.system('rm -rf ' + self.ref[i])
00075 
00076 
00077 
00078 # Test cases    
00079     def test1(self):
00080         '''Test 1: Testing default'''
00081         self.rval = wvrgcal()
00082         print "Expected error ..."
00083         self.assertFalse(self.rval)
00084 
00085     def test2(self):
00086         '''Test 2: Testing with a multi-source dataset'''
00087         myvis = self.vis_f
00088         os.system('cp -R ' + myvis + ' myinput.ms')
00089         os.system('rm -rf '+self.out)
00090         self.rval = wvrgcal(vis="myinput.ms",caltable=self.out, wvrflag=['0', '1'], toffset=0.)
00091 
00092         if(self.rval):
00093             if os.path.exists(self.out+'/CAL_DESC'):
00094                 self.rval = th.compTables(self.ref[0], self.out,
00095                                             ['REF_ANT', 'REF_FEED', 'REF_RECEPTOR', 'REF_FREQUENCY',
00096                                              'REF_DIRECTION'] # ignore these columns because they are empty
00097                                             )
00098             else:
00099                 self.rval = th.compTables(self.ref[1], self.out, ['WEIGHT'] # ignore WEIGHT because it is empty
00100 ##                                             ['TIME',
00101 ##                                              'FIELD_ID',
00102 ##                                              'SPECTRAL_WINDOW_ID',
00103 ##                                              'ANTENNA1',
00104 ##                                              'ANTENNA2',
00105 ##                                              'INTERVAL',
00106 ##                                              'SCAN_NUMBER',
00107 ##                                              'CPARAM',
00108 ##                                              'PARAMERR',
00109 ##                                              'FLAG',
00110 ##                                              'SNR',
00111 ##                                              'WEIGHT']
00112                                             )
00113 
00114         self.assertTrue(self.rval)
00115 
00116     def test3(self):
00117         '''Test 3:  wvrgcal4quasar_10s.ms, segsource False'''
00118         myvis = self.vis_g
00119         os.system('cp -R ' + myvis + ' myinput.ms')
00120         os.system('rm -rf '+self.out)
00121         self.rval = wvrgcal(vis="myinput.ms",caltable=self.out, segsource=False)
00122         if(self.rval):
00123             self.rval = th.compTables(self.ref[3], self.out, ['WEIGHT']) # ignore WEIGHT because it is empty
00124         self.assertTrue(self.rval)
00125 
00126     def test4(self):
00127         '''Test 4:  wvrgcal4quasar_10s.ms, reversespw, segsource False'''
00128         myvis = self.vis_g
00129         os.system('cp -R ' + myvis + ' myinput.ms')
00130         os.system('rm -rf '+self.out)
00131         self.rval = wvrgcal(vis="myinput.ms",caltable=self.out, reversespw='1', segsource=False, toffset=0.)
00132         if(self.rval):
00133             self.rval = th.compTables(self.ref[8], self.out, ['WEIGHT']) # ignore WEIGHT because it is empty
00134         self.assertTrue(self.rval)
00135 
00136 
00137     def test5(self):
00138         '''Test 5:  wvrgcal4quasar_10s.ms, smooth, segsource False'''
00139         myvis = self.vis_g
00140         os.system('cp -R ' + myvis + ' myinput.ms')
00141         os.system('rm -rf '+self.out)
00142         self.rval = wvrgcal(vis="myinput.ms",caltable=self.out, smooth=3, segsource=False, toffset=0.)
00143         if(self.rval):
00144             self.rval = th.compTables(self.ref[9], self.out, ['WEIGHT'], # ignore WEIGHT because it is empty
00145                                       0.01) # tolerance 1 % to accomodate differences between Linux and Mac OSX
00146         self.assertTrue(self.rval)
00147 
00148     def test6(self):
00149         '''Test 6:  wvrgcal4quasar_10s.ms, scale, segsource=False'''
00150         myvis = self.vis_g
00151         os.system('cp -R ' + myvis + ' myinput.ms')
00152         os.system('rm -rf '+self.out)
00153         self.rval = wvrgcal(vis="myinput.ms",caltable=self.out, scale=0.8, segsource=False, toffset=0.)
00154         if(self.rval):
00155             self.rval = th.compTables(self.ref[10], self.out, ['WEIGHT']) # ignore WEIGHT because it is empty
00156         self.assertTrue(self.rval)
00157 
00158     def test7(self):
00159         '''Test 7:  wvrgcal4quasar_10s.ms, tie three sources'''
00160         myvis = self.vis_g
00161         os.system('cp -R ' + myvis + ' myinput.ms')
00162         os.system('rm -rf '+self.out)
00163         self.rval = wvrgcal(vis="myinput.ms", caltable=self.out, tie=['0,1,2'], toffset=0.)
00164         if(self.rval):
00165             self.rval = th.compTables(self.ref[11], self.out, ['WEIGHT']) # ignore WEIGHT because it is empty
00166         self.assertTrue(self.rval)
00167 
00168     def test8(self):
00169         '''Test 8:  wvrgcal4quasar_10s.ms, tie two times two sources'''
00170         myvis = self.vis_g
00171         os.system('cp -R ' + myvis + ' myinput.ms')
00172         os.system('rm -rf '+self.out)
00173         self.rval = wvrgcal(vis="myinput.ms", caltable=self.out, tie=['0,3', '1,2'], toffset=0.)
00174         if(self.rval):
00175             self.rval = th.compTables(self.ref[12], self.out, ['WEIGHT'], 0.01) # ignore WEIGHT because it is empty,
00176                                                                                   # increase tolerance to 1 % to temporarily
00177                                                                                   # overcome difference between 32bit and 64bit output
00178         self.assertTrue(self.rval)
00179 
00180     def test9(self):
00181         '''Test 9:  wvrgcal4quasar_10s.ms, sourceflag two sources'''
00182         myvis = self.vis_g
00183         os.system('cp -R ' + myvis + ' myinput.ms')
00184         os.system('rm -rf '+self.out)
00185         self.rval = wvrgcal(vis="myinput.ms", caltable=self.out, sourceflag=['0455-462','0132-169'], toffset=0.)
00186         if(self.rval):
00187             self.rval = th.compTables(self.ref[14], self.out, ['WEIGHT']) # ignore WEIGHT because it is empty
00188         self.assertTrue(self.rval)
00189 
00190     def test10(self):
00191         '''Test 10:  wvrgcal4quasar_10s.ms, statsource, segsource=False'''
00192         myvis = self.vis_g
00193         os.system('cp -R ' + myvis + ' myinput.ms')
00194         os.system('rm -rf '+self.out)
00195         self.rval = wvrgcal(vis="myinput.ms", caltable=self.out, segsource=False, statsource='0455-462', toffset=0.)
00196         if(self.rval):
00197             self.rval = th.compTables(self.ref[15], self.out, ['WEIGHT']) # ignore WEIGHT because it is empty
00198         self.assertTrue(self.rval)
00199 
00200     def test11(self):
00201         '''Test 11:  wvrgcal4quasar_10s.ms, nsol, segsource=False'''
00202         myvis = self.vis_g
00203         os.system('cp -R ' + myvis + ' myinput.ms')
00204         os.system('rm -rf '+self.out)
00205         self.rval = wvrgcal(vis="myinput.ms", caltable=self.out, segsource=False, nsol=5, toffset=0.)
00206         if(self.rval):
00207             self.rval = th.compTables(self.ref[16], self.out, ['WEIGHT']) # ignore WEIGHT because it is empty
00208         self.assertTrue(self.rval)
00209 
00210     def test12(self):
00211         '''Test 12:  wvrgcal4quasar_10s.ms, disperse'''
00212         myvis = self.vis_g
00213         os.system('cp -R ' + myvis + ' myinput.ms')
00214         os.system('rm -rf '+self.out)
00215         self.rval = wvrgcal(vis="myinput.ms",caltable=self.out, disperse=True)
00216         if(self.rval):
00217             self.rval = th.compTables(self.ref[17], self.out, ['WEIGHT']) # ignore WEIGHT because it is empty
00218         self.assertTrue(self.rval)
00219 
00220 
00221 def suite():
00222     return [wvrgcal_test]
00223