Changes in trunk/python/asapmath.py [1827:1920]
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/python/asapmath.py
r1827 r1920 1 1 from asap.scantable import scantable 2 2 from asap.parameters import rcParams 3 from asap.logging import asaplog, print_log, print_log_dec3 from asap.logging import asaplog, asaplog_post_dec 4 4 from asap.selector import selector 5 5 from asap import asaplotgui 6 6 7 @ print_log_dec7 @asaplog_post_dec 8 8 def average_time(*args, **kwargs): 9 9 """ … … 67 67 if not isinstance(s,scantable): 68 68 msg = "Please give a list of scantables" 69 if rcParams['verbose']: 70 #print msg 71 asaplog.push(msg) 72 print_log('ERROR') 73 return 74 else: 75 raise TypeError(msg) 69 raise TypeError(msg) 76 70 if scanav: scanav = "SCAN" 77 71 else: scanav = "NONE" … … 96 90 s = scantable(stm._new_average(alignedlst, compel, mask, weight.upper(), scanav)) 97 91 s._add_history("average_time",varlist) 98 print_log() 92 99 93 return s 100 94 95 @asaplog_post_dec 101 96 def quotient(source, reference, preserve=True): 102 97 """ … … 119 114 s = scantable(stm._quotient(source, reference, preserve)) 120 115 s._add_history("quotient",varlist) 121 print_log()122 116 return s 123 117 124 @ print_log_dec118 @asaplog_post_dec 125 119 def dototalpower(calon, caloff, tcalval=0.0): 126 120 """ … … 138 132 s = scantable(stm._dototalpower(calon, caloff, tcalval)) 139 133 s._add_history("dototalpower",varlist) 140 print_log()141 134 return s 142 135 143 @ print_log_dec136 @asaplog_post_dec 144 137 def dosigref(sig, ref, smooth, tsysval=0.0, tauval=0.0): 145 138 """ … … 159 152 s = scantable(stm._dosigref(sig, ref, smooth, tsysval, tauval)) 160 153 s._add_history("dosigref",varlist) 161 print_log()162 154 return s 163 155 164 @ print_log_dec156 @asaplog_post_dec 165 157 def calps(scantab, scannos, smooth=1, tsysval=0.0, tauval=0.0, tcalval=0.0, verify=False): 166 158 """ 167 159 Calibrate GBT position switched data 168 160 Adopted from GBTIDL getps 169 Currently calps identify the scans as position switched data if they170 contain '_ps' in the source name. The data must contains 'CAL' signal171 on/off in each integration. To identify 'CAL' on state, the word, 'calon'172 need to be present in the source name field.161 Currently calps identify the scans as position switched data if source 162 type enum is pson or psoff. The data must contains 'CAL' signal 163 on/off in each integration. To identify 'CAL' on state, the source type 164 enum of poncal and poffcal need to be present in the source name field. 173 165 (GBT MS data reading process to scantable automatically append these 174 166 id names to the source names) … … 184 176 tcalval: optional user specified Tcal (default is 0.0, 185 177 use Tcal value in the data) 178 verify: Verify calibration if true 186 179 """ 187 180 varlist = vars() … … 190 183 ## if s is None: 191 184 ## msg = "The input data appear to contain no position-switch mode data." 192 ## if rcParams['verbose']: 193 ## #print msg 194 ## asaplog.push(msg) 195 ## print_log('ERROR') 196 ## return 197 ## else: 198 ## raise TypeError(msg) 185 ## raise TypeError(msg) 199 186 s = scantab.copy() 200 187 from asap._asap import srctype … … 205 192 except Exception, e: 206 193 msg = "The input data appear to contain no position-switch mode data." 207 if rcParams['verbose']: 208 #print msg 209 asaplog.push(msg) 210 print_log('ERROR') 211 return 212 else: 213 raise TypeError(msg) 194 raise TypeError(msg) 214 195 s.set_selection() 215 196 sel.reset() … … 217 198 if ssub is None: 218 199 msg = "No data was found with given scan numbers!" 219 if rcParams['verbose']: 220 #print msg 221 asaplog.push(msg) 222 print_log('ERROR') 223 return 224 else: 225 raise TypeError(msg) 200 raise TypeError(msg) 226 201 #ssubon = ssub.get_scan('*calon') 227 202 #ssuboff = ssub.get_scan('*[^calon]') … … 238 213 if ssubon.nrow() != ssuboff.nrow(): 239 214 msg = "mismatch in numbers of CAL on/off scans. Cannot calibrate. Check the scan numbers." 240 if rcParams['verbose']: 241 #print msg 242 asaplog.push(msg) 243 print_log('ERROR') 244 return 245 else: 246 raise TypeError(msg) 215 raise TypeError(msg) 247 216 cals = dototalpower(ssubon, ssuboff, tcalval) 248 217 #sig = cals.get_scan('*ps') … … 260 229 if sig.nscan() != ref.nscan(): 261 230 msg = "mismatch in numbers of on/off scans. Cannot calibrate. Check the scan numbers." 262 if rcParams['verbose']: 263 #print msg 264 asaplog.push(msg) 265 print_log('ERROR') 266 return 267 else: 268 raise TypeError(msg) 231 raise TypeError(msg) 269 232 270 233 #for user supplied Tsys … … 272 235 if tauval<=0.0: 273 236 msg = "Need to supply a valid tau to use the supplied Tsys" 274 if rcParams['verbose']: 275 #print msg 276 asaplog.push(msg) 277 print_log('ERROR') 278 return 279 else: 280 raise TypeError(msg) 237 raise TypeError(msg) 281 238 else: 282 239 sig.recalc_azel() 283 240 ref.recalc_azel() 284 241 #msg = "Use of user specified Tsys is not fully implemented yet." 285 #if rcParams['verbose']: 286 # print msg 287 # return 288 #else: 289 # raise TypeError(msg) 242 #raise TypeError(msg) 290 243 # use get_elevation to get elevation and 291 244 # calculate a scaling factor using the formula … … 355 308 del sel 356 309 # plot 357 print_log()310 asaplog.post() 358 311 asaplog.push('Plot only first spectrum for each [if,pol] pairs to verify calibration.') 359 print_log('WARN')312 asaplog.post('WARN') 360 313 p=asaplotgui.asaplotgui() 361 314 #nr=min(6,len(ifnos)*len(polnos)) … … 384 337 btics.append(b) 385 338 else: 386 print_log()339 asaplog.post() 387 340 asaplog.push('Only first 6 [if,pol] pairs are plotted.') 388 print_log('WARN')341 asaplog.post('WARN') 389 342 nr=6 390 343 for i in range(2*nr): … … 442 395 ### 443 396 ress._add_history("calps", varlist) 444 print_log()445 397 return ress 446 398 447 @ print_log_dec399 @asaplog_post_dec 448 400 def calnod(scantab, scannos=[], smooth=1, tsysval=0.0, tauval=0.0, tcalval=0.0, verify=False): 449 401 """ … … 458 410 tauval: optional user specified tau value (not implemented yet) 459 411 tcalval: optional user specified Tcal value 412 verify: Verify calibration if true 460 413 """ 461 414 varlist = vars() … … 469 422 ## if s is None: 470 423 ## msg = "The input data appear to contain no Nod observing mode data." 471 ## if rcParams['verbose']: 472 ## #print msg 473 ## asaplog.push(msg) 474 ## print_log('ERROR') 475 ## return 476 ## else: 477 ## raise TypeError(msg) 424 ## raise TypeError(msg) 478 425 s = scantab.copy() 479 426 sel = selector() … … 483 430 except Exception, e: 484 431 msg = "The input data appear to contain no Nod observing mode data." 485 if rcParams['verbose']: 486 #print msg 487 asaplog.push(msg) 488 print_log('ERROR') 489 return 490 else: 491 raise TypeError(msg) 432 raise TypeError(msg) 492 433 sel.reset() 493 434 del sel … … 511 452 #if len(scannos)>2: 512 453 # msg = "calnod can only process a pair of nod scans at time." 513 # if rcParams['verbose']: 514 # print msg 515 # return 516 # else: 517 # raise TypeError(msg) 454 # raise TypeError(msg) 518 455 # 519 456 #if len(scannos)==2: … … 525 462 if tauval<=0.0: 526 463 msg = "Need to supply a valid tau to use the supplied Tsys" 527 if rcParams['verbose']: 528 #print msg 529 asaplog.push(msg) 530 print_log('ERROR') 531 return 532 else: 533 raise TypeError(msg) 464 raise TypeError(msg) 534 465 else: 535 466 scantab.recalc_azel() … … 596 527 del sel 597 528 # plot 598 print_log()529 asaplog.post() 599 530 asaplog.push('Plot only first spectrum for each [if,pol] pairs to verify calibration.') 600 print_log('WARN')531 asaplog.post('WARN') 601 532 p=asaplotgui.asaplotgui() 602 533 #nr=min(6,len(ifnos)*len(polnos)) … … 625 556 btics.append(b) 626 557 else: 627 print_log()558 asaplog.post() 628 559 asaplog.push('Only first 6 [if,pol] pairs are plotted.') 629 print_log('WARN')560 asaplog.post('WARN') 630 561 nr=6 631 562 for i in range(2*nr): … … 683 614 ### 684 615 resspec._add_history("calnod",varlist) 685 print_log()686 616 return resspec 687 617 688 @ print_log_dec618 @asaplog_post_dec 689 619 def calfs(scantab, scannos=[], smooth=1, tsysval=0.0, tauval=0.0, tcalval=0.0, verify=False): 690 620 """ 691 621 Calibrate GBT frequency switched data. 692 622 Adopted from GBTIDL getfs. 693 Currently calfs identify the scans as frequency switched data if they694 contain '_fs' in the source name. The data must contains 'CAL' signal695 on/off in each integration. To identify 'CAL' on state, the word, 'calon'696 need to be present in the source name field.623 Currently calfs identify the scans as frequency switched data if source 624 type enum is fson and fsoff. The data must contains 'CAL' signal 625 on/off in each integration. To identify 'CAL' on state, the source type 626 enum of foncal and foffcal need to be present in the source name field. 697 627 (GBT MS data reading via scantable automatically append these 698 628 id names to the source names) … … 706 636 use Tsys in the data) 707 637 tauval: optional user specified Tau 638 verify: Verify calibration if true 708 639 """ 709 640 varlist = vars() … … 716 647 # if check is None: 717 648 # msg = "The input data appear to contain no Nod observing mode data." 718 # if rcParams['verbose']: 719 # print msg 720 # return 721 # else: 722 # raise TypeError(msg) 649 # raise TypeError(msg) 723 650 s = scantab.get_scan(scannos) 724 651 del scantab … … 812 739 del sel 813 740 # plot 814 print_log()741 asaplog.post() 815 742 asaplog.push('Plot only first spectrum for each [if,pol] pairs to verify calibration.') 816 print_log('WARN')743 asaplog.post('WARN') 817 744 p=asaplotgui.asaplotgui() 818 745 #nr=min(6,len(ifnos)*len(polnos)) … … 821 748 btics=[] 822 749 if nr>3: 823 print_log()750 asaplog.post() 824 751 asaplog.push('Only first 3 [if,pol] pairs are plotted.') 825 print_log('WARN')752 asaplog.post('WARN') 826 753 nr=3 827 754 p.set_panels(rows=nr,cols=3,nplots=3*nr,ganged=False) … … 891 818 ### 892 819 resspec._add_history("calfs",varlist) 893 print_log()894 820 return resspec 895 821 896 @ print_log_dec822 @asaplog_post_dec 897 823 def merge(*args): 898 824 """ … … 921 847 if not isinstance(s,scantable): 922 848 msg = "Please give a list of scantables" 923 if rcParams['verbose']: 924 #print msg 925 asaplog.push(msg) 926 print_log('ERROR') 927 return 928 else: 929 raise TypeError(msg) 849 raise TypeError(msg) 930 850 s = scantable(stm._merge(lst)) 931 851 s._add_history("merge", varlist) 932 print_log()933 852 return s 934 853 854 @asaplog_post_dec 935 855 def calibrate( scantab, scannos=[], calmode='none', verify=None ): 936 856 """ … … 946 866 if ( calmode == 'nod' ): 947 867 asaplog.push( 'Calibrating nod data.' ) 948 print_log()949 868 scal = calnod( scantab, scannos=scannos, verify=verify ) 950 869 elif ( calmode == 'quotient' ): 951 870 asaplog.push( 'Calibrating using quotient.' ) 952 print_log()953 871 scal = scantab.auto_quotient( verify=verify ) 954 872 elif ( calmode == 'ps' ): 955 873 asaplog.push( 'Calibrating %s position-switched data.' % antname ) 956 print_log()957 874 if ( antname.find( 'APEX' ) != -1 ): 958 875 scal = apexcal( scantab, scannos, calmode, verify ) … … 963 880 elif ( calmode == 'fs' or calmode == 'fsotf' ): 964 881 asaplog.push( 'Calibrating %s frequency-switched data.' % antname ) 965 print_log()966 882 if ( antname.find( 'APEX' ) != -1 ): 967 883 scal = apexcal( scantab, scannos, calmode, verify ) … … 972 888 elif ( calmode == 'otf' ): 973 889 asaplog.push( 'Calibrating %s On-The-Fly data.' % antname ) 974 print_log()975 890 scal = almacal( scantab, scannos, calmode, verify ) 976 891 else: … … 1015 930 return scal 1016 931 932 @asaplog_post_dec 1017 933 def splitant(filename, outprefix='',overwrite=False): 1018 934 """ … … 1032 948 """ 1033 949 # Import the table toolkit from CASA 1034 try: 1035 import casac 1036 except ImportError: 1037 if rcParams['verbose']: 1038 #print "failed to load casa" 1039 print_log() 1040 asaplog.push("failed to load casa") 1041 print_log('ERROR') 1042 else: raise 1043 return False 1044 try: 1045 tbtool = casac.homefinder.find_home_by_name('tableHome') 1046 tb = tbtool.create() 1047 tb2 = tbtool.create() 1048 except: 1049 if rcParams['verbose']: 1050 #print "failed to load a table tool:\n", e 1051 print_log() 1052 asaplog.push("failed to load table tool") 1053 print_log('ERROR') 1054 else: raise 1055 return False 950 import casac 951 from asap.scantable import is_ms 952 tbtool = casac.homefinder.find_home_by_name('tableHome') 953 tb = tbtool.create() 1056 954 # Check the input filename 1057 955 if isinstance(filename, str): … … 1061 959 if not os.path.exists(filename): 1062 960 s = "File '%s' not found." % (filename) 1063 if rcParams['verbose']:1064 print_log()1065 asaplog.push(s)1066 print_log('ERROR')1067 return1068 961 raise IOError(s) 1069 962 # check if input file is MS 1070 if not os.path.isdir(filename) \ 1071 or not os.path.exists(filename+'/ANTENNA') \ 1072 or not os.path.exists(filename+'/table.f1'): 963 #if not os.path.isdir(filename) \ 964 # or not os.path.exists(filename+'/ANTENNA') \ 965 # or not os.path.exists(filename+'/table.f1'): 966 if not is_ms(filename): 1073 967 s = "File '%s' is not a Measurement set." % (filename) 1074 if rcParams['verbose']:1075 print_log()1076 asaplog.push(s)1077 print_log('ERROR')1078 return1079 968 raise IOError(s) 1080 969 else: 1081 970 s = "The filename should be string. " 1082 if rcParams['verbose']:1083 print_log()1084 asaplog.push(s)1085 print_log('ERROR')1086 return1087 971 raise TypeError(s) 1088 972 # Check out put file name … … 1096 980 nant=tb.nrows() 1097 981 antnames=tb.getcol('NAME',0,nant,1) 1098 antpos=tb.getcol('POSITION',0,nant,1).transpose()1099 982 tb.close() 1100 983 tb.open(tablename=filename,nomodify=True) 1101 984 ant1=tb.getcol('ANTENNA1',0,-1,1) 1102 985 tb.close() 986 tmpname='asapmath.splitant.tmp' 1103 987 for antid in set(ant1): 1104 scan=scantable(filename,average=False,getpt=True,antenna=int(antid)) 988 tb.open(tablename=filename,nomodify=True) 989 tbsel=tb.query('ANTENNA1 == %s && ANTENNA2 == %s'%(antid,antid),tmpname) 990 scan=scantable(tmpname,average=False,getpt=True,antenna=int(antid)) 1105 991 outname=prefix+antnames[antid]+'.asap' 1106 992 scan.save(outname,format='ASAP',overwrite=overwrite) 993 tbsel.close() 994 tb.close() 995 del tbsel 1107 996 del scan 1108 997 outfiles.append(outname) 1109 del tb, tb2 998 os.system('rm -rf '+tmpname) 999 del tb 1110 1000 return outfiles 1111 1001 1002 @asaplog_post_dec 1112 1003 def _array2dOp( scan, value, mode="ADD", tsys=False ): 1113 1004 """ … … 1128 1019 del stm 1129 1020 elif len( value ) != nrow: 1130 asaplog.push( 'len(value) must be 1 or conform to scan.nrow()' ) 1131 print_log( 'ERROR' ) 1021 raise ValueError( 'len(value) must be 1 or conform to scan.nrow()' ) 1132 1022 else: 1133 1023 from asap._asap import stmath
Note:
See TracChangeset
for help on using the changeset viewer.