Changeset 710 for trunk/python/scantable.py
- Timestamp:
- 11/11/05 10:01:49 (19 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/python/scantable.py
r670 r710 8 8 The ASAP container for scans 9 9 """ 10 10 11 11 def __init__(self, filename, average=None, unit=None): 12 12 """ … … 27 27 (input rpfits/sdfits/ms) or replaces the value 28 28 in existing scantables 29 """ 29 """ 30 30 if average is None or type(average) is not bool: 31 average = rcParams['scantable.autoaverage'] 31 average = rcParams['scantable.autoaverage'] 32 32 33 33 varlist = vars() 34 34 self._vb = rcParams['verbose'] 35 35 self._p = None 36 36 from asap import asaplog 37 37 if isinstance(filename,sdtable): 38 sdtable.__init__(self, filename) 38 sdtable.__init__(self, filename) 39 39 if unit is not None: 40 self.set_fluxunit(unit) 40 self.set_fluxunit(unit) 41 41 else: 42 42 import os.path 43 43 if not os.path.exists(filename): 44 print "File '%s' not found." % (filename) 45 return 44 s = "File '%s' not found." % (filename) 45 if rcParams['verbose']: 46 asaplog.push(s) 47 print asaplog.pop().strip() 48 return 49 raise IOError(s) 46 50 filename = os.path.expandvars(filename) 47 51 if os.path.isdir(filename): … … 50 54 sdtable.__init__(self, filename) 51 55 if unit is not None: 52 self.set_fluxunit(unit) 56 self.set_fluxunit(unit) 53 57 else: 54 58 print "The given file '%s'is not a valid asap table." % (filename) 55 59 return 56 else: 60 else: 57 61 from asap._asap import sdreader 58 62 ifSel = -1 59 63 beamSel = -1 60 r = sdreader(filename,ifSel,beamSel) 61 print 'Importing data...' 64 r = sdreader() 65 r._setlog(asaplog) 66 r._open(filename,ifSel,beamSel) 67 asaplog.push('Importing data...') 62 68 r._read([-1]) 63 69 tbl = r._getdata() … … 66 72 if average: 67 73 from asap._asap import average as _av 68 print 'Auto averaging integrations...'74 asaplog.push('Auto averaging integrations...') 69 75 tbl2 = _av((tbl,),(),True,'none') 70 76 sdtable.__init__(self,tbl2) … … 74 80 del r,tbl 75 81 self._add_history("scantable", varlist) 82 log = asaplog.pop() 83 if len(log): print log 76 84 77 85 def save(self, name=None, format=None, stokes=False, overwrite=False): 78 86 """ 79 Store the scantable on disk. This can be an asap (aips++) Table, SDFITS, 87 Store the scantable on disk. This can be an asap (aips++) Table, SDFITS, 80 88 Image FITS or MS2 format. 81 89 Parameters: … … 88 96 Allowed are - 'ASAP' (save as ASAP [aips++] Table), 89 97 'SDFITS' (save as SDFITS file) 90 'FITS' (saves each row as a FITS Image) 98 'FITS' (saves each row as a FITS Image) 91 99 'ASCII' (saves as ascii text file) 92 100 'MS2' (saves as an aips++ … … 192 200 print "Illegal file name '%s'." % (filename) 193 201 print info 194 202 195 203 def set_cursor(self, beam=0, IF=0, pol=0): 196 204 """ … … 370 378 retval = {'axes': axes, 'data': array(statval), 'cursor':(i,j,k)} 371 379 return retval 372 380 373 381 def get_time(self, row=-1): 374 382 """ … … 409 417 Set the instrument for subsequent processing 410 418 Parameters: 411 instr: Select from 'ATPKSMB', 'ATPKSHOH', 'ATMOPRA', 419 instr: Select from 'ATPKSMB', 'ATPKSHOH', 'ATMOPRA', 412 420 'DSS-43' (Tid), 'CEDUNA', and 'HOBART' 413 421 """ … … 427 435 if self._p: self.plot() 428 436 self._add_history("set_doppler",vars()) 429 437 430 438 def set_freqframe(self, frame=None): 431 439 """ … … 450 458 else: 451 459 print "Please specify a valid freq type. Valid types are:\n",valid 452 460 453 461 def get_unit(self): 454 462 """ … … 474 482 """ 475 483 abc = self._getabcissa(rowno) 476 lbl = self._getabcissalabel(rowno) 484 lbl = self._getabcissalabel(rowno) 477 485 return abc, lbl 478 486 #return {'abcissa':abc,'label':lbl} … … 505 513 # masks the regions between 400 and 500 506 514 # and 800 and 900 in the unit 'channel' 507 515 508 516 """ 509 517 row = 0 … … 517 525 n = self.nchan() 518 526 msk = zeros(n) 519 for window in args: 527 # test if args is a 'list' or a 'normal *args - UGLY!!! 528 529 ws = (isinstance(args[-1][-1],int) or isinstance(args[-1][-1],float)) and args or args[0] 530 print ws 531 for window in ws: 532 print window 520 533 if (len(window) != 2 or window[0] > window[1] ): 521 534 print "A window needs to be defined as [min,max]" … … 527 540 if kwargs.get('invert'): 528 541 from numarray import logical_not 529 msk = logical_not(msk) 542 msk = logical_not(msk) 530 543 return msk 531 544 532 545 def get_restfreqs(self): 533 546 """ … … 558 571 a vector, then it MUST be of length the number of IFs 559 572 (and the available restfrequencies will be replaced by 560 this vector). In this case, *all* data ('source' and 561 'theif' are ignored) have the restfrequency set per IF according 562 to the corresponding value you give in the 'freqs' vector. 563 E.g. 'freqs=[1e9,2e9]' would mean IF 0 gets restfreq 1e9 and 573 this vector). In this case, *all* data ('source' and 574 'theif' are ignored) have the restfrequency set per IF according 575 to the corresponding value you give in the 'freqs' vector. 576 E.g. 'freqs=[1e9,2e9]' would mean IF 0 gets restfreq 1e9 and 564 577 IF 1 gets restfreq 2e9. 565 578 … … 596 609 sdtable._setrestfreqs(self, freqs, unit, lines, source, theif) 597 610 self._add_history("set_restfreqs", varlist) 598 611 599 612 600 613 … … 633 646 """ 634 647 print "Warning! Not fully functional. Use plotter.plot() instead" 635 648 636 649 validcol = {'Beam':self.nbeam(),'IF':self.nif(),'Pol':self.npol()} 637 650 … … 659 672 xlab,ylab,tlab = None,None,None 660 673 self._vb = False 661 sel = self.get_cursor() 674 sel = self.get_cursor() 662 675 for i in range(npan): 663 676 if npan > 1: … … 700 713 return 701 714 702 print out 715 print out 703 716 704 717 def _print_values(self, dat, label='', timestamps=[]): … … 722 735 print " ", label 723 736 print "-"*80 724 print out 737 print out 725 738 726 739 def history(self): … … 735 748 func = items[1] 736 749 items = items[2:] 737 print date 750 print date 738 751 print "Function: %s\n Parameters:" % (func) 739 752 for i in items: … … 765 778 Example: 766 779 # time average the scantable without using a mask 767 newscan = scan.average_time() 780 newscan = scan.average_time() 768 781 """ 769 782 varlist = vars() 770 783 if weight is None: weight = 'tint' 771 784 if mask is None: mask = () 772 from asap._asap import average as _av 785 from asap._asap import average as _av 773 786 s = scantable(_av((self,), mask, scanav, weight)) 774 787 s._add_history("average_time",varlist) 775 788 return s 776 789 777 790 def convert_flux(self, jyperk=None, eta=None, d=None, insitu=None, 778 791 allaxes=None): … … 873 886 self._add_history("gain_el", varlist) 874 887 return 875 888 876 889 def freq_align(self, reftime=None, method='cubic', perif=False, 877 890 insitu=None): … … 957 970 return 958 971 959 972 960 973 def resample(self, width=5, method='cubic', insitu=None): 961 974 """ … … 1111 1124 from asap.asaplinefind import linefinder 1112 1125 from asap import _is_sequence_or_number as _is_valid 1113 1126 1114 1127 if not _is_valid(edge, int): 1115 1128 raise RuntimeError, "Parameter 'edge' has to be an integer or a \ 1116 1129 pair of integers specified as a tuple" 1117 1130 1118 1131 # setup fitter 1119 1132 f = fitter() … … 1161 1174 def rotate_linpolphase(self, angle, allaxes=None): 1162 1175 """ 1163 Rotate the phase of the complex polarization O=Q+iU correlation. 1164 This is always done in situ in the raw data. So if you call this 1176 Rotate the phase of the complex polarization O=Q+iU correlation. 1177 This is always done in situ in the raw data. So if you call this 1165 1178 function more than once then each call rotates the phase further. 1166 1179 Parameters: … … 1178 1191 self._add_history("rotate_linpolphase", varlist) 1179 1192 return 1180 1193 1181 1194 1182 1195 def rotate_xyphase(self, angle, allaxes=None): … … 1266 1279 trailing '_R' (Mopra/Parkes) or 1267 1280 '_e'/'_w' (Tid) 1268 preserve: you can preserve (default) the continuum or 1269 remove it. The equations used are 1281 preserve: you can preserve (default) the continuum or 1282 remove it. The equations used are 1270 1283 preserve: Output = Toff * (on/off) - Toff 1271 1284 remove: Output = Tref * (on/off) - Ton … … 1280 1293 srcs = self.get_scan("*[^_ewR]") 1281 1294 refs = self.get_scan("*[_ewR]") 1282 return scantable(_quot(srcs,refs, preserve)) 1295 if isinstance(srcs,scantable) and isinstance(refs,scantable): 1296 ns,nr = srcs.nrow(),refs.nrow() 1297 if nr > ns: 1298 refs = refs.get_scan(range(ns)) 1299 return scantable(_quot(srcs,refs, preserve)) 1300 else: 1301 raise RuntimeError("Couldn't find any on/off pairs") 1283 1302 else: 1284 1303 print "not yet implemented" 1285 1304 return None 1286 1305 1287 1306 def quotient(self, other, isreference=True, preserve=True): 1288 1307 """ … … 1296 1315 isreference: if the 'other' scan is the reference (default) 1297 1316 or source 1298 preserve: you can preserve (default) the continuum or 1299 remove it. The equations used are 1317 preserve: you can preserve (default) the continuum or 1318 remove it. The equations used are 1300 1319 preserve: Output = Toff * (on/off) - Toff 1301 1320 remove: Output = Tref * (on/off) - Ton … … 1316 1335 s = None 1317 1336 if isinstance(other, scantable): 1318 from asap._asap import b_operate as _bop 1337 from asap._asap import b_operate as _bop 1319 1338 s = scantable(_bop(self, other, 'add', True)) 1320 1339 elif isinstance(other, float): … … 1335 1354 s = None 1336 1355 if isinstance(other, scantable): 1337 from asap._asap import b_operate as _bop 1356 from asap._asap import b_operate as _bop 1338 1357 s = scantable(_bop(self, other, 'sub', True)) 1339 1358 elif isinstance(other, float): … … 1345 1364 s._add_history("operator -", varlist) 1346 1365 return s 1347 1366 1348 1367 def __mul__(self, other): 1349 1368 """ … … 1353 1372 s = None 1354 1373 if isinstance(other, scantable): 1355 from asap._asap import b_operate as _bop 1374 from asap._asap import b_operate as _bop 1356 1375 s = scantable(_bop(self, other, 'mul', True)) 1357 1376 elif isinstance(other, float): … … 1366 1385 s._add_history("operator *", varlist) 1367 1386 return s 1368 1387 1369 1388 1370 1389 def __div__(self, other): … … 1375 1394 s = None 1376 1395 if isinstance(other, scantable): 1377 from asap._asap import b_operate as _bop 1396 from asap._asap import b_operate as _bop 1378 1397 s = scantable(_bop(self, other, 'div', True)) 1379 1398 elif isinstance(other, float): … … 1442 1461 hist = hist[:-2] # remove trailing '##' 1443 1462 self._addhistory(hist) 1444 1463 1445 1464 1446 1465 def _zip_mask(self, mask): … … 1453 1472 j = i + mask[i:].index(0) 1454 1473 else: 1455 j = len(mask) 1474 j = len(mask) 1456 1475 segments.append([i,j]) 1457 i = j 1476 i = j 1458 1477 return segments 1459 1478 def _get_ordinate_label(self): … … 1466 1485 lbl = "Flux density "+ fu 1467 1486 return lbl 1468 1487
Note: See TracChangeset
for help on using the changeset viewer.