Changeset 256
- Timestamp:
- 01/21/05 22:25:08 (20 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/python/scantable.py
r241 r256 59 59 sdtable.__init__(self,tbl) 60 60 61 def save(self, name= "", format=None):61 def save(self, name=None, format=None, overwrite=False): 62 62 """ 63 63 Store the scantable on disk. This can be a asap file or SDFITS/MS2. … … 72 72 'MS2' (saves as an aips++ 73 73 MeasurementSet V2) 74 overwrite: if the file should be overwritten if it exists. 75 The default False is to return with warning 76 without writing the output 74 77 Example: 75 78 scan.save('myscan.asap') … … 77 80 """ 78 81 if format is None: format = rcParams['scantable.save'] 82 suffix = '.'+format.lower() 83 if name is None or name =="": 84 name = 'scantable'+suffix 85 from os import path 86 if path.isfile(name) or path.isdir(name): 87 if not overwrite: 88 print "File %s already exists." % name 89 return 79 90 if format == 'ASAP': 80 91 self._save(name) … … 119 130 120 131 def __str__(self): 121 return sdtable. summary(self)132 return sdtable._summary(self) 122 133 123 134 def summary(self,filename=None): … … 128 139 Default - no file output 129 140 """ 130 info = sdtable. summary(self)141 info = sdtable._summary(self) 131 142 if filename is not None: 143 if filename is "": 144 filename = 'scantable_summary.txt' 132 145 data = open(filename, 'w') 133 146 data.write(info) … … 135 148 print info 136 149 137 def set_ selection(self, thebeam=0,theif=0,thepol=0):150 def set_cursor(self, thebeam=0,theif=0,thepol=0): 138 151 """ 139 152 Set the spectrum for individual operations. … … 141 154 thebeam,theif,thepol: a number 142 155 Example: 143 scan.set_ selection(0,0,1)156 scan.set_cursor(0,0,1) 144 157 pol1sig = scan.stats(all=False) # returns std dev for beam=0 145 158 # if=0, pol=1 … … 150 163 return 151 164 152 def get_ selection(self):165 def get_cursor(self): 153 166 """ 154 167 Return/print a the current 'cursor' into the Beam/IF/Pol cube. … … 165 178 if self._vb: 166 179 print "--------------------------------------------------" 167 print " Cursor selection"180 print " Cursor position" 168 181 print "--------------------------------------------------" 169 182 out = 'Beam=%d IF=%d Pol=%d ' % (i,j,k) … … 191 204 if all is None: all = rcParams['scantable.allaxes'] 192 205 from asap._asap import stats as _stats 206 from numarray import array,zeros,Float 193 207 if mask == None: 194 208 mask = ones(self.nchan()) 209 axes = ['Beam','IF','Pol','Time'] 210 195 211 if all: 196 out = '' 197 tmp = [] 198 for l in range(self.nrow()): 199 tm = self._gettime(l) 200 out += 'Time[%s]:\n' % (tm) 201 for i in range(self.nbeam()): 202 self.setbeam(i) 203 if self.nbeam() > 1: out += ' Beam[%d] ' % (i) 204 for j in range(self.nif()): 205 self.setif(j) 206 if self.nif() > 1: out += ' IF[%d] ' % (j) 207 for k in range(self.npol()): 208 self.setpol(k) 209 if self.npol() > 1: out += ' Pol[%d] ' % (k) 210 statval = _stats(self,mask,stat,l) 211 tmp.append(statval) 212 out += '= %3.3f\n' % (statval[0]) 213 out += "--------------------------------------------------\n" 212 n = self.nbeam()*self.nif()*self.npol()*self.nrow() 213 shp = [self.nbeam(),self.nif(),self.npol(),self.nrow()] 214 arr = array(zeros(n),shape=shp,type=Float) 215 216 for i in range(self.nbeam()): 217 self.setbeam(i) 218 for j in range(self.nif()): 219 self.setif(j) 220 for k in range(self.npol()): 221 self.setpol(k) 222 arr[i,j,k,:] = _stats(self,mask,stat,-1) 223 retval = {'axes': axes, 'data': arr, 'cursor':None} 224 tm = [self._gettime(val) for val in range(self.nrow())] 214 225 if self._vb: 215 print "--------------------------------------------------" 216 print " ",stat 217 out += "--------------------------------------------------\n" 218 print out 219 return tmp 226 self._print_values(retval,stat,tm) 227 return retval 220 228 221 229 else: 222 i = self.getbeam() 223 j = self.getif() 224 k = self.getpol() 230 i,j,k = (self.getbeam(),self.getif(),self.getpol()) 225 231 statval = _stats(self,mask,stat,-1) 226 232 out = '' … … 239 245 print "--------------------------------------------------" 240 246 print out 241 return statval 247 retval = {'axes': axes, 'data': array(statval), 'cursor':(i,j,k)} 248 return retval 242 249 243 250 def stddev(self,mask=None, all=None): … … 267 274 all: optional parameter to get the Tsys values for all 268 275 Beams/IFs/Pols (default) or just the one selected 269 with scantable.set_ selection()276 with scantable.set_cursor() 270 277 [True or False] 271 278 Returns: … … 273 280 """ 274 281 if all is None: all = rcParams['scantable.allaxes'] 282 from numarray import array,zeros,Float 283 axes = ['Beam','IF','Pol','Time'] 284 275 285 if all: 276 out = '' 277 tmp = [] 278 for l in range(self.nrow()): 279 tm = self._gettime(l) 280 out += 'Time[%s]:\n' % (tm) 281 for i in range(self.nbeam()): 282 self.setbeam(i) 283 if self.nbeam() > 1: out += ' Beam[%d] ' % (i) 284 for j in range(self.nif()): 285 self.setif(j) 286 if self.nif() > 1: out += ' IF[%d] ' % (j) 287 for k in range(self.npol()): 288 self.setpol(k) 289 if self.npol() > 1: out += ' Pol[%d] ' % (k) 290 ts = self._gettsys() 291 tmp.append(ts) 292 out += '= %3.3f\n' % (ts[l]) 293 out+= "--------------------------------------------------\n" 286 n = self.nbeam()*self.nif()*self.npol()*self.nrow() 287 shp = [self.nbeam(),self.nif(),self.npol(),self.nrow()] 288 arr = array(zeros(n),shape=shp,type=Float) 289 290 for i in range(self.nbeam()): 291 self.setbeam(i) 292 for j in range(self.nif()): 293 self.setif(j) 294 for k in range(self.npol()): 295 self.setpol(k) 296 arr[i,j,k,:] = self._gettsys() 297 retval = {'axes': axes, 'data': arr, 'cursor':None} 298 tm = [self._gettime(val) for val in range(self.nrow())] 294 299 if self._vb: 295 print "--------------------------------------------------" 296 print " Tsys" 297 print "--------------------------------------------------" 298 print out 299 return tmp 300 self._print_values(retval,'Tsys',tm) 301 return retval 302 300 303 else: 301 i = self.getbeam() 302 j = self.getif() 303 k = self.getpol() 304 ts = self._gettsys() 304 i,j,k = (self.getbeam(),self.getif(),self.getpol()) 305 statval = self._gettsys() 305 306 out = '' 306 307 for l in range(self.nrow()): … … 310 311 if self.nif() > 1: out += ' IF[%d] ' % (j) 311 312 if self.npol() > 1: out += ' Pol[%d] ' % (k) 312 out += '= %3.3f\n' % (ts[l]) 313 out += "--------------------------------------------------\n" 313 out += '= %3.3f\n' % (statval[l]) 314 out += "--------------------------------------------------\n" 315 314 316 if self._vb: 315 317 print "--------------------------------------------------" 316 print " T sys"318 print " TSys" 317 319 print "--------------------------------------------------" 318 320 print out 319 return ts 321 retval = {'axes': axes, 'data': array(statval), 'cursor':(i,j,k)} 322 return retval 320 323 321 324 def get_time(self): … … 388 391 The abcissa values and it's format string. 389 392 """ 390 abc = self. getabcissa(rowno)391 lbl = self. getabcissalabel(rowno)393 abc = self._getabcissa(rowno) 394 lbl = self._getabcissalabel(rowno) 392 395 return abc, lbl 393 396 … … 423 426 print "The current mask window unit is", u 424 427 n = self.nchan() 425 data = self. getabcissa()428 data = self._getabcissa() 426 429 msk = zeros(n) 427 430 for window in args: … … 451 454 sdtable._setrestfreqs(self,freqs, unit) 452 455 return 456 def get_restfreqs(self): 457 """ 458 Get the restfrequency(s) stored in this scantable. 459 The return value(s) are always of unit 'Hz' 460 Parameters: 461 none 462 Returns: 463 a list of doubles 464 """ 465 return list(self._getrestfreqs()) 453 466 454 467 def flag_spectrum(self, thebeam, theif, thepol): … … 507 520 xlab,ylab,tlab = None,None,None 508 521 self._vb = False 509 sel = self.get_ selection()522 sel = self.get_cursor() 510 523 for i in range(npan): 511 524 if npan > 1: … … 534 547 else: 535 548 x,xlab = self.get_abcissa(i) 536 y = self. getspectrum(i)549 y = self._getspectrum(i) 537 550 ylab = r'Flux' 538 m = self. getmask(i)551 m = self._getmask(i) 539 552 llab = col+' '+str(j) 540 553 self._p.set_line(label=llab) … … 544 557 self._p.set_axes('title',tlab) 545 558 self._p.release() 546 self.set_ selection(sel[0],sel[1],sel[2])559 self.set_cursor(sel[0],sel[1],sel[2]) 547 560 self._vb = rcParams['verbose'] 548 561 return 562 563 print out 564 565 def _print_values(self, dat, label='', timestamps=[]): 566 d = dat['data'] 567 a = dat['axes'] 568 shp = d.getshape() 569 out = '' 570 for i in range(shp[3]): 571 out += '%s [%s]:\n' % (a[3],timestamps[i]) 572 t = d[:,:,:,i] 573 for j in range(shp[0]): 574 if shp[0] > 1: out += ' %s[%d] ' % (a[0],j) 575 for k in range(shp[1]): 576 if shp[1] > 1: out += ' %s[%d] ' % (a[1],k) 577 for l in range(shp[2]): 578 if shp[2] > 1: out += ' %s[%d] ' % (a[2],l) 579 out += '= %3.3f\n' % (t[j,k,l]) 580 out += "--------------------------------------------------\n" 581 print "--------------------------------------------------" 582 print " ", label 583 print "--------------------------------------------------" 584 print out
Note:
See TracChangeset
for help on using the changeset viewer.