00001 import os
00002 import sys
00003 import shutil
00004 from __main__ import default
00005 from tasks import *
00006 from taskinit import *
00007 import unittest
00008
00009 '''
00010 Unit tests for the vpmanager tool. Tested methods:
00011 reset()
00012 summarizevps()
00013 getvp()
00014 numvps()
00015 setpbairy()
00016 setpbantresptable()
00017 createantresp()
00018 getrespimagename()
00019 setuserdefault()
00020 getuserdefault()
00021 saveastable()
00022 loadfromtable()
00023 '''
00024 class vpmanager_test(unittest.TestCase):
00025
00026
00027 res = None
00028 inputdir = 'mydir3'
00029
00030 def setUp(self):
00031 self.res = None
00032
00033 def tearDown(self):
00034 os.system('rm -rf ' + self.inputdir)
00035
00036 def test0(self):
00037 '''Test 0: reset'''
00038 self.res = vp.reset()
00039 self.assertTrue(self.res)
00040
00041 def test1(self):
00042 '''Test 1: summarizevps'''
00043 self.res = vp.summarizevps()
00044 self.assertTrue(self.res)
00045
00046 def test2(self):
00047 '''Test 2: getvp for VLA'''
00048 vp.reset()
00049 myrec = vp.getvp(telescope='VLA',
00050 obstime = '1999/07/24/10:00:00',
00051 freq = 'TOPO 30GHz',
00052 antennatype = '',
00053 obsdirection = 'AZEL 30deg 60deg')
00054
00055 self.assertTrue(myrec['commonpb']=='VLA')
00056
00057 def test3(self):
00058 '''Test 3: getvp for ALMA'''
00059 vp.reset()
00060 vp.setpbantresptable(telescope='ALMA',
00061 antresppath=casa['dirs']['data']+'/alma/responses/AntennaResponses-ALMA',
00062 dopb=True)
00063 myrec = vp.getvp(telescope='ALMA',
00064 obstime = '2009/07/24/10:00:00',
00065 freq = 'TOPO 100GHz',
00066 antennatype = 'DV',
00067 obsdirection = 'AZEL 30deg 60deg')
00068
00069 self.assertTrue(myrec['name']=='IMAGE' and myrec['telescope']=='ALMA')
00070
00071 def test4(self):
00072 '''Test 4: numvps for VLA'''
00073 vp.reset()
00074 myrval = vp.numvps(telescope='VLA',
00075 obstime = '1999/07/24/10:00:00',
00076 freq = 'TOPO 30GHz',
00077 obsdirection = 'AZEL 30deg 60deg')
00078
00079 self.assertTrue(myrval==1)
00080
00081 def test5(self):
00082 '''Test 5: numvps for ALMA'''
00083 vp.reset()
00084 vp.setpbantresptable(telescope='ALMA',
00085 antresppath=casa['dirs']['data']+'/alma/responses/AntennaResponses-ALMA',
00086 dopb=True)
00087 myrval = vp.numvps(telescope='ALMA',
00088 obstime = '2009/07/24/10:00:00',
00089 freq = 'TOPO 100GHz',
00090 obsdirection = 'AZEL 30deg 60deg')
00091
00092 self.assertTrue(myrval==4)
00093
00094 def test6(self):
00095 '''Test 6: numvps for ALMA with too high freq'''
00096 vp.reset()
00097 vp.setpbantresptable(telescope='ALMA',
00098 antresppath=casa['dirs']['data']+'/alma/responses/AntennaResponses-ALMA',
00099 dopb=True)
00100 myrval = vp.numvps(telescope='ALMA',
00101 obstime = '2009/07/24/10:00:00',
00102 freq = 'TOPO 1000GHz',
00103 obsdirection = 'AZEL 30deg 60deg')
00104
00105 self.assertTrue(myrval==0)
00106
00107 def test7(self):
00108 '''Test 7: setuserdefault for ALMA'''
00109 vp.reset()
00110 self.res = vp.setuserdefault(vplistnum=-1, telescope='ALMA')
00111 self.assertTrue(self.res)
00112
00113
00114 def test8(self):
00115 '''Test 8: define Airy beam for ALMA, then use it'''
00116 vp.reset()
00117 vp.setpbairy(telescope='ALMA',
00118 dishdiam=str(12./1.18)+'m',
00119 blockagediam='0.75m',
00120 maxrad='1.784deg',
00121 reffreq='1.0GHz',
00122 dopb=True)
00123 myrec = vp.getvp(telescope='ALMA',
00124 obstime = '2009/07/24/10:00:00',
00125 freq = 'TOPO 100GHz',
00126 antennatype = '',
00127 obsdirection = 'AZEL 30deg 60deg')
00128
00129 woanttypeok = (myrec['name']=='AIRY' and myrec['telescope']=='ALMA')
00130
00131 myrec = vp.getvp(telescope='ALMA',
00132 obstime = '2009/07/24/10:00:00',
00133 freq = 'TOPO 100GHz',
00134 antennatype = 'DV',
00135 obsdirection = 'AZEL 30deg 60deg')
00136
00137 withanttypeok = (myrec['name']=='AIRY' and myrec['telescope']=='ALMA')
00138
00139 self.assertTrue(woanttypeok and withanttypeok)
00140
00141 def test9(self):
00142 '''Test 9: define reference to antresp table for ALMA, then use it'''
00143
00144 vp.reset()
00145 os.system('rm -rf BeamCalcTmpImage_*')
00146 vp.setpbantresptable(telescope='ALMA',
00147 antresppath=casa['dirs']['data']+'/alma/responses/AntennaResponses-ALMA-RT',
00148 dopb=True)
00149 myrec1 = vp.getvp(telescope='ALMA',
00150 obstime = '2009/07/24/10:00:00',
00151 freq = 'TOPO 100GHz',
00152 antennatype = 'DV',
00153 obsdirection = 'AZEL 30deg 60deg')
00154 myrec2 = vp.getvp(telescope='ALMA',
00155 obstime = '2009/07/24/10:00:00',
00156 freq = 'TOPO 100GHz',
00157 antennatype = 'DA',
00158 obsdirection = 'AZEL 30deg 60deg')
00159 myrec3 = vp.getvp(telescope='ALMA',
00160 obstime = '2009/07/24/10:00:00',
00161 freq = 'TOPO 100GHz',
00162 antennatype = 'PM',
00163 obsdirection = 'AZEL 30deg 60deg')
00164 myrec4 = vp.getvp(telescope='ALMA',
00165 obstime = '2009/07/24/10:00:00',
00166 freq = 'TOPO 100GHz',
00167 antennatype = 'CM',
00168 obsdirection = 'AZEL 30deg 60deg')
00169
00170 self.assertTrue(myrec1['name']=='IMAGE' and myrec1['telescope']=='ALMA')
00171 self.assertTrue(myrec2['name']=='IMAGE' and myrec2['telescope']=='ALMA')
00172 self.assertTrue(myrec3['name']=='IMAGE' and myrec3['telescope']=='ALMA')
00173 self.assertTrue(myrec4['name']=='IMAGE' and myrec4['telescope']=='ALMA')
00174
00175
00176 def test10(self):
00177 '''Test 10: define Airy beams for ALMA antenna types, then use them'''
00178
00179 vp.reset()
00180 vp.setpbairy(telescope='ALMA',
00181 dishdiam='11m',
00182 blockagediam='0.75m',
00183 maxrad='1.784deg',
00184 reffreq='1.0GHz',
00185 dopb=True)
00186 myid1 = vp.getuserdefault('ALMA')
00187
00188 vp.setpbairy(telescope='ALMA',
00189 dishdiam='12m',
00190 blockagediam='1.0m',
00191 maxrad='1.784deg',
00192 reffreq='1.0GHz',
00193 dopb=True)
00194
00195 myid2 = vp.getuserdefault('ALMA')
00196
00197 vp.setpbairy(telescope='ALMA',
00198 dishdiam='6m',
00199 blockagediam='0.75m',
00200 maxrad='3.5deg',
00201 reffreq='1.0GHz',
00202 dopb=True)
00203
00204 myid3 = vp.getuserdefault('ALMA')
00205
00206
00207 vp.setuserdefault(myid1, 'ALMA', 'DV')
00208 vp.setuserdefault(myid1, 'ALMA', 'DA')
00209 vp.setuserdefault(myid2, 'ALMA', 'PM')
00210 vp.setuserdefault(myid3, 'ALMA', 'CM')
00211
00212 myrec = vp.getvp(telescope='ALMA',
00213 obstime = '2009/07/24/10:00:00',
00214 freq = 'TOPO 100GHz',
00215 antennatype = 'DV',
00216 obsdirection = 'AZEL 30deg 60deg')
00217 tdvok = (myrec['name']=='AIRY' and myrec['dishdiam']['value']==11)
00218
00219 myrec = vp.getvp(telescope='ALMA',
00220 obstime = '2009/07/24/10:00:00',
00221 freq = 'TOPO 100GHz',
00222 antennatype = 'DA',
00223 obsdirection = 'AZEL 30deg 60deg')
00224 tdaok = (myrec['name']=='AIRY' and myrec['dishdiam']['value']==11)
00225
00226 myrec = vp.getvp(telescope='ALMA',
00227 obstime = '2009/07/24/10:00:00',
00228 freq = 'TOPO 100GHz',
00229 antennatype = 'PM',
00230 obsdirection = 'AZEL 30deg 60deg')
00231 tpmok = (myrec['name']=='AIRY' and myrec['dishdiam']['value']==12)
00232
00233 myrec = vp.getvp(telescope='ALMA',
00234 obstime = '2009/07/24/10:00:00',
00235 freq = 'TOPO 100GHz',
00236 antennatype = 'CM',
00237 obsdirection = 'AZEL 30deg 60deg')
00238 tcmok = (myrec['name']=='AIRY' and myrec['dishdiam']['value']==6)
00239
00240 myanttypes = vp.getanttypes('ALMA')
00241
00242 tantok = (('' in myanttypes)
00243 and ('CM' in myanttypes)
00244 and ('DA' in myanttypes)
00245 and ('DV' in myanttypes)
00246 and ('PM' in myanttypes))
00247
00248 vp.setuserdefault(-2, 'ALMA', '')
00249
00250 myanttypes = vp.getanttypes('ALMA')
00251
00252 tantok2 = ((not('' in myanttypes))
00253 and ('CM' in myanttypes)
00254 and ('DA' in myanttypes)
00255 and ('DV' in myanttypes)
00256 and ('PM' in myanttypes))
00257
00258 self.assertTrue(tdvok and tdaok and tpmok and tcmok and tantok and tantok2)
00259
00260
00261 def test11(self):
00262 '''Test 11: getvp without observation parameters'''
00263
00264 vp.reset()
00265
00266 vp.setcannedpb(telescope="ALMA")
00267
00268 myrec = vp.getvp('ALMA')
00269
00270 woanttypeok = (myrec['name']=='COMMONPB' and myrec['telescope']=='ALMA')
00271
00272 myrec = vp.getvp('ALMA', 'DV')
00273
00274 withanttypeok = (myrec['name']=='COMMONPB' and myrec['telescope']=='ALMA')
00275
00276 self.assertTrue(woanttypeok and withanttypeok)
00277
00278
00279 def test12(self):
00280 """Test 12: EXPECTED ERROR createantresp - no images"""
00281 os.system('mkdir '+self.inputdir)
00282 self.res = vp.createantresp(self.inputdir, "2011-02-02-12:00", ["band1","band2","band3"], ["83GHz","110GHz","230GHz"], ["110GHz","230GHz","350GHz"])
00283 self.assertFalse(self.res)
00284
00285 def test13(self):
00286 '''Test 13: EXPECTED ERROR createantresp - two images have faulty band def'''
00287 os.system('mkdir '+self.inputdir)
00288 os.system('touch '+self.inputdir+'/ALMA_0_DV__0._0._360._0._45._90._80._100._110._GHz_ticra2007_EFP.im')
00289 os.system('touch '+self.inputdir+'/ALMA_0_DV__0._0._360._0._45._90._110._200._230._GHz_ticra2007_EFP.im')
00290 os.system('touch '+self.inputdir+'/ALMA_0_DV__0._0._360._0._45._90._230._300._350._GHz_ticra2007_EFP.im')
00291 os.system('touch '+self.inputdir+'/ALMA_0_ME__0._0._360._0._45._90._80._100._110._GHz_ticra2007_EFP.im')
00292 os.system('touch '+self.inputdir+'/ALMA_0_ME__0._0._360._0._45._90._110._200._230._GHz_ticra2007_EFP.im')
00293 os.system('touch '+self.inputdir+'/ALMA_0_ME__0._0._360._0._45._90._230._300._350._GHz_ticra2007_EFP.im')
00294 self.res = vp.createantresp(self.inputdir, "2011-02-02-12:00", ["band1","band2","band3"], ["83GHz","110GHz","230GHz"], ["110GHz","230GHz","350GHz"])
00295 self.assertFalse(self.res)
00296
00297 def test14(self):
00298 '''Test 14: createantresp - good input: six images, two antenna types'''
00299 os.system('mkdir '+self.inputdir)
00300 os.system('touch '+self.inputdir+'/ALMA_0_DV__0._0._360._0._45._90._80._100._110._GHz_ticra2007_EFP.im')
00301 os.system('touch '+self.inputdir+'/ALMA_0_DV__0._0._360._0._45._90._110._200._230._GHz_ticra2007_EFP.im')
00302 os.system('touch '+self.inputdir+'/ALMA_0_DV__0._0._360._0._45._90._230._300._350._GHz_ticra2007_EFP.im')
00303 os.system('touch '+self.inputdir+'/ALMA_0_ME__0._0._360._0._45._90._80._100._110._GHz_ticra2007_EFP.im')
00304 os.system('touch '+self.inputdir+'/ALMA_0_ME__0._0._360._0._45._90._110._200._230._GHz_ticra2007_EFP.im')
00305 os.system('touch '+self.inputdir+'/ALMA_0_ME__0._0._360._0._45._90._230._300._350._GHz_ticra2007_EFP.im')
00306 self.res = vp.createantresp(self.inputdir, "2011-02-02-12:00", ["band1","band2","band3"], ["80GHz","110GHz","230GHz"], ["110GHz","230GHz","350GHz"])
00307 self.assertTrue(self.res)
00308 tb.open(self.inputdir+'/AntennaResponses')
00309 self.assertTrue(tb.nrows()==2)
00310 self.assertTrue(tb.ncols()==19)
00311 self.assertTrue(tb.getcell('NUM_SUBBANDS',0)==3)
00312 self.assertTrue(tb.getcell('NUM_SUBBANDS',1)==3)
00313 tb.close()
00314
00315 def test15(self):
00316 '''Test 15: EXPECTED ERROR get image name from non-existant observatory'''
00317 self.res = vp.getrespimagename("ALMA2","2011/01/01/10:00","100GHz","AIF","DV","0deg","0deg","",0)
00318 self.assertFalse(self.res)
00319
00320 def test16(self):
00321 '''Test 16: define Airy beam for ALMA, save it, load it, then use it'''
00322 vp.reset()
00323 vp.setpbairy(telescope='ALMA',
00324 dishdiam=str(12./1.18)+'m',
00325 blockagediam='0.75m',
00326 maxrad='1.784deg',
00327 reffreq='1.0GHz',
00328 dopb=True)
00329
00330 shutil.rmtree('mydefs.tab', ignore_errors=True)
00331 vp.saveastable('mydefs.tab')
00332 vp.reset()
00333 vp.loadfromtable('mydefs.tab')
00334
00335 myrec = vp.getvp(telescope='ALMA',
00336 obstime = '2009/07/24/10:00:00',
00337 freq = 'TOPO 100GHz',
00338 antennatype = '',
00339 obsdirection = 'AZEL 30deg 60deg')
00340
00341 woanttypeok = (myrec['name']=='AIRY' and myrec['telescope']=='ALMA')
00342
00343 myrec = vp.getvp(telescope='ALMA',
00344 obstime = '2009/07/24/10:00:00',
00345 freq = 'TOPO 100GHz',
00346 antennatype = 'DV',
00347 obsdirection = 'AZEL 30deg 60deg')
00348
00349 withanttypeok = (myrec['name']=='AIRY' and myrec['telescope']=='ALMA')
00350
00351 self.assertTrue(woanttypeok and withanttypeok)
00352
00353
00354
00355
00356
00357
00358
00359
00360
00361
00362
00363 def suite():
00364 return [vpmanager_test]
00365
00366