Changeset 709 for trunk/python
- Timestamp:
- 11/02/05 13:26:04 (19 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/python/asapplotter.py
r702 r709 1 from asap.asaplot import ASAPlot2 1 from asap import rcParams 2 from numarray import logical_and 3 3 4 4 class asapplotter: … … 11 11 other variables. 12 12 """ 13 def __init__(self): 14 self._plotter = ASAPlot() 15 13 def __init__(self, visible=True): 14 15 if visible: 16 from asap.asaplotgui import asaplotgui as asaplot 17 else: 18 from asap.asaplot import asaplot 19 self._plotter = asaplot() 20 16 21 self._tdict = {'Time':'t','time':'t','t':'t','T':'t'} 17 22 self._bdict = {'Beam':'b','beam':'b','b':'b','B':'b'} … … 40 45 self._minmaxx = None 41 46 self._minmaxy = None 47 self._datamask = None 42 48 self._data = None 43 49 self._lmap = None … … 45 51 self._ordinate = None 46 52 self._abcissa = None 53 self._abcunit = None 47 54 self._cursor = {'t':None, 'b':None, 48 55 'i':None, 'p':None … … 54 61 return d[name] 55 62 return None 56 63 57 64 def plot(self, *args): 58 65 """ 59 66 Plot a (list of) scantables. 60 67 Parameters: 61 one or more comma separated scantables 68 one or more comma separated scantables 62 69 Note: 63 70 If a (list) of scantables was specified in a previous call … … 66 73 are consistent e.g. all 'channel' or all 'velocity' etc. 67 74 """ 68 75 if self._plotter.is_dead: 69 76 self._plotter = ASAPlot() 70 77 self._plotter.hold() 71 78 self._plotter.clear() 72 79 if len(args) > 0: 73 if self._data is not None: 80 if self._data is not None: 74 81 if list(args) != self._data: 75 82 self._data = list(args) … … 79 86 self._data = list(args) 80 87 self.set_cursor(refresh=False) 88 # ranges become invalid when unit changes 89 if self._abcunit != self._data[0].get_unit(): 90 self._minmaxx = None 91 self._minmaxy = None 92 self._abcunit = self._data[0].get_unit() 93 self._datamask = None 81 94 if self._panelling == 't': 82 95 maxrows = 25 … … 93 106 else: 94 107 self._plot_other(self._data, self._stacking) 95 if self._minmax x is not None or self._minmaxy is not None:96 self._plotter.set_limits( xlim=self._minmaxx,ylim=self._minmaxy)108 if self._minmaxy is not None: 109 self._plotter.set_limits(ylim=self._minmaxy) 97 110 self._plotter.release() 98 111 return … … 133 146 savej = j 134 147 for k in cdict.keys(): 135 sel = eval(cdict2.get(k)) 148 sel = eval(cdict2.get(k)) 136 149 j = sel[0] 137 150 if k == "p": … … 143 156 if colmode == "p": 144 157 polmode = self._polmode[self._cursor["p"].index(j)] 145 j = jj158 #j = jj 146 159 eval(cdict.get(colmode)) 147 160 x = None … … 149 162 m = None 150 163 if self._title is None: 151 tlab = scan._getsourcename(rowsel) 164 tlab = scan._getsourcename(rowsel) 152 165 else: 153 166 if len(self._title) >= n: … … 171 184 ylab = scan._get_ordinate_label() 172 185 m = scan._getmask(rowsel) 186 if self._datamask is not None: 187 if len(m) == len(self._datamask): 188 m = logical_and(m,self._datamask) 173 189 if self._lmap and len(self._lmap) > 0: 174 190 llab = self._lmap[jj] … … 176 192 if colmode == 'p': 177 193 llab = self._get_pollabel(scan, polmode) 178 else: 194 else: 179 195 llab = self._ldict.get(colmode)+' '+str(j) 180 196 self._plotter.set_line(label=llab) 197 if self._minmaxx is not None: 198 s,e = self._slice_indeces(x) 199 x = x[s:e] 200 y = y[s:e] 201 m = m[s:e] 181 202 self._plotter.plot(x,y,m) 182 203 xlim=[min(x),max(x)] 183 self._plotter.axes.set_xlim(xlim) 204 if self._minmaxx is not None: 205 xlim = self._minmaxx 206 self._plotter.axes.set_xlim(xlim) 184 207 self._plotter.set_axes('xlabel',xlab) 185 208 self._plotter.set_axes('ylabel',ylab) 186 self._plotter.set_axes('title',tlab) 209 self._plotter.set_axes('title',tlab) 187 210 return 188 211 … … 197 220 'i':'self._cursor["i"]', 198 221 'p':'self._cursor["p"]'} 199 222 200 223 n = len(scans) 201 224 ncol = 1 … … 212 235 else: 213 236 self._plotter.set_panels() 237 214 238 for scan in scans: 215 239 self._plotter.palette(0) … … 223 247 savej = j 224 248 for k in cdict.keys(): 225 sel = eval(cdict2.get(k)) 249 sel = eval(cdict2.get(k)) 226 250 j = sel[0] 227 251 eval(cdict.get(k)) … … 233 257 if colmode == "p": 234 258 polmode = self._polmode[self._cursor["p"].index(j)] 235 j = jj259 #j = jj 236 260 eval(cdict.get(colmode)) 237 261 x = None … … 256 280 ylab = scan._get_ordinate_label() 257 281 m = scan._getmask(rowsel) 282 if self._datamask is not None: 283 if len(m) == len(self._datamask): 284 m = logical_and(m,self._datamask) 258 285 if self._lmap and len(self._lmap) > 0: 259 286 llab = self._lmap[jj] … … 264 291 llab = self._ldict.get(colmode)+' '+str(j) 265 292 self._plotter.set_line(label=llab) 293 if self._minmaxx is not None: 294 s,e = self._slice_indeces(x) 295 x = x[s:e] 296 y = y[s:e] 297 m = m[s:e] 298 266 299 self._plotter.plot(x,y,m) 267 300 xlim=[min(x),max(x)] 301 if self._minmaxx is not None: 302 xlim = self._minmaxx 268 303 self._plotter.axes.set_xlim(xlim) 269 304 … … 272 307 self._plotter.set_axes('title',tlab) 273 308 return 274 309 275 310 def _plot_other(self,scans,colmode): 276 311 if colmode == self._panelling: … … 287 322 n = eval(self._cdict.get(self._panelling)) 288 323 ncol=1 289 if self._stacking is not None: 324 if self._stacking is not None: 290 325 ncol = eval(self._cdict.get(colmode)) 291 326 if n > 1: … … 297 332 self._plotter.set_panels(rows=n,cols=0,nplots=n) 298 333 else: 299 self._plotter.set_panels() 300 panels = self._cursor[self._panelling] 334 self._plotter.set_panels() 335 panels = self._cursor[self._panelling] 301 336 for i in panels: 302 337 self._plotter.palette(0) … … 322 357 which = self._cursor["p"].index(i) 323 358 polmode = self._polmode[which] 324 i = which 359 i = which 325 360 eval(cdict.get(k)) 326 361 i = savei … … 328 363 scan = j 329 364 elif colmode == 't': 330 rowsel = j 365 rowsel = j 331 366 else: 332 367 savei = i … … 355 390 ylab = scan._get_ordinate_label() 356 391 m = scan._getmask(rowsel) 392 if self._datamask is not None: 393 if len(m) == len(self._datamask): 394 m = logical_and(m,self._datamask) 357 395 if colmode == 's' or colmode == 't': 358 396 if self._title and len(self._title) > 0: 359 397 tlab = self._title[ii] 360 else: 361 tlab = self._ldict.get(self._panelling)+' '+str(i) 398 else: 399 if self._panelling == 'p': 400 tlab = self._get_pollabel(scan, polmode) 401 else: 402 tlab = self._ldict.get(self._panelling)+' '+str(i) 362 403 if self._lmap and len(self._lmap) > 0: 363 404 llab = self._lmap[jj] … … 380 421 llab = self._ldict.get(colmode)+' '+str(j) 381 422 self._plotter.set_line(label=llab) 423 if self._minmaxx is not None: 424 s,e = self._slice_indeces(x) 425 x = x[s:e] 426 y = y[s:e] 427 m = m[s:e] 428 382 429 self._plotter.plot(x,y,m) 383 430 xlim=[min(x),max(x)] 431 if self._minmaxx is not None: 432 xlim = self._minmaxx 384 433 self._plotter.axes.set_xlim(xlim) 385 434 … … 387 436 self._plotter.set_axes('ylabel',ylab) 388 437 self._plotter.set_axes('title',tlab) 389 438 390 439 return 391 440 … … 443 492 return 444 493 445 def set_stacking(self, what=None): 494 def set_stacking(self, what=None): 446 495 mode = what 447 if mode is None: 448 mode = rcParams['plotter.stacking'] 496 if mode is None: 497 mode = rcParams['plotter.stacking'] 449 498 md = self._translate(mode) 450 499 if md: … … 471 520 self._minmaxy = None 472 521 else: 473 self._minmaxy = [ystart,yend] 522 self._minmaxy = [ystart,yend] 474 523 if self._data: self.plot() 475 524 return 476 525 477 526 def set_legend(self, mp=None): 478 527 """ … … 510 559 return 511 560 512 def save(self, filename=None, orientation= 'landscape'):561 def save(self, filename=None, orientation=None,dpi=None): 513 562 """ 514 563 Save the plot to a file. The know formats are 'png', 'ps', 'eps'. … … 519 568 called 'yyyymmdd_hhmmss.png' is created in the 520 569 current directory. 521 orientation: optional parameter for postscript. 'landscape' 522 (default) and 'portrait' are valid. 523 """ 524 self._plotter.save(filename,orientation) 525 return 526 570 orientation: optional parameter for postscript only (not eps). 571 'landscape', 'portrait' or None (default) are valid. 572 If None is choosen for 'ps' output, the plot is 573 automatically oriented to fill the page. 574 """ 575 self._plotter.save(filename,orientation,dpi) 576 return 577 527 578 def set_cursor(self, row=None,beam=None,IF=None,pol=None, refresh=True): 528 579 """ … … 549 600 550 601 Note: 551 Be careful to select only exisiting polarisations. 602 Be careful to select only exisiting polarisations. 552 603 """ 553 604 if not self._data: 554 605 print "Can only set cursor after a first call to plot()" 555 606 return 556 607 557 608 n = self._data[0].nrow() 558 609 if row is None: … … 572 623 if i < 0 or i >= n: 573 624 print "Beam index '%d' out of range" % i 574 return 625 return 575 626 self._cursor["b"] = beam 576 627 … … 582 633 if i < 0 or i >= n: 583 634 print "IF index '%d' out of range" %i 584 return 585 self._cursor["i"] = IF 635 return 636 self._cursor["i"] = IF 586 637 587 638 n = self._data[0].npol() … … 590 641 draw = {"XX":0, "YY":1,"Real(XY)":2, "Imag(XY)":3} 591 642 dcirc = { "RR":0,"LL":1}#,"Real(RL)":2,"Image(RL)":3} 592 643 593 644 if pol is None: 594 645 self._cursor["p"] = range(n) … … 637 688 tlab = scan._getpolarizationlabel(1,0,0) 638 689 return tlab 639 640 if __name__ == '__main__': 641 plotter = asapplotter() 690 691 def _slice_indeces(self, data): 692 mn = self._minmaxx[0] 693 mx = self._minmaxx[1] 694 asc = data[0] < data[-1] 695 start=0 696 end = len(data)-1 697 inc = 1 698 if not asc: 699 start = len(data)-1 700 end = 0 701 inc = -1 702 # find min index 703 while data[start] < mn: 704 start+= inc 705 # find max index 706 while data[end] > mx: 707 end-=inc 708 end +=1 709 if start > end: 710 return end,start 711 return start,end 712 713 #if __name__ == '__main__': 714 # plotter = asapplotter()
Note:
See TracChangeset
for help on using the changeset viewer.