Go to the documentation of this file.00001 import os
00002 import shutil
00003 import testhelper as th
00004 from __main__ import default
00005 from tasks import gaincal
00006 from taskinit import *
00007 import unittest
00008
00009
00010 ''' Python unit tests for the gaincal task
00011
00012 These tests will only verify if the gain calibration
00013 tables created for an MS and an MMS agree. These are
00014 not full unit tests for the gaincal task.
00015 '''
00016
00017 datapath = os.environ.get('CASAPATH').split()[0] +\
00018 '/data/regression/unittest/gaincal/'
00019
00020
00021
00022 testmms = False
00023 if os.environ.has_key('TEST_DATADIR'):
00024 DATADIR = str(os.environ.get('TEST_DATADIR'))+'/gaincal/'
00025 if os.path.isdir(DATADIR):
00026 testmms = True
00027 datapath = DATADIR
00028 else:
00029 print 'WARN: directory '+DATADIR+' does not exist'
00030
00031 print 'gaincal tests will use data from '+datapath
00032
00033
00034
00035
00036 class test_base(unittest.TestCase):
00037
00038 def cleanUp(self):
00039 shutil.rmtree(self.msfile, ignore_errors=True)
00040 os.system('rm -rf '+self.msfile+'.gcal')
00041
00042 def setUp_ngc5921(self):
00043
00044
00045 prefix = 'ngc5921'
00046 self.msfile = prefix + '.ms'
00047 if testmms:
00048 self.msfile = prefix + '.mms'
00049
00050 self.reffile = datapath + prefix
00051 self.cleanUp()
00052
00053 fpath = os.path.join(datapath,self.msfile)
00054 if os.path.lexists(fpath):
00055 shutil.copytree(fpath, self.msfile)
00056 else:
00057 self.fail('Data does not exist -> '+fpath)
00058
00059 default('gaincal')
00060
00061
00062 def setUp_ngc4826(self):
00063
00064
00065 prefix = 'ngc4826'
00066 self.msfile = prefix + '.ms'
00067 if testmms:
00068 self.msfile = prefix + '.mms'
00069
00070 self.reffile = datapath + prefix
00071 self.cleanUp()
00072
00073 fpath = os.path.join(datapath,self.msfile)
00074 if os.path.lexists(fpath):
00075 shutil.copytree(fpath, self.msfile)
00076 else:
00077 self.fail('Data does not exist -> '+fpath)
00078
00079 default('gaincal')
00080
00081
00082 class gaincal1_test(test_base):
00083
00084 def setUp(self):
00085 self.setUp_ngc5921()
00086
00087 def tearDown(self):
00088 if os.path.lexists(self.msfile):
00089 shutil.rmtree(self.msfile)
00090
00091 os.system('rm -rf ngc5921*.gcal')
00092
00093 def test1a(self):
00094 '''Gaincal 1a: Default values to create a gain table'''
00095 msgcal = self.msfile + '.gcal'
00096 reference = self.reffile + '.ref1a.gcal'
00097 gaincal(vis=self.msfile, caltable=msgcal)
00098 self.assertTrue(os.path.exists(msgcal))
00099
00100
00101 self.assertTrue(th.compTables(msgcal, reference, ['WEIGHT']))
00102
00103
00104 def test2a(self):
00105 '''Gaincal 2a: Create a gain table using field selection'''
00106
00107 msgcal = self.msfile + '.field0.gcal'
00108 reference = self.reffile + '.ref2a.gcal'
00109 gaincal(vis=self.msfile, caltable=msgcal, field='0', gaintype='G',solint='int',
00110 combine='',refant='VA02')
00111 self.assertTrue(os.path.exists(msgcal))
00112
00113
00114 self.assertTrue(th.compTables(msgcal, reference, ['WEIGHT']))
00115
00116
00117 class gaincal2_test(test_base):
00118
00119 def setUp(self):
00120 self.setUp_ngc4826()
00121
00122
00123 def tearDown(self):
00124 if os.path.lexists(self.msfile):
00125 shutil.rmtree(self.msfile)
00126
00127 os.system('rm -rf ngc4826*.gcal')
00128
00129
00130 def test1b(self):
00131 '''Gaincal 1b: Create a gain table for an MS with many spws'''
00132 msgcal = self.msfile + '.gcal'
00133 reference = self.reffile + '.ref1b.gcal'
00134 gaincal(vis=self.msfile, caltable=msgcal, field='0,1',spw='0', gaintype='G',minsnr=2.0,
00135 refant='ANT5',gaincurve=False, opacity=0.0, solint='inf',combine='')
00136 self.assertTrue(os.path.exists(msgcal))
00137
00138
00139 self.assertTrue(th.compTables(msgcal, reference, ['WEIGHT']))
00140
00141
00142 def suite():
00143 return [gaincal1_test, gaincal2_test]
00144
00145
00146
00147
00148
00149
00150