Changeset 525
- Timestamp:
- 03/01/05 14:17:19 (20 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/python/asapplotter.py
r485 r525 19 19 self._pdict = {'Pol':'p','pol':'p','p':'p'} 20 20 self._sdict = {'scan':'s','Scan':'s','s':'s','S':'s'} 21 self._cdict = {'t':' scan.nrow()',22 'b':' scan.nbeam()',23 'i':' scan.nif()',24 'p':' scan.npol()',21 self._cdict = {'t':'len(self._cursor["t"])', 22 'b':'len(self._cursor["b"])', 23 'i':'len(self._cursor["i"])', 24 'p':'len(self._cursor["p"])', 25 25 's':'len(scans)'} 26 26 self._ldict = {'b':'Beam', … … 36 36 self._cols = None 37 37 self._autoplot = False 38 self._minmax = None 38 self._minmaxx = None 39 self._minmaxy = None 39 40 self._data = None 40 41 self._lmap = [] … … 42 43 self._ordinate = None 43 44 self._abcissa = None 45 self._cursor = {'t':None, 'b':None, 46 'i':None, 'p':None 47 } 44 48 45 49 def _translate(self, name): … … 49 53 return None 50 54 51 def plot(self, *args):55 def plot(self, *args): 52 56 """ 53 57 Plot a (list of) scantables. … … 57 61 If a (list) of scantables was specified in a previous call 58 62 to plot, no argument has to be given to 'replot' 59 NO checking is done that the ab scissas of the scantables63 NO checking is done that the abcissas of the scantables 60 64 are consistent e.g. all 'channel' or all 'velocity' etc. 61 65 """ … … 65 69 self._plotter.hold() 66 70 if len(args) > 0: 67 self._data = tuple(args) 71 if self._data is not None: 72 if list(args) != self._data: 73 self._data = list(args) 74 # reset cursor 75 self.set_cursor() 76 else: 77 self._data = list(args) 78 self.set_cursor() 68 79 if self._panels == 't': 69 if self._data[0].nrow() > 25: 70 print "Scan to be plotted contains more than 25 rows.\nCan't plot that many panels..." 80 if self._data[0].nrow() > 49: 81 print "Scan to be plotted contains more than 25 rows.\n \ 82 Can't plot that many panels..." 71 83 return 72 84 self._plot_time(self._data[0], self._stacking) … … 75 87 else: 76 88 self._plot_other(self._data, self._stacking) 77 if self._minmax is not None:78 self._plotter.set_limits(xlim=self._minmax )89 if self._minmaxx is not None or self._minmaxy is not None: 90 self._plotter.set_limits(xlim=self._minmaxx,ylim=self._minmaxy) 79 91 self._plotter.release() 80 92 return … … 83 95 if colmode == 't': 84 96 return 85 n = scan.nrow()97 n = len(self._cursor["t"]) 86 98 cdict = {'b':'scan.setbeam(j)', 87 99 'i':'scan.setif(j)', 88 100 'p':'scan.setpol(j)'} 101 cdict2 = {'b':'self._cursor["b"]', 102 'i':'self._cursor["i"]', 103 'p':'self._cursor["p"]'} 104 ncol = 1 89 105 if self._stacking is not None: 90 106 ncol = eval(self._cdict.get(colmode)) … … 97 113 else: 98 114 self._plotter.set_panels(rows=n,cols=0,nplots=n) 99 for i in range(n): 115 rows = self._cursor["t"] 116 self._plotter.palette(1) 117 for rowsel in rows: 118 i = self._cursor["t"].index(rowsel) 100 119 if n > 1: 101 120 self._plotter.palette(1) 102 121 self._plotter.subplot(i) 103 for j in range(ncol): 122 colvals = eval(cdict2.get(colmode)) 123 for j in colvals: 124 polmode = "raw" 125 jj = colvals.index(j) 126 savej = j 127 for k in cdict.keys(): 128 sel = eval(cdict2.get(k)) 129 j = sel[0] 130 if k == "p": 131 which = self._cursor["p"].index(j) 132 polmode = self._polmode[which] 133 j = which 134 eval(cdict.get(k)) 135 j = savej 136 if colmode == "p": 137 polmode = self._polmode[self._cursor["p"].index(j)] 138 j = jj 104 139 eval(cdict.get(colmode)) 105 140 x = None … … 107 142 m = None 108 143 if not self._title: 109 tlab = scan._getsourcename( i)144 tlab = scan._getsourcename(rowsel) 110 145 else: 111 146 if len(self._title) == n: 112 tlab = self._title[ i]147 tlab = self._title[rowsel] 113 148 else: 114 tlab = scan._getsourcename( i)115 x,xlab = scan.get_abcissa( i)149 tlab = scan._getsourcename(rowsel) 150 x,xlab = scan.get_abcissa(rowsel) 116 151 if self._abcissa: xlab = self._abcissa 117 y = scan._getspectrum(i) 152 y = None 153 if polmode == "stokes": 154 y = scan._getstokesspectrum(rowsel) 155 elif polmode == "stokes2": 156 y = scan._getstokesspectrum(rowsel,True) 157 else: 158 y = scan._getspectrum(rowsel) 118 159 if self._ordinate: 119 160 ylab = self._ordinate 120 161 else: 121 162 ylab = 'Flux ('+scan.get_fluxunit()+')' 122 m = scan._getmask( i)163 m = scan._getmask(rowsel) 123 164 if self._lmap and len(self._lmap) > 0: 124 llab = self._lmap[j] 125 else: 126 llab = self._ldict.get(colmode)+' '+str(j) 165 llab = self._lmap[jj] 166 else: 167 if colmode == 'p': 168 if polmode == "stokes": 169 llab = scan._getpolarizationlabel(0,1,0) 170 elif polmode == "stokes2": 171 llab = scan._getpolarizationlabel(0,1,1) 172 else: 173 llab = scan._getpolarizationlabel(1,0,0) 174 else: 175 llab = self._ldict.get(colmode)+' '+str(j) 127 176 self._plotter.set_line(label=llab) 128 177 self._plotter.plot(x,y,m) … … 134 183 return 135 184 136 def _plot_scans(self, scans, colmode): 185 def _plot_scans(self, scans, colmode): 186 print "Can only plot one row per scan." 137 187 if colmode == 's': 138 188 return … … 140 190 'i':'scan.setif(j)', 141 191 'p':'scan.setpol(j)'} 192 cdict2 = {'b':'self._cursor["b"]', 193 'i':'self._cursor["i"]', 194 'p':'self._cursor["p"]'} 195 142 196 n = len(scans) 197 ncol = 1 143 198 if self._stacking is not None: 144 199 scan = scans[0] … … 152 207 else: 153 208 self._plotter.set_panels(rows=n,cols=0,nplots=n) 154 i = 0209 self._plotter.palette(1) 155 210 for scan in scans: 156 211 if n > 1: 157 self._plotter.subplot( i)212 self._plotter.subplot(scans.index(scan)) 158 213 self._plotter.palette(1) 159 for j in range(ncol): 214 colvals = eval(cdict2.get(colmode)) 215 rowsel = self._cursor["t"][0] 216 for j in colvals: 217 polmode = "raw" 218 jj = colvals.index(j) 219 savej = j 220 for k in cdict.keys(): 221 sel = eval(cdict2.get(k)) 222 j = sel[0] 223 eval(cdict.get(k)) 224 if k == "p": 225 which = self._cursor["p"].index(j) 226 polmode = self._polmode[which] 227 j = which 228 j = savej 229 if colmode == "p": 230 polmode = self._polmode[self._cursor["p"].index(j)] 231 j = jj 160 232 eval(cdict.get(colmode)) 161 233 x = None … … 164 236 tlab = self._title 165 237 if not self._title: 166 tlab = scan._getsourcename( )167 x,xlab = scan.get_abcissa( )238 tlab = scan._getsourcename(rowsel) 239 x,xlab = scan.get_abcissa(rowsel) 168 240 if self._abcissa: xlab = self._abcissa 169 y = scan._getspectrum() 241 if polmode == "stokes": 242 y = scan._getstokesspectrum(rowsel) 243 elif polmode == "stokes2": 244 y = scan._getstokesspectrum(rowsel,True) 245 else: 246 y = scan._getspectrum(rowsel) 170 247 if self._ordinate: 171 248 ylab = self._ordinate 172 249 else: 173 250 ylab = 'Flux ('+scan.get_fluxunit()+')' 174 m = scan._getmask( )251 m = scan._getmask(rowsel) 175 252 if self._lmap and len(self._lmap) > 0: 176 llab = self._lmap[j] 177 else: 178 llab = self._ldict.get(colmode)+' '+str(j) 253 llab = self._lmap[jj] 254 else: 255 if colmode == 'p': 256 if polmode == "stokes": 257 llab = scan._getpolarizationlabel(0,1,0) 258 elif polmode == "stokes2": 259 llab = scan._getpolarizationlabel(0,1,1) 260 else: 261 llab = scan._getpolarizationlabel(1,0,0) 262 else: 263 llab = self._ldict.get(colmode)+' '+str(j) 179 264 self._plotter.set_line(label=llab) 180 265 self._plotter.plot(x,y,m) … … 185 270 self._plotter.set_axes('ylabel',ylab) 186 271 self._plotter.set_axes('title',tlab) 187 i += 1188 272 return 189 273 … … 191 275 if colmode == self._panels: 192 276 return 193 cdict = {'b':'scan.setbeam(j)', 194 'i':'scan.setif(j)', 195 'p':'scan.setpol(j)', 196 's':'scans[j]'} 277 cdict = {'b':'scan.setbeam(i)', 278 'i':'scan.setif(i)', 279 'p':'scan.setpol(i)'} 280 cdict2 = {'b':'self._cursor["b"]', 281 'i':'self._cursor["i"]', 282 'p':'self._cursor["p"]', 283 's': 'scans', 284 't': 'self._cursor["t"]'} 197 285 scan = scans[0] 198 286 n = eval(self._cdict.get(self._panels)) 287 ncol=1 199 288 if self._stacking is not None: 200 289 ncol = eval(self._cdict.get(colmode)) … … 206 295 nplots=n) 207 296 else: 208 print n209 297 self._plotter.set_panels(rows=n,cols=0,nplots=n) 210 for i in range(n): 298 self._plotter.palette(1) 299 panels = self._cursor[self._panels] 300 for i in panels: 301 polmode = "raw" 302 ii = self._cursor[self._panels].index(i) 211 303 if n>1: 212 self._plotter.subplot(i) 213 self._plotter.palette(1) 214 k=0 215 j=i 216 eval(cdict.get(self._panels)) 217 for j in range(ncol): 304 self._plotter.subplot(ii) 305 if self._panels == "p": 306 polmode = self._polmode[ii] 307 eval(cdict.get(self._panels)) 308 else: 309 eval(cdict.get(self._panels)) 310 colvals = eval(cdict2.get(colmode)) 311 for j in colvals: 312 rowsel = self._cursor["t"][0] 313 jj = colvals.index(j) 314 savei = i 315 for k in cdict.keys(): 316 if k != self._panels: 317 sel = eval(cdict2.get(k)) 318 i = sel[0] 319 if k == "p": 320 which = self._cursor["p"].index(j) 321 polmode = self._polmode[which] 322 i = which 323 eval(cdict.get(k)) 324 i = savei 218 325 if colmode == 's': 219 scan = eval(cdict.get(colmode))326 scan = j 220 327 elif colmode == 't': 221 k = j 222 else: 328 rowsel = j 329 else: 330 savei = i 331 if colmode == 'p': 332 polmode = self._polmode[self._cursor["p"].index(j)] 333 i = j 223 334 eval(cdict.get(colmode)) 335 i = savei 224 336 x = None 225 337 y = None 226 338 m = None 227 x,xlab = scan.get_abcissa( k)339 x,xlab = scan.get_abcissa(rowsel) 228 340 if self._abcissa: xlab = self._abcissa 229 y = scan._getspectrum(k) 341 if polmode == "stokes": 342 y = scan._getstokesspectrum(rowsel) 343 elif polmode == "stokes2": 344 y = scan._getstokesspectrum(rowsel,True) 345 else: 346 y = scan._getspectrum(rowsel) 347 230 348 if self._ordinate: 231 349 ylab = self._ordinate 232 350 else: 233 351 ylab = 'Flux ('+scan.get_fluxunit()+')' 234 m = scan._getmask( k)352 m = scan._getmask(rowsel) 235 353 if colmode == 's' or colmode == 't': 236 if not self._title: 354 if self._title and len(self._title) > 0: 355 tlab = self._title[ii] 356 else: 237 357 tlab = self._ldict.get(self._panels)+' '+str(i) 238 else: 239 if len(self.title) == n: 240 tlab = self._title[i] 241 else: 242 tlab = self._ldict.get(self._panels)+' '+str(i) 243 llab = scan._getsourcename(k) 358 llab = scan._getsourcename(rowsel) 244 359 else: 245 360 if self._title and len(self._title) > 0: 246 tlab = self._title[i ]361 tlab = self._title[ii] 247 362 else: 248 363 tlab = self._ldict.get(self._panels)+' '+str(i) 249 364 if self._lmap and len(self._lmap) > 0: 250 llab = self._lmap[j ]365 llab = self._lmap[jj] 251 366 else: 252 llab = self._ldict.get(colmode)+' '+str(j) 367 if colmode == 'p': 368 if polmode == "stokes": 369 llab = scan._getpolarizationlabel(0,1,0) 370 elif polmode == "stokes2": 371 llab = scan._getpolarizationlabel(0,1,1) 372 else: 373 llab = scan._getpolarizationlabel(1,0,0) 374 else: 375 llab = self._ldict.get(colmode)+' '+str(j) 376 if self._panels == 'p': 377 if polmode == "stokes": 378 tlab = scan._getpolarizationlabel(0,1,0) 379 elif polmode == "stokes2": 380 tlab = scan._getpolarizationlabel(0,1,1) 381 else: 382 tlab = scan._getpolarizationlabel(1,0,0) 253 383 self._plotter.set_line(label=llab) 254 384 self._plotter.plot(x,y,m) … … 289 419 290 420 def set_panels(self, what=None): 291 """292 """293 421 if not what: 294 422 what = rcParams['plotter.panelling'] … … 326 454 return False 327 455 328 def set_range(self, start=None,end=None):456 def set_range(self,xstart=None,xend=None,ystart=None,yend=None): 329 457 """ 330 458 Set the range of interest on the abcissa of the plot 331 459 Parameters: 332 start,end: The start an end pointof the 'zoom' window460 [x,y]start,[x,y]end: The start and end points of the 'zoom' window 333 461 Note: 334 462 These become non-sensical when the unit changes. … … 336 464 337 465 """ 338 if start is None andend is None:339 self._minmax = None466 if xstart is None and xend is None: 467 self._minmaxx = None 340 468 if self._data: self.plot() 341 else: 342 self._minmax = [start,end] 469 return 470 if ystart is None and yend is None: 471 self._minmaxy = None 343 472 if self._data: self.plot() 473 return 474 self._minmaxx = [xstart,xend] 475 self._minmaxy = [ystart,yend] 476 if self._data: self.plot() 344 477 return 345 478 … … 391 524 self._plotter.save(filename) 392 525 return 393 526 527 def set_cursor(self, row=None,beam=None,IF=None,pol=None): 528 """ 529 Specify a 'cursor' for plotting selected spectra. Time (rows), 530 Beam, IF, Polarisation ranges can be specified. 531 Parameters: 532 Default for all paramaters is to select all available 533 row: selects the rows (time stamps) to be plotted, this has 534 to be a vector of row indices, e.g. row=[0,2,5] or row=[2] 535 beam: select a range of beams 536 IF: select a range of IFs 537 pol: select Polarisations for plotting these can be by index 538 (raw polarisations (default)) or by names any of: 539 ["I", "Q", "U", "V"] or 540 ["I", "Plinear", "Pangle", "V"] or 541 ["XX", "YY", "Real(XY)", "Imag(XY)"] 542 Circular polarisation are not handled yet. 543 Example: 544 plotter.set_mode('pol','time') 545 plotter.plot(myscan) # plots all raw polarisations colour stacked 546 plotter.set_cursor(pol=["I"]) # plot "I" only for all rows 547 # plot "I" only for two time stamps row=0 and row=2 548 plotter.set_cursor(row=[0,2],pol=["I"]) 549 550 Note: 551 Be careful to select only exisiting polarisations. 552 """ 553 if not self._data: 554 print "Can only set cursor after a first call to plot()" 555 return 556 557 n = self._data[0].nrow() 558 if row is None: 559 self._cursor["t"] = range(n) 560 else: 561 for i in row: 562 if 0 > i >= n: 563 print "Row index '%d' out of range" % i 564 return 565 self._cursor["t"] = row 566 567 n = self._data[0].nbeam() 568 if beam is None: 569 self._cursor["b"] = range(n) 570 else: 571 for i in beam: 572 if 0 > i >= n: 573 print "Beam index '%d' out of range" % i 574 return 575 self._cursor["b"] = beam 576 577 n = self._data[0].nif() 578 if IF is None: 579 self._cursor["i"] = range(n) 580 else: 581 for i in IF: 582 if 0 > i >= n: 583 print "IF index '%d' out of range" %i 584 return 585 self._cursor["i"] = IF 586 587 n = self._data[0].npol() 588 dstokes = {"I":0,"Q":1,"U":2,"V":3} 589 dstokes2 = {"I":0,"Plinear":1,"Pangle":2,"V":3} 590 draw = {"XX":0, "YY":1,"Real(XY)":2, "Imag(XY)":3} 591 dcirc = { "RR":0,"LL":1,"RL":2,"LR":3} 592 593 if pol is None: 594 self._cursor["p"] = range(n) 595 self._polmode = ["raw" for i in range(n)] 596 else: 597 if isinstance(pol,str): 598 pol = pol.split() 599 polmode = [] 600 pols = [] 601 for i in pol: 602 if isinstance(i,str): 603 if draw.has_key(i): 604 pols.append(draw.get(i)) 605 polmode.append("raw") 606 elif dstokes.has_key(i): 607 pols.append(dstokes.get(i)) 608 polmode.append("stokes") 609 elif dstokes2.has_key(i): 610 pols.append(dstokes2.get(i)) 611 polmode.append("stokes2") 612 elif dcirc.has_key(i): 613 pols.append(dcirc.get(i)) 614 polmode.append("cricular") 615 else: 616 "Pol type '%s' not valid" %i 617 return 618 elif 0 > i >= n: 619 print "Pol index '%d' out of range" %i 620 return 621 else: 622 pols.append(i) 623 polmode.append("raw") 624 self._cursor["p"] = pols 625 self._polmode = polmode 626 if self._data: self.plot() 627 628 394 629 if __name__ == '__main__': 395 630 plotter = asapplotter()
Note:
See TracChangeset
for help on using the changeset viewer.