- Timestamp:
- 11/17/05 16:37:53 (19 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/python/scantable.py
r714 r718 33 33 34 34 varlist = vars() 35 self._vb = rcParams['verbose']36 35 self._p = None 37 36 from asap import asaplog … … 57 56 self.set_fluxunit(unit) 58 57 else: 59 print "The given file '%s'is not a valid asap table." % (filename) 60 return 58 msg = "The given file '%s'is not a valid asap table." % (filename) 59 if rcParams['verbose']: 60 print msg 61 return 62 else: 63 raise IOError(msg) 61 64 else: 62 65 from asap._asap import sdreader … … 114 117 if name is None or name =="": 115 118 name = 'scantable'+suffix 116 print "No filename given. Using default name %s..." % name 119 from asap import asaplog 120 msg = "No filename given. Using default name %s..." % name 121 asaplog.push(msg) 117 122 name = path.expandvars(name) 118 123 if path.isfile(name) or path.isdir(name): 119 124 if not overwrite: 120 print "File %s already exists." % name 121 return 125 msg = "File %s exists." % name 126 if rcParams['verbose']: 127 print msg 128 return 129 else: 130 raise IOError(msg) 122 131 format2 = format.upper() 123 132 if format2 == 'ASAP': … … 127 136 w = _sw(format2) 128 137 w.write(self, name, stokes) 138 139 print_log() 129 140 return 130 141 … … 157 168 """ 158 169 if scanid is None: 159 print "Please specify a scan no or name to retrieve from the scantable" 170 if rcParams['verbose']: 171 print "Please specify a scan no or name to retrieve from the scantable" 172 return 173 else: 174 raise RuntimeError("No scan given") 175 160 176 try: 161 177 if type(scanid) is str: … … 169 185 return scantable(s) 170 186 else: 171 print "Illegal scanid type, use 'int' or 'list' if ints." 187 msg = "Illegal scanid type, use 'int' or 'list' if ints." 188 if rcParams['verbose']: 189 print msg 190 else: 191 raise TypeError(msg) 172 192 except RuntimeError: 173 print "Couldn't find any match." 193 if rcParams['verbose']: print "Couldn't find any match." 194 else: raise 174 195 175 196 def __str__(self): … … 197 218 data.close() 198 219 else: 199 print "Illegal file name '%s'." % (filename) 200 print info 220 msg = "Illegal file name '%s'." % (filename) 221 if rcParams['verbose']: 222 print msg 223 else: 224 raise IOError(msg) 225 if rcParams['verbose']: 226 print info 227 else: 228 return info 201 229 202 230 def set_cursor(self, beam=0, IF=0, pol=0): … … 230 258 j = self.getif() 231 259 k = self.getpol() 232 if self._vb:260 if rcParams['verbose']: 233 261 print "--------------------------------------------------" 234 262 print " Cursor position" … … 236 264 out = 'Beam=%d IF=%d Pol=%d ' % (i,j,k) 237 265 print out 238 return i,j,k 266 else: 267 return i,j,k 239 268 240 269 def stats(self, stat='stddev', mask=None, allaxes=None): … … 278 307 retval = {'axes': axes, 'data': arr, 'cursor':None} 279 308 tm = [self._gettime(val) for val in range(self.nrow())] 280 if self._vb:309 if rcParams['verbose']: 281 310 self._print_values(retval,stat,tm) 282 311 self.setbeam(beamSel) … … 297 326 out += "--------------------------------------------------\n" 298 327 299 if self._vb:328 if rcParams['verbose']: 300 329 print "--------------------------------------------------" 301 330 print " ",stat … … 353 382 retval = {'axes': axes, 'data': arr, 'cursor':None} 354 383 tm = [self._gettime(val) for val in range(self.nrow())] 355 if self._vb:384 if rcParams['verbose']: 356 385 self._print_values(retval,'Tsys',tm) 357 386 return retval … … 370 399 out += "--------------------------------------------------\n" 371 400 372 if self._vb:401 if rcParams['verbose']: 373 402 print "--------------------------------------------------" 374 403 print " TSys" … … 437 466 self._setInstrument(instr) 438 467 self._add_history("set_instument",vars()) 468 print_log() 439 469 440 470 def set_doppler(self, doppler='RADIO'): … … 450 480 if self._p: self.plot() 451 481 self._add_history("set_doppler",vars()) 482 print_log() 452 483 453 484 def set_freqframe(self, frame=None): … … 472 503 self._add_history("set_freqframe",varlist) 473 504 else: 474 print "Please specify a valid freq type. Valid types are:\n",valid 505 msg = "Please specify a valid freq type. Valid types are:\n",valid 506 if rcParams['verbose']: 507 print msg 508 else: 509 raise TypeError(msg) 510 print_log() 475 511 476 512 def get_unit(self): … … 498 534 abc = self._getabcissa(rowno) 499 535 lbl = self._getabcissalabel(rowno) 536 print_log() 500 537 return abc, lbl 501 #return {'abcissa':abc,'label':lbl}502 538 503 539 def create_mask(self, *args, **kwargs): … … 535 571 data = self._getabcissa(row) 536 572 u = self._getcoordinfo()[0] 537 if self._vb:573 if rcParams['verbose']: 538 574 if u == "": u = "channel" 539 print "The current mask window unit is", u 575 from asap import asaplog 576 msg = "The current mask window unit is %s" % u 577 asaplog.push(msg) 540 578 n = self.nchan() 541 579 msk = zeros(n) … … 543 581 544 582 ws = (isinstance(args[-1][-1],int) or isinstance(args[-1][-1],float)) and args or args[0] 545 print ws546 583 for window in ws: 547 print window548 584 if (len(window) != 2 or window[0] > window[1] ): 549 print "A window needs to be defined as [min,max]" 550 return 585 raise TypeError("A window needs to be defined as [min,max]") 551 586 for i in range(n): 552 587 if data[i] >= window[0] and data[i] < window[1]: … … 556 591 from numarray import logical_not 557 592 msk = logical_not(msk) 593 print_log() 558 594 return msk 559 595 … … 654 690 print "Please specify a valid (Beam/IF/Pol)" 655 691 return 656 657 def plot(self, what='spectrum',col='Pol', panel=None):658 """659 Plot the spectra contained in the scan. Alternatively you can also660 Plot Tsys vs Time661 Parameters:662 what: a choice of 'spectrum' (default) or 'tsys'663 col: which out of Beams/IFs/Pols should be colour stacked664 panel: set up multiple panels, currently not working.665 """666 print "Warning! Not fully functional. Use plotter.plot() instead"667 668 validcol = {'Beam':self.nbeam(),'IF':self.nif(),'Pol':self.npol()}669 670 validyax = ['spectrum','tsys']671 from asap.asaplot import ASAPlot672 if not self._p:673 self._p = ASAPlot()674 #print "Plotting not enabled"675 #return676 if self._p.is_dead:677 del self._p678 self._p = ASAPlot()679 npan = 1680 x = None681 if what == 'tsys':682 n = self.nrow()683 if n < 2:684 print "Only one integration. Can't plot."685 return686 self._p.hold()687 self._p.clear()688 if panel == 'Time':689 npan = self.nrow()690 self._p.set_panels(rows=npan)691 xlab,ylab,tlab = None,None,None692 self._vb = False693 sel = self.get_cursor()694 for i in range(npan):695 if npan > 1:696 self._p.subplot(i)697 for j in range(validcol[col]):698 x = None699 y = None700 m = None701 tlab = self._getsourcename(i)702 import re703 tlab = re.sub('_S','',tlab)704 if col == 'Beam':705 self.setbeam(j)706 elif col == 'IF':707 self.setif(j)708 elif col == 'Pol':709 self.setpol(j)710 if what == 'tsys':711 x = range(self.nrow())712 xlab = 'Time [pixel]'713 m = list(ones(len(x)))714 y = []715 ylab = r'$T_{sys}$'716 for k in range(len(x)):717 y.append(self._gettsys(k))718 else:719 x,xlab = self.get_abcissa(i)720 y = self._getspectrum(i)721 ylab = r'Flux'722 m = self._getmask(i)723 llab = col+' '+str(j)724 self._p.set_line(label=llab)725 self._p.plot(x,y,m)726 self._p.set_axes('xlabel',xlab)727 self._p.set_axes('ylabel',ylab)728 self._p.set_axes('title',tlab)729 self._p.release()730 self.set_cursor(sel[0],sel[1],sel[2])731 self._vb = rcParams['verbose']732 return733 734 print out735 692 736 693 def _print_values(self, dat, label='', timestamps=[]): … … 805 762 s = scantable(_av((self,), mask, scanav, weight)) 806 763 s._add_history("average_time",varlist) 764 print_log() 807 765 return s 808 766 … … 837 795 s = scantable(_convert(self, d, eta, jyperk, allaxes)) 838 796 s._add_history("convert_flux", varlist) 797 print_log() 839 798 return s 840 799 else: … … 842 801 _convert(self, d, eta, jyperk, allaxes) 843 802 self._add_history("convert_flux", varlist) 803 print_log() 844 804 return 845 805 … … 899 859 s = scantable(_gainEl(self, poly, filename, method, allaxes)) 900 860 s._add_history("gain_el", varlist) 861 print_log() 901 862 return s 902 863 else: … … 904 865 _gainEl(self, poly, filename, method, allaxes) 905 866 self._add_history("gain_el", varlist) 867 print_log() 906 868 return 907 869 … … 932 894 s = scantable(_align(self, reftime, method, perfreqid)) 933 895 s._add_history("freq_align", varlist) 896 print_log() 934 897 return s 935 898 else: … … 937 900 _align(self, reftime, method, perfreqid) 938 901 self._add_history("freq_align", varlist) 902 print_log() 939 903 return 940 904 … … 961 925 s = scantable(_opacity(self, tau, allaxes)) 962 926 s._add_history("opacity", varlist) 927 print_log() 963 928 return s 964 929 else: … … 966 931 _opacity(self, tau, allaxes) 967 932 self._add_history("opacity", varlist) 933 print_log() 968 934 return 969 935 … … 982 948 s = scantable(_bin(self, width)) 983 949 s._add_history("bin",varlist) 950 print_log() 984 951 return s 985 952 else: … … 987 954 _bin(self, width) 988 955 self._add_history("bin",varlist) 956 print_log() 989 957 return 990 958 … … 1007 975 s = scantable(_resample(self, method, width)) 1008 976 s._add_history("resample",varlist) 977 print_log() 1009 978 return s 1010 979 else: … … 1012 981 _resample(self, method, width) 1013 982 self._add_history("resample",varlist) 983 print_log() 1014 984 return 1015 985 … … 1037 1007 s = scantable(_avpol(self, mask, weight)) 1038 1008 s._add_history("average_pol",varlist) 1009 print_log() 1039 1010 return s 1040 1011 else: … … 1042 1013 _avpol(self, mask, weight) 1043 1014 self._add_history("average_pol",varlist) 1015 print_log() 1044 1016 return 1045 1017 … … 1072 1044 s = scantable(_smooth(self,kernel,width,allaxes)) 1073 1045 s._add_history("smooth", varlist) 1046 print_log() 1074 1047 return s 1075 1048 else: … … 1077 1050 _smooth(self,kernel,width,allaxes) 1078 1051 self._add_history("smooth", varlist) 1052 print_log() 1079 1053 return 1080 1054 … … 1107 1081 if insitu: 1108 1082 self._add_history("poly_baseline", varlist) 1083 print_log() 1109 1084 return 1110 1085 else: 1111 1086 sf._add_history("poly_baseline", varlist) 1087 print_log() 1112 1088 return sf 1113 1089 … … 1120 1096 1121 1097 Parameters: 1122 scan: a scantable1123 1098 mask: an optional mask retreived from scantable 1124 1099 edge: an optional number of channel to drop at … … 1145 1120 1146 1121 if not _is_valid(edge, int): 1122 1147 1123 raise RuntimeError, "Parameter 'edge' has to be an integer or a \ 1148 1124 pair of integers specified as a tuple" … … 1162 1138 workscan=self 1163 1139 1164 vb=workscan._vb1165 # remember the verbose parameter and selection1166 workscan._vb=False1167 1140 sel=workscan.get_cursor() 1168 1141 rows=range(workscan.nrow()) 1142 from asap import asaplog 1169 1143 for i in range(workscan.nbeam()): 1170 1144 workscan.setbeam(i) … … 1173 1147 for k in range(workscan.npol()): 1174 1148 workscan.setpol(k) 1175 if f._vb:1176 print "Processing:"1177 print 'Beam[%d], IF[%d], Pol[%d]' % (i,j,k)1149 asaplog.push("Processing:") 1150 msg = 'Beam[%d], IF[%d], Pol[%d]' % (i,j,k) 1151 asaplog.push(msg) 1178 1152 for iRow in rows: 1179 1153 fl.set_scan(workscan,mask,edge) … … 1187 1161 workscan._setspectrum(f.fitter.getresidual(),iRow) 1188 1162 workscan.set_cursor(sel[0],sel[1],sel[2]) 1189 workscan._vb = vb1190 1163 if not insitu: 1191 return workscan1164 return workscan 1192 1165 1193 1166 def rotate_linpolphase(self, angle, allaxes=None): … … 1209 1182 _rotate(self, angle, allaxes) 1210 1183 self._add_history("rotate_linpolphase", varlist) 1184 print_log() 1211 1185 return 1212 1186 … … 1230 1204 _rotate_xyphase(self, angle, allaxes) 1231 1205 self._add_history("rotate_xyphase", varlist) 1206 print_log() 1232 1207 return 1233 1208 … … 1252 1227 s = scantable(_add(self, offset, allaxes)) 1253 1228 s._add_history("add",varlist) 1229 print_log() 1254 1230 return s 1255 1231 else: … … 1257 1233 _add(self, offset, allaxes) 1258 1234 self._add_history("add",varlist) 1235 print_log() 1259 1236 return 1260 1237 … … 1280 1257 s = scantable(_scale(self, factor, allaxes, tsys)) 1281 1258 s._add_history("scale",varlist) 1259 print_log() 1282 1260 return s 1283 1261 else: … … 1285 1263 _scale(self, factor, allaxes, tsys) 1286 1264 self._add_history("scale",varlist) 1265 print_log() 1287 1266 return 1288 1267 … … 1315 1294 if nr > ns: 1316 1295 refs = refs.get_scan(range(ns)) 1296 print_log() 1317 1297 return scantable(_quot(srcs,refs, preserve)) 1318 1298 else: 1319 raise RuntimeError("Couldn't find any on/off pairs") 1320 else: 1321 print "not yet implemented" 1299 msg = "Couldn't find any on/off pairs" 1300 if rcParams['verbose']: 1301 print msg 1302 return 1303 else: 1304 raise RuntimeError() 1305 else: 1306 if rcParams['verbose']: print "not yet implemented" 1322 1307 return None 1323 1308 … … 1344 1329 """ 1345 1330 from asap._asap import quotient as _quot 1346 if isreference: 1347 return scantable(_quot(self, other, preserve)) 1348 else: 1349 return scantable(_quot(other, self, preserve)) 1331 try: 1332 s = None 1333 if isreference: 1334 s = scantable(_quot(self, other, preserve)) 1335 else: 1336 s = scantable(_quot(other, self, preserve)) 1337 print_log() 1338 return s 1339 except RuntimeError,e: 1340 if rcParams['verbose']: 1341 print e 1342 return 1343 else: raise 1344 1345 def freq_switch(self, insitu=None): 1346 """ 1347 Apply frequency switching to the data. 1348 Parameters: 1349 insitu: if False a new scantable is returned. 1350 Otherwise, the swictching is done in-situ 1351 The default is taken from .asaprc (False) 1352 Example: 1353 none 1354 """ 1355 if insitu is None: insitu = rcParams['insitu'] 1356 varlist = vars() 1357 try: 1358 if insitu: 1359 from asap._asap import _frequency_switch_insitu 1360 _frequency_switch_insitu(self) 1361 self._add_history("freq_switch", varlist) 1362 print_log() 1363 return 1364 else: 1365 from asap._asap import _frequency_switch 1366 sf = scantable(_frequency_switch(self)) 1367 sf._add_history("freq_switch", varlist) 1368 print_log() 1369 return sf 1370 except RuntimeError,e: 1371 if rcParams['verbose']: print e 1372 else: raise 1350 1373 1351 1374 def __add__(self, other): … … 1359 1382 s = scantable(_add(self, other, True)) 1360 1383 else: 1361 print "Other input is not a scantable or float value" 1362 return 1384 raise TypeError("Other input is not a scantable or float value") 1363 1385 s._add_history("operator +", varlist) 1386 print_log() 1364 1387 return s 1365 1388 … … 1378 1401 s = scantable(_add(self, -other, True)) 1379 1402 else: 1380 print "Other input is not a scantable or float value" 1381 return 1403 raise TypeError("Other input is not a scantable or float value") 1382 1404 s._add_history("operator -", varlist) 1405 print_log() 1383 1406 return s 1384 1407 … … 1394 1417 elif isinstance(other, float): 1395 1418 if other == 0.0: 1396 print "Multiplying by zero is not recommended." 1397 return 1419 raise ZeroDivisionError("Dividing by zero is not recommended") 1398 1420 from asap._asap import scale as _sca 1399 1421 s = scantable(_sca(self, other, True)) 1400 1422 else: 1401 print "Other input is not a scantable or float value" 1402 return 1423 raise TypeError("Other input is not a scantable or float value") 1403 1424 s._add_history("operator *", varlist) 1425 print_log() 1404 1426 return s 1405 1427 … … 1416 1438 elif isinstance(other, float): 1417 1439 if other == 0.0: 1418 print "Dividing by zero is not recommended" 1419 return 1440 raise ZeroDivisionError("Dividing by zero is not recommended") 1420 1441 from asap._asap import scale as _sca 1421 1442 s = scantable(_sca(self, 1.0/other, True)) 1422 1443 else: 1423 print "Other input is not a scantable or float value" 1424 return 1444 raise TypeError("Other input is not a scantable or float value") 1425 1445 s._add_history("operator /", varlist) 1446 print_log() 1426 1447 return s 1427 1448 … … 1436 1457 from asap import asapfit 1437 1458 fit = asapfit(self._getfit(row)) 1438 if self._vb:1459 if rcParams['verbose']: 1439 1460 print fit 1440 1461 return
Note:
See TracChangeset
for help on using the changeset viewer.