casa  $Rev:20696$
 All Classes Namespaces Files Functions Variables
m51_tpsim_regression.py
Go to the documentation of this file.
00001 import os, time
00002 
00003 modelname = "m51ha.model"
00004 if os.path.exists(modelname):
00005     shutil.rmtree(modelname)
00006 
00007 projname = "m51sd_co32"
00008 
00009 startTime = time.time()
00010 startProc = time.clock()
00011 
00012 print '--Running sim_observe of M51 (total power) --'
00013 # configs are in the repository
00014 
00015 l=locals() 
00016 if not l.has_key("repodir"): 
00017     repodir=os.getenv("CASAPATH").split(' ')[0]
00018 
00019 print casa['build']
00020 print 'I think the data repository is at '+repodir
00021 datadir=repodir+"/data/regression/simdata/"
00022 cfgdir=repodir+"/data/alma/simmos/"
00023 shutil.copytree(datadir+modelname,modelname)
00024 
00025 default(simobserve)
00026 
00027 project = projname
00028 # Clear out results from previous runs.
00029 os.system('rm -rf '+project)
00030 skymodel = modelname
00031 inbright = '0.004'
00032 indirection = 'B1950 23h59m59.96 -34d59m59.50'
00033 incell = '0.5arcsec'
00034 incenter = '330.076GHz'
00035 inwidth = '50MHz'
00036 
00037 setpointings = True
00038 integration = '10s'
00039 mapsize = ''
00040 maptype = 'square'
00041 pointingspacing = '9arcsec'
00042 
00043 #observe = True
00044 obsmode = "sd"
00045 # you should explicitly empty antennalist to avoid synthesis simulation
00046 #antennalist = ''
00047 refdate='2012/11/21/20:00:00'
00048 totaltime = '31360s'
00049 # totaltime = '314s'
00050 sdantlist = cfgdir+'aca.tp.cfg'
00051 #antennalist = cfgdir+'aca.tp.cfg'
00052 sdant = 0
00053 
00054 # only tsys-manual is available so far
00055 #thermalnoise = ''   #w/o noise 
00056 thermalnoise = 'tsys-manual'  #w/ noise
00057 t_sky = 263.0
00058 t_ground = t_sky
00059 
00060 if not l.has_key('interactive'): interactive=False
00061 if interactive:
00062     graphics="both"
00063 else:
00064     graphics="file"
00065 
00066 verbose=True
00067 
00068 inp()
00069 simobserve()
00070 
00071 obsEndTime = time.time()
00072 obsEndProc = time.clock()
00073 
00074 print '--Running sim_analyze of M51 (total power) --'
00075 # configs are in the repository
00076 
00077 #default(sim_analyze)
00078 default(simanalyze)
00079 project = projname
00080 image = True
00081 # default vis name of SD simulation
00082 #vis = '$project.noisy.sd.ms'  #w/ noise
00083 imsize = [512,512]
00084 imdirection = indirection
00085 cell = '1.0arcsec'
00086 
00087 analyze = True
00088 # show psf & residual are not available for SD-only simulation
00089 showpsf = False
00090 showresidual = False
00091 showconvolved = True
00092 
00093 #
00094 #setpointings=False
00095 #observe=False
00096 #thermalnoise=''
00097 #
00098 
00099 if not l.has_key('interactive'): interactive=False
00100 if interactive:
00101     graphics="both"
00102 else:
00103     graphics="file"
00104 
00105 verbose=True
00106 
00107 #inp(simdata)
00108 #simdata()
00109 inp()
00110 #sim_analyze()
00111 simanalyze()
00112 
00113 endTime = time.time()
00114 endProc = time.clock()
00115 
00116 # Regression
00117 
00118 test_name = """simdata observation of M51 (total power)"""
00119 
00120 #ia.open(project+"/"+project + '.aca.tp.image')
00121 ia.open(project+"/"+project + '.image')
00122 m51sd_stats=ia.statistics(verbose=False,list=False)
00123 ia.close()
00124 
00125 refstats = {'max':  1.8829,
00126             'min': -0.52625,
00127             'rms': 0.22069,
00128             'sigma': 0.20145,
00129             'sum': 23627}
00130 
00131 #ia.open(project+"/"+project + '.aca.tp.diff')
00132 ia.open(project+"/"+project + '.diff')
00133 m51sd_diffstats=ia.statistics(verbose=False,list=False)
00134 ia.close()
00135 
00136 diffstats = {'max': 2.4528,
00137              'min': -0.48053,
00138              'rms': 0.26383,
00139              'sigma': 0.24221,
00140              'sum': 27423 }
00141 
00142 # relative tolerances to reference values
00143 reftol   = {'sum':  1e-2,
00144             'max':  1e-2,
00145             'min':  5e-2,
00146             'rms':  1e-2,
00147             'sigma': 1e-2}
00148 
00149 import datetime
00150 datestring = datetime.datetime.isoformat(datetime.datetime.today())
00151 outfile    = project+"/"+project + '.' + datestring + '.log'
00152 logfile    = open(outfile, 'w')
00153 
00154 print 'Writing regression output to ' + outfile + "\n"
00155 print >> logfile,casa['build']
00156 
00157 loghdr = """
00158 ********** Regression *****************
00159 """
00160 
00161 print >> logfile, loghdr
00162 
00163 # more info
00164 ms.open(project+"/"+project+".aca.tp.sd.ms")
00165 #ms.open(project+"/"+project+".aca.tp.ms")
00166 print >> logfile, "Noiseless MS, amp stats:"
00167 print >> logfile, ms.statistics('DATA','amp')
00168 print >> logfile, "Noiseless MS, phase stats:"
00169 print >> logfile, ms.statistics('DATA','phase')
00170 ms.close()
00171 #ms.open(project+"/"+project+".noisy.ms")
00172 #print >> logfile, "Noisy MS, amp stats:"
00173 #print >> logfile, ms.statistics('DATA','amp')
00174 #print >> logfile, "Noisy MS, phase stats:"
00175 #print >> logfile, ms.statistics('DATA','phase')
00176 #ms.close()
00177 
00178 
00179 regstate = True
00180 rskes = refstats.keys()
00181 rskes.sort()
00182 for ke in rskes:
00183     adiff=abs(m51sd_stats[ke][0] - refstats[ke])/abs(refstats[ke])
00184     if adiff < reftol[ke]:
00185         print >> logfile, "* Passed %-5s image test, got % -11.5g expected % -11.5g." % (ke, m51sd_stats[ke][0], refstats[ke])
00186     else:
00187         print >> logfile, "* FAILED %-5s image test, got % -11.5g instead of % -11.5g." % (ke, m51sd_stats[ke][0], refstats[ke])
00188         regstate = False
00189 
00190 rskes = diffstats.keys()
00191 rskes.sort()
00192 for ke in rskes:
00193     adiff=abs(m51sd_diffstats[ke][0] - diffstats[ke])/abs(diffstats[ke])
00194     if adiff < reftol[ke]:
00195         print >> logfile, "* Passed %-5s  diff test, got % -11.5g expected % -11.5g." % (ke, m51sd_diffstats[ke][0], diffstats[ke])
00196     else:
00197         print >> logfile, "* FAILED %-5s  diff test, got % -11.5g instead of % -11.5g." % (ke, m51sd_diffstats[ke][0], diffstats[ke])
00198         regstate = False
00199         
00200 
00201 print >> logfile,'---'
00202 if regstate:
00203     print >> logfile, 'Passed',
00204     print ''
00205     print 'Regression PASSED'
00206     print ''
00207 else:
00208     print >> logfile, 'FAILED',
00209     print ''
00210     print 'Regression FAILED'
00211     print ''
00212 
00213 print >> logfile, 'regression test for simdata of M51 (total power).'
00214 print >>logfile,'---'
00215 print >>logfile,'*********************************'
00216     
00217 print >>logfile,''
00218 print >>logfile,'********** Benchmarking **************'
00219 print >>logfile,''
00220 print >>logfile,'Total wall clock time was: %8.3f s.' % (endTime - startTime)
00221 print >>logfile,'Total CPU        time was: %8.3f s.' % (endProc - startProc)
00222 print >>logfile,'Wall processing  rate was: %8.3f MB/s.' % (17896.0 /
00223                                                             (endTime - startTime))
00224 
00225 ### Get last modification time of .ms.
00226 msfstat = os.stat(project+"/"+project+'.aca.tp.sd.ms')
00227 #msfstat = os.stat(project+"/"+project+'.aca.tp.ms')
00228 print >>logfile,'* Breakdown:                           *'
00229 print >>logfile,'*  generating visibilities took %8.3fs,' % (msfstat[8] - startTime)
00230 print >>logfile,'*************************************'
00231     
00232 logfile.close()
00233                                                     
00234 print '--Finished simdata of M51 (total power) regression--'