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
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053 import os
00054 import time
00055 import regression_utility as tstutl
00056 from __main__ import default
00057 from tasks import *
00058 from taskinit import *
00059
00060
00061
00062 benchmarking = True
00063 usedasync = False
00064
00065
00066
00067
00068
00069 fitsdata='ngc5921.fits'
00070
00071
00072 testdir='accum_regression'
00073
00074
00075 prefix=testdir+"/"+'ngc5921'
00076
00077
00078
00079 tstutl.maketestdir(testdir)
00080
00081
00082 if benchmarking:
00083 startTime = time.time()
00084 startProc = time.clock()
00085
00086
00087
00088
00089
00090
00091 try:
00092
00093 print '--Import--'
00094
00095
00096 default('importuvfits')
00097
00098
00099 msfile = prefix + '.ms'
00100
00101
00102 fitsfile = fitsdata
00103 vis = msfile
00104 antnamescheme="new"
00105 importuvfits()
00106
00107
00108 if benchmarking:
00109 importtime = time.time()
00110
00111
00112
00113
00114
00115
00116 print '--Setjy--'
00117 default('setjy')
00118
00119 setjy(vis=msfile,field='0',scalebychan=False,standard='Perley-Taylor 99')
00120
00121
00122 if benchmarking:
00123 setjytime = time.time()
00124
00125
00126
00127
00128
00129
00130 print '--Gaincal using interval per integration--'
00131 default('gaincal')
00132
00133 Ginttable = prefix + '.int.gcal'
00134 gaincal(vis=msfile,caltable=Ginttable,
00135 field='0', gaintype='G',solint='int',combine='',refant='VA02')
00136
00137
00138
00139 if benchmarking:
00140 gaintime1 = time.time()
00141
00142
00143
00144
00145
00146
00147 print '--Gaincal using interval infinite--'
00148 default('gaincal')
00149
00150 Gscantable = prefix + '.scan.gcal'
00151 gaincal(vis=msfile,caltable=Gscantable,
00152 field='0', gaintype='G',solint='inf',combine='',refant='VA02')
00153
00154
00155
00156 if benchmarking:
00157 gaintime2 = time.time()
00158
00159
00160
00161
00162
00163
00164 print '--Gaincal using previous solution--'
00165 default('gaincal')
00166
00167 Grinttable = prefix + '.rint.gcal'
00168 gaincal(vis=msfile,caltable=Grinttable,field='0', gaintype='G',gaintable=Gscantable,
00169 solint='int',combine='',interp='nearest',refant='VA02')
00170
00171
00172
00173 if benchmarking:
00174 gaintime3 = time.time()
00175
00176
00177
00178
00179
00180
00181 print '--Accum on initial data--'
00182 default('accum')
00183
00184 Acc1table = prefix + '.acc1.gcal'
00185 accum(vis=msfile,tablein='',accumtime=1.0,caltable=Acc1table,incrtable=Gscantable,
00186 field='0', calfield='0',interp='nearest')
00187
00188
00189
00190 if benchmarking:
00191 accumtime1 = time.time()
00192
00193
00194
00195
00196
00197
00198
00199 print '--Accum using previous solution--'
00200 default('accum')
00201
00202 Acc2table = prefix + '.acc2.gcal'
00203 accum(vis=msfile,tablein=Acc1table,caltable=Acc2table,incrtable=Grinttable,
00204 field='0', calfield='0',interp='nearest')
00205
00206
00207
00208 if benchmarking:
00209 accumtime2 = time.time()
00210
00211 endProc = time.clock()
00212 endTime = time.time()
00213
00214
00215 print '--Saving Plots--'
00216 saveplot = prefix + '.pdf'
00217 default('plotcal')
00218 plotcal(caltable=Ginttable,plotsymbol='+',overplot=False,field='0',markersize=10.0,
00219 showgui=False,figfile=saveplot)
00220 plotcal(caltable=Acc2table,plotsymbol='.',overplot=True,field='0',markersize=8.0,
00221 showgui=False,figfile=saveplot)
00222
00223
00224
00225 EPS = 1e-5
00226 total = 0
00227 fail = 0
00228
00229 tb.open(Ginttable)
00230
00231 intcol = tb.getvarcol('CPARAM')
00232 iflag = tb.getvarcol('FLAG')
00233 tb.close()
00234
00235 tb.open(Acc2table)
00236 afield = tb.query('FIELD_ID == 0')
00237
00238 acccol = afield.getvarcol('CPARAM')
00239 aflag = afield.getvarcol('FLAG')
00240 afield.done()
00241 tb.close()
00242
00243 n1 = len(intcol)
00244 n2 = len(acccol)
00245 if n1 != n2 :
00246 print >> sys.stderr, "The two tables have different lengths"
00247
00248
00249 for i in range(1,n1,1) :
00250 row = 'r%s'%i
00251
00252 for pol in range(0,2) :
00253
00254
00255 if (not (iflag[row][pol] and aflag[row][pol])) :
00256 total += 1
00257 intdata = intcol[row][pol]
00258 accdata = acccol[row][pol]
00259
00260 if (abs(intdata - accdata) > EPS) :
00261 fail += 1
00262 print >>sys.stderr, row,pol,intdata,accdata
00263
00264 if fail > 0 :
00265 perc = fail*100/total
00266 regstate = False
00267 print >> sys.stdout, ''
00268 print >> sys.stdout, 'Regression FAILED'
00269 print >> sys.stdout, ''
00270 print >> sys.stderr, "Regression test failed: %f %% of values are different "\
00271 "by more than the allowed maximum %s" %(perc,EPS)
00272 else :
00273 regstate = True
00274 print >> sys.stdout, ''
00275 print >> sys.stdout, 'Regression PASSED'
00276 print >> sys.stdout, ''
00277 print >> sys.stdout, "Regression tests passed. %s rows were analysed" %total
00278
00279 print >>sys.stdout,'********* Benchmarking *****************'
00280 print >>sys.stdout,'* *'
00281 print >>sys.stdout,'Total wall clock time was: '+str(endTime - startTime)
00282 print >>sys.stdout,'Total CPU time was: '+str(endProc - startProc)
00283 print >>sys.stdout,'* Breakdown: *'
00284 print >>sys.stdout,'* import time was: '+str(importtime-startTime)
00285 print >>sys.stdout,'* setjy time was: '+str(setjytime-importtime)
00286 print >>sys.stdout,'* gaincal1 time was: '+str(gaintime1-setjytime)
00287 print >>sys.stdout,'* gaincal2 time was: '+str(gaintime2-gaintime1)
00288 print >>sys.stdout,'* gaincal3 time was: '+str(gaintime3-gaintime2)
00289 print >>sys.stdout,'* accum1 time was: '+str(accumtime1-gaintime3)
00290 print >>sys.stdout,'* accum2 time was: '+str(accumtime2-accumtime1)
00291 print >>sys.stdout,'*****************************************'
00292
00293 except Exception, instance:
00294 print >> sys.stderr, "Regression test failed for accum instance = ", instance
00295