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
00054
00055
00056 import time
00057 import os
00058 import pickle
00059
00060
00061
00062
00063
00064 scriptmode = False
00065
00066
00067 benchmarking = True
00068
00069
00070 scriptprefix='ngc4826_tutorial_regression'
00071
00072
00073
00074
00075
00076 os.system('rm -rf ngc4826.tutorial.*')
00077
00078
00079 prefix='ngc4826.tutorial'
00080 msfile = prefix + '.16apr98.ms'
00081
00082 print 'Tutorial Regression Script for BIMASONG NGC4826 Mosaic'
00083 print 'Version for Release 0 (3.0.0) 7-Dec-2009'
00084 print 'Will do: import, flagging, calibration, imaging'
00085 print ''
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109 if benchmarking:
00110 startTime=time.time()
00111 startProc=time.clock()
00112
00113 _mydatapath = os.environ.get('CASAPATH').split()[0]+'/data/regression/ngc4826/'
00114
00115
00116
00117
00118
00119
00120
00121 print '--Importuvfits (16apr98)--'
00122 default('importuvfits')
00123
00124 print "Starting from the uvfits files exported by miriad"
00125 print "The USB spectral windows were written separately by miriad for 16apr98"
00126
00127 importuvfits(fitsfile=_mydatapath+'fitsfiles/3c273.fits5', vis='ngc4826.tutorial.3c273.5.ms')
00128
00129 importuvfits(fitsfile=_mydatapath+'fitsfiles/3c273.fits6', vis='ngc4826.tutorial.3c273.6.ms')
00130
00131 importuvfits(fitsfile=_mydatapath+'fitsfiles/3c273.fits7', vis='ngc4826.tutorial.3c273.7.ms')
00132
00133 importuvfits(fitsfile=_mydatapath+'fitsfiles/3c273.fits8', vis='ngc4826.tutorial.3c273.8.ms')
00134
00135 importuvfits(fitsfile=_mydatapath+'fitsfiles/1310+323.ll.fits9', vis='ngc4826.tutorial.1310+323.ll.9.ms')
00136
00137 importuvfits(fitsfile=_mydatapath+'fitsfiles/1310+323.ll.fits10', vis='ngc4826.tutorial.1310+323.ll.10.ms')
00138
00139 importuvfits(fitsfile=_mydatapath+'fitsfiles/1310+323.ll.fits11', vis='ngc4826.tutorial.1310+323.ll.11.ms')
00140
00141 importuvfits(fitsfile=_mydatapath+'fitsfiles/1310+323.ll.fits12', vis='ngc4826.tutorial.1310+323.ll.12.ms')
00142
00143 importuvfits(fitsfile=_mydatapath+'fitsfiles/1310+323.ll.fits13', vis='ngc4826.tutorial.1310+323.ll.13.ms')
00144
00145 importuvfits(fitsfile=_mydatapath+'fitsfiles/1310+323.ll.fits14', vis='ngc4826.tutorial.1310+323.ll.14.ms')
00146
00147 importuvfits(fitsfile=_mydatapath+'fitsfiles/1310+323.ll.fits15', vis='ngc4826.tutorial.1310+323.ll.15.ms')
00148
00149 importuvfits(fitsfile=_mydatapath+'fitsfiles/1310+323.ll.fits16', vis='ngc4826.tutorial.1310+323.ll.16.ms')
00150
00151 importuvfits(fitsfile=_mydatapath+'fitsfiles/ngc4826.ll.fits5', vis='ngc4826.tutorial.ngc4826.ll.5.ms')
00152
00153 importuvfits(fitsfile=_mydatapath+'fitsfiles/ngc4826.ll.fits6', vis='ngc4826.tutorial.ngc4826.ll.6.ms')
00154
00155 importuvfits(fitsfile=_mydatapath+'fitsfiles/ngc4826.ll.fits7', vis='ngc4826.tutorial.ngc4826.ll.7.ms')
00156
00157 importuvfits(fitsfile=_mydatapath+'fitsfiles/ngc4826.ll.fits8', vis='ngc4826.tutorial.ngc4826.ll.8.ms')
00158
00159 if benchmarking:
00160 import2time=time.time()
00161
00162
00163
00164
00165 print '--Concat--'
00166 default('concat')
00167
00168 concat(vis=['ngc4826.tutorial.3c273.5.ms',
00169 'ngc4826.tutorial.3c273.6.ms',
00170 'ngc4826.tutorial.3c273.7.ms',
00171 'ngc4826.tutorial.3c273.8.ms',
00172 'ngc4826.tutorial.1310+323.ll.9.ms',
00173 'ngc4826.tutorial.1310+323.ll.10.ms',
00174 'ngc4826.tutorial.1310+323.ll.11.ms',
00175 'ngc4826.tutorial.1310+323.ll.12.ms',
00176 'ngc4826.tutorial.1310+323.ll.13.ms',
00177 'ngc4826.tutorial.1310+323.ll.14.ms',
00178 'ngc4826.tutorial.1310+323.ll.15.ms',
00179 'ngc4826.tutorial.1310+323.ll.16.ms',
00180 'ngc4826.tutorial.ngc4826.ll.5.ms',
00181 'ngc4826.tutorial.ngc4826.ll.6.ms',
00182 'ngc4826.tutorial.ngc4826.ll.7.ms',
00183 'ngc4826.tutorial.ngc4826.ll.8.ms'],
00184 concatvis='ngc4826.tutorial.ms',
00185 freqtol="",dirtol="1arcsec",async=False)
00186
00187 if benchmarking:
00188 concat2time=time.time()
00189
00190
00191
00192
00193
00194
00195
00196
00197
00198
00199
00200
00201
00202
00203
00204
00205
00206
00207
00208
00209
00210
00211
00212
00213
00214
00215
00216
00217
00218
00219
00220
00221
00222
00223
00224
00225
00226
00227
00228
00229
00230
00231
00232
00233
00234
00235
00236
00237
00238
00239
00240
00241
00242
00243
00244
00245
00246
00247
00248
00249
00250
00251
00252
00253
00254
00255
00256
00257
00258
00259 print '--Fixing up spw rest frequencies in MS--'
00260 vis='ngc4826.tutorial.ms'
00261 tb.open(vis+'/SOURCE',nomodify=false)
00262 spwid=tb.getcol('SPECTRAL_WINDOW_ID')
00263
00264
00265 spwid.setfield(-1,'int32')
00266 tb.putcol('SPECTRAL_WINDOW_ID',spwid)
00267 tb.close()
00268
00269
00270
00271
00272
00273
00274
00275 print '--Clearcal--'
00276 print 'Create scratch columns and initialize in '+'ngc4826.tutorial.ms'
00277
00278
00279
00280
00281 clearcal(vis='ngc4826.tutorial.ms', addmodel=False)
00282
00283 if benchmarking:
00284 clearcal2time=time.time()
00285
00286
00287
00288
00289
00290
00291 print '--Listobs--'
00292 listobs(vis='ngc4826.tutorial.ms')
00293
00294
00295
00296
00297
00298 print "There are 3 fields observed in a total of 16 spectral windows"
00299 print " field=0 3c273 spwids 0,1,2,3 64 chans "
00300 print " field=1 1310+323 spwids 4,5,6,7,8,9,10,11 32 chans "
00301 print " field=2~8 NGC4826 spwids 12,13,14,15 64 chans "
00302 print ""
00303 print "See listobs summary in logger"
00304
00305 if benchmarking:
00306 list2time=time.time()
00307
00308
00309
00310
00311
00312
00313
00314
00315
00316
00317
00318
00319
00320
00321
00322
00323
00324
00325
00326
00327
00328
00329
00330
00331
00332
00333
00334
00335
00336
00337
00338
00339
00340
00341
00342
00343
00344
00345
00346
00347
00348
00349
00350
00351
00352
00353
00354
00355
00356
00357
00358
00359
00360
00361
00362
00363
00364
00365
00366
00367
00368
00369
00370
00371
00372
00373
00374
00375
00376
00377
00378
00379
00380
00381
00382
00383
00384
00385
00386
00387
00388
00389
00390
00391
00392
00393
00394
00395
00396
00397
00398
00399
00400
00401
00402
00403
00404
00405
00406
00407
00408
00409
00410
00411
00412
00413
00414
00415
00416
00417
00418
00419
00420
00421
00422
00423
00424
00425
00426
00427
00428
00429
00430
00431
00432
00433
00434
00435
00436
00437
00438
00439
00440
00441
00442
00443
00444
00445
00446
00447
00448
00449
00450
00451
00452
00453
00454
00455
00456
00457
00458
00459
00460
00461
00462
00463
00464 if benchmarking:
00465 plotxy2time=time.time()
00466
00467
00468
00469
00470
00471
00472 print '--Flagdata--'
00473 default('tflagdata')
00474
00475 print ""
00476 print "Flagging edge channels in all spw"
00477 print " 0~3:0~1;62~63 , 4~11:0~1;30~31, 12~15:0~1;62~63 "
00478 print ""
00479
00480 tflagdata(vis='ngc4826.tutorial.ms', mode='manual',
00481 spw='0~3:0;1;62;63,4~11:0;1;30;31,12~15:0;1;62;63')
00482
00483
00484
00485
00486 print ""
00487 print "Flagging bad correlator field 8 antenna 3&9 spw 15 all channels"
00488 print " timerange 1998/04/16/06:19:00.0~1998/04/16/06:20:00.0"
00489 print ""
00490
00491 tflagdata(vis='ngc4826.tutorial.ms', mode='manual', field='8', spw='15', antenna='3&9',
00492 timerange='1998/04/16/06:19:00.0~1998/04/16/06:20:00.0')
00493
00494
00495
00496
00497
00498
00499
00500
00501
00502
00503
00504
00505
00506
00507
00508
00509
00510
00511
00512
00513
00514
00515
00516
00517
00518
00519 print '--Flagmanager--'
00520 default('flagmanager')
00521
00522 print "Now will use flagmanager to save a copy of the flags we just made"
00523 print "These are named myflags"
00524
00525 flagmanager(vis='ngc4826.tutorial.ms',mode='save',versionname='myflags',
00526 comment='My flags',merge='replace')
00527
00528
00529
00530 flagmanager(vis='ngc4826.tutorial.ms',mode='list')
00531
00532 if benchmarking:
00533 flag2time=time.time()
00534
00535 print "Completed pre-calibration flagging"
00536
00537
00538
00539
00540
00541
00542
00543
00544
00545
00546
00547
00548
00549
00550
00551
00552
00553
00554
00555
00556 print '--Setjy (3C273)--'
00557 default('setjy')
00558
00559 setjy(vis='ngc4826.tutorial.ms',field='0',fluxdensity=[23.0,0.,0.,0.],spw='0~3', scalebychan=False, usescratch=False)
00560
00561
00562
00563
00564 if benchmarking:
00565 setjy2time=time.time()
00566
00567
00568
00569
00570
00571
00572 print '--Gaincal--'
00573 default('gaincal')
00574
00575
00576
00577
00578 print 'Gain calibration for fields 0,1 and spw 0~11'
00579 print 'Using solint=inf combining over spw'
00580 print 'Output table ngc4826.tutorial.16apr98.gcal'
00581
00582 gaincal(vis='ngc4826.tutorial.ms', caltable='ngc4826.tutorial.16apr98.gcal',
00583 field='0,1', spw='0~11', gaintype='G', minsnr=2.0,
00584 refant='ANT5', gaincurve=False, opacity=0.0,
00585 solint='inf', combine='spw')
00586
00587 if benchmarking:
00588 gaincal2time=time.time()
00589
00590
00591
00592
00593
00594
00595 print '--Fluxscale--'
00596 default('fluxscale')
00597
00598 print ''
00599 print 'Transferring flux of 3C273 to sources: 1310+323'
00600 print 'Output table ngc4826.tutorial.16apr98.fcal'
00601
00602 fluxscale(vis='ngc4826.tutorial.ms', caltable='ngc4826.tutorial.16apr98.gcal',
00603 fluxtable='ngc4826.tutorial.16apr98.fcal',
00604 reference='3C273', transfer=['1310+323'])
00605
00606
00607
00608 if benchmarking:
00609 fluxscale2time=time.time()
00610
00611
00612
00613
00614
00615 print '--Plotcal (fluxscale)--'
00616 default(plotcal)
00617
00618 if scriptmode:
00619
00620 plotcal(caltable='ngc4826.tutorial.16apr98.fcal', yaxis='amp', field='')
00621 print ''
00622 print 'Plotting final scaled gain calibration table'
00623 print 'First amp vs. time for all fields '
00624
00625
00626 user_check=raw_input('Return to continue script\n')
00627
00628 plotcal(caltable='ngc4826.tutorial.16apr98.fcal', yaxis='phase', field='')
00629 print ''
00630 print 'and phase vs. time '
00631
00632
00633 user_check=raw_input('Return to continue script\n')
00634
00635
00636 plotcal(caltable='ngc4826.tutorial.16apr98.fcal', yaxis='snr', field='')
00637 else:
00638
00639 plotcal(caltable='ngc4826.tutorial.16apr98.fcal',yaxis='amp',field='',
00640 showgui=False,figfile='ngc4826.tutorial.16apr98.fcal.plotcal.amp.png')
00641 plotcal(caltable='ngc4826.tutorial.16apr98.fcal',yaxis='phase',field='',
00642 showgui=False,figfile='ngc4826.tutorial.16apr98.fcal.plotcal.phase.png')
00643 plotcal(caltable='ngc4826.tutorial.16apr98.fcal',yaxis='snr',field='',
00644 showgui=False,figfile='ngc4826.tutorial.16apr98.fcal.plotcal.snr.png')
00645
00646 if benchmarking:
00647 plotcal2time=time.time()
00648
00649
00650
00651
00652
00653
00654
00655 print '--Applycal--'
00656 default('applycal')
00657
00658 print 'Applying calibration table ngc4826.tutorial.16apr98.fcal to data'
00659
00660 applycal(vis='ngc4826.tutorial.ms',
00661 field='', spw='',
00662 gaincurve=False, opacity=0.0,
00663 gaintable='ngc4826.tutorial.16apr98.fcal',
00664 spwmap=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0])
00665
00666 if benchmarking:
00667 correct2time=time.time()
00668
00669
00670
00671
00672
00673
00674
00675
00676
00677
00678
00679
00680
00681
00682
00683
00684
00685
00686
00687
00688
00689
00690
00691
00692
00693
00694
00695
00696
00697
00698
00699
00700
00701
00702
00703
00704
00705
00706
00707
00708
00709
00710
00711
00712
00713
00714
00715
00716
00717
00718
00719
00720
00721
00722
00723
00724
00725
00726
00727
00728
00729
00730
00731
00732
00733
00734
00735
00736
00737
00738
00739
00740
00741
00742
00743 print "Done calibration and plotting"
00744
00745
00746
00747
00748
00749
00750
00751
00752
00753
00754
00755 print '--Split--'
00756 default('split')
00757
00758 print 'Splitting 3C273 data to ngc4826.tutorial.16apr98.3C273.split.ms'
00759
00760 split(vis='ngc4826.tutorial.ms',
00761 outputvis='ngc4826.tutorial.16apr98.3C273.split.ms',
00762 field='0',spw='0~3:0~63', datacolumn='corrected')
00763
00764 print 'Splitting 1310+323 data to ngc4826.tutorial.16apr98.1310+323.split.ms'
00765
00766 split(vis='ngc4826.tutorial.ms',
00767 outputvis='ngc4826.tutorial.16apr98.1310+323.split.ms',
00768 field='1', spw='4~11:0~31', datacolumn='corrected')
00769
00770 print 'Splitting NGC4826 data to ngc4826.tutorial.16apr98.src.split.ms'
00771
00772 split(vis='ngc4826.tutorial.ms',
00773 outputvis='ngc4826.tutorial.16apr98.src.split.ms',
00774 field='2~8', spw='12~15:0~63',
00775 datacolumn='corrected')
00776
00777 if benchmarking:
00778 split2time=time.time()
00779
00780
00781
00782
00783
00784
00785
00786
00787
00788
00789
00790
00791
00792
00793
00794
00795
00796
00797
00798
00799
00800
00801
00802
00803
00804
00805
00806
00807
00808
00809
00810
00811
00812
00813
00814
00815
00816
00817
00818
00819
00820
00821
00822
00823
00824
00825
00826
00827
00828
00829
00830
00831
00832
00833
00834
00835
00836
00837
00838
00839
00840
00841
00842
00843
00844 print '--Clean (NGC4826)--'
00845 default('clean')
00846
00847
00848 clnsize = 400
00849 print " Creating CLEAN image of size "+str(clnsize)
00850
00851 clean(vis='ngc4826.tutorial.16apr98.src.split.ms',
00852 imagename='ngc4826.tutorial.16apr98.src.clean',
00853 field='0~6',spw='0~3',
00854 cell=[1.,1.],imsize=[clnsize,clnsize],
00855 stokes='I',
00856 mode='channel',nchan=36,start=34,width=4,
00857 interpolation='nearest',
00858 psfmode='clark',imagermode='mosaic',ftmachine='mosaic',
00859 scaletype='SAULT',
00860
00861
00862
00863 cyclefactor=4,niter=10000,threshold='45mJy',
00864 minpb=0.3,pbcor=False, usescratch=False)
00865
00866
00867
00868
00869
00870
00871
00872
00873
00874
00875
00876
00877
00878
00879
00880
00881
00882
00883
00884
00885
00886
00887
00888
00889 if benchmarking:
00890 clean2time=time.time()
00891
00892
00893
00894
00895
00896 print '--Viewer--'
00897 if scriptmode:
00898 viewer('ngc4826.tutorial.16apr98.src.clean.image')
00899
00900 print ""
00901 print "This is the non-pbcorrected cube of NGC4826"
00902 print "Use tape deck to move through channels"
00903 print "Close the viewer when done"
00904 print ""
00905
00906
00907 user_check=raw_input('Return to continue script\n')
00908
00909
00910
00911
00912
00913
00914 print '--ImStat (Clean cube)--'
00915
00916 srcstat = imstat('ngc4826.tutorial.16apr98.src.clean.image')
00917
00918 print "Found image max = "+str(srcstat['max'][0])
00919
00920
00921
00922
00923
00924 refpix = int(clnsize/2)
00925 refbox = str(refpix)+','+str(refpix)+','+str(refpix)+','+str(refpix)
00926 print " Using Reference Pixel "+refbox
00927
00928
00929
00930
00931
00932 blcx = refpix - 22
00933 blcy = refpix + 33
00934 trcx = refpix + 25
00935 trcy = refpix + 72
00936 offbox = str(blcx)+','+str(blcy)+','+str(trcx)+','+str(trcy)
00937 print " Using Off-Source Box "+offbox
00938
00939 offstat = imstat('ngc4826.tutorial.16apr98.src.clean.image',
00940 box=offbox)
00941
00942 print "Found off-source image rms = "+str(offstat['sigma'][0])
00943
00944
00945
00946
00947
00948 blcx = refpix - 20
00949 blcy = refpix - 20
00950 trcx = refpix + 20
00951 trcy = refpix + 20
00952 cenbox = str(blcx)+','+str(blcy)+','+str(trcx)+','+str(trcy)
00953 print " Using On-Source Box "+cenbox
00954
00955
00956
00957 offlinestat = imstat('ngc4826.tutorial.16apr98.src.clean.image',
00958 box=cenbox,
00959 chans='0,1,2,3,4,5,30,31,32,33,34,35')
00960
00961 print "Found off-line image rms = "+str(offlinestat['sigma'][0])
00962
00963
00964
00965
00966
00967
00968 print '--ImStat (Clean model)--'
00969
00970 modstat = imstat('ngc4826.tutorial.16apr98.src.clean.model')
00971
00972 print "Found total model flux = "+str(modstat['sum'][0])
00973
00974
00975
00976
00977
00978
00979 print '--ImMath (PBcor)--'
00980
00981 immath(outfile='ngc4826.tutorial.16apr98.src.clean.pbcor',
00982 mode='evalexpr',
00983 expr="'ngc4826.tutorial.16apr98.src.clean.image'/'ngc4826.tutorial.16apr98.src.clean.flux'")
00984
00985
00986
00987 immath(outfile='ngc4826.tutorial.16apr98.src.clean.pbcormod',
00988 mode='evalexpr',
00989 expr="'ngc4826.tutorial.16apr98.src.clean.model'['ngc4826.tutorial.16apr98.src.clean.model'!=0.0]/'ngc4826.tutorial.16apr98.src.clean.flux'")
00990
00991
00992
00993
00994
00995
00996
00997 print '--ImStat (PBcor cube)--'
00998
00999 pbcorstat = imstat('ngc4826.tutorial.16apr98.src.clean.pbcor')
01000
01001 print "Found image max = "+str(pbcorstat['max'][0])
01002
01003 pbcoroffstat = imstat('ngc4826.tutorial.16apr98.src.clean.pbcor',
01004 box=offbox)
01005
01006 print "Found off-source image rms = "+str(pbcoroffstat['sigma'][0])
01007
01008 pbcorofflinestat = imstat('ngc4826.tutorial.16apr98.src.clean.pbcor',
01009 box=cenbox,
01010 chans='0,1,2,3,4,5,30,31,32,33,34,35')
01011
01012 print "Found off-line image rms = "+str(pbcorofflinestat['sigma'][0])
01013
01014
01015
01016
01017 print '--ImStat (PSF)--'
01018
01019 psfstat = imstat('ngc4826.tutorial.16apr98.src.clean.psf',
01020 box=refbox,chans='27')
01021
01022 print "Found PSF value at refpix = "+str(psfstat['mean'][0])+" (should be 1.0)"
01023
01024 if benchmarking:
01025 math2time=time.time()
01026
01027
01028
01029
01030 print '--ImStat (PBcor model)--'
01031
01032 pbcormodstat = imstat('ngc4826.tutorial.16apr98.src.clean.pbcormod')
01033
01034 print "Found total model flux = "+str(pbcormodstat['sum'][0])
01035
01036
01037
01038
01039
01040
01041
01042
01043
01044
01045
01046 print '--ImMoments--'
01047 default('immoments')
01048
01049 momfile = 'ngc4826.tutorial.16apr98.moments'
01050 momzeroimage = 'ngc4826.tutorial.16apr98.moments.integrated'
01051 momoneimage = 'ngc4826.tutorial.16apr98.moments.mom1'
01052
01053 print "Calculating Moments 0,1 for PBcor image"
01054
01055
01056
01057
01058 immoments(imagename='ngc4826.tutorial.16apr98.src.clean.pbcor',
01059 moments=[0],
01060 chans='6~27',
01061 outfile='ngc4826.tutorial.16apr98.moments.integrated')
01062
01063
01064
01065
01066
01067
01068
01069
01070
01071
01072
01073
01074
01075
01076 immoments(imagename='ngc4826.tutorial.16apr98.src.clean.image',
01077 moments=[1],includepix=[0.2,1000.0],
01078 chans='6~27',
01079 outfile='ngc4826.tutorial.16apr98.moments.mom1')
01080
01081
01082 if scriptmode:
01083 viewer('ngc4826.tutorial.16apr98.moments.integrated')
01084
01085 print "Now viewing Moment-0 ngc4826.tutorial.16apr98.moments.integrated"
01086 print "Note PBCOR effects at field edge"
01087 print "Change the colorscale to get better image"
01088 print "You can also Open and overlay Contours of Moment-1 ngc4826.tutorial.16apr98.moments.mom1"
01089 print "Close the viewer when done"
01090
01091
01092 user_check=raw_input('Return to continue script\n')
01093
01094
01095
01096 try:
01097 immoments(imagename='ngc4826.tutorial.16apr98.src.clean.image',
01098 moments=[1],includepix=[],
01099 chans='0',
01100 outfile='ngc4826.tutorial.16apr98.moments.plane0.mom1')
01101 except:
01102 pass
01103
01104
01105 try:
01106 immoments(imagename='ngc4826.tutorial.16apr98.src.clean.image',
01107 moments=[1],includepix=[],
01108 chans='35',
01109 outfile='ngc4826.tutorial.16apr98.moments.plane35.mom1')
01110 except:
01111 pass
01112
01113 if benchmarking:
01114 moments2time=time.time()
01115
01116
01117
01118
01119
01120
01121 print '--ImStat (Moment images)--'
01122
01123 momzerostat=imstat('ngc4826.tutorial.16apr98.moments.integrated')
01124
01125 try:
01126 print "Found moment 0 max = "+str(momzerostat['max'][0])
01127 print "Found moment 0 rms = "+str(momzerostat['rms'][0])
01128 except:
01129 pass
01130
01131 momonestat = imstat('ngc4826.tutorial.16apr98.moments.mom1')
01132
01133 try:
01134 print "Found moment 1 median = "+str(momonestat['median'][0])
01135 except:
01136 pass
01137
01138
01139
01140 ia.open('ngc4826.tutorial.16apr98.src.clean.image')
01141 csys=ia.coordsys()
01142 vel0=0.0
01143 vel35=0.0
01144
01145 try:
01146 momoneplane0=imstat('ngc4826.tutorial.16apr98.moments.plane0.mom1')
01147 print "Found plane 0 moment 1 value = "+str(momoneplane0['median'][0])
01148 except:
01149 pass
01150
01151
01152 try:
01153 momoneplane35=imstat('ngc4826.tutorial.16apr98.moments.plane35.mom1')
01154 print "Found plane 35 moment 1 value = "+str(momoneplane35['median'][0])
01155 except:
01156 pass
01157
01158 if(type(momoneplane0)==bool):
01159 vel0=csys.frequencytovelocity(ia.toworld([0,0,0,0])['numeric'][3])
01160 if(type(momoneplane35)==bool):
01161 vel35=csys.frequencytovelocity(ia.toworld([0,0,0,35])['numeric'][3])
01162
01163
01164
01165
01166
01167
01168
01169 ms.open('ngc4826.tutorial.16apr98.1310+323.split.ms')
01170 vismean_cal=pl.mean(ms.range(["amplitude"]).get("amplitude"))
01171 ms.close()
01172 ms.open('ngc4826.tutorial.16apr98.src.split.ms')
01173 vismean_src=pl.mean(ms.range(["amplitude"]).get("amplitude"))
01174 ms.close()
01175
01176
01177
01178
01179
01180
01181
01182
01183
01184
01185
01186
01187
01188
01189
01190
01191
01192
01193
01194
01195
01196
01197
01198
01199
01200
01201
01202
01203
01204
01205
01206
01207
01208
01209
01210
01211
01212
01213
01214
01215
01216
01217
01218
01219
01220
01221
01222
01223
01224
01225
01226
01227
01228
01229
01230
01231
01232
01233
01234
01235
01236
01237
01238
01239
01240
01241
01242
01243
01244
01245
01246
01247
01248
01249
01250 if benchmarking:
01251 endProc=time.clock()
01252 endTime=time.time()
01253
01254
01255
01256
01257
01258
01259
01260
01261
01262
01263
01264
01265
01266
01267
01268
01269
01270
01271
01272
01273
01274
01275
01276
01277
01278
01279
01280
01281
01282
01283
01284
01285
01286
01287
01288
01289
01290
01291
01292
01293
01294
01295
01296
01297
01298
01299
01300
01301
01302
01303
01304
01305
01306
01307
01308
01309
01310
01311
01312
01313
01314
01315
01316
01317
01318
01319
01320
01321
01322
01323
01324
01325
01326
01327
01328
01329
01330
01331
01332
01333
01334
01335
01336
01337
01338
01339
01340
01341
01342
01343
01344
01345
01346
01347
01348
01349
01350
01351
01352
01353
01354
01355
01356
01357
01358
01359
01360
01361
01362
01363
01364
01365
01366
01367
01368
01369
01370
01371
01372
01373
01374
01375
01376
01377
01378
01379
01380
01381
01382
01383
01384
01385
01386
01387
01388
01389
01390
01391
01392
01393
01394
01395
01396
01397
01398
01399
01400
01401
01402
01403
01404
01405
01406
01407
01408
01409
01410
01411
01412
01413
01414
01415
01416 testdate = '2010-04-29 (RR)'
01417 testvers = 'CASA Version 3.0.2 (build #11306)'
01418 clean_image_max = 1.615747
01419 clean_offsrc_rms = 0.058497
01420 clean_offline_rms = 0.055416
01421 clean_momentzero_max = 165.74
01422 clean_momentzero_rms = 14.234
01423
01424
01425
01426 clean_momentone_median = 422.92
01427 clean_momentone_planezero = 696.702393
01428 clean_momentone_planelast = 127.786629
01429 vis_mean_cal = 195.0509
01430 vis_mean_src = 54.665
01431 model_sum = 71.349
01432 model_pbcor_sum = 75.92
01433
01434
01435
01436
01437
01438
01439 clean_offsrc_rms = 0.0604
01440 clean_offline_rms = 0.0625
01441 clean_momentzero_rms = 14.05
01442
01443 clean_momentone_median = 435.368103
01444
01445 model_pbcor_sum = 72.72
01446
01447
01448
01449
01450
01451
01452
01453
01454
01455
01456
01457
01458 clean_image_max = 1.4647
01459 clean_momentone_median = 424.40
01460 clean_momentone_planezero = 690.6068
01461 clean_momentone_planelast = 121.6911
01462
01463 canonical = {}
01464 canonical['exist'] = True
01465
01466 canonical['date'] = testdate
01467 canonical['version'] = testvers
01468 canonical['user'] = 'smyers'
01469 canonical['host'] = 'sandrock'
01470 canonical['cwd'] = '/home/sandrock/smyers/Testing/Patch4/N4826'
01471 print "Using internal regression from "+canonical['version']+" on "+canonical['date']
01472
01473 canonical_results = {}
01474 canonical_results['clean_image_max'] = {}
01475 canonical_results['clean_image_max']['value'] = clean_image_max
01476 canonical_results['clean_image_offsrc_max'] = {}
01477 canonical_results['clean_image_offsrc_max']['value'] = clean_offsrc_rms
01478 canonical_results['clean_image_offline_max'] = {}
01479 canonical_results['clean_image_offline_max']['value'] = clean_offline_rms
01480 canonical_results['clean_momentzero_max'] = {}
01481 canonical_results['clean_momentzero_max']['value'] = clean_momentzero_max
01482 canonical_results['clean_momentzero_rms'] = {}
01483 canonical_results['clean_momentzero_rms']['value'] = clean_momentzero_rms
01484
01485 canonical_results['clean_momentone_median'] = {}
01486 canonical_results['clean_momentone_median']['value'] = clean_momentone_median
01487
01488 canonical_results['clean_momentone_planezero'] = {}
01489 canonical_results['clean_momentone_planezero']['value'] = clean_momentone_planezero
01490 canonical_results['clean_momentone_planelast'] = {}
01491 canonical_results['clean_momentone_planelast']['value'] = clean_momentone_planelast
01492 canonical_results['clean_psfcenter'] = {}
01493 canonical_results['clean_psfcenter']['value'] = 1.0
01494
01495
01496 canonical_results['vis_mean_cal'] = {}
01497 canonical_results['vis_mean_cal']['value'] = vis_mean_cal
01498 canonical_results['vis_mean_src'] = {}
01499 canonical_results['vis_mean_src']['value'] = vis_mean_src
01500
01501
01502 canonical_results['model_sum'] = {}
01503 canonical_results['model_sum']['value'] = model_sum
01504 canonical_results['model_pbcor_sum'] = {}
01505 canonical_results['model_pbcor_sum']['value'] = model_pbcor_sum
01506
01507 canonical['results'] = canonical_results
01508
01509 print "Canonical Regression (default) from "+canonical['date']
01510
01511
01512
01513
01514 regression = {}
01515 regressfile = scriptprefix + '.pickle'
01516 prev_results = {}
01517
01518 try:
01519 fr = open(regressfile,'r')
01520 except:
01521 print "No previous regression results file "+regressfile
01522 regression['exist'] = False
01523 else:
01524 u = pickle.Unpickler(fr)
01525 regression = u.load()
01526 fr.close()
01527 print "Regression results filled from "+regressfile
01528 print "Regression from version "+regression['version']+" on "+regression['date']
01529 regression['exist'] = True
01530
01531 prev_results = regression['results']
01532
01533
01534
01535
01536
01537
01538 print '--Calculate Results--'
01539 print ''
01540
01541
01542
01543 try:
01544 srcmax = srcstat['max'][0]
01545 except:
01546 srcmax = 0.0
01547
01548 try:
01549 offrms = offstat['sigma'][0]
01550 except:
01551 offrms = 0.0
01552
01553 try:
01554 offlinerms = offlinestat['sigma'][0]
01555 except:
01556 offlinerms = 0.0
01557
01558 try:
01559 momzero_max = momzerostat['max'][0]
01560 except:
01561 momzero_max = 0.0
01562
01563 try:
01564 momzero_rms = momzerostat['rms'][0]
01565 except:
01566 momzero_rms = 0.0
01567
01568 try:
01569 momone_median = momonestat['median'][0]
01570 except:
01571 momone_median = 0.0
01572
01573
01574
01575
01576 try:
01577 momone_plane0 = momoneplane0['median'][0]
01578 except:
01579 momone_plane0 = vel0
01580
01581 try:
01582 momone_plane35 = momoneplane35['median'][0]
01583 except:
01584 momone_plane35 = vel35
01585
01586 try:
01587 psfcenter = psfstat['mean'][0]
01588 except:
01589 psfcenter = 0.0
01590
01591
01592
01593
01594 try:
01595 modflux = modstat['sum'][0]
01596 except:
01597 modflux = 0.0
01598
01599 try:
01600 pbcormodflux = pbcormodstat['sum'][0]
01601 except:
01602 pbcormodflux = 0.0
01603
01604
01605
01606
01607 new_regression = {}
01608
01609
01610 import datetime
01611 datestring=datetime.datetime.isoformat(datetime.datetime.today())
01612
01613
01614 myvers = casalog.version()
01615 try:
01616 myuser = os.getlogin()
01617 except:
01618 myuser = os.getenv('USER')
01619
01620 myuname = os.uname()
01621 myhost = myuname[1]
01622 myos = myuname[0]+' '+myuname[2]+' '+myuname[4]
01623 mycwd = os.getcwd()
01624 mypath = os.environ.get('CASAPATH')
01625
01626 mydataset = 'NGC4826 16apr98 BIMA'
01627
01628
01629 new_regression['date'] = datestring
01630 new_regression['version'] = myvers
01631 new_regression['user'] = myuser
01632 new_regression['host'] = myhost
01633 new_regression['cwd'] = mycwd
01634 new_regression['os'] = myos
01635 new_regression['uname'] = myuname
01636 new_regression['aipspath'] = mypath
01637
01638 new_regression['dataset'] = mydataset
01639
01640
01641
01642
01643
01644
01645 results = {}
01646
01647 op = 'divf'
01648 tol = 0.08
01649 results['clean_image_max'] = {}
01650 results['clean_image_max']['name'] = 'Clean image max'
01651 results['clean_image_max']['value'] = srcmax
01652 results['clean_image_max']['op'] = op
01653 results['clean_image_max']['tol'] = tol
01654
01655 results['clean_image_offsrc_max'] = {}
01656 results['clean_image_offsrc_max']['name'] = 'Clean image off-src rms'
01657 results['clean_image_offsrc_max']['value'] = offrms
01658 results['clean_image_offsrc_max']['op'] = op
01659 results['clean_image_offsrc_max']['tol'] = tol
01660
01661 results['clean_image_offline_max'] = {}
01662 results['clean_image_offline_max']['name'] = 'Clean image off-line rms'
01663 results['clean_image_offline_max']['value'] = offlinerms
01664 results['clean_image_offline_max']['op'] = op
01665 results['clean_image_offline_max']['tol'] = tol
01666
01667 results['clean_momentzero_max'] = {}
01668 results['clean_momentzero_max']['name'] = 'Moment 0 image max'
01669 results['clean_momentzero_max']['value'] = momzero_max
01670 results['clean_momentzero_max']['op'] = op
01671 results['clean_momentzero_max']['tol'] = tol
01672
01673 results['clean_momentzero_rms'] = {}
01674 results['clean_momentzero_rms']['name'] = 'Moment 0 image rms'
01675 results['clean_momentzero_rms']['value'] = momzero_rms
01676 results['clean_momentzero_rms']['op'] = op
01677 results['clean_momentzero_rms']['tol'] = tol
01678
01679 op = 'diff'
01680 tol = 0.1
01681 results['clean_momentone_median'] = {}
01682 results['clean_momentone_median']['name'] = 'Moment 1 image median'
01683 results['clean_momentone_median']['value'] = momone_median
01684 results['clean_momentone_median']['op'] = op
01685 results['clean_momentone_median']['tol'] = 3.0
01686
01687
01688
01689
01690 results['clean_momentone_planezero'] = {}
01691 results['clean_momentone_planezero']['name'] = 'Moment 1 plane 0'
01692 results['clean_momentone_planezero']['value'] = momone_plane0
01693 results['clean_momentone_planezero']['op'] = op
01694 results['clean_momentone_planezero']['tol'] = tol
01695
01696 results['clean_momentone_planelast'] = {}
01697 results['clean_momentone_planelast']['name'] = 'Moment 1 plane 35'
01698 results['clean_momentone_planelast']['value'] = momone_plane35
01699 results['clean_momentone_planelast']['op'] = op
01700 results['clean_momentone_planelast']['tol'] = tol
01701
01702 tol = 0.01
01703 results['clean_psfcenter'] = {}
01704 results['clean_psfcenter']['name'] = 'PSF CH27 at RefPix'
01705 results['clean_psfcenter']['value'] = psfcenter
01706 results['clean_psfcenter']['op'] = op
01707 results['clean_psfcenter']['tol'] = tol
01708
01709
01710 op = 'divf'
01711 tol = 0.08
01712 results['vis_mean_cal'] = {}
01713 results['vis_mean_cal']['name'] = 'Vis mean of cal'
01714 results['vis_mean_cal']['value'] = vismean_cal
01715 results['vis_mean_cal']['op'] = op
01716 results['vis_mean_cal']['tol'] = tol
01717
01718 results['vis_mean_src'] = {}
01719 results['vis_mean_src']['name'] = 'Vis mean of src'
01720 results['vis_mean_src']['value'] = vismean_src
01721 results['vis_mean_src']['op'] = op
01722 results['vis_mean_src']['tol'] = tol
01723
01724
01725
01726 results['model_sum'] = {}
01727 results['model_sum']['name'] = 'Model image sum'
01728 results['model_sum']['value'] = modflux
01729 results['model_sum']['op'] = op
01730 results['model_sum']['tol'] = tol
01731
01732 results['model_pbcor_sum'] = {}
01733 results['model_pbcor_sum']['name'] = 'PBcor Model image sum'
01734 results['model_pbcor_sum']['value'] = pbcormodflux
01735 results['model_pbcor_sum']['op'] = op
01736 results['model_pbcor_sum']['tol'] = tol
01737
01738
01739 resultlist = ['clean_image_max','clean_image_offsrc_max','clean_image_offline_max',
01740 'clean_momentzero_max','clean_momentzero_rms','clean_momentone_median',
01741 'clean_momentone_planezero','clean_momentone_planelast','clean_psfcenter',
01742 'vis_mean_cal','vis_mean_src','model_sum','model_pbcor_sum']
01743
01744 for keys in resultlist:
01745 res = results[keys]
01746 prev = None
01747 if prev_results.has_key(keys):
01748
01749 prev = prev_results[keys]
01750 results[keys]['test'] = 'Last'
01751 elif canonical_results.has_key(keys):
01752
01753 prev = canonical_results[keys]
01754 results[keys]['test'] = 'Canon'
01755 if prev:
01756 new_val = res['value']
01757 prev_val = prev['value']
01758 new_diff = new_val - prev_val
01759 if res['op'] == 'divf':
01760 new_diff /= prev_val
01761
01762 if abs(new_diff) > res['tol']:
01763 new_status = 'Failed'
01764 else:
01765 new_status = 'Passed'
01766
01767 results[keys]['prev'] = prev_val
01768 results[keys]['diff'] = new_diff
01769 results[keys]['status'] = new_status
01770 else:
01771
01772 results[keys]['prev'] = 0.0
01773 results[keys]['diff'] = 1.0
01774 results[keys]['status'] = 'Missed'
01775 results[keys]['test'] = 'none'
01776
01777
01778 new_regression['results'] = results
01779
01780
01781 datasize_raw = 96.0
01782 datasize_ms = 279.0
01783 new_regression['datasize'] = {}
01784 new_regression['datasize']['raw'] = datasize_raw
01785 new_regression['datasize']['ms'] = datasize_ms
01786
01787
01788
01789
01790 if benchmarking:
01791
01792 new_regression['timing'] = {}
01793
01794 total = {}
01795 total['wall'] = (endTime - startTime)
01796 total['cpu'] = (endProc - startProc)
01797 total['rate_raw'] = (datasize_raw/(endTime - startTime))
01798 total['rate_ms'] = (datasize_ms/(endTime - startTime))
01799
01800 new_regression['timing']['total'] = total
01801
01802 nstages = 15
01803 new_regression['timing']['nstages'] = nstages
01804
01805 stages = {}
01806 stages[0] = ['import',(import2time-startTime)]
01807 stages[1] = ['concat',(concat2time-import2time)]
01808 stages[2] = ['clearcal',(clearcal2time-concat2time)]
01809 stages[3] = ['listobs',(list2time-clearcal2time)]
01810 stages[4] = ['plotxy',(plotxy2time-list2time)]
01811 stages[5] = ['tflagdata',(flag2time-plotxy2time)]
01812 stages[6] = ['setjy',(setjy2time-flag2time)]
01813 stages[7] = ['gaincal',(gaincal2time-setjy2time)]
01814 stages[8] = ['fluxscale',(fluxscale2time-gaincal2time)]
01815 stages[9] = ['plotcal',(plotcal2time-fluxscale2time)]
01816 stages[10] = ['applycal',(correct2time-plotcal2time)]
01817 stages[11] = ['split',(split2time-correct2time)]
01818 stages[12] = ['clean',(clean2time-split2time)]
01819 stages[13] = ['math/stat',(math2time-clean2time)]
01820 stages[14] = ['moments',(moments2time-math2time)]
01821
01822 new_regression['timing']['stages'] = stages
01823
01824
01825
01826
01827
01828
01829 pickfile = 'out.'+prefix + '.regression.'+datestring+'.pickle'
01830 f = open(pickfile,'w')
01831 p = pickle.Pickler(f)
01832 p.dump(new_regression)
01833 f.close()
01834
01835 print ""
01836 print "Regression result dictionary saved in "+pickfile
01837 print ""
01838 print "Use Pickle to retrieve these"
01839 print ""
01840
01841
01842
01843
01844
01845
01846
01847
01848
01849
01850
01851
01852
01853
01854
01855
01856
01857 outfile='out.'+prefix+'.'+datestring+'.log'
01858 logfile=open(outfile,'w')
01859
01860
01861 print >>logfile,'Running '+myvers+' on host '+myhost
01862 print >>logfile,'at '+datestring
01863 print >>logfile,''
01864
01865
01866
01867
01868 print ' NGC4826 Image Cube Max = '+str(srcstat['max'][0])
01869 print " At ("+str(srcstat['maxpos'][0])+","+str(srcstat['maxpos'][1])+") Channel "+str(srcstat['maxpos'][3])
01870 print ' '+srcstat['maxposf']
01871 print ''
01872 print ' Off-Source Rms = '+str(offstat['sigma'][0])
01873 print ' Signal-to-Noise ratio = '+str(srcstat['max'][0]/offstat['sigma'][0])
01874 print ''
01875 print ' Off-Line Rms = '+str(offlinestat['sigma'][0])
01876 print ' Signal-to-Noise ratio = '+str(srcstat['max'][0]/offlinestat['sigma'][0])
01877 print ''
01878
01879 print >>logfile,' NGC4826 Image Cube Max = '+str(srcstat['max'][0])
01880 print >>logfile," At ("+str(srcstat['maxpos'][0])+","+str(srcstat['maxpos'][1])+") Channel "+str(srcstat['maxpos'][3])
01881 print >>logfile,' '+srcstat['maxposf']
01882 print >>logfile,''
01883 print >>logfile,' Off-Source Rms = '+str(offstat['sigma'][0])
01884 print >>logfile,' Signal-to-Noise ratio = '+str(srcstat['max'][0]/offstat['sigma'][0])
01885 print >>logfile,''
01886 print >>logfile,' Off-Line Rms = '+str(offlinestat['sigma'][0])
01887 print >>logfile,' Signal-to-Noise ratio = '+str(srcstat['max'][0]/offlinestat['sigma'][0])
01888 print >>logfile,''
01889
01890
01891 res = {}
01892 resultlist = ['clean_image_max','clean_image_offsrc_max','clean_image_offline_max',
01893 'clean_momentzero_max','clean_momentzero_rms','clean_momentone_median',
01894 'clean_momentone_planezero','clean_momentone_planelast','clean_psfcenter',
01895 'vis_mean_cal','vis_mean_src','model_sum','model_pbcor_sum']
01896
01897
01898 print >>logfile,'---'
01899 print >>logfile,'Regression versus previous values:'
01900 print >>logfile,'---'
01901 print '---'
01902 print 'Regression versus previous values:'
01903 print '---'
01904
01905 if regression['exist']:
01906 print >>logfile," Regression results filled from "+regressfile
01907 print >>logfile," Regression from version "+regression['version']+" on "+regression['date']
01908 print >>logfile," Regression platform "+regression['host']
01909
01910 print " Regression results filled from "+regressfile
01911 print " Regression from version "+regression['version']+" on "+regression['date']
01912 print " Regression platform "+regression['host']
01913 if regression.has_key('aipspath'):
01914 print >>logfile," Regression casapath "+regression['aipspath']
01915 print " Regression casapath "+regression['aipspath']
01916
01917 else:
01918 print >>logfile," No previous regression file"
01919
01920 print ""
01921 print >>logfile,""
01922
01923 final_status = 'Passed'
01924 for keys in resultlist:
01925 res = results[keys]
01926 print '--%30s : %12.6f was %12.6f %4s %12.6f (%6s) %s ' % ( res['name'], res['value'], res['prev'], res['op'], res['diff'], res['status'], res['test'] )
01927 print >>logfile,'--%30s : %12.6f was %12.6f %4s %12.6f (%6s) %s ' % ( res['name'], res['value'], res['prev'], res['op'], res['diff'], res['status'], res['test'] )
01928 if res['status']=='Failed':
01929 final_status = 'Failed'
01930
01931 if (final_status == 'Passed'):
01932 regstate=True
01933 print >>logfile,'---'
01934 print >>logfile,'Passed Regression test for NGC 4826 Mosaic'
01935 print >>logfile,'---'
01936 print 'Passed Regression test for NGC 4826 Mosaic'
01937 print ''
01938 print 'Regression PASSED'
01939 print ''
01940 else:
01941 regstate=False
01942 print >>logfile,'----FAILED Regression test for NGC 4826 Mosaic'
01943 print '----FAILED Regression test for NGC 4826 Mosaic'
01944 print ''
01945 print 'Regression FAILED'
01946 print ''
01947
01948
01949
01950
01951
01952 if benchmarking:
01953 print ''
01954 print 'Total wall clock time was: %10.3f ' % total['wall']
01955 print 'Total CPU time was: %10.3f ' % total['cpu']
01956 print 'Raw processing rate MB/s was: %8.1f ' % total['rate_raw']
01957 print 'MS processing rate MB/s was: %8.1f ' % total['rate_ms']
01958 print ''
01959 print '* Breakdown: *'
01960
01961 print >>logfile,''
01962 print >>logfile,'********* Benchmarking *************************'
01963 print >>logfile,'* *'
01964 print >>logfile,'Total wall clock time was: %10.3f ' % total['wall']
01965 print >>logfile,'Total CPU time was: %10.3f ' % total['cpu']
01966 print >>logfile,'Raw processing rate MB/s was: %8.1f ' % total['rate_raw']
01967 print >>logfile,'MS processing rate MB/s was: %8.1f ' % total['rate_ms']
01968 print >>logfile,'* Breakdown: *'
01969
01970 for i in range(nstages):
01971 print '* %16s * time was: %10.3f ' % tuple(stages[i])
01972 print >>logfile,'* %16s * time was: %10.3f ' % tuple(stages[i])
01973
01974 print >>logfile,'************************************************'
01975 print >>logfile,'sandrock (2008-06-17) wall time was: 377 seconds'
01976 print >>logfile,'sandrock (2008-06-17) CPU time was: 312 seconds'
01977
01978 logfile.close()
01979
01980 print "Done with NGC4826 Tutorial Regression"
01981
01982