00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034 myscriptvers = '2012-01-15 RI'
00035
00036 import time
00037 import os
00038 import pickle
00039
00040
00041 from os import F_OK
00042
00043 scriptprefix='run_orionmos4sim'
00044 prefix='simtest_orionmos4sim'
00045
00046
00047 os.system('rm -rf '+prefix+'*')
00048
00049
00050
00051
00052 mytmp = '==========================='
00053 mydataset = 'Orion VLA mosaic simulation'
00054
00055 print "========================"+mytmp
00056 print "Simulating and Cleaning "+mydataset
00057 print "========================"+mytmp
00058 print "Script version "+myscriptvers
00059 print "Output will be prefixed with "+prefix
00060
00061
00062 templatems = 'orion_calsplit.ms'
00063
00064 if os.access(templatems,F_OK):
00065
00066 print " Using "+templatems+" found in current directory"
00067 else:
00068 pathname=os.environ.get('CASAPATH').split()[0]
00069
00070 datapath=pathname+'/data/regression/orionmos4sim/'
00071 msname='orion.ms'
00072 mspath=datapath+msname
00073
00074 webms = 'http://casa.nrao.edu/Data/VLA/Orion/'+msname+'.tgz'
00075
00076 altms = '/home/ballista/casa/active/data/regression/ATST3/Orion/'+msname
00077 if os.access(msname,F_OK):
00078
00079 print " Using "+msname+" found in current directory"
00080 elif os.access(mspath,F_OK):
00081 print '--Copy data to local directory--'
00082 print " Using "+mspath
00083 os.system("cp -r "+mspath+" .")
00084 os.system('chmod -R a+wx '+msname)
00085 elif os.access(altms,F_OK):
00086 print '--Copy data to local directory--'
00087 print " Using "+altms
00088 os.system("cp -r "+altms+" .")
00089 os.system('chmod -R a+wx '+msname)
00090 else:
00091 if os.access(msname+'.tgz',F_OK):
00092
00093 print " Using "+msname+".tgz found in current directory"
00094 else:
00095
00096 print '--Retrieve data from '+webms
00097
00098 os.system('curl '+webms+' -f -o '+msname+'.tgz')
00099
00100
00101
00102 print '--Unpacking tarball '
00103 os.system('tar xzf '+msname+'.tgz')
00104 if os.access(msname,F_OK):
00105
00106 print " Using "+msname+" found in current directory"
00107 else:
00108 raise IOError," ERROR: "+msname+" not found"
00109
00110
00111 print '--Split--'
00112 split(vis=msname,outputvis=templatems,datacolumn='corrected')
00113 print " Created "+templatems
00114
00115
00116 myimsize = 800
00117
00118 mycell = "2.0arcsec"
00119 mycen = "J2000 05:35:17.470 -5.23.06.790"
00120 myniter = 400
00121
00122 mymask = ""
00123 myfield = "2~10"
00124 myspw = ""
00125 myftmachine = "mosaic"
00126 mycyclefactor = 1.5
00127 myminpb = 0.2
00128
00129
00130 myflux = 1.0
00131 mynoise = ""
00132
00133
00134
00135 print "Will use template MS "+ templatems
00136 print "Will image with imsize %5i and cell %s " % (myimsize,mycell)
00137 print "Will clean "+str(myniter)+" iterations"
00138 if mycen!="":
00139 print "Will use phasecenter "+mycen
00140 if myfield!="":
00141 print "Will image fields "+myfield
00142 if myspw!="":
00143 print "Will use spw "+myspw
00144 if myftmachine!="":
00145 print "Will mosaic using ftmachine "+myftmachine
00146 if mymask!="":
00147 print "Will use clean mask "+mymask
00148 if mynoise!="":
00149 print "Will add noise level of "+mynoise
00150
00151
00152 params = {}
00153
00154 params['version'] = myscriptvers
00155
00156 params['user'] = {}
00157 params['user']['templatems'] = templatems
00158 params['user']['myimsize'] = myimsize
00159 params['user']['mycell'] = mycell
00160 params['user']['mycen'] = mycen
00161 params['user']['myniter'] = myniter
00162 params['user']['mymask'] = mymask
00163 params['user']['myfield'] = myfield
00164 params['user']['myspw'] = myspw
00165 params['user']['myftmachine'] = myftmachine
00166 params['user']['mycyclefactor'] = mycyclefactor
00167 params['user']['myminpb'] = myminpb
00168 params['user']['mynoise'] = mynoise
00169
00170
00171
00172
00173 phc = me.direction(mycen.split()[0],mycen.split()[1],mycen.split()[2])
00174
00175 myref = int((myimsize+0.5)/2.0)
00176 dcell = qa.convert(mycell,'arcsec')['value']
00177
00178
00179
00180
00181
00182
00183
00184 complist = {}
00185 complist['A'] = {}
00186 complist['A']['rf'] = 'J2000'
00187 complist['A']['RA'] = '05:35:22.024'
00188 complist['A']['Dec'] = '-05.24.14.789'
00189 complist['A']['flux'] = myflux
00190
00191
00192
00193 complist['B'] = {}
00194 complist['B']['rf'] = 'J2000'
00195 complist['B']['RA'] = '05:35:17.47'
00196 complist['B']['Dec'] = '-05.23.06.79'
00197 complist['B']['flux'] = myflux
00198
00199
00200
00201 complist['C'] = {}
00202 complist['C']['rf'] = 'J2000'
00203 complist['C']['RA'] = '05:35:27.52'
00204 complist['C']['Dec'] = '-05.20.37.52'
00205 complist['C']['flux'] = myflux
00206
00207
00208
00209 complist['D'] = {}
00210 complist['D']['rf'] = 'J2000'
00211 complist['D']['RA'] = '05:35:08.746'
00212 complist['D']['Dec'] = '-05.27.19.013'
00213 complist['D']['flux'] = myflux
00214
00215
00216 compnames = ['A','B','C','D']
00217
00218
00219 dbox = 10
00220 for comp in compnames:
00221
00222 mydir = me.direction(complist[comp]['rf'],complist[comp]['RA'],complist[comp]['Dec'])
00223
00224 off_sep = me.separation(phc,mydir)
00225 off_sec = qa.convert(off_sep,'arcsec')['value']
00226 off_pa = me.posangle(phc,mydir)
00227 off_par = qa.convert(off_pa,'rad')['value']
00228
00229 off_x = off_sec*sin(off_par)/dcell
00230 off_y = off_sec*cos(off_par)/dcell
00231 xpix = int( myref + 0.5 - off_x )
00232 ypix = int( myref + 0.5 + off_y )
00233
00234 complist[comp]['xpix'] = xpix
00235 complist[comp]['ypix'] = ypix
00236
00237 blcx = xpix - dbox
00238 blcy = ypix - dbox
00239 trcx = xpix + dbox
00240 trcy = ypix + dbox
00241 mybox = str(blcx)+","+ str(blcy)+","+ str(trcx)+","+ str(trcy)
00242 complist[comp]['box'] = mybox
00243 myclnbox = [blcx,blcy,trcx,trcy]
00244 complist[comp]['clnbox'] = myclnbox
00245
00246
00247
00248
00249 startTime=time.time()
00250 startProc=time.clock()
00251
00252
00253
00254 clfile = prefix + "_sim.cl"
00255 print "Creating componentlist "
00256
00257 for comp in compnames:
00258 mydirection = "J2000 "+complist[comp]['RA']+" "+complist[comp]['Dec']
00259 compflux = complist[comp]['flux']
00260 cl.addcomponent(dir=mydirection, flux=compflux, freq='230.0GHz', spectrumtype='constant')
00261 print " Added comp "+comp+" "+str(compflux)+" Jy at "+mydirection+" ("+str(complist[comp]['xpix'])+","+str(complist[comp]['ypix'])+")"
00262
00263 cl.rename(clfile)
00264 mycl = cl.torecord()
00265 cl.close()
00266
00267 print "Created componentlist "+clfile
00268
00269
00270 msfile = prefix + "_sim.ms"
00271
00272 print "Copying "+templatems+" to "+msfile
00273
00274 os.system('cp -rf '+templatems+' '+msfile)
00275
00276 sm.openfromms(msfile)
00277 sm.setvp(dovp=T, usedefaultvp=T, dosquint=F)
00278
00279
00280 sm.predict(complist=clfile)
00281
00282
00283 if mynoise!="":
00284 print 'Adding noise '+mynoise
00285 sm.setvp(dovp=F)
00286 sm.setnoise(mode='simplenoise',simplenoise=mynoise)
00287 sm.corrupt()
00288
00289 sm.close()
00290
00291 print "Completed simulating MS "+msfile
00292
00293 listobs(msfile)
00294
00295
00296
00297
00298
00299
00300
00301
00302
00303
00304
00305
00306
00307
00308
00309
00310
00311
00312
00313
00314
00315
00316
00317
00318
00319
00320
00321
00322
00323
00324
00325
00326
00327
00328
00329 sim1time=time.time()
00330
00331
00332
00333
00334
00335
00336
00337
00338
00339
00340
00341
00342
00343
00344 print "Preparing to image data"
00345
00346
00347 clnbox = []
00348 for comp in compnames:
00349 clnbox.append(complist[comp]['clnbox'])
00350
00351 print ""
00352 print "Will be cleaning in box(es) "+str(clnbox)
00353
00354
00355 default("clean")
00356 vis = msfile
00357 field = myfield
00358 spw = myspw
00359 selectdata = False
00360 timerange = ""
00361 uvrange = ""
00362 antenna = ""
00363 scan = ""
00364 mode = "mfs"
00365 gain = 0.1
00366 threshold = "0.0mJy"
00367 psfmode = "clark"
00368 imagermode = "mosaic"
00369 ftmachine = myftmachine
00370 mosweight = False
00371 scaletype = "SAULT"
00372 flatnoise = False
00373 multiscale = []
00374 negcomponent = -1
00375 interactive = F
00376 mask = []
00377 nchan = 1
00378 start = 0
00379 width = 1
00380 phasecenter = mycen
00381 imsize = myimsize
00382 cell = mycell
00383 restfreq = ""
00384 stokes = "I"
00385 weighting = "natural"
00386 robust = 0.0
00387 uvtaper = False
00388 outertaper = []
00389 innertaper = []
00390 modelimage = ""
00391 restoringbeam = ['']
00392 minpb = myminpb
00393 noise = "1.0Jy"
00394 npixels = 0
00395 npercycle = 100
00396 cyclefactor = mycyclefactor
00397 cyclespeedup = -1
00398
00399
00400
00401 print "Will be mosaicing using phasecenter "+phasecenter
00402
00403 print "First make dirty image"
00404 pbcor = T
00405 dirtimag = prefix + ".dirty"
00406 imagename = dirtimag
00407 niter = 0
00408 clean()
00409 print "Output images are called "+imagename
00410
00411 dirty1time=time.time()
00412
00413 if mymask == "":
00414 mask = clnbox
00415 print "Will be cleaning using box(es) "+str(mask)
00416 else:
00417 mask = mymask
00418 print "Will be cleaning using mask "+mask
00419
00420
00421 contimag = prefix + ".clean"
00422 pbcor = F
00423 imagename = contimag
00424 niter = myniter
00425 print "Now actually clean the image using niter = "+str(niter)
00426 clean()
00427 print "Output images are called "+imagename
00428
00429 clean1time=time.time()
00430
00431
00432
00433
00434
00435
00436
00437
00438
00439
00440
00441
00442
00443
00444 dirimage = dirtimag+'.image'
00445 clnimage = contimag+'.image'
00446 fluximage = contimag+'.flux'
00447 modimage = contimag+'.model'
00448 resimage = contimag+'.residual'
00449 covimage = contimag+'.flux.pbcoverage'
00450
00451
00452
00453
00454 pbmodimage = contimag+'.pbcormod'
00455 pbcorimage = contimag+'.pbcorimg'
00456
00457
00458
00459
00460
00461
00462
00463
00464
00465
00466 if myflux!=0.0:
00467 immath(outfile=pbmodimage,
00468 mode='evalexpr',
00469 imagename=[modimage,fluximage],
00470 expr="IM0[IM1!=0.0]/IM1")
00471
00472 immath(outfile=pbcorimage,
00473 mode='evalexpr',
00474 imagename=[clnimage,fluximage],
00475 expr="IM0[IM1!=0.0]/IM1")
00476
00477
00478
00479
00480
00481
00482
00483
00484 doffx = 75
00485 doffy = 65
00486 doffbox = 30
00487 xpix = complist[compnames[0]]['xpix']
00488 ypix = complist[compnames[0]]['ypix']
00489 blcx = xpix + doffx - doffbox
00490 blcy = ypix + doffy - doffbox
00491 trcx = xpix + doffx + doffbox
00492 trcy = ypix + doffy + doffbox
00493 offbox = str(blcx)+","+ str(blcy)+","+ str(trcx)+","+ str(trcy)
00494 print "Off-source stats in box "+offbox
00495
00496
00497 dirstats = imstat(imagename=dirimage,box = '')
00498 dirtyimg_max = dirstats['max'][0]
00499 dirtyimg_rms = dirstats['sigma'][0]
00500
00501 diroffstats = imstat(imagename=dirimage,box=offbox)
00502 dirtyoff_rms = diroffstats['sigma'][0]
00503
00504
00505 allstats = imstat(imagename=pbcorimage,box = '')
00506 imageall_max = allstats['max'][0]
00507 imageall_rms = allstats['sigma'][0]
00508
00509 offstats = imstat(imagename=pbcorimage,box=offbox)
00510 imageoff_rms = offstats['sigma'][0]
00511
00512
00513 resstats = imstat(imagename=resimage,box = '')
00514 residall_max = resstats['max'][0]
00515 residall_rms = resstats['sigma'][0]
00516
00517 resoffstats = imstat(imagename=resimage,box=offbox)
00518 residoff_rms = resoffstats['sigma'][0]
00519
00520 if myflux!=0.0:
00521
00522 modstats = imstat(imagename=modimage,box = '')
00523 modelall_flux = modstats['sum'][0]
00524
00525 pbmodstats = imstat(imagename=pbmodimage,box = '')
00526 pbmodelall_flux = pbmodstats['sum'][0]
00527
00528
00529 fluxstats = imstat(imagename=fluximage,box = '')
00530 fluximg_sum = fluxstats['sum'][0]
00531 fluximg_npt = fluxstats['npts'][0]
00532
00533 pixsec = qa.convert(qa.quantity(mycell),'arcsec')
00534 pixarea = qa.quantity(pixsec)['value']**2
00535
00536 stats1time=time.time()
00537
00538
00539
00540
00541
00542
00543
00544
00545
00546
00547
00548
00549
00550
00551
00552
00553
00554
00555
00556
00557
00558
00559
00560
00561
00562 totalflux = 0.0
00563
00564 for comp in compnames:
00565 compflux = complist[comp]['flux']
00566 totalflux = totalflux + compflux
00567 mybox = complist[comp]['box']
00568 print "Component "+comp+" stats in box "+mybox
00569
00570 xstat_dirimg = imstat(imagename=dirimage,box=mybox)
00571
00572 xstat_img = imstat(imagename=pbcorimage,box=mybox)
00573 if myflux!=0.0:
00574
00575 xstat_mod = imstat(imagename=modimage,box=mybox)
00576 xstat_pbmod = imstat(imagename=pbmodimage,box=mybox)
00577
00578 xstat_res = imstat(imagename=resimage,box=mybox)
00579
00580 complist[comp]['dirtystat'] = xstat_dirimg
00581 complist[comp]['imstat'] = xstat_img
00582 if myflux!=0.0:
00583 complist[comp]['modstat'] = xstat_mod
00584 complist[comp]['pbmodstat'] = xstat_pbmod
00585 complist[comp]['resstat'] = xstat_res
00586
00587
00588
00589
00590 endProc=time.clock()
00591 endTime=time.time()
00592
00593 import datetime
00594 datestring=datetime.datetime.isoformat(datetime.datetime.today())
00595
00596 myvers = casalog.version()
00597 myuser = os.getenv('USER')
00598 myhost = str( os.getenv('HOST') )
00599 mycwd = os.getcwd()
00600 myos = os.uname()
00601 mypath = os.environ.get('CASAPATH')
00602
00603 walltime = (endTime - startTime)
00604 cputime = (endProc - startProc)
00605
00606
00607 outfile = 'out.'+prefix+'.'+datestring+'.log'
00608 logfile = open(outfile,'w')
00609
00610 def lprint(msg, lfile):
00611 """
00612 Prints msg to both stdout and lfile.
00613 """
00614 print msg
00615 print >> logfile, msg
00616
00617 lprint('Running '+myvers+' on host '+myhost, logfile)
00618 lprint(' at '+datestring, logfile)
00619 lprint(' using '+mypath, logfile)
00620
00621
00622
00623
00624 lprint('', logfile)
00625 lprint('---', logfile)
00626 lprint('Script version: '+params['version'], logfile)
00627 lprint('User set parameters used in execution:', logfile)
00628 lprint('---', logfile)
00629
00630 for keys in params['user'].keys():
00631 lprint(' %s = %s ' % ( keys, params['user'][keys] ), logfile)
00632
00633 lprint('', logfile)
00634
00635
00636
00637
00638
00639 new_regression = {}
00640
00641 new_regression['date'] = datestring
00642 new_regression['version'] = myvers
00643 new_regression['user'] = myuser
00644 new_regression['host'] = myhost
00645 new_regression['cwd'] = mycwd
00646 new_regression['os'] = myos
00647 new_regression['aipspath'] = mypath
00648
00649 new_regression['dataset'] = mydataset
00650
00651
00652 new_regression['params'] = params
00653
00654
00655 results = {}
00656
00657
00658 op = 'divf'
00659 tol = 0.01
00660 results['clean_dirtyimg_max'] = {}
00661 results['clean_dirtyimg_max']['name'] = 'Dirty image (all) max'
00662 results['clean_dirtyimg_max']['value'] = dirtyimg_max
00663 results['clean_dirtyimg_max']['op'] = op
00664 results['clean_dirtyimg_max']['tol'] = tol
00665
00666 results['clean_dirtyimg_rms'] = {}
00667 results['clean_dirtyimg_rms']['name'] = 'Dirty image (all) rms'
00668 results['clean_dirtyimg_rms']['value'] = dirtyimg_rms
00669 results['clean_dirtyimg_rms']['op'] = op
00670 results['clean_dirtyimg_rms']['tol'] = tol
00671
00672 results['clean_dirtyoff_rms'] = {}
00673 results['clean_dirtyoff_rms']['name'] = 'Dirty image (off-src) rms'
00674 results['clean_dirtyoff_rms']['value'] = dirtyoff_rms
00675 results['clean_dirtyoff_rms']['op'] = op
00676 results['clean_dirtyoff_rms']['tol'] = tol
00677
00678 results['clean_imageall_max'] = {}
00679 results['clean_imageall_max']['name'] = 'Clean image (all) max'
00680 results['clean_imageall_max']['value'] = imageall_max
00681 results['clean_imageall_max']['op'] = op
00682 results['clean_imageall_max']['tol'] = tol
00683
00684 results['clean_imageall_rms'] = {}
00685 results['clean_imageall_rms']['name'] = 'Clean image (all) rms'
00686 results['clean_imageall_rms']['value'] = imageall_rms
00687 results['clean_imageall_rms']['op'] = op
00688 results['clean_imageall_rms']['tol'] = tol
00689
00690 results['clean_imageoff_rms'] = {}
00691 results['clean_imageoff_rms']['name'] = 'Clean image (off-src) rms'
00692 results['clean_imageoff_rms']['value'] = imageoff_rms
00693 results['clean_imageoff_rms']['op'] = op
00694 results['clean_imageoff_rms']['tol'] = tol
00695
00696 results['clean_residall_max'] = {}
00697 results['clean_residall_max']['name'] = 'Residual image (all) max'
00698 results['clean_residall_max']['value'] = residall_max
00699 results['clean_residall_max']['op'] = op
00700 results['clean_residall_max']['tol'] = tol
00701
00702 results['clean_residall_rms'] = {}
00703 results['clean_residall_rms']['name'] = 'Residual image (all) rms'
00704 results['clean_residall_rms']['value'] = residall_rms
00705 results['clean_residall_rms']['op'] = op
00706 results['clean_residall_rms']['tol'] = tol
00707
00708 results['clean_residoff_rms'] = {}
00709 results['clean_residoff_rms']['name'] = 'Residual image (off-src) rms'
00710 results['clean_residoff_rms']['value'] = residoff_rms
00711 results['clean_residoff_rms']['op'] = op
00712 results['clean_residoff_rms']['tol'] = tol
00713
00714 if myflux!=0.0:
00715 results['clean_modelall_flux'] = {}
00716 results['clean_modelall_flux']['name'] = 'Model image (all) flux'
00717 results['clean_modelall_flux']['value'] = modelall_flux
00718 results['clean_modelall_flux']['op'] = op
00719 results['clean_modelall_flux']['tol'] = tol
00720
00721 results['clean_pbmodelall_flux'] = {}
00722 results['clean_pbmodelall_flux']['name'] = 'PBCOR Model image (all) flux'
00723 results['clean_pbmodelall_flux']['value'] = pbmodelall_flux
00724 results['clean_pbmodelall_flux']['op'] = op
00725 results['clean_pbmodelall_flux']['tol'] = tol
00726
00727 results['sim_comp_flux'] = {}
00728 results['sim_comp_flux']['name'] = 'Sim Model total flux'
00729 results['sim_comp_flux']['value'] = totalflux
00730 results['sim_comp_flux']['op'] = op
00731 results['sim_comp_flux']['tol'] = tol
00732
00733 results['flux_area'] = {}
00734 results['flux_area']['name'] = 'Eff. mosaic area (sq.arcmin.)'
00735 results['flux_area']['value'] = fluximg_sum*pixarea/3600.0
00736 results['flux_area']['op'] = op
00737 results['flux_area']['tol'] = tol
00738
00739
00740 new_regression['results'] = results
00741
00742
00743 new_regression['compnames'] = compnames
00744
00745 new_regression['compstats'] = complist
00746
00747 compresults = {}
00748 for comp in compnames:
00749 compresults[comp] = {}
00750
00751 xstat_dirimg = complist[comp]['dirtystat']
00752 xstat_img = complist[comp]['imstat']
00753 if myflux!=0.0:
00754 xstat_mod = complist[comp]['modstat']
00755 xstat_pbmod = complist[comp]['pbmodstat']
00756 xstat_res = complist[comp]['resstat']
00757
00758 compresults[comp]['box'] = complist[comp]['box']
00759
00760 op = 'divf'
00761 tol = 0.08
00762 compresults[comp]['dirty_image_max'] = {}
00763 compresults[comp]['dirty_image_max']['name'] = 'Dirty image max'
00764 compresults[comp]['dirty_image_max']['value'] = xstat_dirimg['max'][0]
00765 compresults[comp]['dirty_image_max']['op'] = op
00766 compresults[comp]['dirty_image_max']['tol'] = tol
00767
00768 op = 'diff'
00769 tol = 0.5
00770 compresults[comp]['dirty_image_maxposx'] = {}
00771 compresults[comp]['dirty_image_maxposx']['name'] = 'Dirty image max pos x'
00772 compresults[comp]['dirty_image_maxposx']['value'] = xstat_dirimg['maxpos'][0]
00773 compresults[comp]['dirty_image_maxposx']['op'] = op
00774 compresults[comp]['dirty_image_maxposx']['tol'] = tol
00775
00776 compresults[comp]['dirty_image_maxposy'] = {}
00777 compresults[comp]['dirty_image_maxposy']['name'] = 'Dirty image max pos y'
00778 compresults[comp]['dirty_image_maxposy']['value'] = xstat_dirimg['maxpos'][1]
00779 compresults[comp]['dirty_image_maxposy']['op'] = op
00780 compresults[comp]['dirty_image_maxposy']['tol'] = tol
00781
00782 op = 'divf'
00783 tol = 0.08
00784 compresults[comp]['clean_image_max'] = {}
00785 compresults[comp]['clean_image_max']['name'] = 'Restored image max'
00786 compresults[comp]['clean_image_max']['value'] = xstat_img['max'][0]
00787 compresults[comp]['clean_image_max']['op'] = op
00788 compresults[comp]['clean_image_max']['tol'] = tol
00789
00790 op = 'diff'
00791 tol = 0.5
00792 compresults[comp]['clean_image_maxposx'] = {}
00793 compresults[comp]['clean_image_maxposx']['name'] = 'Restored image max pos x'
00794 compresults[comp]['clean_image_maxposx']['value'] = xstat_img['maxpos'][0]
00795 compresults[comp]['clean_image_maxposx']['op'] = op
00796 compresults[comp]['clean_image_maxposx']['tol'] = tol
00797
00798 compresults[comp]['clean_image_maxposy'] = {}
00799 compresults[comp]['clean_image_maxposy']['name'] = 'Restored image max pos y'
00800 compresults[comp]['clean_image_maxposy']['value'] = xstat_img['maxpos'][1]
00801 compresults[comp]['clean_image_maxposy']['op'] = op
00802 compresults[comp]['clean_image_maxposy']['tol'] = tol
00803
00804 op = 'divf'
00805 tol = 0.08
00806 compresults[comp]['residual_image_max'] = {}
00807 compresults[comp]['residual_image_max']['name'] = 'Residual image max'
00808 compresults[comp]['residual_image_max']['value'] = xstat_res['max'][0]
00809 compresults[comp]['residual_image_max']['op'] = op
00810 compresults[comp]['residual_image_max']['tol'] = tol
00811
00812 compresults[comp]['residual_image_rms'] = {}
00813 compresults[comp]['residual_image_rms']['name'] = 'Residual image rms'
00814 compresults[comp]['residual_image_rms']['value'] = xstat_res['sigma'][0]
00815 compresults[comp]['residual_image_rms']['op'] = op
00816 compresults[comp]['residual_image_rms']['tol'] = tol
00817
00818 if myflux!=0.0:
00819 compresults[comp]['model_image_sum'] = {}
00820 compresults[comp]['model_image_sum']['name'] = 'Model image flux'
00821 compresults[comp]['model_image_sum']['value'] = xstat_mod['sum'][0]
00822 compresults[comp]['model_image_sum']['op'] = op
00823 compresults[comp]['model_image_sum']['tol'] = tol
00824
00825 compresults[comp]['pbmodel_image_sum'] = {}
00826 compresults[comp]['pbmodel_image_sum']['name'] = 'PBCOR Model image flux'
00827 compresults[comp]['pbmodel_image_sum']['value'] = xstat_pbmod['sum'][0]
00828 compresults[comp]['pbmodel_image_sum']['op'] = op
00829 compresults[comp]['pbmodel_image_sum']['tol'] = tol
00830
00831 compresults[comp]['sim_comp_flux'] = {}
00832 compresults[comp]['sim_comp_flux']['name'] = 'Simulated comp flux'
00833 compresults[comp]['sim_comp_flux']['value'] = complist[comp]['flux']
00834 compresults[comp]['sim_comp_flux']['op'] = op
00835 compresults[comp]['sim_comp_flux']['tol'] = tol
00836
00837 op = 'diff'
00838 tol = 0.5
00839 compresults[comp]['sim_comp_posx'] = {}
00840 compresults[comp]['sim_comp_posx']['name'] = 'Simulated comp pos x'
00841 compresults[comp]['sim_comp_posx']['value'] = complist[comp]['xpix']
00842 compresults[comp]['sim_comp_posx']['op'] = op
00843 compresults[comp]['sim_comp_posx']['tol'] = tol
00844
00845 compresults[comp]['sim_comp_posy'] = {}
00846 compresults[comp]['sim_comp_posy']['name'] = 'Simulated comp pos y'
00847 compresults[comp]['sim_comp_posy']['value'] = complist[comp]['ypix']
00848 compresults[comp]['sim_comp_posy']['op'] = op
00849 compresults[comp]['sim_comp_posy']['tol'] = tol
00850
00851 new_regression['compresults'] = compresults
00852
00853
00854 datasize_raw = 110.0
00855 datasize_ms = 110.0
00856 new_regression['datasize'] = {}
00857 new_regression['datasize']['raw'] = datasize_raw
00858 new_regression['datasize']['ms'] = datasize_ms
00859
00860
00861 new_regression['timing'] = {}
00862
00863 total = {}
00864 total['wall'] = (endTime - startTime)
00865 total['cpu'] = (endProc - startProc)
00866 total['rate_raw'] = (datasize_raw/(endTime - startTime))
00867 total['rate_ms'] = (datasize_ms/(endTime - startTime))
00868
00869 new_regression['timing']['total'] = total
00870
00871 nstages = 4
00872 new_regression['timing']['nstages'] = nstages
00873
00874 stages = {}
00875 stages[0] = ['simulate',(sim1time-startTime)]
00876 stages[1] = ['invert',(dirty1time-sim1time)]
00877 stages[2] = ['clean',(clean1time-dirty1time)]
00878 stages[3] = ['stats',(endTime-clean1time)]
00879
00880 new_regression['timing']['stages'] = stages
00881
00882
00883
00884
00885
00886
00887
00888 regression = {}
00889 regressfile = scriptprefix + '.pickle'
00890 prev_results = {}
00891
00892 repodir=os.getenv("CASAPATH")
00893 repodir=repodir.split()[0]
00894 regressdirfile= repodir+ "/data/regression/orionmos4sim/"+scriptprefix + '.pickle'
00895
00896
00897
00898
00899 webfile = 'http://casa.nrao.edu/Release0/Doc/Scripts/'+scriptprefix+'.pickle'
00900
00901 if os.access(regressfile,F_OK):
00902
00903 print " Found "+regressfile+" in current directory"
00904 else:
00905 if os.access(regressdirfile,F_OK):
00906
00907 print " Found "+regressdirfile+" in your local data repo"
00908 regressfile=regressdirfile
00909 else:
00910 print "Trying web download of "+webfile
00911 os.system('curl '+webfile+' -f -o '+regressfile)
00912
00913
00914
00915
00916 try:
00917 fr = open(regressfile,'r')
00918 except:
00919 print "No previous regression results file "+regressfile
00920 regression['exist'] = False
00921 else:
00922 u = pickle.Unpickler(fr)
00923 regression = u.load()
00924 fr.close()
00925 print "Regression results filled from "+regressfile
00926 print "Regression from version "+regression['version']+" on "+regression['date']
00927 regression['exist'] = True
00928
00929 prev_results = regression['results']
00930
00931 prev_compresults = regression['compresults']
00932
00933
00934
00935
00936 if myflux!=0.0:
00937 resultlist = ['clean_dirtyimg_max','clean_dirtyimg_rms',
00938 'clean_imageall_max','clean_imageall_rms','clean_imageoff_rms',
00939 'clean_residall_max','clean_residall_rms','clean_residoff_rms',
00940 'clean_modelall_flux','clean_pbmodelall_flux',
00941 'sim_comp_flux','flux_area']
00942
00943 compreslist = ['dirty_image_max','dirty_image_maxposx','dirty_image_maxposy',
00944 'clean_image_max','clean_image_maxposx','clean_image_maxposy',
00945 'residual_image_max','residual_image_rms',
00946 'model_image_sum','pbmodel_image_sum',
00947 'sim_comp_flux','sim_comp_posx','sim_comp_posy']
00948 else:
00949 resultlist = ['clean_dirtyimg_max','clean_dirtyimg_rms',
00950 'clean_imageall_max','clean_imageall_rms','clean_imageoff_rms',
00951 'clean_residall_max','clean_residall_rms','clean_residoff_rms',
00952 'flux_area']
00953
00954 compreslist = ['dirty_image_max','dirty_image_maxposx','dirty_image_maxposy',
00955 'clean_image_max','clean_image_maxposx','clean_image_maxposy',
00956 'residual_image_max','residual_image_rms']
00957
00958 testresults = {}
00959 testcompresults = {}
00960
00961 if regression['exist']:
00962 lprint('---', logfile)
00963 lprint('Regression versus previous values:', logfile)
00964 lprint('---', logfile)
00965 lprint(" Regression results filled from "+regressfile, logfile)
00966 lprint(" Regression from version " + regression['version'] + " on " +
00967 regression['date'], logfile)
00968 lprint(" Regression platform " + regression['host'] + " using " +
00969 regression['aipspath'], logfile)
00970 final_status = 'Passed'
00971 else:
00972
00973 lprint('---', logfile)
00974 lprint('Results of imaging:', logfile)
00975 lprint('---', logfile)
00976 lprint(" No previous regression file", logfile)
00977
00978
00979 for comp in compnames:
00980 lprint("", logfile)
00981 lprint(" Component " + comp + " :", logfile)
00982
00983 if regression['exist']:
00984
00985 testcompresults[comp] = {}
00986
00987 for keys in compreslist:
00988 res = compresults[comp][keys]
00989 new_val = res['value']
00990
00991 if regression['exist']:
00992 testcompresults[comp][keys] = {}
00993 testres = {}
00994 testres['value'] = new_val
00995 testres['op'] = res['op']
00996 testres['tol'] = res['tol']
00997
00998 if prev_compresults.has_key(comp):
00999
01000 if prev_compresults[comp].has_key(keys):
01001
01002 prev = prev_compresults[comp][keys]
01003 prev_val = prev['value']
01004 if res['op'] == 'divf':
01005 new_diff = (new_val - prev_val)/prev_val
01006 else:
01007 new_diff = new_val - prev_val
01008
01009 if abs(new_diff) > res['tol']:
01010 new_status = 'Failed'
01011 else:
01012 new_status = 'Passed'
01013
01014 testres['prev'] = prev_val
01015 testres['diff'] = new_diff
01016 testres['status'] = new_status
01017 testres['test'] = 'Last'
01018
01019 else:
01020
01021 testres['prev'] = 0.0
01022 testres['diff'] = 1.0
01023 testres['status'] = 'Missed'
01024 testres['test'] = 'none'
01025
01026 else:
01027
01028 testres['prev'] = 0.0
01029 testres['diff'] = 1.0
01030 testres['status'] = 'Unknown'
01031 testres['test'] = 'none'
01032
01033
01034 testcompresults[comp][keys] = testres
01035
01036 if testres['status']=='Failed':
01037 final_status = 'Failed'
01038
01039
01040 lprint('--%30s : %12.6f was %12.6f %4s %12.6f (%6s) %s ' % (res['name'],
01041 testres['value'],
01042 testres['prev'],
01043 testres['op'],
01044 testres['diff'],
01045 testres['status'],
01046 testres['test']),
01047 logfile)
01048 else:
01049
01050 lprint('--%30s : %12.6f ' % ( res['name'], res['value'] ), logfile)
01051
01052
01053 lprint("", logfile)
01054 lprint(" Whole image :", logfile)
01055 for keys in resultlist:
01056 res = results[keys]
01057 new_val = res['value']
01058 if regression['exist']:
01059
01060 testresults[keys] = {}
01061 testres = {}
01062 testres['value'] = new_val
01063 testres['op'] = res['op']
01064 testres['tol'] = res['tol']
01065
01066
01067 if prev_results.has_key(keys):
01068
01069 prev = prev_results[keys]
01070 prev_val = prev['value']
01071 if res['op'] == 'divf':
01072 new_diff = (new_val - prev_val)/prev_val
01073 else:
01074 new_diff = new_val - prev_val
01075
01076 if abs(new_diff)>res['tol']:
01077 new_status = 'Failed'
01078 else:
01079 new_status = 'Passed'
01080
01081 testres['prev'] = prev_val
01082 testres['diff'] = new_diff
01083 testres['status'] = new_status
01084 testres['test'] = 'Last'
01085 else:
01086
01087 testres['prev'] = 0.0
01088 testres['diff'] = 1.0
01089 testres['status'] = 'Missed'
01090 testres['test'] = 'none'
01091
01092
01093 testresults[keys] = testres
01094
01095
01096 lprint('--%30s : %12.6f was %12.6f %4s %12.6f (%6s) %s ' % (res['name'],
01097 testres['value'],
01098 testres['prev'],
01099 testres['op'],
01100 testres['diff'],
01101 testres['status'],
01102 testres['test'] ),
01103 logfile)
01104 if testres['status']=='Failed':
01105 final_status = 'Failed'
01106
01107 else:
01108
01109 lprint('--%30s : %12.6f ' % ( res['name'], res['value'] ), logfile)
01110
01111
01112
01113 if regression['exist']:
01114
01115 if (final_status == 'Passed'):
01116 regstate=True
01117 print >>logfile,'---'
01118 lprint('Passed Regression test for ' + mydataset, logfile)
01119 print >>logfile,'---'
01120 print ''
01121 print 'Regression PASSED'
01122 print ''
01123 else:
01124 regstate=False
01125 lprint('----FAILED Regression test for ' + mydataset, logfile)
01126
01127
01128 new_regression['testresults'] = testresults
01129 new_regression['testcompresults'] = testcompresults
01130 else:
01131 regstate=False
01132 lprint('----Unable to complete regression test for '+ mydataset, logfile)
01133
01134
01135
01136
01137
01138 lprint('', logfile)
01139 lprint('********* Benchmarking *************************', logfile)
01140 lprint('* *', logfile)
01141 lprint('Total wall clock time was: %10.3f ' % total['wall'], logfile)
01142 lprint('Total CPU time was: %10.3f ' % total['cpu'], logfile)
01143 lprint('Raw processing rate MB/s was: %8.1f ' % total['rate_raw'], logfile)
01144 lprint('MS processing rate MB/s was: %8.1f ' % total['rate_ms'], logfile)
01145 lprint('', logfile)
01146 lprint('* Breakdown: *', logfile)
01147
01148 for i in range(nstages):
01149 lprint('* %16s * time was: %10.3f ' % tuple(stages[i]), logfile)
01150
01151 lprint('************************************************', logfile)
01152 if regression['exist']:
01153 lprint('Previous wall time was %10.3f sec on %s ' %
01154 (regression['timing']['total']['wall'], regression['host'] ), logfile)
01155 lprint('Previous CPU time was %10.3f sec on %s ' %
01156 (regression['timing']['total']['cpu'], regression['host'] ), logfile)
01157
01158
01159
01160
01161
01162
01163 pickfile = 'out.'+prefix + '.regression.'+datestring+'.pickle'
01164 f = open(pickfile,'w')
01165 p = pickle.Pickler(f)
01166 p.dump(new_regression)
01167 f.close()
01168
01169 print ""
01170 print "Regression result dictionary saved in "+pickfile
01171 print ""
01172 print "Use Pickle to retrieve these"
01173 print ""
01174
01175
01176
01177
01178
01179
01180
01181
01182 lprint("", logfile)
01183 lprint("Done with " + mydataset, logfile)
01184
01185 logfile.close()
01186 print "Results are in "+outfile
01187
01188
01189