00001 '''
00002 Unit tests for task partition.
00003
00004 This is mostly just a check of the python layers,ensuring correct commands are
00005 passed to the JobQueueManager and assuming that the ms.partition function
00006 works correctly.
00007 '''
00008
00009 import os
00010 import unittest
00011 from task_partition import PartitionHelper
00012 from simple_cluster import JobData
00013
00014 datapath = os.environ.get('CASAPATH').split()[0] + '/data/regression/'
00015
00016 class PartitionHelperTest(unittest.TestCase,
00017 PartitionHelper):
00018
00019 def __init__(self, methodName='runTest'):
00020
00021 argList = {}
00022 argList['vis'] = ''
00023 argList['outputvis'] = ''
00024 argList['createmms'] = False
00025 argList['separationaxis'] = 'scan'
00026 argList['numsubms'] = 64
00027 argList['calmsselection'] = 'none'
00028 argList['calmsname'] = ''
00029 argList['calfield'] = ''
00030 argList['calintent'] =''
00031 argList['calscan'] = ''
00032 argList['datacolumn'] = 'corrected'
00033 argList['field'] = ''
00034 argList['spw'] = ''
00035 argList['width'] = 1
00036 argList['antenna'] = ''
00037 argList['timebin'] = '0s'
00038 argList['timerange'] = ''
00039 argList['scan'] = ''
00040 argList['scanintent'] = ''
00041 argList['array'] = ''
00042 argList['uvrange'] = ''
00043 argList['correlation'] = ''
00044 argList['combine'] = ''
00045 argList['keepflags'] = True
00046
00047
00048 self.testSPWList = None
00049 self.testScanList = None
00050
00051 PartitionHelper.__init__(self, argList)
00052 unittest.TestCase.__init__(self, methodName)
00053
00054
00055 def testScanSeparationCommands(self):
00056
00057 self.dataDir='dataDir'
00058 self.outputBase='outputBase'
00059
00060
00061
00062 self._arg['numsubms'] = 8
00063 self.setScanList(range(16))
00064 self._createScanSeparationCommands()
00065
00066 commandList = []
00067 for idx in xrange(8):
00068 outputvis = '%s/%s.%04d.ms' % (self.dataDir,self.outputBase,idx)
00069 commandList.append(JobData('partition',{
00070 'outputvis': outputvis,
00071 'scan': self.listToCasaString([2*idx,(2*idx)+1])}))
00072 self.checkCommandList(commandList)
00073
00074
00075
00076 self._arg['numsubms'] = 8
00077 self.setScanList(range(6))
00078 self._createScanSeparationCommands()
00079
00080 commandList = []
00081 for idx in xrange(6):
00082 outputvis = '%s/%s.%04d.ms' % (self.dataDir,self.outputBase,idx)
00083 commandList.append(JobData('partition',{
00084 'outputvis': outputvis,
00085 'scan': str(idx)}))
00086 self.checkCommandList(commandList)
00087
00088
00089
00090 self._arg['numsubms'] = 8
00091 self.setScanList(range(32))
00092
00093
00094 self._selectMS(True)
00095 self._calScanList = self._getScanList()
00096
00097
00098 self.setScanList(range(32))
00099 self._createScanSeparationCommands()
00100
00101 commandList = []
00102 for idx in xrange(8):
00103 outputvis = '%s/%s.%04d.ms' % (self.dataDir,self.outputBase,idx)
00104 commandList.append(JobData('partition',{
00105 'outputvis': outputvis,
00106 'scan': self.listToCasaString([4*idx + 1,4*idx +3])}))
00107 self.checkCommandList(commandList)
00108
00109
00110 def testSpwSeparationCommands(self):
00111
00112 self.dataDir='dataDir'
00113 self.outputBase='outputBase'
00114
00115
00116 self._arg['numsubms'] = 8
00117 self.setSPWList(range(16))
00118 self._createSPWSeparationCommands()
00119
00120 commandList = []
00121 for idx in xrange(8):
00122 outputvis = '%s/%s.%04d.ms' % (self.dataDir,self.outputBase,idx)
00123 commandList.append(JobData('partition',{
00124 'outputvis': outputvis,
00125 'spw': self.listToCasaString([2*idx,(2*idx)+1])}))
00126 self.checkCommandList(commandList)
00127
00128
00129
00130 self._arg['numsubms'] = 8
00131 self.setSPWList(range(6))
00132 self._createSPWSeparationCommands()
00133
00134 commandList = []
00135 for idx in xrange(6):
00136 outputvis = '%s/%s.%04d.ms' % (self.dataDir,self.outputBase,idx)
00137 commandList.append(JobData('partition',{
00138 'outputvis': outputvis,
00139 'spw': str(idx)}))
00140 self.checkCommandList(commandList)
00141
00142
00143
00144 self._arg['numsubms'] = 8
00145 self.setScanList(range(32))
00146 self.setSPWList(range(16))
00147
00148
00149 self._selectMS(True)
00150 self._calScanList = self._getScanList()
00151
00152
00153 self.setScanList(range(32))
00154 self._createSPWSeparationCommands()
00155
00156 commandList = []
00157 for idx in xrange(8):
00158 outputvis = '%s/%s.%04d.ms' % (self.dataDir,self.outputBase,idx)
00159 commandList.append(JobData('partition',{
00160 'outputvis': outputvis,
00161 'spw' : self.listToCasaString([2*idx, 2*idx+1]),
00162 'scan': self.listToCasaString(range(1,32,2))}))
00163 self.checkCommandList(commandList)
00164
00165
00166 def testDefaultSeparationCommands(self):
00167
00168 self.dataDir='dataDir'
00169 self.outputBase='outputBase'
00170
00171
00172
00173 self._arg['numsubms'] = 8
00174 self.setSPWList(range(16))
00175 self.setScanList(range(10))
00176 self._createDefaultSeparationCommands()
00177
00178
00179
00180 commandList = []
00181 for idx in xrange(8):
00182 outputvis = '%s/%s.%04d.ms' % (self.dataDir,self.outputBase,idx)
00183 commandList.append(JobData('partition',{
00184 'outputvis': outputvis,
00185 'spw': self.listToCasaString([2*idx,(2*idx)+1])}))
00186 self.checkCommandList(commandList)
00187
00188
00189
00190 self._arg['numsubms'] = 16
00191 self.setSPWList(range(4))
00192 self.setScanList(range(12))
00193 self._createDefaultSeparationCommands()
00194
00195
00196 commandList = []
00197 for idx in xrange(16):
00198 outputvis = '%s/%s.%04d.ms' % (self.dataDir,self.outputBase,idx)
00199 commandList.append(JobData('partition',{
00200 'outputvis': outputvis,
00201 'scan': self.listToCasaString(range((idx%4)*3,((idx%4)+1)*3)),
00202 'spw': str(idx/4)}))
00203 self.checkCommandList(commandList)
00204
00205
00206
00207 self._arg['numsubms'] = 48
00208 self.setSPWList(range(15))
00209 self.setScanList(range(2))
00210 self._createDefaultSeparationCommands()
00211
00212
00213 commandList = []
00214 for idx in xrange(30):
00215 outputvis = '%s/%s.%04d.ms' % (self.dataDir,self.outputBase,idx)
00216 commandList.append(JobData('partition',{
00217 'outputvis': outputvis,
00218 'scan': str(idx % 2),
00219 'spw': str(idx/2)}))
00220 self.checkCommandList(commandList)
00221
00222
00223 self._arg['numsubms'] = 8
00224 self.setSPWList(range(16))
00225 self._createDefaultSeparationCommands()
00226
00227
00228 commandList = []
00229 for idx in xrange(8):
00230 outputvis = '%s/%s.%04d.ms' % (self.dataDir,self.outputBase,idx)
00231 commandList.append(JobData('partition',{
00232 'outputvis': outputvis,
00233 'scan': '',
00234 'spw': self.listToCasaString([2*idx,(2*idx)+1])}))
00235 self.checkCommandList(commandList)
00236
00237
00238
00239 self._arg['numsubms'] = 16
00240 self.setSPWList(range(4))
00241 self.setScanList(range(4))
00242 self._createDefaultSeparationCommands()
00243
00244
00245 commandList = []
00246 for idx in xrange(16):
00247 outputvis = '%s/%s.%04d.ms' % (self.dataDir,self.outputBase,idx)
00248 commandList.append(JobData('partition',{
00249 'outputvis': outputvis,
00250 'scan': str(idx%4),
00251 'spw': str(idx/4)}))
00252 self.checkCommandList(commandList)
00253
00254 def testCreateCalibrationCommand(self):
00255 pass
00256
00257 def testCreatePrimarySplitCommand(self):
00258
00259
00260 pass
00261
00262 def testSelectMS(self):
00263 pass
00264
00265
00266 def testGetSPWList(self):
00267 pass
00268
00269
00270 def testGetScanList(self):
00271 pass
00272
00273 def testPostExecution(self):
00274 pass
00275
00276 def testPartition(self):
00277 pass
00278
00279
00280 def checkCommandList(self, commandList):
00281 '''
00282 Probably could be smarter but lets do it the easy way.
00283 '''
00284 for expJob in commandList:
00285 matchFound = False
00286 for job in self._executionList:
00287
00288 if expJob.getCommandNames() != job.getCommandNames():
00289 continue
00290
00291
00292 try:
00293 for cmdName in expJob.getCommandNames():
00294 expArgs = expJob.getCommandArguments(cmdName)
00295 jobArgs = job.getCommandArguments(cmdName)
00296 if [expArgs[key] for key in expArgs] != \
00297 [jobArgs[key] for key in expArgs]:
00298 raise KeyError
00299 except KeyError:
00300
00301 continue
00302
00303 self._executionList.remove(job)
00304 matchFound = True
00305 break
00306 if not matchFound:
00307 self.fail("Unable to find match for expected Job")
00308
00309 if len(self._executionList) != 0:
00310 self.fail("Found %d uexpected job(s)" % len(self._executionList))
00311
00312 def setScanList(self, scanList):
00313 self.testScanList = scanList
00314
00315
00316 def setSPWList(self,spwList):
00317 self.testSPWList = spwList
00318
00319
00320 def _getScanList(self):
00321 return self.testScanList
00322
00323 def _getSPWList(self):
00324 '''
00325 Override the method of the Helper class for testing purposes
00326 '''
00327 return self.testSPWList
00328
00329 def _selectMS(self, doCalibrationSelection = False):
00330 '''
00331 Override the method of the helper class for testing purposes
00332 Assume all even scans are calibration scans.
00333 '''
00334 if not doCalibrationSelection and self._calScanList is not None:
00335 if self._selectionScanList is None:
00336 self._selectionScanList = self._getScanList()
00337
00338 for scan in self._calScanList:
00339 self._selectionScanList.remove(scan)
00340
00341 self.setScanList(self._selectionScanList)
00342
00343 if doCalibrationSelection:
00344 for scan in self.testScanList:
00345 if scan%2 == 1:
00346 self.testScanList.remove(scan)
00347
00348
00349 def suite():
00350 return [PartitionHelperTest]
00351
00352
00353 if __name__ == '__main__':
00354 testSuite = []
00355 for testClass in suite():
00356 testSuite.append(unittest.makeSuite(testClass,'test'))
00357 allTests = unittest.TestSuite(testSuite)
00358 unittest.TextTestRunner(verbosity=2).run(allTests)
00359