Changeset 1859 for trunk/python/scantable.py
- Timestamp:
- 08/05/10 14:40:38 (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/python/scantable.py
r1857 r1859 15 15 from asap.linecatalog import linecatalog 16 16 from asap.coordinate import coordinate 17 from asap.utils import _n_bools, mask_not, mask_and, mask_or 17 from asap.utils import _n_bools, mask_not, mask_and, mask_or, page 18 18 19 19 … … 101 101 tmpstr=tmpstr+antenna[i]+',' 102 102 else: 103 asaplog.push('Bad antenna selection.') 104 print_log('ERROR') 105 return 103 raise TypeError('Bad antenna selection.') 106 104 antenna = tmpstr.rstrip(',') 107 105 parallactify = parallactify or rcParams['scantable.parallactify'] … … 117 115 if not os.path.exists(filename): 118 116 s = "File '%s' not found." % (filename) 119 if rcParams['verbose']:120 asaplog.push(s)121 print_log('ERROR')122 return123 117 raise IOError(s) 124 118 if is_scantable(filename): … … 133 127 msg = "The given file '%s'is not a valid " \ 134 128 "asap table." % (filename) 135 if rcParams['verbose']: 136 #print msg 137 asaplog.push( msg ) 138 print_log( 'ERROR' ) 139 return 140 else: 141 raise IOError(msg) 129 raise IOError(msg) 142 130 else: 143 131 self._fill([filename], unit, average, getpt, antenna) … … 191 179 if not overwrite: 192 180 msg = "File %s exists." % name 193 if rcParams['verbose']: 194 #print msg 195 asaplog.push( msg ) 196 print_log( 'ERROR' ) 197 return 198 else: 199 raise IOError(msg) 181 raise IOError(msg) 200 182 format2 = format.upper() 201 183 if format2 == 'ASAP': … … 236 218 from asap import unique 237 219 if not _is_valid(scanid): 238 if rcParams['verbose']: 239 asaplog.push( 'Please specify a scanno to drop from the scantable' ) 240 print_log( 'ERROR' ) 241 return 242 else: 243 raise RuntimeError("No scan given") 244 try: 245 scanid = _to_list(scanid) 246 allscans = unique([ self.getscan(i) for i in range(self.nrow())]) 247 for sid in scanid: allscans.remove(sid) 248 if len(allscans) == 0: 249 raise ValueError("Can't remove all scans") 250 except ValueError: 251 if rcParams['verbose']: 252 print_log() 253 asaplog.push( "Couldn't find any match." ) 254 print_log( 'ERROR' ) 255 return 256 else: raise 257 try: 258 sel = selector(scans=allscans) 259 return self._select_copy(sel) 260 except RuntimeError: 261 if rcParams['verbose']: 262 print_log() 263 asaplog.push( "Couldn't find any match." ) 264 print_log( 'ERROR' ) 265 else: 266 raise 220 raise RuntimeError( 'Please specify a scanno to drop from the scantable' ) 221 scanid = _to_list(scanid) 222 allscans = unique([ self.getscan(i) for i in range(self.nrow())]) 223 for sid in scanid: allscans.remove(sid) 224 if len(allscans) == 0: 225 raise ValueError("Can't remove all scans") 226 sel = selector(scans=allscans) 227 return self._select_copy(sel) 267 228 268 229 def _select_copy(self, selection): … … 299 260 """ 300 261 if scanid is None: 301 if rcParams['verbose']: 302 #print "Please specify a scan no or name to " \ 303 # "retrieve from the scantable" 304 asaplog.push( 'Please specify a scan no or name to retrieve' 305 ' from the scantable' ) 306 print_log( 'ERROR' ) 307 return 308 else: 309 raise RuntimeError("No scan given") 310 262 raise RuntimeError( 'Please specify a scan no or name to ' 263 'retrieve from the scantable' ) 311 264 try: 312 265 bsel = self.get_selection() … … 323 276 else: 324 277 msg = "Illegal scanid type, use 'int' or 'list' if ints." 325 if rcParams['verbose']: 326 #print msg 327 asaplog.push( msg ) 328 print_log( 'ERROR' ) 329 else: 330 raise TypeError(msg) 278 raise TypeError(msg) 331 279 except RuntimeError: 332 if rcParams['verbose']: 333 #print "Couldn't find any match." 334 print_log() 335 asaplog.push( "Couldn't find any match." ) 336 print_log( 'ERROR' ) 337 else: raise 280 raise 338 281 339 282 def __str__(self): … … 362 305 else: 363 306 msg = "Illegal file name '%s'." % (filename) 364 if rcParams['verbose']: 365 #print msg 366 asaplog.push( msg ) 367 print_log( 'ERROR' ) 368 else: 369 raise IOError(msg) 370 if rcParams['verbose']: 371 try: 372 from IPython.genutils import page as pager 373 except ImportError: 374 from pydoc import pager 375 pager(info) 376 else: 377 return info 307 raise IOError(msg) 308 return page(info) 378 309 379 310 def get_spectrum(self, rowno): … … 518 449 return workscan 519 450 520 #def stats(self, stat='stddev', mask=None):451 @print_log_dec 521 452 def stats(self, stat='stddev', mask=None, form='3.3f'): 522 453 """\ … … 591 522 out += sep+"\n" 592 523 593 if rcParams['verbose']: 594 import os 595 if os.environ.has_key( 'USER' ): 596 usr=os.environ['USER'] 597 else: 598 import commands 599 usr=commands.getoutput( 'whoami' ) 600 tmpfile='/tmp/tmp_'+usr+'_casapy_asap_scantable_stats' 601 f=open(tmpfile,'w') 602 print >> f, sep 603 print >> f, ' %s %s' % (label, statunit) 604 print >> f, sep 605 print >> f, out 606 f.close() 607 f=open(tmpfile,'r') 608 x=f.readlines() 609 f.close() 610 blanc='' 611 asaplog.push(blanc.join(x), False) 612 #for xx in x: 613 # asaplog.push( xx, False ) 614 print_log() 524 525 import os 526 if os.environ.has_key( 'USER' ): 527 usr = os.environ['USER'] 528 else: 529 import commands 530 usr = commands.getoutput( 'whoami' ) 531 tmpfile = '/tmp/tmp_'+usr+'_casapy_asap_scantable_stats' 532 f = open(tmpfile,'w') 533 print >> f, sep 534 print >> f, ' %s %s' % (label, statunit) 535 print >> f, sep 536 print >> f, out 537 f.close() 538 f = open(tmpfile,'r') 539 x = f.readlines() 540 f.close() 541 asaplog.push(''.join(x), False) 542 615 543 return statvals 616 544 … … 727 655 out += '= %3.3f\n' % (outvec[i]) 728 656 out += sep+'\n' 729 if rcParams['verbose']: 730 731 732 733 734 657 658 asaplog.push(sep) 659 asaplog.push(" %s" % (label)) 660 asaplog.push(sep) 661 asaplog.push(out) 662 print_log() 735 663 return outvec 736 664 … … 945 873 else: 946 874 msg = "Please specify a valid freq type. Valid types are:\n", valid 947 if rcParams['verbose']: 948 #print msg 949 asaplog.push( msg ) 950 print_log( 'ERROR' ) 951 else: 952 raise TypeError(msg) 953 875 raise TypeError(msg) 876 877 @print_log_dec 954 878 def set_dirframe(self, frame=""): 955 879 """\ … … 967 891 """ 968 892 varlist = vars() 969 try: 970 Scantable.set_dirframe(self, frame) 971 except RuntimeError, msg: 972 if rcParams['verbose']: 973 #print msg 974 print_log() 975 asaplog.push( str(msg) ) 976 print_log( 'ERROR' ) 977 else: 978 raise 893 Scantable.set_dirframe(self, frame) 979 894 self._add_history("set_dirframe", varlist) 980 895 … … 1013 928 return abc, lbl 1014 929 930 @print_log_dec 1015 931 def flag(self, mask=None, unflag=False): 1016 932 """\ … … 1027 943 varlist = vars() 1028 944 mask = mask or [] 1029 try: 1030 self._flag(mask, unflag) 1031 except RuntimeError, msg: 1032 if rcParams['verbose']: 1033 #print msg 1034 print_log() 1035 asaplog.push( str(msg) ) 1036 print_log( 'ERROR' ) 1037 return 1038 else: raise 945 self._flag(mask, unflag) 1039 946 self._add_history("flag", varlist) 1040 947 948 @print_log_dec 1041 949 def flag_row(self, rows=[], unflag=False): 1042 950 """\ … … 1052 960 """ 1053 961 varlist = vars() 1054 try: 1055 self._flag_row(rows, unflag) 1056 except RuntimeError, msg: 1057 if rcParams['verbose']: 1058 print_log() 1059 asaplog.push( str(msg) ) 1060 print_log('ERROR') 1061 return 1062 else: raise 962 self._flag_row(rows, unflag) 1063 963 self._add_history("flag_row", varlist) 1064 964 965 @print_log_dec 1065 966 def clip(self, uthres=None, dthres=None, clipoutside=True, unflag=False): 1066 967 """\ … … 1080 981 """ 1081 982 varlist = vars() 1082 try: 1083 self._clip(uthres, dthres, clipoutside, unflag) 1084 except RuntimeError, msg: 1085 if rcParams['verbose']: 1086 print_log() 1087 asaplog.push(str(msg)) 1088 print_log('ERROR') 1089 return 1090 else: raise 983 self._clip(uthres, dthres, clipoutside, unflag) 1091 984 self._add_history("clip", varlist) 1092 985 … … 1120 1013 if not (unit == "" or base.has_key(unit)): 1121 1014 raise ValueError("%s is not a valid unit." % unit) 1122 try: 1123 if unit == "": 1124 s = scantable(self._math._lag_flag(self, start, end, "lags")) 1125 else: 1126 s = scantable(self._math._lag_flag(self, start*base[unit], 1127 end*base[unit], "frequency")) 1128 except RuntimeError, msg: 1129 if rcParams['verbose']: 1130 #print msg 1131 print_log() 1132 asaplog.push( str(msg) ) 1133 print_log( 'ERROR' ) 1134 return 1135 else: raise 1015 if unit == "": 1016 s = scantable(self._math._lag_flag(self, start, end, "lags")) 1017 else: 1018 s = scantable(self._math._lag_flag(self, start*base[unit], 1019 end*base[unit], "frequency")) 1136 1020 s._add_history("lag_flag", varlist) 1137 1021 if insitu: … … 1182 1066 data = self._getabcissa(row) 1183 1067 u = self._getcoordinfo()[0] 1184 if rcParams['verbose']:1185 if u == "":u = "channel"1186 1187 1188 1189 1190 1068 if u == "": 1069 u = "channel" 1070 msg = "The current mask window unit is %s" % u 1071 i = self._check_ifs() 1072 if not i: 1073 msg += "\nThis mask is only valid for IF=%d" % (self.getif(i)) 1074 asaplog.push(msg) 1191 1075 n = self.nchan() 1192 1076 msk = _n_bools(n, False) … … 1240 1124 data = self._getabcissa(row) 1241 1125 u = self._getcoordinfo()[0] 1242 if rcParams['verbose']:1243 if u == "":u = "channel"1244 1245 1246 1247 1248 1126 if u == "": 1127 u = "channel" 1128 msg = "The current mask window unit is %s" % u 1129 i = self._check_ifs() 1130 if not i: 1131 msg += "\nThis mask is only valid for IF=%d" % (self.getif(i)) 1132 asaplog.push(msg) 1249 1133 masklist=[] 1250 1134 ist, ien = None, None … … 1464 1348 Scantable.shift_refpix(self, delta) 1465 1349 1350 @print_log_dec 1466 1351 def history(self, filename=None): 1467 1352 """\ … … 1500 1385 else: 1501 1386 msg = "Illegal file name '%s'." % (filename) 1502 if rcParams['verbose']: 1503 #print msg 1504 asaplog.push( msg ) 1505 print_log( 'ERROR' ) 1506 else: 1507 raise IOError(msg) 1508 if rcParams['verbose']: 1509 try: 1510 from IPython.genutils import page as pager 1511 except ImportError: 1512 from pydoc import pager 1513 pager(out) 1514 else: 1515 return out 1516 return 1387 raise IOError(msg) 1388 return page(out) 1517 1389 # 1518 1390 # Maths business … … 1558 1430 scanav = (scanav and 'SCAN') or 'NONE' 1559 1431 scan = (self, ) 1560 try: 1561 if align: 1562 scan = (self.freq_align(insitu=False), ) 1563 s = None 1564 if weight.upper() == 'MEDIAN': 1565 s = scantable(self._math._averagechannel(scan[0], 'MEDIAN', 1566 scanav)) 1567 else: 1568 s = scantable(self._math._average(scan, mask, weight.upper(), 1569 scanav)) 1570 except RuntimeError, msg: 1571 if rcParams['verbose']: 1572 #print msg 1573 print_log() 1574 asaplog.push( str(msg) ) 1575 print_log( 'ERROR' ) 1576 return 1577 else: raise 1432 1433 if align: 1434 scan = (self.freq_align(insitu=False), ) 1435 s = None 1436 if weight.upper() == 'MEDIAN': 1437 s = scantable(self._math._averagechannel(scan[0], 'MEDIAN', 1438 scanav)) 1439 else: 1440 s = scantable(self._math._average(scan, mask, weight.upper(), 1441 scanav)) 1578 1442 s._add_history("average_time", varlist) 1579 1443 return s … … 1854 1718 """ 1855 1719 varlist = vars() 1856 try: 1857 s = scantable(self._math._convertpol(self, poltype)) 1858 except RuntimeError, msg: 1859 if rcParams['verbose']: 1860 #print msg 1861 print_log() 1862 asaplog.push( str(msg) ) 1863 print_log( 'ERROR' ) 1864 return 1865 else: 1866 raise 1720 s = scantable(self._math._convertpol(self, poltype)) 1867 1721 s._add_history("convert_pol", varlist) 1868 1722 return s … … 2032 1886 except RuntimeError: 2033 1887 msg = "The fit failed, possibly because it didn't converge." 2034 if rcParams['verbose']: 2035 #print msg 2036 print_log() 2037 asaplog.push( str(msg) ) 2038 print_log( 'ERROR' ) 2039 return 2040 else: 2041 raise RuntimeError(msg) 1888 raise RuntimeError(msg) 2042 1889 2043 1890 … … 2550 2397 from asap.asapfit import asapfit 2551 2398 fit = asapfit(self._getfit(row)) 2552 if rcParams['verbose']: 2553 #print fit 2554 asaplog.push( '%s' %(fit) ) 2555 return 2556 else: 2557 return fit.as_dict() 2399 asaplog.push( '%s' %(fit) ) 2400 return fit.as_dict() 2558 2401 2559 2402 def flag_nans(self): … … 2649 2492 return (sum(nchans)/len(nchans) == nchans[0]) 2650 2493 2494 @print_log_dec 2651 2495 def _fill(self, names, unit, average, getpt, antenna): 2652 2496 first = True … … 2657 2501 if not os.path.exists(name): 2658 2502 msg = "File '%s' does not exists" % (name) 2659 if rcParams['verbose']:2660 asaplog.push(msg)2661 print_log( 'ERROR' )2662 return2663 2503 raise IOError(msg) 2664 2504 fullnames.append(name) … … 2673 2513 msg = "Importing %s..." % (name) 2674 2514 asaplog.push(msg, False) 2675 print_log()2676 2515 r.open(name)# antenna, -1, -1, getpt) 2677 2516 r.fill()
Note: See TracChangeset
for help on using the changeset viewer.