00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 import time
00021 import os
00022
00023
00024
00025
00026
00027
00028
00029 scriptmode = True
00030
00031
00032
00033
00034
00035
00036
00037
00038 prefix='jupiter6cm.demo'
00039
00040
00041 os.system('rm -rf '+prefix+'*')
00042
00043
00044 msfile = prefix + '.ms'
00045
00046
00047
00048
00049
00050
00051 calprefix = prefix
00052
00053
00054 usespw = ''
00055 usespwlist = ['0','1']
00056
00057
00058 usegaincurve = True
00059 gainopacity = 0.0
00060
00061
00062 calrefant = '11'
00063
00064 gtable = calprefix + '.gcal'
00065 ftable = calprefix + '.fluxscale'
00066 atable = calprefix + '.accum'
00067
00068
00069
00070
00071
00072 dopolcal = True
00073
00074 ptable = calprefix + '.pcal'
00075 xtable = calprefix + '.polx'
00076
00077
00078 poldfield = '0137+331'
00079
00080
00081 polxfield = '1331+305'
00082
00083
00084 polxfpol = 0.112
00085 polxrlpd_deg = 66.0
00086
00087 polxipol = {'0' : 7.462,
00088 '1' : 7.510}
00089
00090
00091 polxiquv = {}
00092 for spw in ['0','1']:
00093 ipol = polxipol[spw]
00094 fpol = polxfpol
00095 ppol = ipol*fpol
00096 rlpd = polxrlpd_deg*pi/180.0
00097 qpol = ppol*cos(rlpd)
00098 upol = ppol*sin(rlpd)
00099 polxiquv[spw] = [ipol,qpol,upol,0.0]
00100
00101
00102
00103
00104 srcname = 'JUPITER'
00105 srcsplitms = calprefix + '.' + srcname + '.split.ms'
00106 calname = '0137+331'
00107 calsplitms = calprefix + '.' + calname + '.split.ms'
00108
00109
00110
00111
00112
00113
00114
00115
00116 imprefix = prefix
00117
00118
00119
00120
00121
00122
00123
00124
00125
00126 clncell = [4.,4.]
00127
00128
00129
00130 clnalg = 'clark'
00131 clnmode = ''
00132
00133 clnmode = 'csclean'
00134 clnimsize = [288,288]
00135
00136
00137 clniter = 10000
00138
00139
00140
00141
00142
00143
00144 clnthreshold=0.05
00145
00146
00147
00148
00149 imname1 = imprefix + '.clean1'
00150 clnimage1 = imname1+'.image'
00151 clnmodel1 = imname1+'.model'
00152 clnresid1 = imname1+'.residual'
00153 clnmask1 = imname1+'.clean_interactive.mask'
00154
00155 imname2 = imprefix + '.clean2'
00156 clnimage2 = imname2+'.image'
00157 clnmodel2 = imname2+'.model'
00158 clnresid2 = imname2+'.residual'
00159 clnmask2 = imname2+'.clean_interactive.mask'
00160
00161 imname3 = imprefix + '.clean3'
00162 clnimage3 = imname3+'.image'
00163 clnmodel3 = imname3+'.model'
00164 clnresid3 = imname3+'.residual'
00165 clnmask3 = imname3+'.clean_interactive.mask'
00166
00167
00168
00169
00170
00171 calrefant = '11'
00172
00173
00174
00175
00176 selfcaltab1 = imprefix + '.selfcal1.gtable'
00177
00178 selfcaltab2 = imprefix + '.selfcal2.gtable'
00179 smoothcaltab2 = imprefix + '.smoothcal2.gtable'
00180
00181
00182
00183
00184
00185
00186
00187
00188 polprefix = prefix + '.polimg'
00189
00190
00191 polclnalg = 'hogbom'
00192 polclnmode = 'csclean'
00193
00194 polimname = polprefix + '.clean'
00195 polimage = polimname+'.image'
00196 polmodel = polimname+'.model'
00197 polresid = polimname+'.residual'
00198 polmask = polimname+'.clean_interactive.mask'
00199
00200
00201
00202
00203 ipolimage = polimage+'.I'
00204 qpolimage = polimage+'.Q'
00205 upolimage = polimage+'.U'
00206
00207 poliimage = polimage+'.poli'
00208 polaimage = polimage+'.pola'
00209
00210
00211
00212
00213
00214
00215
00216 pathname=os.environ.get('CASAPATH').split()[0]
00217
00218
00219
00220
00221
00222
00223
00224
00225
00226
00227
00228 fitsdata='planets_6cm.fits'
00229
00230
00231
00232
00233
00234
00235
00236
00237 print '--Import--'
00238
00239
00240 default('importuvfits')
00241
00242 print "Use importuvfits to read UVFITS and make an MS"
00243
00244
00245 msfile = prefix + '.ms'
00246
00247 print "MS will be called "+msfile
00248
00249
00250 fitsfile = fitsdata
00251 vis = msfile
00252 importuvfits()
00253
00254
00255
00256
00257
00258 print '--Listobs--'
00259
00260
00261
00262
00263 print "Use listobs to print verbose summary to logger"
00264
00265
00266
00267 verbose = True
00268
00269 listobs()
00270
00271
00272
00273
00274
00275
00276
00277
00278
00279
00280
00281
00282
00283
00284
00285
00286
00287
00288
00289
00290
00291
00292
00293
00294
00295
00296
00297
00298
00299
00300
00301
00302
00303
00304
00305
00306
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 print '--Plotxy--'
00459 default('plotxy')
00460
00461 print "Now we use plotxy to examine and interactively flag data"
00462
00463 vis = msfile
00464
00465
00466 selectdata = True
00467
00468
00469 field = '1331+305'
00470
00471
00472 correlation = 'RR LL'
00473
00474
00475 xaxis = 'uvdist'
00476 yaxis = 'amp'
00477 multicolor = 'both'
00478
00479
00480 selectplot = True
00481 title = field+" "
00482
00483 iteration = ''
00484
00485 plotxy()
00486
00487 print ""
00488 print "-----------------------------------------------------"
00489 print "Plotxy"
00490 print "Showing 1331+305 RR LL for all antennas"
00491 print "Use MarkRegion then draw boxes around points to flag"
00492 print "You can use ESC to drop last drawn box"
00493 print "When happy with boxes, hit Flag to flag"
00494 print "You can repeat as necessary"
00495
00496
00497 if scriptmode:
00498 user_check=raw_input('Return to continue script\n')
00499
00500
00501
00502
00503
00504 correlation = 'RL LR'
00505
00506 plotxy()
00507
00508 print ""
00509 print "-----------------------------------------------------"
00510 print "Looking at RL LR"
00511 print "Now flag the bad data here"
00512
00513
00514 if scriptmode:
00515 user_check=raw_input('Return to continue script\n')
00516
00517
00518
00519 field = '0137+331'
00520 correlation = 'RR LL'
00521 xaxis = 'uvdist'
00522 spw = ''
00523 iteration = ''
00524 antenna = ''
00525
00526 title = field+" "
00527
00528 plotxy()
00529
00530
00531
00532
00533
00534 print ""
00535 print "-----------------------------------------------------"
00536 print "Plotting 0137+331 RR LL all antennas"
00537 print "You see bad data along bottom"
00538 print "Mark a box around a bit of it and hit Locate"
00539 print "Look in logger to see what it is"
00540 print "You see much is Antenna 9 (ID=8) in spw 1"
00541
00542
00543 if scriptmode:
00544 user_check=raw_input('Return to continue script\n')
00545
00546 xaxis = 'time'
00547 spw = '1'
00548 correlation = ''
00549
00550
00551
00552
00553 antenna = '9'
00554
00555 plotxy()
00556
00557
00558
00559 print ""
00560 print "-----------------------------------------------------"
00561 print "Plotting vs. time antenna='9' and spw='1' "
00562 print "Box up last 4 scans which are bad and Flag"
00563
00564
00565 if scriptmode:
00566 user_check=raw_input('Return to continue script\n')
00567
00568
00569 xaxis = 'uvdist'
00570 spw = ''
00571 antenna = ''
00572 correlation = 'RR LL'
00573
00574 plotxy()
00575
00576
00577
00578
00579
00580 print ""
00581 print "-----------------------------------------------------"
00582 print "Back to all data"
00583 print "Clean up remaining bad points"
00584
00585
00586 if scriptmode:
00587 user_check=raw_input('Return to continue script\n')
00588
00589
00590
00591 field = 'JUPITER'
00592 correlation = 'RR LL'
00593 iteration = ''
00594 xaxis = 'uvdist'
00595
00596 title = field+" "
00597
00598 plotxy()
00599
00600
00601
00602
00603 print ""
00604 print "-----------------------------------------------------"
00605 print "Now plot JUPITER versus uvdist"
00606 print "Lots of bad stuff near bottom"
00607 print "Lets go and find it - try Locate"
00608 print "Looks like lots of different antennas but at same time"
00609
00610
00611 if scriptmode:
00612 user_check=raw_input('Return to continue script\n')
00613
00614 correlation = ''
00615 xaxis = 'time'
00616
00617 plotxy()
00618
00619
00620
00621
00622 print ""
00623 print "-----------------------------------------------------"
00624 print "Now plotting vs. time"
00625 print "See bad scan at end - flag it!"
00626
00627
00628 if scriptmode:
00629 user_check=raw_input('Return to continue script\n')
00630
00631
00632 correlation = 'RR LL'
00633 xaxis = 'uvdist'
00634 spw = '1'
00635 antenna = ''
00636 iteration = 'antenna'
00637
00638 plotxy()
00639
00640
00641
00642
00643
00644 print ""
00645 print "-----------------------------------------------------"
00646 print "Looking now at SPW 1"
00647 print "Now we set iteration to Antenna"
00648 print "Step through antennas with Next"
00649 print "See bad Antenna 9 (ID 8) as in 0137+331"
00650
00651
00652 if scriptmode:
00653 user_check=raw_input('Return to continue script\n')
00654
00655
00656
00657 antenna = '9'
00658 iteration = ''
00659 xaxis = 'time'
00660 correlation = ''
00661
00662 plotxy()
00663
00664
00665
00666 print ""
00667 print "-----------------------------------------------------"
00668 print "Now plotting vs. time antenna 9 spw 1"
00669 print "Box up the bad scans and Flag"
00670
00671
00672 if scriptmode:
00673 user_check=raw_input('Return to continue script\n')
00674
00675
00676 xaxis = 'uvdist'
00677 correlation = 'RR LL'
00678 antenna = ''
00679 spw = ''
00680
00681
00682
00683
00684
00685 plotxy()
00686
00687
00688
00689
00690
00691 print ""
00692 print "-----------------------------------------------------"
00693 print "Final cleanup of JUPITER data"
00694 print "Back to uvdist plot, see remaining bad data"
00695 print "You can draw little boxes around the outliers and Flag"
00696 print "Depends how patient you are in drawing boxes!"
00697 print "Could also use Locate to find where they come from"
00698
00699
00700 if scriptmode:
00701 user_check=raw_input('Return to continue script\n')
00702
00703 print "Done with plotxy!"
00704
00705
00706
00707
00708
00709
00710 print '--Flagmanager--'
00711 default('flagmanager')
00712
00713 print "Now will use flagmanager to save a copy of the flags we just made"
00714 print "These are named xyflags"
00715
00716 vis = msfile
00717 mode = 'save'
00718 versionname = 'xyflags'
00719 comment = 'Plotxy flags'
00720 merge = 'replace'
00721
00722 flagmanager()
00723
00724
00725
00726
00727
00728 print '--Flagmanager--'
00729 default('flagmanager')
00730
00731 print "Now will use flagmanager to list all the versions we saved"
00732
00733 vis = msfile
00734 mode = 'list'
00735
00736 flagmanager()
00737
00738
00739
00740 print '--Done with flagging--'
00741
00742
00743
00744
00745
00746
00747
00748
00749 print '--Setjy--'
00750 default('setjy')
00751
00752 print "Use setjy to set flux of 1331+305 (3C286)"
00753
00754 vis = msfile
00755
00756
00757
00758 field = '1331+305'
00759
00760
00761
00762 setjy()
00763
00764
00765
00766
00767
00768
00769
00770
00771 print "Look in logger for the fluxes (should be 7.462 and 7.510 Jy)"
00772
00773
00774
00775
00776
00777
00778 print '--Gaincal--'
00779 default('gaincal')
00780
00781 print "Solve for antenna gains on 1331+305 and 0137+331"
00782 print "We have 2 single-channel continuum spw"
00783 print "Do not want bandpass calibration"
00784
00785 vis = msfile
00786
00787
00788 caltable = gtable
00789
00790 print "Output gain cal table will be "+gtable
00791
00792
00793
00794
00795
00796 field = '1331+305,0137+331'
00797 spw = ''
00798
00799
00800 gaincurve = usegaincurve
00801 opacity = gainopacity
00802
00803
00804 gaintype = 'G'
00805 calmode = 'ap'
00806
00807
00808 solint = 'inf'
00809 combine = ''
00810
00811
00812 parang = False
00813
00814
00815 refant = calrefant
00816
00817
00818 minsnr = 3
00819
00820 gaincal()
00821
00822
00823
00824
00825
00826
00827 print '--Fluxscale--'
00828 default('fluxscale')
00829
00830 print "Use fluxscale to rescale gain table to make new one"
00831
00832 vis = msfile
00833
00834
00835 fluxtable = ftable
00836
00837 print "Output scaled gain cal table is "+ftable
00838
00839
00840 caltable = gtable
00841
00842
00843
00844 reference = '1331+305'
00845
00846
00847
00848 transfer = '0137+331'
00849
00850 fluxscale()
00851
00852
00853
00854
00855
00856
00857
00858
00859
00860
00861
00862 print '--PlotCal--'
00863 default('plotcal')
00864
00865 showgui = True
00866
00867 caltable = ftable
00868 multiplot = True
00869 yaxis = 'amp'
00870
00871 showgui = True
00872
00873 plotcal()
00874
00875 print ""
00876 print "-------------------------------------------------"
00877 print "Plotcal"
00878 print "Looking at amplitude in cal-table "+caltable
00879
00880
00881 if scriptmode:
00882 user_check=raw_input('Return to continue script\n')
00883
00884
00885
00886
00887 showgui = False
00888
00889 yaxis = 'amp'
00890
00891 figfile = caltable + '.plotcal.amp.png'
00892 print "Plotting calibration to file "+figfile
00893
00894 plotcal()
00895
00896 yaxis = 'phase'
00897
00898 figfile = caltable + '.plotcal.phase.png'
00899 print "Plotting calibration to file "+figfile
00900
00901 plotcal()
00902
00903
00904
00905
00906
00907
00908 if (dopolcal):
00909 print '--Polcal (D)--'
00910 default('polcal')
00911
00912 print "Solve for polarization leakage on 0137+331"
00913 print "Pretend it has unknown polarization"
00914
00915 vis = msfile
00916
00917
00918 gaintable = gtable
00919
00920
00921 gaincurve = usegaincurve
00922 opacity = gainopacity
00923
00924
00925 caltable = ptable
00926
00927
00928 field = '0137+331'
00929 spw = ''
00930
00931
00932 selectdata=False
00933
00934
00935 poltype = 'D+QU'
00936
00937
00938 solint = 'inf'
00939 combine = 'scan'
00940
00941
00942 refant = calrefant
00943
00944
00945 minsnr = 3
00946
00947
00948 polcal()
00949
00950
00951
00952
00953
00954 print '--Listcal (PolD)--'
00955
00956 listfile = caltable + '.list'
00957
00958 print "Listing calibration to file "+listfile
00959
00960 listcal()
00961
00962
00963
00964
00965
00966 print '--Plotcal (PolD)--'
00967
00968 iteration = ''
00969 showgui = False
00970
00971 xaxis = 'real'
00972 yaxis = 'imag'
00973 figfile = caltable + '.plotcal.reim.png'
00974 print "Plotting calibration to file "+figfile
00975
00976 plotcal()
00977
00978 xaxis = 'antenna'
00979 yaxis = 'amp'
00980 figfile = caltable + '.plotcal.antamp.png'
00981 print "Plotting calibration to file "+figfile
00982
00983 plotcal()
00984
00985 xaxis = 'antenna'
00986 yaxis = 'phase'
00987 figfile = caltable + '.plotcal.antphase.png'
00988 print "Plotting calibration to file "+figfile
00989
00990 plotcal()
00991
00992 xaxis = 'antenna'
00993 yaxis = 'snr'
00994 figfile = caltable + '.plotcal.antsnr.png'
00995 print "Plotting calibration to file "+figfile
00996
00997 plotcal()
00998
00999
01000
01001
01002
01003 print '--Setjy--'
01004 default('setjy')
01005
01006 vis = msfile
01007
01008 print "Use setjy to set IQU fluxes of "+polxfield
01009 field = polxfield
01010
01011 for spw in usespwlist:
01012 fluxdensity = polxiquv[spw]
01013
01014
01015 setjy()
01016
01017
01018
01019
01020 print '--PolCal (X)--'
01021 default('polcal')
01022
01023 print "Polarization R-L Phase Calibration (linear approx)"
01024
01025 vis = msfile
01026
01027
01028 gaintable = [gtable,ptable]
01029
01030
01031 gaincurve = usegaincurve
01032 opacity = gainopacity
01033
01034
01035 caltable = xtable
01036
01037
01038 field = polxfield
01039 spw = ''
01040
01041 selectdata=False
01042
01043
01044 poltype = 'X'
01045 solint = 'inf'
01046 combine = 'scan'
01047
01048
01049 refant = calrefant
01050
01051
01052 minsnr = 3
01053
01054
01055 polcal()
01056
01057
01058
01059
01060
01061
01062
01063
01064
01065
01066
01067
01068
01069
01070
01071
01072
01073
01074
01075
01076
01077
01078
01079
01080
01081
01082
01083
01084
01085
01086
01087
01088 atable = ftable
01089
01090
01091
01092
01093
01094
01095 print '--ApplyCal--'
01096 default('applycal')
01097
01098 print "This will apply the calibration to the DATA"
01099 print "Fills CORRECTED_DATA"
01100
01101 vis = msfile
01102
01103
01104 gaintable = [atable,ptable,xtable]
01105
01106
01107 gaincurve = usegaincurve
01108 opacity = gainopacity
01109
01110
01111 field = '1331+305,0137+331,JUPITER'
01112 spw = ''
01113 selectdata = False
01114
01115
01116 parang = True
01117
01118
01119
01120 gainfield = ''
01121
01122 applycal()
01123
01124
01125
01126
01127
01128
01129 print '--Split Jupiter--'
01130 default('split')
01131
01132 vis = msfile
01133
01134
01135
01136
01137 field = srcname
01138 spw = ''
01139
01140
01141 datacolumn = 'corrected'
01142
01143
01144 outputvis = srcsplitms
01145
01146 print "Split "+field+" data into new ms "+srcsplitms
01147
01148 split()
01149
01150
01151 field = calname
01152
01153 outputvis = calsplitms
01154
01155 print "Split "+field+" data into new ms "+calsplitms
01156
01157 split()
01158
01159
01160
01161
01162 vis = srcsplitms
01163 clearcal()
01164
01165 vis = calsplitms
01166 clearcal()
01167
01168
01169
01170
01171 print '--Plotxy--'
01172 default('plotxy')
01173
01174 vis = srcsplitms
01175 selectdata = True
01176
01177
01178 correlation = 'RR LL'
01179
01180
01181 xaxis = 'uvdist'
01182 datacolumn = 'data'
01183 multicolor = 'both'
01184
01185 iteration = ''
01186 selectplot = True
01187 interactive = True
01188
01189 field = 'JUPITER'
01190 yaxis = 'amp'
01191
01192 title = field+" "
01193
01194 plotxy()
01195
01196 print ""
01197 print "-----------------------------------------------------"
01198 print "Plotting JUPITER corrected visibilities"
01199 print "Look for outliers"
01200
01201
01202 if scriptmode:
01203 user_check=raw_input('Return to continue script\n')
01204
01205
01206 interactive = False
01207
01208
01209
01210
01211 vis = srcsplitms
01212 field = srcname
01213 yaxis = 'amp'
01214
01215 title = field+" "
01216 figfile = vis + '.plotxy.amp.png'
01217 print "Plotting to file "+figfile
01218
01219
01220 plotxy()
01221
01222 yaxis = 'phase'
01223
01224 figfile = vis + '.plotxy.phase.png'
01225 print "Plotting to file "+figfile
01226
01227
01228 plotxy()
01229
01230
01231
01232
01233 vis = calsplitms
01234 field = calname
01235 yaxis = 'amp'
01236
01237 title = field+" "
01238 figfile = vis + '.plotxy.amp.png'
01239 print "Plotting to file "+figfile
01240
01241
01242 plotxy()
01243
01244 yaxis = 'phase'
01245
01246 figfile = vis + '.plotxy.phase.png'
01247 print "Plotting to file "+figfile
01248
01249
01250 plotxy()
01251
01252 print 'Calibration completed'
01253
01254
01255
01256
01257
01258
01259
01260
01261
01262 print '--Clearcal--'
01263 default('clearcal')
01264
01265 vis = srcsplitms
01266
01267 clearcal()
01268
01269 print "Created scratch columns for MS "+vis
01270 print ""
01271
01272
01273
01274
01275
01276
01277
01278
01279 print '--Clean 1--'
01280 default('clean')
01281
01282
01283 vis = srcsplitms
01284
01285
01286 imagename = imname1
01287
01288 print "Output images will be prefixed with "+imname1
01289
01290
01291 mode = 'mfs'
01292 stokes = 'I'
01293
01294 print "Will be a single MFS continuum image"
01295
01296
01297 field = '*'
01298
01299
01300 spw = ''
01301
01302
01303 psfmode = clnalg
01304 imagermode = clnmode
01305
01306
01307 imsize = clnimsize
01308 cell = clncell
01309
01310
01311
01312
01313
01314 gain = 0.1
01315
01316
01317 niter = clniter
01318 threshold = clnthreshold
01319
01320
01321
01322
01323
01324
01325 weighting = 'briggs'
01326 robust = 0.5
01327
01328
01329 mask = ''
01330
01331
01332 interactive = True
01333
01334
01335 npercycle = 100
01336
01337 saveinputs('clean',imagename+'.clean.saved')
01338 clean()
01339
01340
01341
01342
01343
01344
01345
01346
01347
01348 print ""
01349 print "----------------------------------------------------"
01350 print "Clean"
01351 print "Final clean model is "+clnmodel1
01352 print "Final restored clean image is "+clnimage1
01353 print "The clean residual image is "+clnresid1
01354 print "Your final clean mask is "+clnmask1
01355
01356 print ""
01357 print "This is the final restored clean image in the viewer"
01358 print "Zoom in and set levels to see faint emission"
01359 print "Use rectangle drawing tool to box off source"
01360 print "Double-click inside to print statistics"
01361 print "Move box on-source and get the max"
01362 print "Calcualte DynRange = MAXon/RMSoff"
01363 print "I got 1.060/0.004 = 270"
01364 print "Still not as good as it can be - lets selfcal"
01365 print "Close viewer panel when done"
01366
01367
01368
01369
01370
01371 viewer(clnimage1,'image')
01372
01373
01374 if scriptmode:
01375 user_check=raw_input('Return to continue script\n')
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 print '--Imstat--'
01409 default('imstat')
01410
01411 imagename = clnimage1
01412 on_statistics1 = imstat()
01413
01414
01415
01416 box = '216,1,287,72'
01417 off_statistics1 = imstat()
01418
01419
01420 thistest_immax=on_statistics1['max'][0]
01421 print ' Found : Max in image = ',thistest_immax
01422 thistest_imrms=off_statistics1['rms'][0]
01423 print ' Found : rms in image = ',thistest_imrms
01424 print ' Clean image Dynamic Range = ',thistest_immax/thistest_imrms
01425 print ''
01426
01427
01428
01429
01430
01431
01432
01433
01434
01435 print '--SelfCal 1--'
01436 default('gaincal')
01437
01438 vis = srcsplitms
01439
01440 print "Will self-cal using MODEL_DATA left in MS by clean"
01441
01442
01443 caltable = selfcaltab1
01444
01445 print "Will write gain table "+selfcaltab1
01446
01447
01448 selectdata = False
01449 gaincurve = False
01450 opacity = 0.0
01451
01452
01453 refant = calrefant
01454
01455
01456 gaintype = 'G'
01457 calmode = 'ap'
01458
01459
01460 solint = 30.0
01461 minsnr = 1.0
01462 print "Calibrating amplitudes and phases on 30s timescale"
01463
01464
01465 solnorm = False
01466
01467 gaincal()
01468
01469
01470
01471
01472
01473
01474 print '--PlotCal--'
01475 default('plotcal')
01476
01477 caltable = selfcaltab1
01478 multiplot = True
01479 yaxis = 'amp'
01480
01481 plotcal()
01482
01483 print ""
01484 print "-------------------------------------------------"
01485 print "Plotcal"
01486 print "Looking at amplitude in self-cal table "+caltable
01487
01488
01489 if scriptmode:
01490 user_check=raw_input('Return to continue script\n')
01491
01492 yaxis = 'phase'
01493
01494 plotcal()
01495
01496 print ""
01497 print "-------------------------------------------------"
01498 print "Plotcal"
01499 print "Looking at phases in self-cal table "+caltable
01500
01501
01502
01503 if scriptmode:
01504 user_check=raw_input('Return to continue script\n')
01505
01506
01507
01508
01509
01510
01511 print '--ApplyCal--'
01512 default('applycal')
01513
01514 vis = srcsplitms
01515
01516 print "Will apply self-cal table to over-write CORRECTED_DATA in MS"
01517
01518 gaintable = selfcaltab1
01519
01520 gaincurve = False
01521 opacity = 0.0
01522 field = ''
01523 spw = ''
01524 selectdata = False
01525
01526 calwt = True
01527
01528 applycal()
01529
01530
01531
01532
01533
01534 print '--Plotxy--'
01535 default('plotxy')
01536
01537 vis = srcsplitms
01538 selectdata = True
01539 field = 'JUPITER'
01540
01541 correlation = 'RR LL'
01542 xaxis = 'uvdist'
01543 yaxis = 'amp'
01544 datacolumn = 'corrected'
01545 multicolor = 'both'
01546
01547
01548 selectplot = True
01549 title = field+" "
01550
01551 iteration = ''
01552
01553 plotxy()
01554
01555 print ""
01556 print "-----------------------------------------------------"
01557 print "Plotting JUPITER self-corrected visibilities"
01558 print "Look for outliers, and you can flag them"
01559
01560
01561 if scriptmode:
01562 user_check=raw_input('Return to continue script\n')
01563
01564
01565
01566
01567
01568
01569 print '--Clean 2--'
01570 default('clean')
01571
01572 print "Now clean on self-calibrated data"
01573
01574 vis = srcsplitms
01575
01576 imagename = imname2
01577
01578 field = '*'
01579 spw = ''
01580 mode = 'mfs'
01581 gain = 0.1
01582
01583
01584 psfmode = clnalg
01585 imagermode = clnmode
01586 imsize = clnimsize
01587 cell = clncell
01588 niter = clniter
01589 threshold = clnthreshold
01590
01591 weighting = 'briggs'
01592 robust = 0.5
01593
01594 mask = ''
01595 interactive = True
01596 npercycle = 100
01597
01598 saveinputs('clean',imagename+'.clean.saved')
01599 clean()
01600
01601 print ""
01602 print "----------------------------------------------------"
01603 print "Clean"
01604 print "Final clean model is "+clnmodel2
01605 print "Final restored clean image is "+clnimage2
01606 print "The clean residual image is "+clnresid2
01607 print "Your final clean mask is "+clnmask2
01608
01609 print ""
01610 print "This is the final restored clean image in the viewer"
01611 print "Zoom in and set levels to see faint emission"
01612 print "Use rectangle drawing tool to box off source"
01613 print "Double-click inside to print statistics"
01614 print "Move box on-source and get the max"
01615 print "Calcualte DynRange = MAXon/RMSoff"
01616 print "This time I got 1.076 / 0.001389 = 775 (better)"
01617 print "Still not as good as it can be - lets selfcal again"
01618 print "Close viewer panel when done"
01619
01620
01621
01622
01623
01624 viewer(clnimage2,'image')
01625
01626
01627 if scriptmode:
01628 user_check=raw_input('Return to continue script\n')
01629
01630
01631
01632
01633
01634
01635
01636
01637
01638
01639
01640
01641
01642
01643
01644
01645
01646
01647
01648
01649
01650
01651
01652 print ""
01653 print "--------------------------------------------------"
01654 print "After this script is done you can continue on with"
01655 print "more self-cal, or try different cleaning options"
01656
01657
01658
01659
01660
01661
01662
01663 print '--Imstat (Cycle 2)--'
01664 default('imstat')
01665
01666 imagename = clnimage2
01667 on_statistics2 = imstat()
01668
01669
01670
01671 box = '216,1,287,72'
01672 off_statistics2 = imstat()
01673
01674
01675 thistest_immax=on_statistics2['max'][0]
01676 print ' Found : Max in image = ',thistest_immax
01677 thistest_imrms=off_statistics2['rms'][0]
01678 print ' Found : rms in image = ',thistest_imrms
01679 print ' Clean image Dynamic Range = ',thistest_immax/thistest_imrms
01680 print ''
01681
01682
01683
01684
01685
01686 print ""
01687 print ' Final Jupiter results '
01688 print ' ===================== '
01689 print ''
01690
01691 thistest_immax=on_statistics2['max'][0]
01692 oldtest_immax = 1.07732224464
01693 print ' Clean image ON-SRC max = ',thistest_immax
01694 print ' Previously found to be = ',oldtest_immax
01695 diff_immax = abs((oldtest_immax-thistest_immax)/oldtest_immax)
01696 print ' Difference (fractional) = ',diff_immax
01697
01698 print ''
01699 thistest_imrms=off_statistics2['rms'][0]
01700 oldtest_imrms = 0.0010449
01701 print ' Clean image OFF-SRC rms = ',thistest_imrms
01702 print ' Previously found to be = ',oldtest_imrms
01703 diff_imrms = abs((oldtest_imrms-thistest_imrms)/oldtest_imrms)
01704 print ' Difference (fractional) = ',diff_imrms
01705
01706 print ''
01707 print ' Final Clean image Dynamic Range = ',thistest_immax/thistest_imrms
01708 print ''
01709 print '--- Done with I Imaging and Selfcal---'
01710
01711
01712
01713
01714
01715
01716 print '--Clean (Polarization)--'
01717 default('clean')
01718
01719 print "Now clean polarized data"
01720
01721 vis = srcsplitms
01722
01723 imagename = polimname
01724
01725 field = '*'
01726 spw = ''
01727 mode = 'mfs'
01728 gain = 0.1
01729
01730
01731 stokes = 'IQUV'
01732
01733 psfmode = polclnalg
01734 imagermode = polclnmode
01735
01736 niter = clniter
01737 threshold = clnthreshold
01738
01739 imsize = clnimsize
01740 cell = clncell
01741
01742 weighting = 'briggs'
01743 robust = 0.5
01744
01745 interactive = True
01746 npercycle = 100
01747
01748 saveinputs('clean',imagename+'.clean.saved')
01749 clean()
01750
01751 print ""
01752 print "----------------------------------------------------"
01753 print "Clean"
01754 print "Final restored clean image is "+polimage
01755 print "Final clean model is "+polmodel
01756 print "The clean residual image is "+polresid
01757 print "Your final clean mask is "+polmask
01758
01759
01760
01761
01762
01763
01764
01765 print '--Final Pol Imstat--'
01766 default('imstat')
01767
01768 imagename = polimage
01769
01770 on_statistics = {}
01771 off_statistics = {}
01772
01773
01774 onbox = ''
01775
01776 offbox = '216,1,287,72'
01777
01778 for stokes in ['I','Q','U','V']:
01779 box = onbox
01780 on_statistics[stokes] = imstat()
01781 box = offbox
01782 off_statistics[stokes] = imstat()
01783
01784
01785
01786
01787 print '--Immath--'
01788 default('immath')
01789
01790 mode = 'evalexpr'
01791
01792 stokes = 'I'
01793 outfile = ipolimage
01794 expr = '\"'+polimage+'\"'
01795
01796 immath()
01797 print "Created I image "+outfile
01798
01799 stokes = 'Q'
01800 outfile = qpolimage
01801 expr = '\"'+polimage+'\"'
01802
01803 immath()
01804 print "Created Q image "+outfile
01805
01806 stokes = 'U'
01807 outfile = upolimage
01808 expr = '\"'+polimage+'\"'
01809
01810 immath()
01811 print "Created U image "+outfile
01812
01813
01814
01815
01816
01817 stokes = ''
01818 outfile = poliimage
01819 mode = 'poli'
01820 imagename = [qpolimage,upolimage]
01821
01822 mysigma = 0.5*( off_statistics['Q']['rms'][0] + off_statistics['U']['rms'][0] )
01823
01824
01825 sigma = '0.0Jy/beam'
01826
01827 immath()
01828 print "Created POLI image "+outfile
01829
01830 outfile = polaimage
01831 mode = 'pola'
01832
01833 immath()
01834 print "Created POLA image "+outfile
01835
01836
01837
01838
01839 default('imstat')
01840
01841 imagename = poliimage
01842 stokes = ''
01843 box = onbox
01844 on_statistics['POLI'] = imstat()
01845 box = offbox
01846 off_statistics['POLI'] = imstat()
01847
01848
01849
01850
01851
01852
01853
01854 viewer(polimage,'image')
01855
01856 print "Displaying pol I now. You should overlay pola vectors"
01857 print "Bring up the Load Data panel:"
01858 print ""
01859 print "Use LEL for POLA VECTOR with cut above 6*mysigma in POLI = "+str(6*mysigma)
01860 print "For example:"
01861 print "\'"+polaimage+"\'[\'"+poliimage+"\'>0.0048]"
01862 print ""
01863 print "In the Data Display Options for the vector plot:"
01864 print " Set the x,y increments to 2 (default is 3)"
01865 print " Use an extra rotation this 90deg to get B field"
01866 print "Note the lengths are all equal. You can fiddle these."
01867 print ""
01868 print "You can also load the poli image as contours"
01869
01870
01871 if scriptmode:
01872 user_check=raw_input('Return to continue script\n')
01873
01874
01875
01876
01877
01878
01879
01880
01881
01882
01883
01884
01885
01886 po = casac.imagepol()
01887 po.open(polimage)
01888
01889 complexlinpolimage = polimname + '.cmplxlinpol'
01890 po.complexlinpol(complexlinpolimage)
01891 po.close()
01892
01893
01894
01895
01896
01897
01898
01899
01900
01901
01902
01903
01904
01905 print ""
01906 print ' Jupiter polarization results '
01907 print ' ============================ '
01908 print ''
01909 for stokes in ['I','Q','U','V','POLI']:
01910 print ''
01911 print ' =============== '
01912 print ''
01913 print ' Polarization (Stokes '+stokes+'):'
01914 mymax = on_statistics[stokes]['max'][0]
01915 mymin = on_statistics[stokes]['min'][0]
01916 myrms = off_statistics[stokes]['rms'][0]
01917 absmax = max(mymax,mymin)
01918 mydra = absmax/myrms
01919 print ' Clean image ON-SRC max = ',mymax
01920 print ' Clean image ON-SRC min = ',mymin
01921 print ' Clean image OFF-SRC rms = ',myrms
01922 print ' Clean image dynamic rng = ',mydra
01923
01924
01925 print '--- Done ---'
01926
01927
01928