00001
00002
00003
00004
00005
00006
00007
00008 asap_init()
00009
00010 import os
00011 import sys
00012
00013
00014
00015 tpdemo = True
00016
00017
00018
00019
00020
00021 tpdemo2 = False
00022
00023
00024
00025
00026 datapath1 = os.environ['CASAPATH'].split()[0]+'/data/regression/ATST5/OrionS/'
00027 datapath2 = os.environ['CASAPATH'].split()[0]+'/data/alma/atf/sd/'
00028 datafile1 = 'OrionS_rawACSmod'
00029 datafile2='uid___X1e1_X3197_X1.ms'
00030
00031 print "*******SD analysis demo for Beta Patch 3*******"
00032 print "This script shows new/modified feautures of single dish tools/tasks\n"
00033
00034
00035 files=['orion_pscal', 'orion_pscal_if0_3000_5000', 'orion_pscal_bs_if0_blparam.txt',
00036 'orion_pscal_bs_if0','orion_pscal_bs_if0_f', 'orion_pscal_bs_if0_f_f','orion_pscal_allif_tave',
00037 'orion_pscal_scaled1.5']
00038 for f in files:
00039 if os.path.isdir(f) or os.path.isfile(f):
00040 os.system('rm -rf %s' % f)
00041
00042 if os.path.isdir(datapath1+datafile1):
00043 os.system('mkdir %s;cp -r %s/[!.svn]* ./%s' % (datafile1, datapath1+datafile1, datafile1))
00044 else:
00045 if not os.path.isdir(datafile1):
00046 print "Data file, %s, not found." % datafile1
00047 sys.exit()
00048 if os.path.isdir(datapath2+datafile2):
00049 os.system('mkdir %s;cp -r %s/[!.svn]* ./%s' % (datafile2, datapath2+datafile2, datafile2))
00050 else:
00051 if not os.path.isdir(datafile2):
00052 print "Data file, %s, not found." % datafile2
00053 print "total power data analysis will be skipped"
00054 tpdemo = False
00055
00056
00057
00058
00059
00060 print "###############\n 1. sdcal \n###############"
00061 default(sdcal)
00062 desc="* At first, run calibration for the position switch observation\n" \
00063 "* (taken from ori_hc3n_task_regression.py) to get calibrated data\n"
00064 print desc
00065 sdfile='OrionS_rawACSmod'
00066 fluxunit='K'
00067 calmode='ps'
00068 scanlist=[20,21,22,23]
00069 iflist=[0,1,2,3]
00070 scanaverage=False
00071 timeaverage=True
00072 tweight='tintsys'
00073 polaverage=True
00074 pweight='tsys'
00075 tau=0.09
00076 outfile='orion_pscal'
00077 overwrite=True
00078 plotlevel=1
00079 inp(sdcal)
00080 pause=raw_input('* Hit Return to continue ')
00081
00082 print "\n* Run sdcal with these parameters...\n"
00083 sdcal()
00084 print "*** Done sdcal ****\n"
00085 desc="\n" \
00086 "* NEW FEATURE: channelrange\n" \
00087 "* now try new parameter, channelrange to save a subset of the spectra\n" \
00088 "* with restricted channel range. We do the same calibration as the previous\n" \
00089 "* sdcal run but select IF0 only and set a channel range from 3000 to 5000\n"
00090 print desc
00091 iflist=[0]
00092 channelrange=[3000,5000]
00093 outfile='orion_pscal_if0_3000_5000'
00094 inp(sdcal)
00095 pause=raw_input('* Hit Return to continue ')
00096
00097 print "\n* Run sdcal with these parameters...\n"
00098 sdcal()
00099 print "*** Done sdcal ****\n"
00100
00101 pause=raw_input('* Hit Return to continue ')
00102
00103 desc="\n" \
00104 "NEW FEATURE: multi-resolution spectra averaging\n"\
00105 "Set timeaverage=True and averageall=True. \n" \
00106 "SKIPPED: This is not test here since we do not have a good test data now\n"
00107 print desc
00108
00109 pause=raw_input('\n* Hit Return to continue ')
00110
00111
00112
00113 print "\n###############\n 2. sdbaseline \n###############"
00114 desc="\n" \
00115 "* NEW FEATURE: set mask for baseline fitting interactively.\n" \
00116 "* Set blmode='interact'\n"
00117 print desc
00118
00119
00120
00121 default(sdbaseline)
00122
00123 sdfile='orion_pscal'
00124 specunit='channel'
00125 iflist=0
00126 blmode='interact'
00127 outfile=sdfile+'_bs'+'_if0'
00128 plotlevel=1
00129 inp(sdbaseline)
00130 pause=raw_input('\n* Hit Return to continue ')
00131 print "\n* Run sdbaseline...\n"
00132 desc="\n" \
00133 "* By using mouse bottons, specify region(s).\n" \
00134 "* To mask (included in baseline fitting) using\n"\
00135 "* the left mouse button or to unmask (exculded in baseline fitting)\n" \
00136 "* using the right mouse button.\n" \
00137 "*\n" \
00138 "* For the example here, initially no masklist was given in the task parameter,\n" \
00139 "* which will be defaulted to put mask to entire spectrum, shown in the plot in yellow.\n" \
00140 "*\n" \
00141 "* Using right mouse button to unmask the line region...\n" \
00142 "* Once you satisfy with your masks, go back to the casapy console, \n" \
00143 "* and hit Return key to start processing.\n"
00144 print desc
00145 sdbaseline()
00146 print "*** Done sdbaseline ****\n"
00147
00148
00149
00150
00151
00152
00153
00154
00155
00156
00157
00158
00159
00160
00161
00162
00163 print "* Saved the fit paramters and rms after baseline fit"
00164 print "!cat %s" % outfile+'_blparam.txt'
00165
00166
00167 os.system('cat %s' % outfile+'_blparam.txt')
00168
00169
00170
00171
00172
00173
00174
00175
00176
00177
00178
00179
00180
00181
00182
00183
00184
00185
00186
00187
00188 pause=raw_input('\n* Hit Return to continue ')
00189 print "\n###############\n 3. sdflag \n###############"
00190
00191
00192
00193
00194 desc="\n" \
00195 "* Flag\n" \
00196 "* use the baselined data in the previous step.\n" \
00197 "* set plotlevel=1 to plot the spectrum with flagged region(s).\n"
00198 print desc
00199 default(sdflag)
00200 sdfile='orion_pscal_bs_if0'
00201 specunit='channel'
00202 maskflag=[[0,100],[2000,3000]]
00203 flagmode='flag'
00204 plotlevel=1
00205 inp(sdflag)
00206 pause=raw_input('\n* Hit Return to continue ')
00207 print "* Run sdflag...\n"
00208 print "* Type y when asked to apply flag."
00209
00210 sdflag()
00211 print "*** Done sdflag ****\n"
00212
00213
00214 desc="\n" \
00215 "* NEW FEATURE: restore\n" \
00216 "* get flag masks applied to the data"
00217 print desc
00218
00219
00220 default(sdflag)
00221 sdfile='orion_pscal_bs_if0_f'
00222 flagmode='restore'
00223 inp(sdflag)
00224 pause=raw_input('\n* Hit Return to continue ')
00225 print "\n* Run sdflag...\n"
00226 sdflag()
00227 print "* You will see all flag masks applied to the data...\n"
00228 print "*** Done sdflag ****\n"
00229
00230
00231
00232
00233
00234
00235
00236
00237
00238
00239
00240 desc="\n" \
00241 "* Try unflag...\n" \
00242 "* Set flagmode='unflag' \n"
00243 print desc
00244 sdfile='orion_pscal_bs_if0_f'
00245 flagmode='unflag'
00246 maskflag=[2000,3000]
00247 plotlevel=1
00248 inp(sdflag)
00249 pause=raw_input('\n* Hit Return to continue ')
00250 print "\n* Run sdflag...\n"
00251 print "* Type y when asked to apply flag."
00252 sdflag()
00253 print "*** Done sdflag ****\n"
00254
00255 pause=raw_input('\n* Hit Return to continue ')
00256
00257
00258
00259 print "\n###############\n 4. sdplot \n###############"
00260 desc="\n" \
00261 "* First, generate calibrated data without polarization average.\n" \
00262 "* This time use sdreduce.\n"
00263 print desc
00264
00265
00266
00267
00268
00269
00270
00271
00272
00273
00274
00275
00276
00277 default(sdreduce)
00278 sdfile='OrionS_rawACSmod'
00279 calmode='ps'
00280 scanlist=[20, 21, 22, 23]
00281 iflist=[0, 1, 2, 3]
00282 average=True
00283 timeaverage=True
00284 tweight='tintsys'
00285 tau=0.09
00286 blmode='auto'
00287 outfile='orion_pscal_allif_tave'
00288 inp(sdreduce)
00289 pause=raw_input('\n* Hit Return to continue ')
00290 print "\n* Run sdreduce...\n"
00291 sdreduce()
00292 print "*** Done sdreduce ****\n"
00293
00294 desc="\n" \
00295 "* NEW FEATURE: plot color control\n" \
00296 "* specify colors to be used for plot lines\n" \
00297 "* stacking IFs, different panel for each polarization.\n"
00298 print desc
00299
00300 default(sdplot)
00301 sdfile='orion_pscal_allif_tave'
00302 stack='i'
00303 panel='p'
00304 flrange=[-1,1.5]
00305 sprange=[2500,4500]
00306 colormap='c m g b'
00307 inp(sdplot)
00308 pause=raw_input('\n* Hit Return to continue ')
00309 print "\n* Run sdplot...\n"
00310 sdplot()
00311 print "*** Done sdplot ****\n"
00312
00313 desc="\n" \
00314 "* NEW FEATURE:\n"\
00315 "* click left mouse button on one of the lines, a pop-up window will\n" \
00316 "* appear to display spectral data values as you move the mouse along\n" \
00317 "* horizontal direction while keep holding the left mouse button.\n"
00318 print desc
00319
00320 pause=raw_input('\n* Hit Return to continue ')
00321
00322 desc="\n" \
00323 "* NEW FEATURE: line styles \n" \
00324 "* specify line styles to be used for plot line. \n"
00325 print desc
00326 colormap='none'
00327 linestyles='line dotted dashed dashdot'
00328 linewidth=2
00329 pollist=0
00330 sprange=[2500,4500]
00331 inp(sdplot)
00332 pause=raw_input('\n* Hit Return to continue ')
00333 print "\n* Run sdplot...\n"
00334 sdplot()
00335 print "*** Done sdplot ****\n"
00336
00337 desc="\n" \
00338 "* Currently flrange, and sprange are set globally. \n" \
00339 "* For now, to reset, you need to run sdplot with \n" \
00340 "* default parameters.\n"
00341 print desc
00342
00343 default(sdplot)
00344 sdfile='orion_pscal_allif_tave'
00345 iflist=0
00346 pollist=0
00347 print "* Run sdplot...\n"
00348 sdplot()
00349 print "*** Done sdplot ****\n"
00350
00351
00352
00353
00354
00355
00356 if tpdemo2:
00357 desc="\n" \
00358 "* NEW FEATURE: total power plotting\n" \
00359 "* (NOTE: functionality is still limited and processing speed is slow)\n" \
00360 "* This example needs the ATF total power data converted from ASDM to MS. \n" \
00361 "* Also, currently most of the plot control parameters are no effect or \n" \
00362 "* ignored in total power plotting mode. \n"
00363 print desc
00364 sdfile='uid___X1e1_X3197_X1.ms'
00365 plottype='totalpower'
00366 inp(sdplot)
00367 pause=raw_input('\n* Hit Return to continue ')
00368 print "\n* Run sdplot...\n"
00369 sdplot()
00370 print "*** Done sdplot ****\n"
00371
00372
00373
00374
00375 print "###############\n 5. sdscale \n###############"
00376 desc="\n" \
00377 "* NEW FEATURE: print out Tsys values before and after scaling\n"
00378 print desc
00379 default(sdscale)
00380 sdfile='orion_pscal'
00381 factor=1.5
00382 inp(sdscale)
00383 pause=raw_input('\n* Hit Return to continue ')
00384 print "\n* Run sdscale...\n"
00385 sdscale()
00386 print "*** Done sdscale ****\n"
00387
00388
00389
00390
00391
00392
00393
00394
00395
00396
00397
00398
00399
00400
00401
00402
00403 pause=raw_input('\n* Hit Return to continue ')
00404
00405
00406
00407 print "\n###############\n 6. sdstat \n###############"
00408 desc="\n" \
00409 "* NEW FEATURE: statistics to an ASCII file \n" \
00410 "* Specify by statfile parameter\n"
00411 print desc
00412
00413
00414
00415
00416 default(sdstat)
00417 sdfile='orion_pscal'
00418 specunit='GHz'
00419 iflist=0
00420 interactive=True
00421 statfile='orion_stat.txt'
00422 inp(sdstat)
00423 pause=raw_input('\n* Hit Return to continue ')
00424 print "* Run sdstat...\n"
00425 desc="\n" \
00426 "* Initial mask is set to the entire spectrum\n" \
00427 "* as shown in yellow. The behavior for multi-IF\n" \
00428 "* cases is same as that of sdbaseline.\n"\
00429 "* Use right mouse botton to deselect regions\n"\
00430 "* Hit Return in the casapy console after you \n"\
00431 "* satisfy your mask selection.\n"
00432 print desc
00433 sdstat()
00434 print "*** Done sdstat ****\n"
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
00465
00466
00467
00468
00469
00470
00471
00472
00473
00474
00475
00476
00477
00478
00479
00480
00481
00482
00483
00484
00485
00486
00487
00488
00489
00490
00491
00492
00493
00494
00495
00496
00497
00498
00499
00500
00501
00502
00503
00504
00505
00506
00507
00508
00509
00510 if tpdemo:
00511
00512
00513
00514
00515 print "###############\n 7. New task: sdtpimaging \n###############"
00516 desc="* Sdtpimaging is a new task to do data analysis of the total power\n" \
00517 "* raster scan data.\n"
00518 print desc
00519 default(sdtpimaging)
00520
00521 plotlevel=2
00522 antenna='0'
00523 sdfile='uid___X1e1_X3197_X1.ms'
00524 inp()
00525 desc="\n" \
00526 "* For this example, we do it in three steps to illustrate features,\n" \
00527 "* but it can be run the entire process in a single run of sdtpimaiging.\n" \
00528 "* First, do just plotting of the uncalibrated data leaving \n" \
00529 "* calmode and createimage to defaults (calmode='none', createimage=False).\n" \
00530 "* If there is CORRECTED_DATA column in the MS data, the calibrated data\n"\
00531 "* will be plotted instead.\n"
00532 print desc
00533 pause=raw_input('\n* Hit Return to continue ')
00534 print "\n* Run sdtpimaging...\n"
00535 sdtpimaging()
00536 print "*** sdtpimaging done***\n"
00537
00538 calmode='baseline'
00539 masklist=[50]
00540 plotlevel=1
00541
00542 inp()
00543 desc="\n"\
00544 "* Now try to calibrate the data, currently only a simple baseline subtraction\n" \
00545 "* is available.\n"
00546 print desc
00547 pause=raw_input('\n* Hit Return to continue ')
00548 print "\n* Run sdtpimaging...\n"
00549 sdtpimaging()
00550 print "*** sdtpimaging done***\n"
00551
00552 calmode='none'
00553 createimage=True
00554 imagename='moon.im'
00555 imsize=[200,200]
00556 cell=[0.2]
00557 phasecenter='AZEL 187d54m22s 41d03m0s'
00558 ephemsrcname='moon'
00559 inp()
00560 desc="\n" \
00561 "* Finally, to create an image, set createimage=True.\n" \
00562 "* The data contain the observation of the Moon so set\n"\
00563 "* ephemsrcname (the task automatically look up SOURCE table\n"\
00564 "* to check if it is ephemeris source or not, even you left\n"\
00565 "* this blank.\n"
00566 print desc
00567 pause=raw_input('\n* Hit Return to continue ')
00568 print "\n* Run sdtpimaging...\n"
00569 sdtpimaging()
00570 print "*** sdtpimaging done***\n"
00571
00572 print "* Let's check the create image"
00573 pause=raw_input('\n* Hit Return to continue ')
00574 viewer(imagename)
00575
00576
00577
00578 print "\n###############\n Tool changes \n###############"
00579
00580
00581 desc="\n" \
00582 "* Now ASAP scantable supports the storage of multiple rest\n" \
00583 "* frequencies. As the result, behaviors of setting/getting rest \n" \
00584 "* frequencies slightly changed\n" \
00585 "*\n" \
00586 "* For example, \n"\
00587 "s=sd.scantable('orion_pscal') \n" \
00588 "restfreqs=s.get_restfreqs() \n"
00589 print desc
00590
00591 s=sd.scantable('orion_pscal')
00592 restfreqs=s.get_restfreqs()
00593 desc="* Returned rest frequencies are in a dictionary, and only list\n" \
00594 "* one(s) current used.\n";
00595 print desc
00596 print "restfreqs=", restfreqs
00597
00598 pause=raw_input('\n* Hit Return to continue ')
00599 desc="\n* Set new rest frequencies for IF=0.\n" \
00600 "* let\n"\
00601 "newrestfreqs=[45490258000.0,45590258000.0]\n"\
00602 "*(Note: arbitary values used as an example)\n" \
00603 "sel=sd.selector()\n"\
00604 "sel.set_ifs(0)\n" \
00605 "s.set_selection(sel)\n"\
00606 "s.set_restfreqs(newrestfreqs)\n"
00607 print desc
00608 newrestfreqs=[45490258000.0,45590258000.0]
00609 sel=sd.selector()
00610 sel.set_ifs(0)
00611 s.set_selection(sel)
00612 s.set_restfreqs(newrestfreqs)
00613
00614 desc="* Check the new values\n" \
00615 "s.get_restfreqs() \n"
00616 print desc
00617 newrestfs=s.get_restfreqs()
00618 print newrestfs
00619 pause=raw_input('\n* Hit Return to continue ')
00620
00621 desc="\n* List all the rest frequencies currently set for all IFs\n" \
00622 "sel.reset()\n"\
00623 "s.set_selection(sel)\n"\
00624 "s.get_restfreqs()\n"
00625 print desc
00626 sel.reset()
00627 s.set_selection(sel)
00628 newrestfs=s.get_restfreqs()
00629 print newrestfs
00630
00631 print "*** done get/set_restfreqs demo ***"
00632
00633 print "**** End of the script ****"