- Timestamp:
- 02/21/05 08:25:12 (20 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/python/scantable.py
r474 r484 9 9 """ 10 10 11 def __init__(self, filename, unit=None):11 def __init__(self, filename, average=None, unit=None): 12 12 """ 13 13 Create a scantable from a saved one or make a reference … … 21 21 [advanced] a reference to an existing 22 22 scantable 23 unit: brightness unit; must be consistent with K or Jy. 23 average: average all integrations withinb a scan on read. 24 The default (True) is taken from .asaprc. 25 unit: brightness unit; must be consistent with K or Jy. 24 26 Over-rides the default selected by the reader 25 27 (input rpfits/sdfits/ms) or replaces the value 26 28 in existing scantables 27 29 """ 30 varlist = vars() 28 31 self._vb = rcParams['verbose'] 29 32 self._p = None 30 from os import stat as st 31 import stat 33 34 if average is None or type(average) is not bool: 35 autoav = rcParams['scantable.autoaverage'] 36 32 37 if isinstance(filename,sdtable): 33 38 sdtable.__init__(self, filename) … … 49 54 print "The given file '%s'is not a valid asap table." % (filename) 50 55 return 51 else: 52 autoav = rcParams['scantable.autoaverage'] 53 56 else: 54 57 from asap._asap import sdreader 55 58 ifSel = -1 … … 70 73 else: 71 74 sdtable.__init__(self,tbl) 75 self._add_history("scantable", varlist) 72 76 73 77 def save(self, name=None, format=None, stokes=False, overwrite=False): … … 178 182 print "Illegal file name '%s'." % (filename) 179 183 print info 180 184 181 185 def set_cursor(self, thebeam=0,theif=0,thepol=0): 182 186 """ … … 189 193 # if=0, pol=1 190 194 """ 195 varlist = vars() 191 196 self.setbeam(thebeam) 192 197 self.setpol(thepol) 193 198 self.setif(theif) 199 self._add_history("set_cursor",varlist) 194 200 return 195 201 … … 380 386 one of '*Hz','km/s','channel', '' 381 387 """ 382 388 varlist = vars() 383 389 if unit in ['','pixel', 'channel']: 384 390 unit = '' … … 387 393 self._setcoordinfo(inf) 388 394 if self._p: self.plot() 389 390 def set_instrument (self, instr): 395 self._add_history("set_unit",varlist) 396 397 def set_instrument(self, instr): 391 398 """ 392 399 Set the instrument for subsequent processing … … 396 403 """ 397 404 self._setInstrument(instr) 405 self._add_history("set_instument",vars()) 398 406 399 407 def set_doppler(self, doppler='RADIO'): … … 403 411 doppler: One of 'RADIO', 'OPTICAL', 'Z', 'BETA', 'GAMMA' 404 412 """ 405 413 varlist = vars() 406 414 inf = list(self._getcoordinfo()) 407 415 inf[2] = doppler 408 416 self._setcoordinfo(inf) 409 417 if self._p: self.plot() 418 self._add_history("set_doppler",vars()) 410 419 411 420 def set_freqframe(self, frame=None): … … 417 426 scan.set_freqframe('BARY') 418 427 """ 419 if not frame: frame = rcParams['scantable.freqframe'] 428 if frame is None: frame = rcParams['scantable.freqframe'] 429 varlist = vars() 420 430 valid = ['REST','TOPO','LSRD','LSRK','BARY', \ 421 431 'GEO','GALACTO','LGROUP','CMB'] … … 424 434 inf[1] = frame 425 435 self._setcoordinfo(inf) 436 self._add_history("set_freqframe",varlist) 426 437 else: 427 438 print "Please specify a valid freq type. Valid types are:\n",valid … … 480 491 481 492 """ 493 varlist = vars() 482 494 u = self._getcoordinfo()[0] 483 495 if self._vb: … … 487 499 data = self._getabcissa() 488 500 msk = zeros(n) 489 for 501 for window in args: 490 502 if (len(window) != 2 or window[0] > window[1] ): 491 503 print "A window needs to be defined as [min,max]" … … 498 510 from numarray import logical_not 499 511 msk = logical_not(msk) 512 self._add_history("create_mask", varlist) 500 513 return msk 501 514 … … 517 530 sdtable._lines(self) 518 531 519 def set_restfreqs(self, freqs=None, unit='Hz', lines=None, source=None, theif=None): 532 def set_restfreqs(self, freqs=None, unit='Hz', lines=None, source=None, 533 theif=None): 520 534 """ 521 535 Select the restfrequency for the specified source and IF OR … … 548 562 scan.set_restfreqs(freqs=[1.4e9,1.67e9]) 549 563 """ 564 varlist = vars() 550 565 if source is None: 551 566 source = "" … … 563 578 lines = [] 564 579 sdtable._setrestfreqs(self, freqs, unit, lines, source, theif) 565 return 580 self._add_history("set_restfreqs", varlist) 581 566 582 567 583 … … 585 601 sdtable.setpol(self, thepol) 586 602 sdtable._flag(self) 603 self._add_history("flag_spectrum", vars()) 587 604 else: 588 605 print "Please specify a valid (Beam/IF/Pol)" … … 683 700 if shp[2] > 1: out += ' %s[%d] ' % (a[2],l) 684 701 out += '= %3.3f\n' % (t[j,k,l]) 685 out += "--------------------------------------------------\n" 686 print "--------------------------------------------------" 702 out += "-"*80 703 out += "\n" 704 print "-"*80 687 705 print " ", label 688 print "- -------------------------------------------------"706 print "-"*80 689 707 print out 708 709 def history(self): 710 hist = list(self._gethistory()) 711 print "-"*80 712 for h in hist: 713 items = h.split("##") 714 date = items[0] 715 func = items[1] 716 items = items[2:] 717 print date 718 print "Function: %s\n Parameters:" % (func) 719 for i in items: 720 s = i.split("=") 721 print " %s: %s" % (s[0],s[1]) 722 print "-"*80 723 return 724 725 def _add_history(self, funcname, parameters): 726 # create date 727 sep = "##" 728 from datetime import datetime 729 dstr = datetime.now().strftime('%Y/%m/%d %H:%M:%S') 730 hist = dstr+sep 731 hist += funcname+sep#cdate+sep 732 if parameters.has_key('self'): del parameters['self'] 733 for k,v in parameters.iteritems(): 734 if type(v) is dict: 735 for k2,v2 in v.iteritems(): 736 hist += k2 737 hist += "=" 738 if isinstance(v2,scantable): 739 hist += 'scantable' 740 elif k2 == 'mask': 741 hist += str(self._zip_mask(v2)) 742 else: 743 hist += str(v2) 744 else: 745 hist += k 746 hist += "=" 747 if isinstance(v,scantable): 748 hist += 'scantable' 749 elif k == 'mask': 750 hist += str(self._zip_mask(v)) 751 else: 752 hist += str(v) 753 hist += sep 754 hist = hist[:-2] # remove trailing '##' 755 self._addhistory(hist) 756 757 758 def _zip_mask(self, mask): 759 mask = list(mask) 760 i = 0 761 segments = [] 762 while mask[i:].count(1): 763 i += mask[i:].index(1) 764 if mask[i:].count(0): 765 j = i + mask[i:].index(0) 766 else: 767 j = len(mask) 768 segments.append([i,j]) 769 i = j 770 return segments
Note:
See TracChangeset
for help on using the changeset viewer.