casa  $Rev:20696$
 All Classes Namespaces Files Functions Variables
wproj3ddat_regression.py
Go to the documentation of this file.
00001 import os
00002 import time
00003 
00004 
00005 # Enable benchmarking?
00006 benchmarking = True
00007 usedasync = False
00008 
00009 # 
00010 # Set up some useful variables
00011 #
00012 # Get path to CASA home directory by stipping name from '$CASAPATH'
00013 pathname=os.environ.get('CASAPATH').split()[0]
00014 
00015 # This is where the NGC5921 UVFITS data will be
00016 fitsdata=pathname+'/data/demo/3DDAT.fits'
00017 
00018 os.system('rm -rf n3ddat*')
00019 
00020 # Start benchmarking
00021 if benchmarking:
00022     startTime = time.time()
00023     startProc = time.clock()
00024 
00025 #
00026 #=====================================================================
00027 #
00028 # Import the data from FITS to MS
00029 #
00030 print '--Import--'
00031 
00032 # Safest to start from task defaults
00033 default('importuvfits')
00034 
00035 prefix='n3ddat'
00036 # Set up the MS filename and save as new global variable
00037 msfile = prefix + '.ms'
00038 
00039 # Use task importuvfits
00040 fitsfile = fitsdata
00041 vis = msfile
00042 antnamescheme = 'new'
00043 importuvfits()
00044 
00045 # Note that there will be a ngc5921.ms.flagversions
00046 # containing the initial flags as backup for the main ms flags.
00047 
00048 # Record import time
00049 if benchmarking:
00050     importtime = time.time()
00051 
00052 tflagdata(vis=msfile, mode='manual', antenna='VA10', spw='*', field='0')
00053 
00054 print '--Widefield--'
00055 default('widefield')
00056 
00057 # Pick up our split source data
00058 vis = msfile
00059 
00060 # Make an image root file name
00061 imname = prefix + '.clean'
00062 imagename = imname
00063 
00064 # Set up the output image cube
00065 mode = 'mfs'
00066 
00067 
00068 # This is a single-source MS with one spw
00069 field = '0'
00070 spw = '*'
00071 
00072 selectdata=True
00073 #uvrange='0.15~10000 klambda'
00074 # Standard gain factor 0.1
00075 gain = 0.1
00076 
00077 # Set the output image size and cell size (arcsec)
00078 imsize = [3000,3000]
00079 
00080 # Do a simple Clark clean
00081 psfmode = 'clark'
00082 
00083 cell = ['30arcsec','30arcsec']
00084 
00085 # Fix maximum number of iterations
00086 niter = 6000
00087 
00088 # Also set flux residual threshold (in mJy)
00089 threshold=0.0
00090 
00091 # Set up the weighting
00092 weighting = 'natural'
00093 
00094 #ftmachine
00095 ftmachine='wproject'
00096 wprojplanes=200
00097 cyclefactor=3
00098 
00099 # No clean mask or cleanbox for now
00100 mask = ''
00101 #cleanbox = []
00102 
00103 # But if you had a cleanbox saved in a file, e.g. "regionfile.txt"
00104 # you could use it:
00105 #cleanbox='regionfile.txt'
00106 #
00107 # and if you wanted to use interactive clean
00108 #cleanbox='interactive'
00109 
00110 widefield()
00111 
00112 #
00113 # Following is should be the equivalent clean task setup
00114 #
00115 #clean(vis="n3ddat.ms",imagename="ttt",outlierfile="",field="0",spw="*",selectdata=False,timerange="",uvrange="",antenna="",scan="",mode="mfs",gridmode="widefield",wprojplanes=200,facets=1,cfcache="cfcache.dir",painc=360.0,epjtable="",interpolation="nearest",niter=6000,gain=0.1,threshold=0.0,psfmode="clark",imagermode="csclean",ftmachine="mosaic",mosweight=False,scaletype="SAULT",multiscale=[],negcomponent=-1,smallscalebias=0.6,interactive=False,mask=[],nchan=1,start=0,width=1,imsize=[3000, 3000],cell=['30arcsec', '30arcsec'],phasecenter="",restfreq="",stokes="I",weighting="natural",robust=0.0,uvtaper=False,outertaper=[],innertaper=[],modelimage="",restoringbeam=[''],pbcor=False,minpb=0.1,calready=False,noise="1.0Jy",npixels=0,npercycle=100,cyclefactor=3,cyclespeedup=-1,nterms=1,reffreq="")
00116 
00117 
00118 
00119 # Should find stuff in the logger like:
00120 #
00121 # Fitted beam used in restoration: 51.5643 by 45.6021 (arcsec)
00122 #     at pa 14.5411 (deg)
00123 #
00124 # It will have made the images:
00125 # -----------------------------
00126 # ngc5921.clean.image
00127 # ngc5921.clean.model
00128 # ngc5921.clean.residual
00129 
00130 clnimage = imname+'.image'
00131 
00132 # Record clean completion time
00133 if benchmarking:
00134     cleantime = time.time()
00135 
00136 print '--Imstat--'
00137 default('imstat')
00138 
00139 imagename = clnimage
00140 
00141 cubestats =imstat()
00142 
00143 #
00144 #=====================================================================
00145 #
00146 # Can do some image statistics if you wish
00147 # Treat this like a regression script
00148 # WARNING: currently requires toolkit
00149 #
00150 print ""
00151 print ' 3DDAT results '
00152 print ' =============== '
00153 
00154 print ''
00155 print ' --Regression Tests--'
00156 print ''
00157 # Pull the max from the cubestats dictionary
00158 # created above using imstat
00159 thistest_immax=cubestats['max'][0]
00160 oldtest_immax = 7.50
00161 print ' Clean image max should be ',oldtest_immax
00162 print ' Found : Image Max = ',thistest_immax
00163 diff_immax = abs((oldtest_immax-thistest_immax)/oldtest_immax)
00164 print ' Difference (fractional) = ',diff_immax
00165 
00166 print ''
00167 # Pull the rms from the cubestats dictionary
00168 thistest_imrms=cubestats['rms'][0]
00169 oldtest_imrms = 0.134
00170 print ' Clean image rms should be ',oldtest_imrms
00171 print ' Found : Image rms = ',thistest_imrms
00172 diff_imrms = abs((oldtest_imrms-thistest_imrms)/oldtest_imrms)
00173 print ' Difference (fractional) = ',diff_imrms
00174 
00175 
00176 
00177 # Record processing completion time
00178 if benchmarking:
00179     endProc = time.clock()
00180     endTime = time.time()
00181 
00182 #
00183 #=====================================================================
00184 #
00185 if not benchmarking:
00186     print ''
00187     print '--- Done ---'
00188 else:
00189     import datetime
00190     datestring=datetime.datetime.isoformat(datetime.datetime.today())
00191     outfile='wproj3ddat.'+datestring+'.log'
00192     logfile=open(outfile,'w')
00193 
00194     print >>logfile,''
00195     print >>logfile,''
00196 
00197 
00198     if (diff_immax < 0.05):
00199         passimmax = True
00200         print >>logfile,'* Passed image max test'
00201     else:
00202         passimmax = False
00203         print >>logfile,'* FAILED image max test'
00204     print >>logfile,'*  Image max '+str(thistest_immax)
00205 
00206     if (diff_imrms < 0.05):
00207         passimrms = True
00208         print >>logfile,'* Passed image rms test'
00209     else:
00210         passimrms = False
00211         print >>logfile,'* FAILED image rms test'
00212     print >>logfile,'*  Image rms '+str(thistest_imrms)
00213 
00214     if (passimmax and passimrms ): 
00215         regstate=True
00216         print >>logfile,'---'
00217         print >>logfile,'Passed Regression test for wproj3ddat'
00218         print >>logfile,'---'
00219     else: 
00220         regstate=False
00221         print >>logfile,'---'
00222         print >>logfile,'FAILED Regression test for wproj3ddat'
00223         print >>logfile,'---'
00224     print >>logfile,'*********************************'
00225 
00226     print >>logfile,''
00227     print >>logfile,''
00228     print >>logfile,'********* Benchmarking *****************'
00229     print >>logfile,'*                                      *'
00230     print >>logfile,'Total wall clock time was: ', endTime - startTime
00231     print >>logfile,'Total CPU        time was: ', endProc - startProc
00232     print >>logfile,'Processing rate MB/s  was: ', 35.1/(endTime - startTime)
00233     print >>logfile,'* Breakdown:                           *'
00234     print >>logfile,'*   import       time was: '+str(importtime-startTime)
00235     print >>logfile,'*   clean        time was: '+str(cleantime-importtime)
00236     print >>logfile,'*****************************************'
00237     print >>logfile,'basho (test cpu) time was: ?? seconds'
00238 
00239     logfile.close()
00240 
00241     print ""
00242     print "Done!"
00243         
00244 #exit()
00245 #
00246 #=====================================================================