00001 import os
00002 import sys
00003 import shutil
00004 from __main__ import default
00005 from tasks import *
00006 from taskinit import *
00007 from simutil import *
00008 import unittest
00009
00010 import numpy
00011 import glob
00012
00013 import inspect
00014 glb = sys._getframe(len(inspect.stack())-1).f_globals
00015 if glb.has_key('__rethrow_casa_exceptions'):
00016 rethrow_org = glb['__rethrow_casa_exceptions']
00017 else:
00018 rethrow_org = False
00019
00020
00021
00022
00023 class simobserve_unittest_base:
00024 """
00025 Base class of simobserve unit test.
00026 The class defines common variables and test methods.
00027 """
00028 graphics = "file"
00029
00030 datapath=os.environ.get('CASAPATH').split()[0] + '/data/regression/unittest/simobserve/'
00031 thistask = "simobserve"
00032 imkeys=['max','mean','min','npts','rms','blc','blcf','trc','trcf','sigma','sum','sumsq']
00033
00034
00035 rtol = 1.0e-5
00036 atol = 1.0e8
00037
00038
00039 def _check_file( self, name ):
00040 isthere = os.path.exists(name)
00041 self.assertEqual(isthere,True,
00042 msg='output file %s was not created because of the task failure'%(name))
00043
00044 def _get_imstats( self, name ):
00045 self._check_file(name)
00046 ia.open(name)
00047 stats = ia.statistics()
00048 ia.close()
00049 return stats
00050
00051 def _get_msstats( self, name, column, compval):
00052 self._check_file(name)
00053 ms.open(name)
00054 stats = ms.statistics(column, compval)
00055 ms.close()
00056 return stats[column]
00057
00058 def _check_imstats(self, name, ref):
00059
00060
00061 if type(ref) == str:
00062
00063 ref = self._get_imstats(ref)
00064
00065 stats = self._get_imstats(name)
00066
00067 if hasattr(self,'imkeys'):
00068 compkeys = self.imkeys
00069 else:
00070 compkeys = ref.keys()
00071 print("Comparing image statistics of '%s' with reference" % name)
00072 for key in compkeys:
00073 message="image statistic '%s' does not match" % key
00074 if type(stats[key])==str:
00075 self.assertEqual(stats[key],ref[key],
00076 msg=message)
00077 else:
00078 ret=numpy.allclose(stats[key],ref[key],
00079 rtol=self.rtol,atol=self.atol)
00080 self.assertEqual(ret,True,msg=message)
00081
00082 def _check_msstats(self,name,ref):
00083
00084
00085 column = "DATA"
00086 compval = "real"
00087 if type(ref) == str:
00088
00089 ref=self._get_msstats(ref,column,compval)
00090 stats=self._get_msstats(name,column,compval)
00091
00092 if hasattr(self,'mskeys'):
00093 compkeys = self.mskeys
00094 else:
00095 compkeys = ref.keys()
00096 print("Comparing MS statistics of '%s' with reference" % name)
00097 for key in compkeys:
00098 message="MS statistic '%s' does not match" % key
00099 ret=numpy.allclose([stats[key]],[ref[key]],
00100 rtol=self.rtol,atol=self.atol)
00101 self.assertEqual(ret,True,msg=message)
00102
00103
00104 def _copy_input(self,datanames=None):
00105 if not datanames:
00106 return
00107 if type(datanames) == str:
00108 datanames = [datanames]
00109 if len(datanames) > 0:
00110 for indata in datanames:
00111 if os.path.exists(indata): self._remove(indata)
00112 if os.path.exists(self.datapath+indata):
00113
00114 self._copy(self.datapath+indata, indata)
00115
00116 def _remove(self, path):
00117 if os.path.isdir(path):
00118 shutil.rmtree(path)
00119 else:
00120 os.remove(path)
00121
00122 def _copy(self, src, dest):
00123 if os.path.isdir(src):
00124 shutil.copytree(src, dest)
00125 else:
00126 shutil.copy(src, dest)
00127
00128 def _get_data_prefix(self,cfgname, project=""):
00129 if str.upper(cfgname[0:4]) == "ALMA":
00130 foo=cfgname.replace(';','_')
00131 else:
00132 foo = cfgname
00133
00134 foo=foo.replace(".cfg","")
00135 sfoo=foo.split('/')
00136 if len(sfoo)>1: foo=sfoo[-1]
00137
00138 return project+"."+foo
00139
00140
00141
00142
00143
00144 class simobserve_sky(simobserve_unittest_base,unittest.TestCase):
00145 """
00146 Test skymodel simulations
00147 - Single step at a time
00148 - All steps with 2D, 3D and 4D input skymodel
00149 """
00150 project = simobserve_unittest_base.thistask+"_sky"
00151 inmodel = "core5ps.skymodel4mod"
00152 sdantlist = "aca.tp.cfg"
00153 antlist = "alma.out01.cfg"
00154
00155 refproj = "ref_sky"
00156 refpref = simobserve_unittest_base.datapath + refproj + "/"
00157
00158
00159 def setUp(self):
00160
00161
00162
00163 print("")
00164 default(simobserve)
00165 self.refpref_sd = self.refpref + \
00166 self._get_data_prefix(self.sdantlist,self.refproj)
00167 self.refpref_int = self.refpref + \
00168 self._get_data_prefix(self.antlist,self.refproj)
00169 self.refmodel = self.refpref_sd+".skymodel"
00170
00171 self.refms_sd = self.refpref_sd+".sd.ms"
00172 self.refms_int = self.refpref_int+".ms"
00173
00174 def tearDown(self):
00175
00176
00177 shutil.rmtree(self.project)
00178
00179
00180
00181 def testSky_skymodel(self):
00182 """Test skymodel simulation: only modify model"""
00183 skymodel = self.inmodel
00184 self._copy_input(skymodel)
00185 inbright = "5.95565834e-05Jy/pixel"
00186 indirection = "J2000 19h00m00 -23d00m00"
00187 incell = "0.043080964943481216arcsec"
00188 incenter = "345GHz"
00189 inwidth = "10MHz"
00190
00191
00192 obsmode = ""
00193 antennalist="alma.out01.cfg"
00194 res = simobserve(project=self.project,skymodel=skymodel,
00195 inbright=inbright,indirection=indirection,
00196 incell=incell,incenter=incenter,inwidth=inwidth,
00197 setpointings=True,obsmode=obsmode,
00198 antennalist=antennalist,
00199 thermalnoise="",graphics=self.graphics)
00200 self.assertTrue(res)
00201
00202 currmodel = self.project + "/" + \
00203 self._get_data_prefix(antennalist,self.project)+".skymodel"
00204 self._check_imstats(currmodel, self.refmodel)
00205
00206 def testSky_almaptg(self):
00207 """Test skymodel simulation: only setpointing (maptype='ALMA')"""
00208 skymodel = self.refmodel
00209 setpointings = True
00210 maptype = "ALMA"
00211 obsmode = ""
00212 antennalist = "alma.out01.cfg"
00213 res = simobserve(project=self.project,skymodel=skymodel,
00214 setpointings=setpointings,maptype=maptype,
00215 obsmode=obsmode,antennalist=antennalist,
00216 thermalnoise="",graphics=self.graphics)
00217 self.assertTrue(res)
00218
00219 refptg = "alma.alma.out01.ptg.txt"
00220
00221 def testSky_hexptg(self):
00222 """Test skymodel simulation: only setpointing (maptype='hexagonal')"""
00223 skymodel = self.refmodel
00224 setpointings = True
00225 maptype = "hexagonal"
00226 obsmode = ""
00227 antennalist = "aca.i.cfg"
00228 res = simobserve(project=self.project,skymodel=skymodel,
00229 setpointings=setpointings,maptype=maptype,
00230 obsmode=obsmode,antennalist=antennalist,
00231 thermalnoise="",graphics=self.graphics)
00232 self.assertTrue(res)
00233
00234 refptg = "hex.aca.i.ptg.txt"
00235
00236 def testSky_sqptg(self):
00237 """Test skymodel simulation: only setpointing (maptype='square')"""
00238 skymodel = self.refmodel
00239 setpointings = True
00240 maptype = "square"
00241 obsmode = ""
00242 antennalist = ""
00243 sdantlist = self.sdantlist
00244 res = simobserve(project=self.project,skymodel=skymodel,
00245 setpointings=setpointings,maptype=maptype,
00246 obsmode=obsmode,antennalist=antennalist,
00247 sdantlist=sdantlist,
00248 thermalnoise="",graphics=self.graphics)
00249 self.assertTrue(res)
00250
00251 refptg = "square.aca.tp.ptg.txt"
00252
00253 def testSky_sdObs(self):
00254 """Test skymodel simulation: only observation (SD)"""
00255 skymodel = self.refmodel
00256 setpointings = False
00257 ptgfile = self.refpref_sd + ".ptg.txt"
00258 integration = "4s"
00259 obsmode = "sd"
00260 sdantlist = self.sdantlist
00261 totaltime = "144s"
00262 thermalnoise = ""
00263 res = simobserve(project=self.project,skymodel=skymodel,
00264 setpointings=setpointings,ptgfile=ptgfile,
00265 integration=integration,obsmode=obsmode,
00266 sdantlist=sdantlist,totaltime=totaltime,
00267 thermalnoise=thermalnoise,graphics=self.graphics)
00268 self.assertTrue(res)
00269
00270 currms = self.project + "/" + \
00271 self._get_data_prefix(sdantlist,self.project)+".sd.ms"
00272 self._check_msstats(currms,self.refms_sd)
00273
00274
00275 def testSky_intObs(self):
00276 """Test skymodel simulation: only observation (INT)"""
00277 skymodel = self.refmodel
00278 setpointings = False
00279 ptgfile = self.refpref_int + ".ptg.txt"
00280 integration = "4s"
00281 obsmode = "int"
00282 antennalist = 'alma.out01.cfg'
00283 totaltime = "28s"
00284 res = simobserve(project=self.project,skymodel=skymodel,
00285 setpointings=setpointings,ptgfile=ptgfile,
00286 integration=integration,obsmode=obsmode,
00287 antennalist=antennalist,totaltime=totaltime,
00288 thermalnoise="",graphics=self.graphics)
00289 self.assertTrue(res)
00290
00291 currms = self.project + "/" + \
00292 self._get_data_prefix(antennalist,self.project)+".ms"
00293 self._check_msstats(currms,self.refms_sd)
00294
00295
00296
00297
00298
00299
00300
00301
00302
00303
00304
00305
00306
00307 def testSky_sdAll(self):
00308 """Test skymodel simulation: single dish"""
00309 skymodel = self.inmodel
00310 inbright = "5.95565834e-05Jy/pixel"
00311 indirection = "J2000 19h00m00 -23d00m00"
00312 incell = "0.043080964943481216arcsec"
00313 incenter = "345GHz"
00314 inwidth = "10MHz"
00315 integration = "4s"
00316 mapsize = ["60arcsec", "60arcsec"]
00317 maptype = "square"
00318 obsmode = "sd"
00319 sdantlist = "aca.tp.cfg"
00320 totaltime = "144s"
00321 res = simobserve(project=self.project,skymodel=skymodel,
00322 inbright=inbright,indirection=indirection,
00323 incell=incell,incenter=incenter,inwidth=inwidth,
00324 setpointings=True,integration=integration,
00325 mapsize=mapsize,maptype=maptype,obsmode=obsmode,
00326 totaltime=totaltime,antennalist="",sdantlist=sdantlist,
00327 thermalnoise="",graphics=self.graphics)
00328 self.assertTrue(res)
00329
00330 currpref = self.project + "/" + \
00331 self._get_data_prefix(sdantlist,self.project)
00332 self._check_imstats(currpref+".skymodel", self.refmodel)
00333
00334 self._check_msstats(currpref+".sd.ms",self.refms_sd)
00335
00336 def testSky_intAll(self):
00337 """Test skymodel simulation: interferometer"""
00338 skymodel = self.inmodel
00339 inbright = "5.95565834e-05Jy/pixel"
00340 indirection = "J2000 19h00m00 -23d00m00"
00341 incell = "0.043080964943481216arcsec"
00342 incenter = "345GHz"
00343 inwidth = "10MHz"
00344 integration = "4s"
00345 mapsize = ['20arcsec', '20arcsec']
00346 maptype = "ALMA"
00347 obsmode = 'int'
00348 antennalist = 'alma.out01.cfg'
00349 totaltime = "28s"
00350 res = simobserve(project=self.project,skymodel=skymodel,
00351 inbright=inbright,indirection=indirection,
00352 incell=incell,incenter=incenter,inwidth=inwidth,
00353 setpointings=True,integration=integration,
00354 mapsize=mapsize,maptype=maptype,obsmode=obsmode,
00355 totaltime=totaltime,antennalist=antennalist,
00356 thermalnoise="",graphics=self.graphics)
00357 self.assertTrue(res)
00358
00359 currpref = self.project + "/" + \
00360 self._get_data_prefix(antennalist,self.project)
00361 self._check_imstats(currpref+".skymodel", self.refmodel)
00362
00363 self._check_msstats(currpref+".ms",self.refms_int)
00364
00365
00366
00367
00368
00369
00370
00371
00372
00373
00374
00375
00376
00377
00378
00379
00380
00381
00382
00383
00384
00385
00386
00387
00388 class simobserve_noise(simobserve_unittest_base,unittest.TestCase):
00389 """
00390 Test noise level of simulated MS
00391 """
00392
00393 inimage = "flatone.model"
00394 ptgfile = "flatone.single.ptg.txt"
00395 indata = [inimage, ptgfile]
00396
00397
00398
00399 project = "noise_sd"
00400 project_int = "noise_int"
00401
00402
00403
00404 tint = "4s"
00405 tottime = "1800s"
00406 mapsize = ["5arcsec","5arcsec"]
00407 pointingspacing = "10arcsec"
00408 sdantlist = "aca.tp.cfg"
00409 antennalist = ""
00410 tau0 = 1.0
00411 pwv = 1.0
00412 graphics = 'file'
00413
00414 skymodel = project + "/" + project + ".aca.tp.model"
00415
00416 prevmsg = "The noise level differs from the previous value: %f (previous: %f)"
00417 anamsg = "The noise level differs more than 10%% from the analytic value: %f (analytic: %f)"
00418
00419
00420 def setUp(self):
00421
00422 print ""
00423 self._copy_input(self.indata)
00424 default(simobserve)
00425
00426 def tearDown(self):
00427 if (os.path.exists(self.inimage)):
00428 shutil.rmtree(self.inimage)
00429 if os.path.exists(self.project):
00430 shutil.rmtree(self.project)
00431
00432
00433
00434 def testNZ_intMan(self):
00435 """Test INT thermal noise (tsys-manual)"""
00436 project = self.project_int
00437 self._copy_input(project)
00438 skymodel = project+"/noise_int.aca_cycle1.model"
00439 antlist = "aca_cycle1.cfg"
00440 thermalnoise="tsys-manual"
00441 res = simobserve(project=project,skymodel=skymodel,
00442 setpointings=False,integration=self.tint,
00443 obsmode='',sdantlist="",antennalist=antlist,
00444 thermalnoise=thermalnoise,tau0=self.tau0,
00445 graphics=self.graphics)
00446 self.assertTrue(res)
00447
00448 msdict = self._get_ms_names(project,antlist)
00449 if msdict is None:
00450 self.fail("Could not find output MSes")
00451 noisyms = msdict['noisy']
00452 origms = msdict['original']
00453 msnoise = self._get_noise(noisyms, origms)
00454 ananoise = self._calc_alma_noise(mode="manual",sd=False,aca7m=True)
00455
00456
00457
00458 refval = 9.78451847017
00459 self.assertTrue(abs((msnoise-refval)/refval) < 5.e-2,\
00460 msg=self.prevmsg % (msnoise, refval))
00461 self.assertTrue(abs((msnoise-ananoise)/ananoise) < 1.e-1, \
00462 msg=self.anamsg % (msnoise, ananoise))
00463
00464 def testNZ_sdMan(self):
00465 """Test SD thermal noise (tsys-manual): standard parameter set"""
00466 thermalnoise="tsys-manual"
00467 self._copy_input(self.project)
00468 res = simobserve(project=self.project,skymodel=self.skymodel,
00469 setpointings = False,integration=self.tint,
00470 obsmode="",sdantlist=self.sdantlist,antennalist="",
00471 thermalnoise=thermalnoise,tau0=self.tau0,
00472 graphics=self.graphics)
00473 self.assertTrue(res)
00474
00475 msdict = self._get_ms_names(self.project,self.sdantlist)
00476 if msdict is None:
00477 self.fail("Could not find output MSes")
00478 noisyms = msdict['noisy']
00479 origms = msdict['original']
00480 msnoise = self._get_noise(noisyms, origms)
00481 ananoise = self._calc_alma_noise(mode="manual",sd=True)
00482
00483 refval = 4.91379000092
00484 self.assertTrue(abs((msnoise-refval)/refval) < 5.e-2,\
00485 msg=self.prevmsg % (msnoise, refval))
00486 self.assertTrue(abs((msnoise-ananoise)/ananoise) < 1.e-1, \
00487 msg=self.anamsg % (msnoise, ananoise))
00488
00489 def testNZ_sdMan_tau(self):
00490 """Test SD thermal noise (tsys-manual): tau0=1.5"""
00491 thermalnoise="tsys-manual"
00492 tau0 = 1.5
00493 self._copy_input(self.project)
00494 res = simobserve(project=self.project,skymodel=self.skymodel,
00495 setpointings = False,integration=self.tint,
00496 obsmode="",sdantlist=self.sdantlist,antennalist="",
00497 thermalnoise=thermalnoise,tau0=tau0,
00498 graphics=self.graphics)
00499 self.assertTrue(res)
00500
00501 msdict = self._get_ms_names(self.project,self.sdantlist)
00502 if msdict is None:
00503 self.fail("Could not find output MSes")
00504 noisyms = msdict['noisy']
00505 origms = msdict['original']
00506 msnoise = self._get_noise(noisyms, origms)
00507 ananoise = self._calc_alma_noise(mode="manual",sd=True,tau0=tau0)
00508
00509 refval = 9.27620818144
00510 self.assertTrue(abs((msnoise-refval)/refval) < 5.e-2,\
00511 msg=self.prevmsg % (msnoise, refval))
00512 self.assertTrue(abs((msnoise-ananoise)/ananoise) < 1.e-1, \
00513 msg=self.anamsg % (msnoise, ananoise))
00514
00515 def testNZ_sdMan_dnu(self):
00516 """Test SD thermal noise (tsys-manual): inwidth='1MHz'"""
00517 thermalnoise="tsys-manual"
00518 inwidth = '1MHz'
00519
00520 res = simobserve(project=self.project,skymodel=self.inimage,
00521 inwidth=inwidth,setpointings=False,
00522 ptgfile=self.ptgfile,integration=self.tint,
00523 obsmode='sd',sdantlist=self.sdantlist,
00524 antennalist=self.antennalist,totaltime=self.tottime,
00525 thermalnoise=thermalnoise,tau0=self.tau0,
00526 graphics=self.graphics)
00527 self.assertTrue(res)
00528
00529 msdict = self._get_ms_names(self.project,self.sdantlist)
00530 if msdict is None:
00531 self.fail("Could not find output MSes")
00532 noisyms = msdict['noisy']
00533 origms = msdict['original']
00534 msnoise = self._get_noise(noisyms, origms)
00535 ananoise = self._calc_alma_noise(mode="manual",sd=True,dnu=inwidth)
00536
00537 refval = 15.5387677134
00538 self.assertTrue(abs((msnoise-refval)/refval) < 5.e-2,\
00539 msg=self.prevmsg % (msnoise, refval))
00540 self.assertTrue(abs((msnoise-ananoise)/ananoise) < 1.e-1, \
00541 msg=self.anamsg % (msnoise, ananoise))
00542
00543 def testNZ_sdMan_tint(self):
00544 """Test SD thermal noise (tsys-manual): integration='2s'"""
00545 thermalnoise="tsys-manual"
00546 integration = '2s'
00547 totaltime = '900s'
00548
00549 res = simobserve(project=self.project,skymodel=self.inimage,
00550 setpointings=False,ptgfile=self.ptgfile,
00551 integration=integration,
00552 obsmode='sd',sdantlist=self.sdantlist,
00553 antennalist=self.antennalist,totaltime=totaltime,
00554 thermalnoise=thermalnoise,tau0=self.tau0,
00555 graphics=self.graphics)
00556 self.assertTrue(res)
00557
00558 msdict = self._get_ms_names(self.project,self.sdantlist)
00559 if msdict is None:
00560 self.fail("Could not find output MSes")
00561 noisyms = msdict['noisy']
00562 origms = msdict['original']
00563 msnoise = self._get_noise(noisyms, origms)
00564 ananoise = self._calc_alma_noise(mode="manual",sd=True,integration=integration)
00565
00566 refval = 6.94461790663
00567 self.assertTrue(abs((msnoise-refval)/refval) < 5.e-2,\
00568 msg=self.prevmsg % (msnoise, refval))
00569 self.assertTrue(abs((msnoise-ananoise)/ananoise) < 1.e-1, \
00570 msg=self.anamsg % (msnoise, ananoise))
00571
00572 def testNZ_sdMan_el(self):
00573 """Test SD thermal noise (tsys-manual): elevation = 60 deg"""
00574 thermalnoise="tsys-manual"
00575 indir = 'J2000 19h00m00 -53d00m00'
00576
00577 res = simobserve(project=self.project,skymodel=self.inimage,
00578 indirection=indir,setpointings=True,
00579 integration=self.tint,mapsize=self.mapsize,
00580 pointingspacing=self.pointingspacing,
00581 obsmode='sd',sdantlist=self.sdantlist,
00582 antennalist=self.antennalist,totaltime=self.tottime,
00583 thermalnoise=thermalnoise,tau0=self.tau0,
00584 graphics=self.graphics)
00585 self.assertTrue(res)
00586
00587 msdict = self._get_ms_names(self.project,self.sdantlist)
00588 if msdict is None:
00589 self.fail("Could not find output MSes")
00590 noisyms = msdict['noisy']
00591 origms = msdict['original']
00592 msnoise = self._get_noise(noisyms, origms)
00593 ananoise = self._calc_alma_noise(mode="manual",sd=True,dir=-53.)
00594 print "MS noise:", msnoise
00595 print "Analytic:", ananoise
00596
00597 refval = 6.0450620991
00598 self.assertTrue(abs((msnoise-refval)/refval) < 5.e-2,\
00599 msg=self.prevmsg % (msnoise, refval))
00600 self.assertTrue(abs((msnoise-ananoise)/ananoise) < 1.e-1, \
00601 msg=self.anamsg % (msnoise, ananoise))
00602
00603
00604
00605 def testNZ_intAtm(self):
00606 """Test INT thermal noise (tsys-atm): standard parameter set"""
00607 project = self.project_int
00608 self._copy_input(project)
00609 skymodel = project+"/noise_int.aca_cycle1.model"
00610 antlist = "aca_cycle1.cfg"
00611 thermalnoise="tsys-atm"
00612 res = simobserve(project=project,skymodel=skymodel,
00613 setpointings=False,integration=self.tint,
00614 obsmode='',sdantlist="",antennalist=antlist,
00615 thermalnoise=thermalnoise,tau0=self.tau0,
00616 graphics=self.graphics)
00617 self.assertTrue(res)
00618
00619 msdict = self._get_ms_names(project,antlist)
00620 if msdict is None:
00621 self.fail("Could not find output MSes")
00622 noisyms = msdict['noisy']
00623 origms = msdict['original']
00624 msnoise = self._get_noise(noisyms, origms)
00625 ananoise = self._calc_alma_noise(mode="atm",sd=False,aca7m=True)
00626
00627 refval = 2.27105136133
00628 self.assertTrue(abs((msnoise-refval)/refval) < 5.e-2,\
00629 msg=self.prevmsg % (msnoise, refval))
00630 self.assertTrue(abs((msnoise-ananoise)/ananoise) < 1.e-1, \
00631 msg=self.anamsg % (msnoise, ananoise))
00632
00633 def testNZ_sdAtm(self):
00634 """Test SD thermal noise (tsys-atm): standard parameter set"""
00635 thermalnoise="tsys-atm"
00636 self._copy_input(self.project)
00637 res = simobserve(project=self.project,skymodel=self.skymodel,
00638 setpointings = False,integration=self.tint,
00639 obsmode="",sdantlist=self.sdantlist,antennalist="",
00640 thermalnoise=thermalnoise,user_pwv=self.pwv,
00641 graphics=self.graphics)
00642 self.assertTrue(res)
00643
00644 msdict = self._get_ms_names(self.project,self.sdantlist)
00645 if msdict is None:
00646 self.fail("Could not find output MSes")
00647 noisyms = msdict['noisy']
00648 origms = msdict['original']
00649 msnoise = self._get_noise(noisyms, origms)
00650 ananoise = self._calc_alma_noise(mode="atm",sd=True)
00651
00652 refval = 1.13985820952
00653 self.assertTrue(abs((msnoise-refval)/refval) < 5.e-2,\
00654 msg=self.prevmsg % (msnoise, refval))
00655 self.assertTrue(abs((msnoise-ananoise)/ananoise) < 1.e-1, \
00656 msg=self.anamsg % (msnoise, ananoise))
00657
00658 def testNZ_sdAtm_pwv(self):
00659 """Test SD thermal noise (tsys-atm): pwv = 2.0"""
00660 thermalnoise="tsys-atm"
00661 pwv = 2.0
00662 self._copy_input(self.project)
00663 res = simobserve(project=self.project,skymodel=self.skymodel,
00664 setpointings = False,integration=self.tint,
00665 obsmode="",sdantlist=self.sdantlist,antennalist="",
00666 thermalnoise=thermalnoise,user_pwv=pwv,
00667 graphics=self.graphics)
00668 self.assertTrue(res)
00669
00670 msdict = self._get_ms_names(self.project,self.sdantlist)
00671 if msdict is None:
00672 self.fail("Could not find output MSes")
00673 noisyms = msdict['noisy']
00674 origms = msdict['original']
00675 msnoise = self._get_noise(noisyms, origms)
00676 ananoise = self._calc_alma_noise(mode="atm",sd=True,pwv=pwv)
00677
00678 refval = 1.61886644931
00679 self.assertTrue(abs((msnoise-refval)/refval) < 5.e-2,\
00680 msg=self.prevmsg % (msnoise, refval))
00681 self.assertTrue(abs((msnoise-ananoise)/ananoise) < 1.e-1, \
00682 msg=self.anamsg % (msnoise, ananoise))
00683
00684 def testNZ_sdAtm_dnu(self):
00685 """Test SD thermal noise (tsys-atm): inwidth='1MHz'"""
00686 thermalnoise="tsys-atm"
00687 inwidth = '1MHz'
00688
00689 res = simobserve(project=self.project,skymodel=self.inimage,
00690 inwidth=inwidth,setpointings=False,
00691 ptgfile=self.ptgfile,integration=self.tint,
00692 obsmode='sd',sdantlist=self.sdantlist,
00693 antennalist=self.antennalist,totaltime=self.tottime,
00694 thermalnoise=thermalnoise,user_pwv=self.pwv,
00695 graphics=self.graphics)
00696 self.assertTrue(res)
00697
00698 msdict = self._get_ms_names(self.project,self.sdantlist)
00699 if msdict is None:
00700 self.fail("Could not find output MSes")
00701 noisyms = msdict['noisy']
00702 origms = msdict['original']
00703 msnoise = self._get_noise(noisyms, origms)
00704 ananoise = self._calc_alma_noise(mode="atm",sd=True,dnu=inwidth)
00705
00706 refval = 3.60454794841
00707 self.assertTrue(abs((msnoise-refval)/refval) < 5.e-2,\
00708 msg=self.prevmsg % (msnoise, refval))
00709 self.assertTrue(abs((msnoise-ananoise)/ananoise) < 1.e-1, \
00710 msg=self.anamsg % (msnoise, ananoise))
00711
00712 def testNZ_sdAtm_tint(self):
00713 """Test SD thermal noise (tsys-atm): integration = '2s'"""
00714 thermalnoise="tsys-atm"
00715 integration = '2s'
00716 totaltime = '900s'
00717
00718 res = simobserve(project=self.project,skymodel=self.inimage,
00719 setpointings=False,ptgfile=self.ptgfile,
00720 integration=integration,
00721 obsmode='sd',sdantlist=self.sdantlist,
00722 antennalist=self.antennalist,totaltime=totaltime,
00723 thermalnoise=thermalnoise,user_pwv=self.pwv,
00724 graphics=self.graphics)
00725 self.assertTrue(res)
00726
00727 msdict = self._get_ms_names(self.project,self.sdantlist)
00728 if msdict is None:
00729 self.fail("Could not find output MSes")
00730 noisyms = msdict['noisy']
00731 origms = msdict['original']
00732 msnoise = self._get_noise(noisyms, origms)
00733 ananoise = self._calc_alma_noise(mode="atm",sd=True,integration=integration)
00734
00735 refval = 1.61165299786
00736 self.assertTrue(abs((msnoise-refval)/refval) < 5.e-2,\
00737 msg=self.prevmsg % (msnoise, refval))
00738 self.assertTrue(abs((msnoise-ananoise)/ananoise) < 1.e-1, \
00739 msg=self.anamsg % (msnoise, ananoise))
00740
00741 def testNZ_sdAtm_el(self):
00742 """Test SD thermal noise (tsys-atm): elevation = 60 deg"""
00743 thermalnoise="tsys-atm"
00744 indir = 'J2000 19h00m00 -53d00m00'
00745
00746 res = simobserve(project=self.project,skymodel=self.inimage,
00747 indirection=indir,setpointings=True,
00748 integration=self.tint,mapsize=self.mapsize,
00749 pointingspacing=self.pointingspacing,
00750 obsmode='sd',sdantlist=self.sdantlist,
00751 antennalist=self.antennalist,totaltime=self.tottime,
00752 thermalnoise=thermalnoise,user_pwv=self.pwv,
00753 graphics=self.graphics)
00754 self.assertTrue(res)
00755
00756 msdict = self._get_ms_names(self.project,self.sdantlist)
00757 if msdict is None:
00758 self.fail("Could not find output MSes")
00759 noisyms = msdict['noisy']
00760 origms = msdict['original']
00761 msnoise = self._get_noise(noisyms, origms)
00762 ananoise = self._calc_alma_noise(mode="atm",sd=True,dir=-53.)
00763
00764
00765
00766 refval = 1.22177450558
00767 self.assertTrue(abs((msnoise-refval)/refval) < 5.e-2,\
00768 msg=self.prevmsg % (msnoise, refval))
00769 self.assertTrue(abs((msnoise-ananoise)/ananoise) < 1.e-1, \
00770 msg=self.anamsg % (msnoise, ananoise))
00771
00772
00773
00774 def _get_ms_names(self, project, antennalist):
00775 retDict = {"original": None, "noisy": None}
00776 prefix = project+"/"+self._get_data_prefix(antennalist, project)
00777 mslist = glob.glob(prefix+"*.noisier*.ms")
00778 if len(mslist) > 0:
00779 retDict['noisy'] = mslist[0]
00780 else:
00781 mslist = glob.glob(prefix+"*.noisy*.ms")
00782 if len(mslist) > 0:
00783 retDict['noisy'] = mslist[0]
00784 else:
00785 return None
00786
00787 if os.path.exists(prefix+".ms"):
00788 retDict["original"] = prefix+".ms"
00789 elif os.path.exists(prefix+".sd.ms"):
00790 retDict["original"] = prefix+".sd.ms"
00791 else:
00792 return None
00793
00794 return retDict
00795
00796 def _get_noise(self, noisyms, origms):
00797 tb.open(noisyms)
00798 noisy_data = tb.getcol("DATA")
00799 tb.close()
00800 tb.open(origms)
00801 orig_data = tb.getcol("DATA")
00802 tb.close()
00803 diff_data = noisy_data - orig_data
00804
00805
00806
00807
00808 return diff_data.real.std()
00809
00810 def _calc_alma_noise(self, mode="manual",sd=True,aca7m=False,\
00811 freq="345GHz",dnu="10MHz",integration='4s',dir=-23.,\
00812 pwv=1.0,tground=269.,tsky=263.,tau0=1.0):
00813 if sd:
00814 senscoeff = 1.0
00815 else:
00816 senscoeff = 1./numpy.sqrt(2)
00817
00818 freq_ghz = qa.convert(freq,"GHz")['value']
00819 dnu_hz = qa.convert(dnu,"Hz")['value']
00820 tint_sec = qa.convert(integration,"s")['value']
00821
00822 if aca7m:
00823 telescope = "ACA"
00824 diam = 7.
00825 else:
00826 telescope = "ALMA"
00827 diam = 12.
00828
00829 myutil = simutil()
00830 eta_phase, espill, eta_block, eta_taper, ecorr, trx \
00831 = myutil.noisetemp(telescope=telescope,freq=freq)
00832 eant = eta_phase * espill * eta_block * eta_taper
00833
00834 tcmb = 2.725
00835
00836 antpos = -23.022886
00837 el = numpy.pi/2.- (dir-antpos)/180.*numpy.pi
00838 airmass = 1./numpy.sin(el)
00839
00840 hn_k = 0.04799274551*freq_ghz
00841
00842 if mode.find("manual") > -1:
00843 tau = tau0*airmass
00844 Rtcmb = 1./(numpy.exp(hn_k/tcmb)-1.)
00845 Rtatmos = 1./(numpy.exp(hn_k/tsky)-1.)
00846 Rtground = 1./(numpy.exp(hn_k/tground)-1.)
00847 R = Rtcmb*espill + \
00848 numpy.exp(tau) *( espill * (1.-numpy.exp(-tau)) * Rtatmos \
00849 + (1.-espill) * Rtground + trx/hn_k)
00850 else:
00851 tsky, tau0 = self._get_atmsky(tground, tcmb, freq, dnu,
00852 espill, pwv, airmass)
00853 tau = tau0*airmass
00854 R = numpy.exp(tau) * (1./(numpy.exp(hn_k/tsky)-1.) + trx/hn_k)
00855
00856 amp = 8 * 1.38062e-16 * 1e23 * 1e-4 / (eant * ecorr * numpy.pi)
00857 tsys=hn_k*R
00858 factor = numpy.sqrt(senscoeff * amp / numpy.sqrt(dnu_hz * tint_sec))
00859 par = diam / factor / numpy.sqrt(tsys)
00860
00861 return 1./par**2
00862
00863 def _get_atmsky(self, tground, tcmb, freq, dnu, espill, pwv, airmass):
00864 freq_ghz = qa.convert(freq,"GHz")['value']
00865 hn_k = 0.04799274551*freq_ghz
00866
00867 at.initAtmProfile(temperature=qa.quantity(tground))
00868 atmnchan = 10.
00869 fcntr = qa.quantity(freq)
00870 bw = qa.quantity(dnu)
00871 fres = qa.div(qa.quantity(dnu),atmnchan)
00872 at.initSpectralWindow(nbands=1,fCenter=fcntr,fWidth=bw,fRes=fres)
00873 at.setSkyBackgroundTemperature(qa.quantity(tcmb,"K"))
00874 at.setAirMass(airmass)
00875 at.setUserWH2O(qa.quantity(pwv,"mm"))
00876 rchan = at.getRefChan(spwid=0)
00877 ratio = at.getUserWH2O()["value"]/at.getGroundWH2O()["value"]
00878
00879
00880 dz = at.getProfile()[1]["value"]
00881 tz = at.getProfile()[2]["value"]
00882 radiance = 0.
00883 kv = 0.
00884 for iz in range(at.getNumLayers()):
00885 dtau0 = dz[iz] * (at.getAbsTotalDry(iz, rchan, 0)["value"] + \
00886 at.getAbsTotalWet(iz, rchan, 0)["value"] * ratio)
00887 dmass = dtau0[0]*airmass
00888 radiance += (1./(numpy.exp(hn_k/tz[iz])-1.)) * numpy.exp(-kv*airmass) \
00889 * (1. - numpy.exp(-dmass))
00890 kv += dtau0[0]
00891
00892 R = espill * (radiance + (1./(numpy.exp(hn_k/tcmb)-1.))*numpy.exp(-kv*airmass))\
00893 + (1./(numpy.exp(hn_k/qa.quantity(tground)["value"]) - 1.)) * (1. - espill)
00894 tsky = hn_k / numpy.log(1. + (1. / R))
00895 tau0 = at.getDryOpacity(spwid=0) + \
00896 at.getWetOpacity(spwid=0)['value'][0]
00897 return tsky, tau0
00898
00899
00900
00901
00902
00903
00904 class simobserve_badinputs(simobserve_unittest_base,unittest.TestCase):
00905 """
00906 Tests on bad input parameter setting
00907 """
00908
00909 inimage = "core5ps.skymodel"
00910 incomp = "core5ps.clist"
00911 indata = [inimage,incomp]
00912
00913 tottime = "1"
00914 mapsize = ["5arcsec","5arcsec"]
00915 sdmapsize = ["40arcsec","40arcsec"]
00916 sdantlist = "aca.tp.cfg"
00917
00918
00919 badsize = "-60arcsec"
00920 badfreq = "-3GHz"
00921 baddir = "J3000 19h00m00 -23d00m00"
00922 badname = "badname"
00923 badtime = "-100s"
00924 badquant = "5bad"
00925 badnum = -1.
00926 project = simobserve_unittest_base.thistask+"_bad"
00927
00928 failmsg = "The task must throw exception"
00929 errmsg = "Unexpected exception was thrown: %s"
00930
00931
00932 def setUp(self):
00933 if (os.path.exists(self.project)):
00934 shutil.rmtree(self.project)
00935
00936 for data in self.indata:
00937 if os.path.exists(data):
00938 os.system("rm -rf %s" % data)
00939 os.system("cp -r %s %s" % (self.datapath+data, data))
00940
00941
00942 glb['__rethrow_casa_exceptions'] = True
00943
00944 default(simobserve)
00945
00946 print ""
00947
00948 def tearDown(self):
00949 glb['__rethrow_casa_exceptions'] = rethrow_org
00950 for data in self.indata:
00951 if os.path.exists(data):
00952 os.system("rm -rf %s" % data)
00953 if (os.path.exists(self.project)):
00954 shutil.rmtree(self.project)
00955
00956
00957 def test_default(self):
00958 """Test Default parameter set. Neigher skymodel nor complist"""
00959 try:
00960 res = simobserve()
00961 self.fail(self.failmsg)
00962 except Exception, e:
00963 pos=str(e).find("No sky input found")
00964 msg = self.errmsg % str(e)
00965 self.assertNotEqual(pos,-1,msg=msg)
00966
00967
00968 def test_noProject(self):
00969 """Test no project name"""
00970 project = ''
00971 try:
00972 res = simobserve(project=project)
00973 self.fail(self.failmsg)
00974 except Exception, e:
00975 pos=str(e).find("No such file or directory: ''")
00976 msg = self.errmsg % str(e)
00977 self.assertNotEqual(pos,-1,msg=msg)
00978
00979
00980 def testBad_skymodel(self):
00981 """Test bad skymodel name"""
00982 skymodel=self.badname
00983 try:
00984 res = simobserve(project=self.project,skymodel=skymodel)
00985 self.fail(self.failmsg)
00986 except Exception, e:
00987 pos=str(e).find("No sky input found")
00988 msg = self.errmsg % str(e)
00989 self.assertNotEqual(pos,-1,msg=msg)
00990
00991 def test_notImage(self):
00992 """Test non-image skymodel"""
00993 skymodel=self.incomp
00994 try:
00995 res = simobserve(project=self.project,
00996 totaltime=self.tottime,mapsize=self.mapsize,
00997 skymodel=skymodel)
00998 self.fail(self.failmsg)
00999 except Exception, e:
01000 pos=str(e).find("Image %s cannot be opened; its type is unknown" % skymodel)
01001 msg = self.errmsg % str(e)
01002 self.assertNotEqual(pos,-1,msg=msg)
01003
01004 def testBad_inbright(self):
01005 """Test bad inbright"""
01006 inbright=self.badquant
01007 try:
01008 res = simobserve(project=self.project,skymodel=self.inimage,
01009 totaltime=self.tottime,mapsize=self.mapsize,
01010 inbright=inbright)
01011 self.fail(self.failmsg)
01012 except Exception, e:
01013 pos=str(e).find("invalid literal for float(): %s" % inbright)
01014 msg = self.errmsg % str(e)
01015 self.assertNotEqual(pos,-1,msg=msg)
01016
01017 def testBad_indirection(self):
01018 """Test bad indirection ('J3000' is defaulted to 'J2000')"""
01019 indirection=self.baddir
01020 res = simobserve(project=self.project,skymodel=self.inimage,
01021 totaltime=self.tottime,mapsize=self.mapsize,
01022 indirection=indirection,graphics=self.graphics)
01023 self.assertTrue(res)
01024
01025
01026 def testBad_incell(self):
01027 """Test bad incell"""
01028 incell=self.badquant
01029 try:
01030 res = simobserve(project=self.project,skymodel=self.inimage,
01031 totaltime=self.tottime,mapsize=self.mapsize,
01032 incell=incell)
01033 self.fail(self.failmsg)
01034 except Exception, e:
01035 pos=str(e).find('Error in QuantumHolder::fromString with input string "%s": Illegal input units or format' % incell)
01036 msg = self.errmsg % str(e)
01037 self.assertNotEqual(pos,-1,msg=msg)
01038
01039 def testBad_incenter(self):
01040 """Test bad incenter"""
01041
01042 incenter=self.badfreq
01043
01044 res = simobserve(project=self.project,skymodel=self.inimage,
01045 totaltime=self.tottime,mapsize=self.mapsize,
01046 incenter=incenter,graphics=self.graphics)
01047 self.assertTrue(res)
01048
01049
01050 def testBad_inwidth(self):
01051 """Test bad inwidth"""
01052
01053 inwidth=self.badfreq
01054
01055 res = simobserve(project=self.project,skymodel=self.inimage,
01056 totaltime=self.tottime,mapsize=self.mapsize,
01057 inwidth=inwidth,graphics=self.graphics)
01058 self.assertTrue(res)
01059
01060
01061 def testBad_complist(self):
01062 """Test bad complist name"""
01063 complist=self.badname
01064 try:
01065 res = simobserve(project=self.project,complist=complist,
01066 totaltime=self.tottime,mapsize=self.mapsize)
01067 self.fail(self.failmsg)
01068 except Exception, e:
01069 pos=str(e).find("No sky input found")
01070 msg = self.errmsg % str(e)
01071 self.assertNotEqual(pos,-1,msg=msg)
01072
01073 def test_notComp(self):
01074 """Test non-components list complist"""
01075 complist=self.inimage
01076 try:
01077 res = simobserve(project=self.project,complist=complist,
01078 totaltime=self.tottime,mapsize=self.mapsize)
01079 self.fail(self.failmsg)
01080 except Exception, e:
01081 pos=str(e).find("%s is non existant or is not a componentlist table" % complist)
01082 msg = self.errmsg % str(e)
01083 self.assertNotEqual(pos,-1,msg=msg)
01084
01085 def testBad_compwidth(self):
01086 """Test bad compwidth"""
01087
01088 compwidth="2arcsec"
01089 try:
01090 res = simobserve(project=self.project,complist=self.incomp,
01091 totaltime=self.tottime,mapsize=self.mapsize,
01092 compwidth=compwidth)
01093 self.fail(self.failmsg)
01094 except Exception, e:
01095 pos=str(e).find("Quantum::operator- unequal units 'GHz, 'arcsec'")
01096 msg = self.errmsg % str(e)
01097 self.assertNotEqual(pos,-1,msg=msg)
01098
01099 def testBad_ptgfile(self):
01100 """Test bad ptgfile name"""
01101 setpointings=False
01102 ptgfile = self.badname
01103 try:
01104 res = simobserve(project=self.project,skymodel=self.inimage,
01105 totaltime=self.tottime,mapsize=self.mapsize,
01106 setpointings=setpointings,ptgfile=ptgfile)
01107 self.fail(self.failmsg)
01108 except Exception, e:
01109 pos=str(e).find("Can't find pointing file")
01110 msg = self.errmsg % str(e)
01111 self.assertNotEqual(pos,-1,msg=msg)
01112
01113 def test_notPtgfile(self):
01114 """Test nonconforming ptgfile"""
01115
01116 fname = self.project+".badptg.txt"
01117 f = open(fname,"w")
01118 f.write("#This is bad pointing file\nsome bad data written")
01119 f.close()
01120 del f
01121
01122 setpointings=False
01123 ptgfile = fname
01124 try:
01125 res = simobserve(project=self.project,skymodel=self.inimage,
01126 totaltime=self.tottime,mapsize=self.mapsize,
01127 setpointings=setpointings,ptgfile=ptgfile)
01128 self.fail(self.failmsg)
01129 except Exception, e:
01130 pos=str(e).find("No valid lines found in pointing file")
01131 msg = self.errmsg % str(e)
01132 self.assertNotEqual(pos,-1,msg=msg)
01133
01134 def testBad_integration(self):
01135 """Test bad integration"""
01136 integration = self.badtime
01137 try:
01138 res = simobserve(project=self.project,skymodel=self.inimage,
01139 totaltime=self.tottime,mapsize=self.mapsize,
01140 integration=integration)
01141 self.fail(self.failmsg)
01142 except Exception, e:
01143 pos=str(e).find('Failed AlwaysAssert qIntTime.getValue("s")>=0')
01144 msg = self.errmsg % str(e)
01145 self.assertNotEqual(pos,-1,msg=msg)
01146
01147 def testBad_direction(self):
01148 """Test bad direction ('J3000' is defaulted to 'J2000')"""
01149 direction = self.baddir
01150
01151 res = simobserve(project=self.project,skymodel=self.inimage,
01152 totaltime=self.tottime,mapsize=self.mapsize,
01153 direction=direction,graphics=self.graphics)
01154 self.assertTrue(res)
01155
01156
01157 def testBad_mapsize(self):
01158 """Test bad mapsize"""
01159 setpointings=True
01160 mapsize = [self.badquant, self.badquant]
01161 try:
01162 res = simobserve(project=self.project,skymodel=self.inimage,
01163 totaltime=self.tottime,
01164 setpointings=setpointings,mapsize=mapsize)
01165 self.fail(self.failmsg)
01166 except Exception, e:
01167 pos=str(e).find("can't interpret '%s' as a CASA quantity" % self.badquant)
01168 msg = self.errmsg % str(e)
01169 self.assertNotEqual(pos,-1,msg=msg)
01170
01171 def testBad_maptype(self):
01172 """Test bad maptype"""
01173 maptype = self.badname
01174 try:
01175 res = simobserve(project=self.project,skymodel=self.inimage,
01176 totaltime=self.tottime,mapsize=self.mapsize,
01177 maptype=maptype)
01178 self.fail(self.failmsg)
01179 except Exception, e:
01180 pos=str(e).find("Parameter verification failed")
01181 msg = self.errmsg % str(e)
01182 self.assertNotEqual(pos,-1,msg=msg)
01183
01184
01185 def testBad_spacing(self):
01186 """Test bad pointingspacing"""
01187 pointingspacing = self.badquant
01188 try:
01189 res = simobserve(project=self.project,skymodel=self.inimage,
01190 totaltime=self.tottime,mapsize=self.mapsize,
01191 pointingspacing=pointingspacing)
01192 self.fail(self.failmsg)
01193 except Exception, e:
01194 pos=str(e).find("can't interpret '%s' as a CASA quantity" % pointingspacing)
01195 msg = self.errmsg % str(e)
01196 self.assertNotEqual(pos,-1,msg=msg)
01197
01198
01199 def testBad_obsmode(self):
01200 """Test bad obsmode"""
01201 obsmode = self.badname
01202 try:
01203 res = simobserve(project=self.project,skymodel=self.inimage,
01204 totaltime=self.tottime,mapsize=self.mapsize,
01205 obsmode=obsmode)
01206 self.fail(self.failmsg)
01207 except Exception, e:
01208 pos=str(e).find("Parameter verification failed")
01209 msg = self.errmsg % str(e)
01210 self.assertNotEqual(pos,-1,msg=msg)
01211
01212 def testBad_antennalist(self):
01213 """Test bad antennalist name"""
01214 antennalist = self.badname
01215 try:
01216 res = simobserve(project=self.project,skymodel=self.inimage,
01217 totaltime=self.tottime,mapsize=self.mapsize,
01218 antennalist=antennalist)
01219 self.fail(self.failmsg)
01220 except Exception, e:
01221 pos=str(e).find("Couldn't find antennalist")
01222 msg = self.errmsg % str(e)
01223 self.assertNotEqual(pos,-1,msg=msg)
01224
01225 def testBad_caldirection(self):
01226 """Test bad caldirection ('J3000' is defaulted to 'J2000')"""
01227 caldirection = self.baddir
01228
01229 res = simobserve(project=self.project,skymodel=self.inimage,
01230 totaltime=self.tottime,mapsize=self.mapsize,
01231 caldirection=caldirection,graphics=self.graphics)
01232 self.assertTrue(res)
01233
01234
01235
01236
01237 def testBad_calflux(self):
01238 """Test bad calflux"""
01239 caldirection = "J2000 19h00m00 -23d00m50"
01240 calflux = self.badquant
01241 try:
01242 res = simobserve(project=self.project,skymodel=self.inimage,
01243 totaltime=self.tottime,mapsize=self.mapsize,
01244 caldirection=caldirection,calflux=calflux)
01245 self.fail(self.failmsg)
01246 except Exception, e:
01247 pos=str(e).find("can't interpret '%s' as a CASA quantity" % calflux)
01248 msg = self.errmsg % str(e)
01249 self.assertNotEqual(pos,-1,msg=msg)
01250
01251 def testBad_sdantlist(self):
01252 """Test bad sdantlist name"""
01253 obsmode = "sd"
01254 mapsize = self.sdmapsize
01255 sdantlist = self.badname
01256 try:
01257 res = simobserve(project=self.project,skymodel=self.inimage,
01258 totaltime=self.tottime,mapsize=mapsize,
01259 obsmode=obsmode,sdantlist=sdantlist)
01260 self.fail(self.failmsg)
01261 except Exception, e:
01262 pos=str(e).find("Couldn't find antennalist")
01263 msg = self.errmsg % str(e)
01264 self.assertNotEqual(pos,-1,msg=msg)
01265
01266
01267
01268 def testBad_sdant(self):
01269 """Test bad sdant (non-numeric sdant)"""
01270 obsmode = "sd"
01271 mapsize = self.sdmapsize
01272 sdantlist = self.sdantlist
01273 sdant = self.badname
01274 try:
01275 res = simobserve(project=self.project,skymodel=self.inimage,
01276 totaltime=self.tottime,mapsize=mapsize,
01277 obsmode=obsmode,sdantlist=sdantlist,
01278 sdant=sdant)
01279 self.fail(self.failmsg)
01280 except Exception, e:
01281 pos=str(e).find("Parameter verification failed")
01282 msg = self.errmsg % str(e)
01283 self.assertNotEqual(pos,-1,msg=msg)
01284
01285 def testBad_refdate(self):
01286 """Test bad refdate"""
01287 obsmode = "sd"
01288 mapsize = self.sdmapsize
01289 sdantlist = self.sdantlist
01290 refdate = "05/21"
01291 try:
01292 res = simobserve(project=self.project,skymodel=self.inimage,
01293 totaltime=self.tottime,mapsize=mapsize,
01294 obsmode=obsmode,sdantlist=sdantlist,
01295 refdate=refdate)
01296 self.fail(self.failmsg)
01297 except Exception, e:
01298 pos=str(e).find("Invalid reference date")
01299 msg = self.errmsg % str(e)
01300 self.assertNotEqual(pos,-1,msg=msg)
01301
01302 def testBad_hourangle(self):
01303 """Test bad hourangle"""
01304 obsmode = "sd"
01305 mapsize = self.sdmapsize
01306 sdantlist = self.sdantlist
01307 hourangle = self.badname
01308 try:
01309 res = simobserve(project=self.project,skymodel=self.inimage,
01310 totaltime=self.tottime,mapsize=mapsize,
01311 obsmode=obsmode,sdantlist=sdantlist,
01312 hourangle=hourangle)
01313 self.fail(self.failmsg)
01314 except Exception, e:
01315 pos=str(e).find('Error in QuantumHolder::fromString with input string "%s": Illegal input units or format' % hourangle)
01316 msg = self.errmsg % str(e)
01317 self.assertNotEqual(pos,-1,msg=msg)
01318
01319
01320 def testBad_totaltime(self):
01321 """Test bad totaltime"""
01322 obsmode = "sd"
01323 mapsize = self.sdmapsize
01324 sdantlist = self.sdantlist
01325 totaltime = self.badtime
01326 try:
01327 res = simobserve(project=self.project,skymodel=self.inimage,
01328 mapsize=mapsize,
01329 obsmode=obsmode,sdantlist=sdantlist,
01330 totaltime=totaltime)
01331 self.fail(self.failmsg)
01332 except Exception, e:
01333 pos=str(e).find("Negative totaltime is not allowed")
01334 msg = self.errmsg % str(e)
01335 self.assertNotEqual(pos,-1,msg=msg)
01336
01337 def testBad_noisetype(self):
01338 """Test bad thermalnoise type"""
01339 thermalnoise = self.badname
01340 try:
01341 res = simobserve(project=self.project,skymodel=self.inimage,
01342 totaltime=self.tottime,mapsize=self.mapsize,
01343 thermalnoise=thermalnoise)
01344 self.fail(self.failmsg)
01345 except Exception, e:
01346 pos=str(e).find("Parameter verification failed")
01347 msg = self.errmsg % str(e)
01348 self.assertNotEqual(pos,-1,msg=msg)
01349
01350 def testBad_pwv(self):
01351 """Test bad user_pwv"""
01352 thermalnoise = 'tsys-atm'
01353 user_pwv = self.badnum
01354 try:
01355 res = simobserve(project=self.project,skymodel=self.inimage,
01356 totaltime=self.tottime,mapsize=self.mapsize,
01357 thermalnoise=thermalnoise,user_pwv=user_pwv)
01358 self.fail(self.failmsg)
01359 except Exception, e:
01360 pos=str(e).find("Parameter verification failed")
01361 msg = self.errmsg % str(e)
01362 self.assertNotEqual(pos,-1,msg=msg)
01363
01364 def testBad_Tground(self):
01365 """Test bad t_ground"""
01366 thermalnoise = 'tsys-atm'
01367 t_ground = self.badnum
01368 try:
01369 res = simobserve(project=self.project,skymodel=self.inimage,
01370 totaltime=self.tottime,mapsize=self.mapsize,
01371 thermalnoise=thermalnoise,t_ground=t_ground)
01372 self.fail(self.failmsg)
01373 except Exception, e:
01374 pos=str(e).find("Parameter verification failed")
01375 msg = self.errmsg % str(e)
01376 self.assertNotEqual(pos,-1,msg=msg)
01377
01378 def testBad_Tsky(self):
01379 """Test bad t_sky"""
01380 thermalnoise = 'tsys-manual'
01381 t_sky = self.badnum
01382 try:
01383 res = simobserve(project=self.project,skymodel=self.inimage,
01384 totaltime=self.tottime,mapsize=self.mapsize,
01385 thermalnoise=thermalnoise,t_sky=t_sky)
01386 self.fail(self.failmsg)
01387 except Exception, e:
01388 pos=str(e).find("Parameter verification failed")
01389 msg = self.errmsg % str(e)
01390 self.assertNotEqual(pos,-1,msg=msg)
01391
01392 def testBad_tau0(self):
01393 """Test bad tau0"""
01394 thermalnoise = 'tsys-manual'
01395 tau0 = self.badnum
01396 try:
01397 res = simobserve(project=self.project,skymodel=self.inimage,
01398 totaltime=self.tottime,mapsize=self.mapsize,
01399 thermalnoise=thermalnoise,tau0=tau0)
01400 self.fail(self.failmsg)
01401 except Exception, e:
01402 pos=str(e).find("Parameter verification failed")
01403 msg = self.errmsg % str(e)
01404 self.assertNotEqual(pos,-1,msg=msg)
01405
01406 def testBad_leakage(self):
01407 """Test bad leakage"""
01408 leakage = self.badnum
01409 try:
01410 res = simobserve(project=self.project,skymodel=self.inimage,
01411 totaltime=self.tottime,mapsize=self.mapsize,
01412 leakage=leakage)
01413 self.fail(self.failmsg)
01414 except Exception, e:
01415 pos=str(e).find("Parameter verification failed")
01416 msg = self.errmsg % str(e)
01417 self.assertNotEqual(pos,-1,msg=msg)
01418
01419 def testBad_graphics(self):
01420 """Test bad graphics selection"""
01421 graphics = self.badname
01422 try:
01423 res = simobserve(project=self.project,skymodel=self.inimage,
01424 totaltime=self.tottime,mapsize=self.mapsize,
01425 graphics=graphics)
01426 self.fail(self.failmsg)
01427 except Exception, e:
01428 pos=str(e).find("Parameter verification failed")
01429 msg = self.errmsg % str(e)
01430 self.assertNotEqual(pos,-1,msg=msg)
01431
01432
01433 def suite():
01434 return [simobserve_sky, simobserve_noise, simobserve_badinputs]
01435
01436