00001
00002
00003
00004
00005
00006 import time
00007 import os
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
00054 pathname=os.environ.get('CASAPATH').split()[0]
00055 datapath=pathname+'/data/regression/ATST2/NGC4826/'
00056
00057 os.system('rm -rf n4826_22apr.* n4826_16apr.* n4826_tboth.ms')
00058 os.system('rm -rf srca.split.ms src.split.ms')
00059 os.system('rm -rf tmosaic* gcal*.split.* tgcal* n4826_t*')
00060
00061 startTime=time.time()
00062 startProc=time.clock()
00063
00064 print '--Copy/reinitialize--'
00065
00066 copystring22apr='cp -r '+datapath+'n4826_22apr98.ms n4826_22apr.ms'
00067 os.system(copystring22apr)
00068 tb.open('n4826_22apr.ms/HISTORY', nomodify=False)
00069 tb.removerows(range(tb.nrows()))
00070 tb.done()
00071
00072 clearcal(vis='n4826_22apr.ms')
00073
00074 copytime=time.time()
00075
00076
00077 print '--setjy - 22apr98--'
00078 default('setjy')
00079 setjy(vis='n4826_22apr.ms',field='0',fluxdensity=[23.0,0.,0.,0.],scalebychan=False)
00080 setjy1time=time.time()
00081
00082 print '--flag data - 22apr97--'
00083 default('tflagdata')
00084
00085
00086
00087
00088
00089 tflagdata(vis="n4826_22apr.ms", mode='clip',
00090 correlation='ABS_YY',
00091 clipminmax=[0.0,80.0],
00092 clipoutside=True)
00093
00094 flag1time=time.time()
00095
00096 print '--gaincal - 22par98--'
00097 default('gaincal')
00098 gaincal(vis='n4826_22apr.ms',caltable='n4826_22apr.gcal',
00099 field='0,1',spw='0', gaintype='G',
00100 minsnr=2.0,
00101 refant='ANT5',gaincurve=False,opacity=0.0,solint='inf',combine='')
00102 gaincal1time=time.time()
00103
00104 print '--fluxscale - 22apr98--'
00105 default('fluxscale')
00106 fluxscale(vis='n4826_22apr.ms',caltable='n4826_22apr.gcal',
00107 fluxtable='n4826_22apr.fcal',
00108 reference='3C273-F0',transfer=['1230+123-F0']);
00109 fluxscale1time=time.time()
00110
00111
00112
00113
00114 print '--correct 22apr98--'
00115 default('applycal')
00116 applycal(vis='n4826_22apr.ms',
00117 field='1',spw='0',
00118 gaincurve=False,opacity=0.0,gaintable='n4826_22apr.fcal')
00119 applycal(vis='n4826_22apr.ms',
00120 field='2~8',spw='1~4',
00121 gaincurve=False,opacity=0.0,gaintable='n4826_22apr.fcal',spwmap=[0])
00122 correct1time=time.time()
00123
00124
00125 print '--split - 22apr98--'
00126 default('split')
00127 split(vis='n4826_22apr.ms',outputvis='gcal.split.ms',
00128
00129 field='1',spw='0:0~1',datacolumn='corrected')
00130 default('split')
00131 split(vis='n4826_22apr.ms',outputvis='src.split.ms',
00132
00133 field='2~8',spw='1~4:0~63',
00134 datacolumn='corrected')
00135 split1time=time.time()
00136
00137
00138
00139 print '--image cal - 22apr98--'
00140 default('clean')
00141 clean(vis='gcal.split.ms',imagename='tgcal',
00142 cell=[1.,1.],imsize=[256,256],interpolation='nearest',
00143 field='0',spw='0',threshold=10.,ftmachine='ft',
00144 psfmode='clark',niter=100,stokes='I')
00145 imagecal1time=time.time()
00146
00147
00148 print '--image src - 22apr98--'
00149 default('clean')
00150 clean(vis='src.split.ms',imagename='tmosaicb',
00151 nchan=30,start=47,width=4,interpolation='nearest',
00152
00153 spw='0,1,2',field='0,1,2,3,4,5,6',
00154 cell=[1.,1.],imsize=[256,256],
00155 stokes='I',mode='channel',
00156 psfmode='clark',imagermode='mosaic', ftmachine='mosaic',
00157 niter=300,
00158 scaletype='SAULT',
00159 pbcor=False,
00160 minpb=0.01,
00161 cyclefactor=2.0, usescratch=False, mask=[66,72,195,185])
00162 imagesrc1time=time.time()
00163
00164
00165 print '--write fits image--'
00166 default('exportfits')
00167 exportfits(imagename='tmosaicb.image',fitsimage='tmosaicb.fits')
00168 writefits1time=time.time()
00169
00170
00171
00172
00173
00174
00175
00176 print '--copy/initialize - 16apr98 --'
00177 copystring16apr='cp -r '+datapath+'n4826_16apr98.ms n4826_16apr.ms'
00178 os.system(copystring16apr)
00179 tb.open('n4826_16apr.ms/HISTORY', nomodify=False)
00180 tb.removerows(range(tb.nrows()))
00181 tb.done()
00182 clearcal(vis='n4826_16apr.ms')
00183 copy2time=time.time()
00184
00185 print '--setjy - 16apr98--'
00186 default('setjy')
00187 setjy(vis='n4826_16apr.ms',field='0',fluxdensity=[23.0,0.,0.,0.],scalebychan=False)
00188 setjy2time=time.time()
00189
00190 print '--flagdata - 16apr98 --'
00191 default('tflagdata')
00192
00193 tflagdata(vis='n4826_16apr.ms',spw='2~5:0;1;62;63', mode='manual')
00194 flagdata2time=time.time()
00195
00196 print '--gaincal - 16apr98 --'
00197 default('gaincal')
00198 gaincal(vis='n4826_16apr.ms',caltable='n4826_16apr.gcal',
00199 field='0,1',spw='0,1', gaintype='G',
00200 minsnr=2.0,
00201 refant='ANT5',gaincurve=False,opacity=0.0,solint='inf',combine='')
00202 gaincal2time=time.time()
00203
00204
00205 print '--fluxscale - 16apr98 --'
00206 default('fluxscale')
00207 fluxscale(vis='n4826_16apr.ms',caltable='n4826_16apr.gcal',
00208 fluxtable='n4826_16apr.fcal',
00209 reference='3C273-F0',transfer=['1310+323-F0'],refspwmap=[0,0]);
00210 fluxscale2time=time.time()
00211
00212
00213
00214
00215
00216
00217
00218
00219 print '--correct - 16apr98 --'
00220 default('applycal')
00221 applycal(vis='n4826_16apr.ms',
00222 field='1',spw='1',
00223 gaincurve=False,opacity=0.0,gaintable='n4826_16apr.fcal')
00224 applycal(vis='n4826_16apr.ms',
00225 field='2~8',spw='2~5',
00226 gaincurve=False,opacity=0.0,gaintable='n4826_16apr.fcal',spwmap=[1])
00227 correct2time=time.time()
00228
00229 print '--split - 16apr98 --'
00230 default('split')
00231 split(vis='n4826_16apr.ms',outputvis='gcala.split.ms',
00232
00233 field='1',spw='1:0~1',datacolumn='corrected')
00234 default('split')
00235 split(vis='n4826_16apr.ms',outputvis='srca.split.ms',
00236
00237 field='2~8',spw='2~5:0~63',
00238 datacolumn='corrected')
00239 split2time=time.time()
00240
00241
00242
00243
00244
00245
00246
00247
00248 default('tflagdata')
00249 tflagdata(vis="srca.split.ms", mode='clip',
00250 antenna='5',
00251 correlation="ABS_I",
00252 clipminmax=[0.0,0.0],
00253 clipoutside=True,
00254 timerange='1998/04/16/09:42:39.0~1998/04/16/10:24:46.0')
00255
00256
00257
00258 print '--image cal - 16apr98 --'
00259 default('clean')
00260 clean(vis='gcala.split.ms',imagename='tgcala',
00261 cell=[1.,1.],imsize=[256,256],interpolation='nearest',
00262 field='0',spw='0',threshold=10.,ftmachine='ft',
00263 psfmode='clark',niter=100,stokes='I')
00264 imagecal2time=time.time()
00265
00266
00267
00268 print '--image src - 16apr98 --'
00269 default('clean')
00270
00271
00272 clean(vis='srca.split.ms',imagename='tmosaica',
00273 nchan=30,start=47,width=4,interpolation='nearest',
00274 spw='0~2',field='0~6',
00275 cell=[1.,1.],imsize=[256,256],
00276 stokes='I',mode='channel',
00277 psfmode='clark',niter=300,imagermode='mosaic', ftmachine='mosaic',scaletype='SAULT',cyclefactor=3, usescratch=False)
00278
00279
00280
00281 exportfits('tmosaica.image','tmosaica.fits')
00282
00283
00284 print '-- Initialize src.split.ms --'
00285 os.system('cp -r srca.split.ms n4826_tboth.ms');
00286 cb.open('src.split.ms')
00287 cb.initcalset()
00288 cb.close()
00289 print '-- Concatenate --'
00290 ms.open(thems='n4826_tboth.ms',nomodify=False);
00291 ms.concatenate(msfile='src.split.ms',freqtol='50MHz')
00292 ms.close()
00293
00294
00295
00296 default('clean')
00297 clean(vis='n4826_tboth.ms',imagename='tmosaic',
00298 nchan=30,start=46,width=4,
00299 spw='0~2',field='0~6',interpolation='nearest',
00300 cell=[1.,1.],imsize=[256,256],
00301 stokes='I',mode='channel',
00302 psfmode='clark',niter=500,imagermode='mosaic',ftmachine='mosaic',scaletype='SAULT',
00303 cyclefactor=3, usescratch=False)
00304
00305 ia.open(infile='tmosaic.image');
00306 ia.moments(outfile='n4826_tmom0.im',
00307 moments=0,axis=3,includepix=[0.070,1000.0],
00308 mask='indexin(3,[3:24])')
00309 ia.moments(outfile='n4826_tmom1.im',
00310 moments=1,axis=3,includepix=[0.007,1000.0],
00311 mask='indexin(3,[3:24])')
00312 ia.close()
00313
00314
00315
00316
00317 exportfits(imagename='tmosaic.image',fitsimage='tmosaic.fits')
00318
00319 endProc=time.clock()
00320 endTime=time.time()
00321
00322
00323
00324 ms.open('gcal.split.ms')
00325 thistest_cal_22apr=pl.mean(ms.range(["amplitude"]).get("amplitude"))
00326 ms.close()
00327 ms.open('src.split.ms')
00328 thistest_src_22apr=pl.mean(ms.range(["amplitude"]).get("amplitude"))
00329 ms.close
00330 ia.open('tgcal.image')
00331 statistics=ia.statistics()
00332 im_calmax22=statistics['max'][0]
00333 ia.close()
00334 ia.open('tmosaicb.image')
00335 statistics=ia.statistics()
00336 im_srcmax22=statistics['max'][0]
00337
00338
00339 ms.open('gcala.split.ms')
00340 thistest_cal_16apr=pl.mean(ms.range(["amplitude"]).get("amplitude"))
00341 ms.close()
00342 ms.open('srca.split.ms')
00343 thistest_src_16apr=pl.mean(ms.range(["amplitude"]).get("amplitude"))
00344 ms.close
00345 ia.open('tgcala.image')
00346 statistics=ia.statistics()
00347 ia.close()
00348 im_calmax16=statistics['max'][0]
00349 ia.open('tmosaica.image')
00350 statistics=ia.statistics()
00351 ia.close()
00352 im_srcmax16=statistics['max'][0]
00353
00354
00355 ms.open('n4826_tboth.ms')
00356 thistest_src=pl.mean(ms.range(["amplitude"]).get("amplitude"))
00357 ms.close()
00358 ia.open('n4826_tmom0.im')
00359 statistics=ia.statistics()
00360 ia.close()
00361 thistest_immax=statistics['max'][0]
00362 thistest_imrms=statistics['rms'][0]
00363
00364
00365 calmean22=10.51
00366 srcmean22=122.21
00367 calmax22=3.0459
00368
00369 srcmax22=1.632
00370 calmean16=4.3269
00371 srcmean16=147.43
00372 srcmax16=1.584
00373 calmax16=1.43
00374
00375 srcmean=147.43
00376
00377 immax=162.22
00378
00379 imrms=13.18
00380
00381
00382
00383
00384
00385
00386
00387
00388
00389
00390
00391
00392
00393
00394 diff_cal22apr=abs((calmean22-thistest_cal_22apr)/calmean22)
00395 diff_src22apr=abs((srcmean22-thistest_src_22apr)/srcmean22)
00396 diff_calmax22=abs((calmax22-im_calmax22)/calmax22)
00397 diff_srcmax22=abs((srcmax22-im_srcmax22)/srcmax22)
00398 diff_cal16apr=abs((calmean16-thistest_cal_16apr)/calmean16)
00399 diff_src16apr=abs((srcmean16-thistest_src_16apr)/srcmean16)
00400 diff_calmax16=abs((calmax16-im_calmax16)/calmax16)
00401 diff_srcmax16=abs((srcmax16-im_srcmax16)/srcmax16)
00402
00403 diff_src=abs((srcmean-thistest_src)/srcmean)
00404 diff_immax=abs((immax-thistest_immax)/immax)
00405 diff_imrms=abs((imrms-thistest_imrms)/imrms)
00406
00407 import datetime
00408 datestring=datetime.datetime.isoformat(datetime.datetime.today())
00409 outfile='n4826.'+datestring+'.log'
00410 logfile=open(outfile,'w')
00411
00412 print >>logfile,'********** Regression ***********'
00413 print >>logfile,'* (Values: got, then expected) *'
00414 statstrs = {True: 'Passed', False: 'FAILED'}
00415 print >>logfile, '*', statstrs[diff_cal22apr<0.08], 'cal mean amp (22apr)'
00416 print >>logfile,'--Cal mean amp (22apr) '+str(thistest_cal_22apr)+', '+str(calmean22)
00417 print >>logfile, '*', statstrs[diff_src22apr<0.08], 'src mean amp (22apr)'
00418 print >>logfile,'--Src mean amp (22apr) '+str(thistest_src_22apr)+', '+str(srcmean22)
00419 print >>logfile, '*', statstrs[diff_calmax22<0.08], 'cal image max (22apr)'
00420 print >>logfile,'--Image max (cal;22apr) '+str(im_calmax22)+', '+str(calmax22)
00421 print >>logfile, '*', statstrs[diff_srcmax22<0.08], 'src image max (22apr)'
00422 print >>logfile,'--Image max (src;22apr): '+str(im_srcmax22)+', '+str(srcmax22)
00423 print >>logfile, '*', statstrs[diff_cal16apr<0.08], 'cal mean amp (16apr)'
00424 print >>logfile,'--Cal mean amp (16apr) '+str(thistest_cal_16apr)+', '+str(calmean16)
00425 print >>logfile, '*', statstrs[diff_src16apr<0.08], 'src mean amp (16apr)'
00426 print >>logfile,'--Src mean amp (16apr) '+str(thistest_src_16apr)+', '+str(srcmean16)
00427 print >>logfile, '*', statstrs[diff_calmax16<0.08], 'cal image max (16apr)'
00428 print >>logfile,'--Image max (cal;16apr): '+str(im_calmax16)+', '+str(calmax16)
00429 print >>logfile, '*', statstrs[diff_srcmax16<0.08], 'src image max (16apr)'
00430 print >>logfile,'--Image max (src;16apr): '+str(im_srcmax16)+', '+str(srcmax16)
00431 print >>logfile, '*', statstrs[diff_src<0.08], 'src mean amplitude test'
00432 print >>logfile,'--Src mean amp '+str(thistest_src)+', '+str(srcmean)
00433 print >>logfile, '*', statstrs[diff_immax<0.08], 'image max test'
00434 print >>logfile,'--Image max '+str(thistest_immax)+', '+str(immax)
00435 print >>logfile, '*', statstrs[diff_imrms<0.08], 'image rms test'
00436 print >>logfile,'--Image rms '+str(thistest_imrms)+', '+str(imrms)
00437
00438 if ((diff_cal22apr<0.08) & (diff_src22apr<0.08) & (diff_cal16apr<0.08) & (diff_src16apr<0.08) &(diff_src<0.08) & (diff_immax<0.08) & (diff_imrms<0.08)):
00439 regstate=True
00440 print >>logfile,'---'
00441 print >>logfile,'Passed Regression test for NGC 4826 Mosaic'
00442 print >>logfile,'---'
00443 else:
00444 regstate=False
00445 print >>logfile,'----FAILED Regression test for NGC 4826 Mosaic'
00446 print >>logfile,'*********************************'
00447 print >>logfile,''
00448 print >>logfile,'********* Benchmarking *****************'
00449 print >>logfile,'* *'
00450 print >>logfile,'Total wall clock time was: '+str(endTime - startTime)
00451 print >>logfile,'Total CPU time was: '+str(endProc - startProc)
00452 print >>logfile,'Processing rate MB/s was: '+str(300./(endTime - startTime))
00453 print >>logfile,'* Breakdown: *'
00454
00455 logfile.close()