casa  $Rev:20696$
 All Classes Namespaces Files Functions Variables
test_bandpass.py
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 bandpass
00006 from taskinit import *
00007 import unittest
00008 
00009 
00010 ''' Python unit tests for the bandpass task
00011 
00012 These tests will only verify if the bandpass calibration
00013 tables created for an MS and an MMS agree. These are
00014 not full unit tests for the bandpass task.
00015 '''
00016 
00017 datapath = os.environ.get('CASAPATH').split()[0] +\
00018                             '/data/regression/unittest/bandpass/'
00019 
00020 # Pick up alternative data directory to run tests on MMSs
00021 testmms = False
00022 if os.environ.has_key('TEST_DATADIR'):   
00023     DATADIR = str(os.environ.get('TEST_DATADIR'))+'/bandpass/'
00024     if os.path.isdir(DATADIR):
00025         testmms = True
00026         datapath = DATADIR
00027     else:
00028         print 'WARN: directory '+DATADIR+' does not exist'
00029 
00030 print 'bandpass tests will use data from '+datapath         
00031 
00032 # Base class which defines setUp functions
00033 # for importing different data sets
00034 class test_base(unittest.TestCase):
00035 
00036     def cleanUp(self):
00037         shutil.rmtree(self.msfile, ignore_errors=True)
00038         os.system('rm -rf '+self.msfile+'.bcal')
00039     
00040     def setUp_ngc5921(self):
00041         
00042         # Input names
00043         prefix = 'ngc5921'
00044         self.msfile = prefix + '.ms'
00045         if testmms:
00046             self.msfile = prefix + '.mms'
00047 
00048         self.reffile = datapath + prefix
00049         self.cleanUp()
00050         
00051         fpath = os.path.join(datapath,self.msfile)
00052         if os.path.lexists(fpath):        
00053             shutil.copytree(fpath, self.msfile)
00054         else:
00055             self.fail('Data does not exist -> '+fpath)
00056 
00057         default('bandpass')
00058                
00059         
00060     def setUp_ngc4826(self):
00061         
00062         # Input names
00063         prefix = 'ngc4826'
00064         self.msfile = prefix + '.ms'
00065         if testmms:
00066             self.msfile = prefix + '.mms'
00067 
00068         self.reffile = datapath + prefix
00069         self.cleanUp()
00070         
00071         fpath = os.path.join(datapath,self.msfile)
00072         if os.path.lexists(fpath):
00073             shutil.copytree(fpath, self.msfile)
00074         else:
00075             self.fail('Data does not exist -> '+fpath)
00076 
00077         default('bandpass')
00078 
00079 
00080 class bandpass1_test(test_base):
00081 
00082     def setUp(self):
00083         self.setUp_ngc5921()
00084 
00085     def tearDown(self):
00086         if os.path.lexists(self.msfile):
00087             shutil.rmtree(self.msfile)
00088 
00089         os.system('rm -rf ngc5921*.bcal')
00090         
00091     def test1a(self):
00092         '''Bandpass 1a: Create bandpass table using field=0'''
00093         msbcal = self.msfile + '.bcal'
00094         reference = self.reffile + '.ref1a.bcal'
00095         bandpass(vis=self.msfile, caltable=msbcal, field='0',opacity=0.0,bandtype='B',
00096                  solint='inf',combine='scan',refant='VA15')
00097         self.assertTrue(os.path.exists(msbcal))
00098                 
00099         # Compare the calibration tables
00100         self.assertTrue(th.compTables(msbcal, reference, ['WEIGHT']))
00101 
00102 
00103 class bandpass2_test(test_base):
00104 
00105     def setUp(self):
00106         self.setUp_ngc4826()
00107                        
00108     def tearDown(self):
00109         if os.path.lexists(self.msfile):
00110             shutil.rmtree(self.msfile)
00111 
00112 
00113         os.system('rm -rf ngc4826*.bcal')
00114         
00115         
00116     def test1b(self):
00117         '''Bandpass 1b: Create cal tables for the MS and MMS split by spws'''
00118         msbcal = self.msfile + '.bcal'
00119         reference = self.reffile + '.ref1b.bcal'
00120         bandpass(vis=self.msfile, caltable=msbcal, field='0',spw='0', opacity=0.0,bandtype='B',
00121                  solint='inf',combine='scan',refant='ANT5')
00122         self.assertTrue(os.path.exists(msbcal))
00123         
00124         # Compare the calibration tables
00125         self.assertTrue(th.compTables(msbcal, reference, ['WEIGHT']))
00126 
00127 
00128 def suite():
00129     return [bandpass1_test, bandpass2_test]
00130 
00131 
00132 
00133 
00134 
00135 
00136