casa  $Rev:20696$
 All Classes Namespaces Files Functions Variables
ppdisk2_regression.py
Go to the documentation of this file.
00001 ########################################
00002 # Regression Script for simdata of  #
00003 #        a protoplanetary disk         #
00004 
00005 import os, time
00006 
00007 # configs are in the repository
00008 l=locals() 
00009 if not l.has_key("repodir"): 
00010     repodir=os.getenv("CASAPATH").split(' ')[0]
00011 
00012 startTime = time.time()
00013 startProc = time.clock()
00014 
00015 print '--Running simdata of input672GHz_50pc.image--'
00016 
00017 my_project="psim2"
00018 my_modelimage="diskmodel.im2"
00019 
00020 # Clear out results from previous runs.
00021 os.system('rm -rf '+my_project+'.* '+my_modelimage)
00022 tb.clearlocks()
00023 
00024 print casa['build']
00025 print 'I think the data repository is at '+repodir
00026 #importfits(fitsimage=repodir+"/data/alma/simmos/input50pc_672GHz.fits",imagename=my_modelimage)
00027 
00028 default("simanalyze")
00029 default("simobserve")
00030 project=my_project
00031 skymodel=my_modelimage
00032 skymodel=repodir+"/data/regression/simdata/input50pc_672GHz.fits"
00033 direction="J2000 18h00m00.031s -22d59m59.6s"
00034 
00035 complist="star672GHz.cl"
00036 if os.path.exists(complist):
00037     shutil.rmtree(complist)
00038 cl.done()
00039 cl.addcomponent(dir=direction,flux=0.0003,freq="672GHz")
00040 cl.rename("star672GHz.cl")
00041 cl.done()
00042 
00043 setpointings=True
00044 mapsize="0.76arcsec"
00045 pointingspacing="0.5arcsec"
00046 integration="10s"
00047 
00048 obsmode="int"
00049 antennalist=repodir+"/data/alma/simmos/alma.out20.cfg"
00050 refdate="2012/06/21/03:25:00"
00051 totaltime="1200s"
00052 
00053 thermalnoise="tsys-atm"
00054 #tau0=0.
00055 #t_ground=0.
00056 #t_sky=0.
00057 user_pwv=0.5
00058 
00059 maptype="ALMA2012"
00060 
00061 verbose=True
00062 if not l.has_key('interactive'): interactive=False
00063 if interactive:
00064     graphics="both"
00065 else:
00066     graphics="file"
00067 
00068 go()
00069 
00070 
00071 taskname="simanalyze"
00072 
00073 image=True
00074 cleanmode="clark"
00075 cell=""
00076 niter=1000
00077 threshold="1e-7Jy"
00078 imsize=[192, 192]
00079 stokes="I"
00080 weighting="natural"
00081 
00082 analyze=True
00083 
00084 go()
00085 
00086 
00087 
00088 endTime = time.time()
00089 endProc = time.clock()
00090 
00091 # Regression
00092 
00093 test_name_ppd = """simdata observation of Wolf & D'Angelo's protoplanetary disk"""
00094 
00095 ppdso_im=ia.open(project+"/"+project + '.alma.out20.noisy.image')
00096 ppdso_stats=ia.statistics()
00097 ia.close()
00098 
00099 refstats = { 'flux': 0.0359,
00100              'max': 6.1e-04,
00101              'min': -1.6e-04, 
00102              'rms': 1.9e-04,
00103              'sigma': 1.4e-04 }
00104 
00105 reftol   = {'flux':  0.05,
00106             'max':   0.1,
00107             'min':   0.1,
00108             'rms':   0.1,
00109             'sigma': 0.1}
00110 
00111 import datetime
00112 datestring = datetime.datetime.isoformat(datetime.datetime.today())
00113 outfile    = project + "/" + project + '.' + datestring + '.log'
00114 logfile    = open(outfile, 'w')
00115 
00116 print 'Writing regression output to ' + outfile + "\n"
00117 
00118 loghdr = """
00119 ********** Simulation Summary *********
00120 
00121 The disk input image is a simulation done by Wolf and D'Angelo, converted from
00122 900 GHz to 672 GHz
00123 
00124 ********** Regression *****************
00125 """
00126 
00127 #A minimally bright star has been included as a clean component.
00128 
00129 
00130 print >> logfile, loghdr
00131 print >> logfile,casa['build']
00132 
00133 regstate = True
00134 rskes = refstats.keys()
00135 rskes.sort()
00136 for ke in rskes:
00137     adiff=abs(ppdso_stats[ke][0] - refstats[ke])/abs(refstats[ke])
00138     if adiff < reftol[ke]:
00139         print >> logfile, "* Passed %-5s test, got % -11.5g , expected % -11.5g." % (ke, ppdso_stats[ke][0], refstats[ke])
00140     else:
00141         print >> logfile, "* FAILED %-5s test, got % -11.5g instead of % -11.5g." % (ke, ppdso_stats[ke][0], refstats[ke])
00142         regstate = False
00143 
00144 print >> logfile,'---'
00145 if regstate:
00146     print >> logfile, 'Passed',
00147     print ''
00148     print 'Regression PASSED'
00149     print ''
00150 else:
00151     print >> logfile, 'FAILED',
00152     print ''
00153     print 'Regression FAILED'
00154     print ''
00155 
00156 print >> logfile, 'regression test for simdata of protoplanetary disk.'
00157 print >>logfile,'---'
00158 print >>logfile,'*********************************'
00159     
00160 print >>logfile,''
00161 print >>logfile,'********** Benchmarking **************'
00162 print >>logfile,''
00163 print >>logfile,'Total wall clock time was: %8.3f s.' % (endTime - startTime)
00164 print >>logfile,'Total CPU        time was: %8.3f s.' % (endProc - startProc)
00165 print >>logfile,'Wall processing  rate was: %8.3f MB/s.' % (17896.0 /
00166                                                          (endTime - startTime))
00167 
00168 ### Get last modification time of .ms.
00169 ## msfstat = os.stat('almasimmos_regression.ms')
00170 ## print >>logfile,'* Breakdown:                           *'
00171 ## print >>logfile,'*  generating visibilities took %8.3fs,' % (msfstat[8] - startTime)
00172 ## print >>logfile,'*  %s deconvolution with %d iterations took %8.3fs.' % (alg,
00173 ##                                                                         niter,
00174 ##                                                                         endTime - msfstat[8])
00175 print >>logfile,'*************************************'
00176     
00177 logfile.close()
00178                                                     
00179 print '--Finished simdata of input672GHz_50pc.image regression--'