Changeset 113 for trunk/python/scantable.py
- Timestamp:
- 12/01/04 11:29:39 (20 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/python/scantable.py
r102 r113 7 7 The ASAP container for scans 8 8 """ 9 def functions(self): 10 return ['copy','get_scan','summary','rms','set_unit','create_mask'] 11 9 12 10 def __init__(self, filename): 13 11 """ … … 18 16 scantable 19 17 """ 18 self._vb = True 19 self._p = None 20 20 sdtable.__init__(self, filename) 21 self._unit = 'channel' 21 22 def _verbose(self, *args): 23 """ 24 Set the verbose level True or False, to indicate if output 25 should be printed as well as returned. 26 """ 27 if type(args[0]) is bool: 28 self._vb = args[0] 29 return 30 elif len(args) == 0: 31 return self._vb 32 22 33 23 34 def copy(self): … … 25 36 Return a copy of this scantable. 26 37 Parameters: 27 38 none 28 39 Example: 29 40 copiedscan = scan.copy() 30 41 """ 31 sd = sdtable._copy(self) 32 return scantable(sd) 42 sd = scantable(sdtable._copy(self)) 43 return sd 44 33 45 def get_scan(self, scanid=None): 34 46 """ … … 38 50 scanid: a scanno or a source name 39 51 Example: 40 scan.get scan('323p459')52 scan.get_scan('323p459') 41 53 # gets all scans containing the source '323p459' 42 54 """ … … 45 57 try: 46 58 if type(scanid) is str: 47 s = sdtable. getsource(self,scanid)59 s = sdtable._getsource(self,scanid) 48 60 return scantable(s) 49 61 elif type(scanid) is int: 50 s = sdtable. getscan(self,scanid)62 s = sdtable._getscan(self,scanid) 51 63 return scantable(s) 52 64 except RuntimeError: … … 86 98 87 99 def get_selection(self): 100 """ 101 Return/print a the current 'cursor' into the Beam/IF/Pol cube. 102 Parameters: 103 none 104 Returns: 105 a list of values (currentBeam,currentIF,currentPol) 106 Example: 107 none 108 """ 88 109 i = self.getbeam() 89 110 j = self.getif() 90 111 k = self.getpol() 91 out = 'Beam=%d IF=%d Pol=%d '% (i,j,k) 92 print out 112 if self._vb: 113 out = 'Beam=%d IF=%d Pol=%d '% (i,j,k) 114 print out 93 115 return i,j,k 94 116 … … 105 127 106 128 Example: 107 scan.set uint('channel')129 scan.set_unit('channel') 108 130 msk = scan.create_mask([100,200],[500,600]) 109 131 scan.rms(mask=m) … … 124 146 tmp.append(rmsval) 125 147 out += 'Beam[%d], IF[%d], Pol[%d] = %3.3f\n' % (i,j,k,rmsval) 126 print out 148 if self._vb: 149 print out 127 150 return tmp 128 151 … … 133 156 rmsval = _rms(self,mask) 134 157 out = 'Beam[%d], IF[%d], Pol[%d] = %3.3f' % (i,j,k,rmsval) 135 print out 158 if self._vb: 159 print out 136 160 return rmsval 137 161 138 162 def get_tsys(self, all=True): 163 """ 164 Return the System temperatures. 165 Parameters: 166 all: optional parameter to get the Tsys values for all 167 Beams/IFs/Pols (default) or just the one selected 168 with scantable.set_selection() 169 [True or False] 170 Returns: 171 a list of Tsys values. 172 """ 139 173 if all: 140 174 tmp = [] … … 146 180 for k in range(self.npol()): 147 181 self.setpol(k) 148 ts = self. gettsys()182 ts = self._gettsys() 149 183 tmp.append(ts) 150 184 out += 'TSys: Beam[%d], IF[%d], Pol[%d] = %3.3f\n' % (i,j,k,ts) 151 print out 185 if self._vb: 186 print out 152 187 return tmp 153 188 else: … … 155 190 j = self.getif() 156 191 k = self.getpol() 157 ts = self. gettsys()192 ts = self._gettsys() 158 193 out = 'TSys: Beam[%d], IF[%d], Pol[%d] = %3.3f' % (i,j,k,ts) 159 print out 194 if self._vb: 195 print out 160 196 return ts 197 198 def get_time(self): 199 """ 200 Get a list of time stamps for the observations. 201 Return a string for each intergration in the scantable. 202 Parameters: 203 none 204 Example: 205 none 206 """ 207 out = [] 208 for i in range(self.nrow()): 209 out.append(self._gettime(i)) 210 return out 161 211 162 212 def set_unit(self, unit='channel'): … … 165 215 Parameters: 166 216 unit: optional unit, default is 'channel' 167 one of 'GHz','MHz','km/s','channel' 168 """ 169 units = ['GHz','MHz','km/s','channel','pixel',''] 170 if unit in units: 171 if unit in ['','pixel']: 172 unit = 'channel' 173 self._unit = unit 217 one of '*Hz','km/s','channel', '' 218 """ 219 220 if unit in ['','pixel', 'channel']: 221 unit = '' 222 inf = list(self._getcoordinfo()) 223 inf[0] = unit 224 self._setcoordinfo(inf) 225 if self._p: self.plot() 226 227 def set_freqframe(self, frame='LSRK'): 228 """ 229 Set the frame type of the Spectral Axis. 230 Parameters: 231 frame: an optional frame type, default 'LSRK'. 232 Examples: 233 scan.set_freqframe('BARY') 234 """ 235 valid = ['REST','TOPO','LSRD','LSRK','BARY', \ 236 'GEO','GALACTO','LGROUP','CMB'] 237 if frame in valid: 238 inf = list(self._getcoordinfo()) 239 inf[1] = frame 240 self._setcoordinfo(inf) 174 241 else: 175 print "Invalid unit given, please use one of:" 176 print units 177 178 def create_mask(self, *args): 242 print "Please specify a valid freq type. Valid types are:\n",valid 243 244 def get_unit(self): 245 """ 246 Get the default unit set in this scantable 247 Parameters: 248 Returns: 249 A unit string 250 """ 251 inf = self._getcoordinfo() 252 unit = inf[0] 253 if unit == '': unit = 'channel' 254 return unit 255 256 def get_abscissa(self, rowno=0): 257 """ 258 Get the abscissa in the current coordinate setup for the currently 259 selected Beam/IF/Pol 260 Parameters: 261 none 262 Returns: 263 The abscissa values and it's format string. 264 """ 265 absc = self.getabscissa(rowno) 266 lbl = self.getabscissalabel(rowno) 267 return absc, lbl 268 269 def create_mask(self, *args, **kwargs): 179 270 """ 180 271 Compute and return a mask based on [min,max] windows. 272 The specified windows are to be EXCLUDED, when the mask is 273 applied. 181 274 Parameters: 182 275 [min,max],[min2,max2],... 183 276 Pairs of start/end points specifying the regions 184 277 to be masked 185 Example: 186 scan.setunit('channel') 278 invert: return an inverted mask, i.e. the regions 279 specified are not masked (INCLUDED) 280 Example: 281 scan.set_unit('channel') 282 283 a) 187 284 msk = scan.set_mask([400,500],[800,900]) 188 masks the regions between 400 and 500 189 and 800 and 900 in the unit 'channel' 190 """ 191 print "The current mask window unit is", self._unit 285 # masks the regions between 400 and 500 286 # and 800 and 900 in the unit 'channel' 287 288 b) 289 msk = scan.set_mask([400,500],[800,900], invert=True) 290 # masks the regions outside 400 and 500 291 # and 800 and 900 in the unit 'channel' 292 293 """ 294 u = self._getcoordinfo()[0] 295 if self._vb: 296 if u == "": u = "channel" 297 print "The current mask window unit is", u 192 298 n = self.nchan() 193 if self._unit == 'channel': 194 data = range(n) 195 else: 196 data = self.getabscissa(unit=self._unit) 299 data = self.getabscissa() 197 300 msk = ones(n) 198 301 for window in args: … … 201 304 return 202 305 for i in range(n): 203 if data[i] > window[0] and data[i] < window[1]:306 if data[i] >= window[0] and data[i] < window[1]: 204 307 msk[i] = 0 308 if kwargs.has_key('invert'): 309 if kwargs.get('invert'): 310 from numarray import logical_not 311 msk = logical_not(msk) 205 312 return msk 206 def set_restfrequencies(self, freqs, unit='Hz'): 313 314 def set_restfreqs(self, freqs, unit='Hz'): 207 315 """ 208 316 Set the restfrequency(s) for this scantable. … … 211 319 unit: optional 'unit', default 'Hz' 212 320 Example: 213 scan.set_restfrequencies([1000000000.0]) 214 """ 215 self.setrestfreqs(freqs, unit) 321 scan.set_restfreqs([1000000000.0]) 322 """ 323 if type(freqs) is float or int: 324 freqs = (freqs) 325 sdtable._setrestfreqs(self,freqs, unit) 216 326 return 217 327 … … 236 346 print "Please specify a valid (Beam/IF/Pol)" 237 347 return 348 349 def plot(self, what='spectrum',col='Pol', panel=None): 350 """ 351 Plot the spectra contained in the scan. Alternatively you can also 352 Plot Tsys vs Time 353 Parameters: 354 what: a choice of 'spectrum' (default) or 'tsys' 355 col: which out of Beams/IFs/Pols should be colour stacked 356 panel: set up multiple panels, currently not working. 357 """ 358 validcol = {'Beam':self.nbeam(),'IF':self.nif(),'Pol':self.npol()} 359 validyax = ['spectrum','tsys'] 360 if not self._p: 361 from asap.asaplot import ASAPlot 362 self._p = ASAPlot() 363 # print "Plotting not enabled" 364 # return 365 npan = 1 366 x = None 367 if what == 'tsys': 368 n = self.nrow() 369 if n < 2: 370 print "Only one integration. Can't plot." 371 return 372 if panel == 'Time': 373 npan = self.nrow() 374 self._p.hold() 375 self._p.clear() 376 xlab,ylab,tlab = None,None,None 377 vb = self._verbose 378 self._verbose(False) 379 sel = self.get_selection() 380 for i in range(npan): 381 for j in range(validcol[col]): 382 x = None 383 y = None 384 m = None 385 tlab = self._getsourcename(i) 386 if col == 'Beam': 387 self.setbeam(j) 388 elif col == 'IF': 389 self.setif(j) 390 elif col == 'Pol': 391 self.setpol(j) 392 if what == 'tsys': 393 x = range(self.nrow()) 394 xlab = 'Time [pixel]' 395 m = list(ones(len(x))) 396 y = [] 397 ylab = r'$T_{sys}$' 398 for k in range(len(x)): 399 y.append(self._gettsys(k)) 400 else: 401 x,xlab = self.get_abscissa(i) 402 y = self.getspectrum(i) 403 ylab = r'Flux' 404 m = self.getmask(i) 405 llab = col+' '+str(j) 406 self._p.set_line(label=llab) 407 self._p.plot(x,y,m) 408 self._p.set_axes('xlabel',xlab) 409 self._p.set_axes('ylabel',ylab) 410 self._p.set_axes('title',tlab) 411 self._p.release() 412 self.set_selection(sel[0],sel[1],sel[2]) 413 self._verbose(vb) 414 return
Note: See TracChangeset
for help on using the changeset viewer.