Changeset 1153 for trunk/python
- Timestamp:
- 08/21/06 10:48:45 (18 years ago)
- Location:
- trunk/python
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/python/asaplotbase.py
r1147 r1153 454 454 if what[-6:] == 'colour': what = what[:-6] + 'color' 455 455 456 newargs = {} 457 458 for k, v in kwargs.iteritems(): 459 k = k.lower() 460 if k == 'colour': k = 'color' 461 newargs[k] = v 462 463 getattr(self.axes, "set_%s"%what)(*args, **newargs) 464 465 self.show() 456 key = "colour" 457 if kwargs.has_key(key): 458 val = kwargs.pop(key) 459 kwargs["color"] = val 460 461 getattr(self.axes, "set_%s"%what)(*args, **kwargs) 462 463 self.show(hardrefresh=False) 466 464 467 465 … … 485 483 486 484 getattr(self.figure, "set_%s"%what)(*args, **newargs) 487 self.show( )485 self.show(hardrefresh=False) 488 486 489 487 … … 552 550 self.attributes[k] = v 553 551 554 if redraw: self.show( )552 if redraw: self.show(hardrefresh=False) 555 553 556 554 … … 613 611 for i in range(nplots): 614 612 self.subplots.append({}) 615 self.subplots[i]['axes'] = self.figure.add_subplot(rows, 613 self.subplots[i]['lines'] = [] 614 if not ganged: 615 self.subplots[i]['axes'] = self.figure.add_subplot(rows, 616 616 cols, i+1) 617 self.subplots[i]['lines'] = [] 618 619 if ganged: 617 else: 618 if i == 0: 619 self.subplots[i]['axes'] = self.figure.add_subplot(rows, 620 cols, i+1) 621 else: 622 self.subplots[i]['axes'] = self.figure.add_subplot(rows, 623 cols, i+1, 624 sharex=self.subplots[0]['axes'], 625 sharey=self.subplots[0]['axes']) 620 626 # Suppress tick labelling for interior subplots. 621 627 if i <= (rows-1)*cols - 1: … … 623 629 # Suppress x-labels for frames width 624 630 # adjacent frames 625 self.subplots[i]['axes'].xaxis.set_major_locator(NullLocator()) 631 for tick in self.subplots[i]['axes'].xaxis.majorTicks: 632 tick.label1On = False 626 633 self.subplots[i]['axes'].xaxis.label.set_visible(False) 627 634 if i%cols: … … 631 638 self.subplots[i]['axes'].yaxis.label.set_visible(False) 632 639 # disable the first tick of [1:ncol-1] of the last row 633 if (nplots-cols) < i <= nplots-1:634 self.subplots[i]['axes'].xaxis.set_major_formatter(MyFormatter())640 #if i+1 < nplots: 641 # self.subplots[i]['axes'].xaxis.majorTicks[0].label1On = False 635 642 self.rows = rows 636 643 self.cols = cols 637 644 self.subplot(0) 638 645 646 def tidy(self): 647 # this needs to be exceuted after the first "refresh" 648 nplots = len(self.subplots) 649 if nplots == 1: return 650 for i in xrange(nplots): 651 ax = self.subplots[i]['axes'] 652 if i%self.cols: 653 ax.xaxis.majorTicks[0].label1On = False 654 else: 655 if i != 0: 656 ax.yaxis.majorTicks[-1].label1On = False 657 658 639 659 def set_title(self, title=None): 640 660 """ … … 648 668 649 669 650 def show(self ):670 def show(self, hardrefresh=True): 651 671 """ 652 672 Show graphics dependent on the current buffering state. 653 673 """ 674 if not hardrefresh: return 654 675 if not self.buffering: 655 676 if self.loc is not None: -
trunk/python/asaplotgui.py
r1084 r1153 26 26 v = vars() 27 27 del v['self'] 28 28 29 29 asaplotbase.__init__(self, **v) 30 30 self.window = Tk.Tk() … … 38 38 # Simply instantiating this is enough to get a working toolbar. 39 39 self.figmgr = FigureManagerTkAgg(self.canvas, 1, self.window) 40 self.window.wm_title('ASAP lot graphics window')40 self.window.wm_title('ASAP Plotter - Tk') 41 41 42 42 self.events = {'button_press':None, … … 44 44 'motion_notify':None} 45 45 46 matplotlib. interactive= True47 self.buffering = buffering46 matplotlib.rcParams["interactive"] = True 47 #self.buffering = buffering 48 48 49 49 self.canvas.show() … … 177 177 178 178 179 def show(self ):179 def show(self, hardrefresh=True): 180 180 """ 181 181 Show graphics dependent on the current buffering state. 182 182 """ 183 183 if not self.buffering: 184 asaplotbase.show(self) 184 if hardrefresh: 185 asaplotbase.show(self) 185 186 self.window.wm_deiconify() 186 self.canvas. draw()187 self.canvas.show() 187 188 188 189 def terminate(self): -
trunk/python/asaplotgui_gtk.py
r1089 r1153 8 8 import matplotlib 9 9 from matplotlib.backends.backend_gtkagg import FigureCanvasGTKAgg as FigureCanvas 10 from matplotlib.backends.backend_gtkagg import FigureManagerGTKAgg 10 11 matplotlib.use("GTkAgg") 11 12 matplotlib.rcParams['toolbar'] = 'toolbar2' 13 from matplotlib.backends.backend_gtk import NavigationToolbar2GTK as NavigationToolbar 12 14 13 15 class asaplotgui(asaplotbase): … … 27 29 28 30 asaplotbase.__init__(self, **v) 29 self.window = gtk.Window() 31 matplotlib.interactive = True 32 self.canvas = FigureCanvas(self.figure) 33 # Simply instantiating this is enough to get a working toolbar. 34 self.figmgr = FigureManagerGTKAgg(self.canvas, 1) 30 35 def dest_callback(val): 31 36 self.is_dead = True 32 self.window.destroy() 37 self.figmgr.window.destroy() 38 self.window = self.figmgr.window 33 39 self.window.connect("destroy", dest_callback ) 34 self.window.set_default_size(800,600) 35 self.subwin = gtk.ScrolledWindow() 36 self.window.add(self.subwin) 37 self.subwin.set_border_width(10) 38 self.canvas = FigureCanvas(self.figure) 39 # Simply instantiating this is enough to get a working toolbar. 40 self.figmgr = None#FigureManagerTkAgg(self.canvas, 1, self.window) 41 self.window.set_title('ASAPlot graphics window') 42 40 self.window.set_title('ASAP Plotter - GTK') 43 41 self.events = {'button_press':None, 44 42 'button_release':None, 45 43 'motion_notify':None} 46 44 47 self.subwin.add_with_viewport(self.canvas)48 matplotlib.interactive = True49 45 self.buffering = buffering 50 self.canvas.set_size_request(800,600) 51 52 self.canvas.show() 46 matplotlib.rcParams['interactive'] = True 47 #self.canvas.set_size_request(800,600) 48 49 #self.canvas.show() 53 50 54 51 def map(self): … … 180 177 181 178 182 def show(self ):179 def show(self, hardrefresh=True): 183 180 """ 184 181 Show graphics dependent on the current buffering state. 185 182 """ 186 183 if not self.buffering: 187 asaplotbase.show(self) 184 if hardrefresh: 185 asaplotbase.show(self, hardrefresh) 188 186 self.window.deiconify() 189 187 self.canvas.draw() -
trunk/python/asapplotter.py
r1148 r1153 1 1 from asap import rcParams, print_log, selector 2 2 from asap import NUM 3 import matplotlib.axes 3 4 4 5 class asapplotter: … … 95 96 self._plotter.set_limits(ylim=self._minmaxy) 96 97 self._plotter.release() 98 self._plotter.tidy() 99 self._plotter.show(hardrefresh=False) 97 100 print_log() 98 101 return 102 103 104 # forwards to matplotlib axes 105 def text(self, *args, **kwargs): 106 self._axes_callback("text", *args, **kwargs) 107 text. __doc__ = matplotlib.axes.Axes.text.__doc__ 108 def arrow(self, *args, **kwargs): 109 self._axes_callback("arrow", *args, **kwargs) 110 arrow. __doc__ = matplotlib.axes.Axes.arrow.__doc__ 111 def axvline(self, *args, **kwargs): 112 self._axes_callback("axvline", *args, **kwargs) 113 axvline. __doc__ = matplotlib.axes.Axes.axvline.__doc__ 114 def axhline(self, *args, **kwargs): 115 self._axes_callback("axhline", *args, **kwargs) 116 axhline. __doc__ = matplotlib.axes.Axes.axhline.__doc__ 117 def axvspan(self, *args, **kwargs): 118 self._axes_callback("axvspan", *args, **kwargs) 119 # hack to preventy mpl from redrawing the patch 120 # it seem to convert the patch into lines on every draw. 121 # This doesn't happen in a test script??? 122 del self._plotter.axes.patches[-1] 123 axvspan. __doc__ = matplotlib.axes.Axes.axvspan.__doc__ 124 def axhspan(self, *args, **kwargs): 125 self._axes_callback("ahvspan", *args, **kwargs) 126 # hack to preventy mpl from redrawing the patch 127 # it seem to convert the patch into lines on every draw. 128 # This doesn't happen in a test script??? 129 del self._plotter.axes.patches[-1] 130 axhspan. __doc__ = matplotlib.axes.Axes.axhspan.__doc__ 131 132 def _axes_callback(self, axesfunc, *args, **kwargs): 133 panel = 0 134 if kwargs.has_key("panel"): 135 panel = kwargs.pop("panel") 136 coords = None 137 if kwargs.has_key("coords"): 138 coords = kwargs.pop("coords") 139 if coords.lower() == 'world': 140 kwargs["transform"] = self._plotter.axes.transData 141 elif coords.lower() == 'relative': 142 kwargs["transform"] = self._plotter.axes.transAxes 143 self._plotter.subplot(panel) 144 self._plotter.axes.set_autoscale_on(False) 145 getattr(self._plotter.axes, axesfunc)(*args, **kwargs) 146 self._plotter.show(False) 147 self._plotter.axes.set_autoscale_on(True) 148 # end matplotlib.axes fowarding functions 99 149 100 150 def set_mode(self, stacking=None, panelling=None): … … 357 407 if self._data: self.plot(self._data) 358 408 359 def plot_lines(self, linecat=None, offset=0.0, peak=5.0, rotate=0.0,409 def plot_lines(self, linecat=None, offset=0.0, deltachan=10, rotate=0.0, 360 410 location=None): 361 411 """ … … 365 415 if not isinstance(linecat, linecatalog): return 366 416 if not self._data.get_unit().endswith("GHz"): return 367 self._plotter.hold() 417 #self._plotter.hold() 418 from matplotlib.numerix import ma 368 419 for j in range(len(self._plotter.subplots)): 369 420 self._plotter.subplot(j) 370 421 lims = self._plotter.axes.get_xlim() 371 for iin range(linecat.nrow()):372 freq = linecat.get_frequency( i)/1000.0 + offset422 for row in range(linecat.nrow()): 423 freq = linecat.get_frequency(row)/1000.0 + offset 373 424 if lims[0] < freq < lims[1]: 374 425 if location is None: 375 426 loc = 'bottom' 376 if i%2: loc='top'427 if row%2: loc='top' 377 428 else: loc = location 378 self._plotter.vline_with_label(freq, peak, linecat.get_name(i), 429 maxys = [] 430 for line in self._plotter.axes.lines: 431 v = line._x 432 asc = v[0] < v[-1] 433 434 idx = None 435 if not asc: 436 if v[len(v)-1] <= freq <= v[0]: 437 i = len(v)-1 438 while i>=0 and v[i] < freq: 439 idx = i 440 i-=1 441 else: 442 if v[0] <= freq <= v[len(v)-1]: 443 i = 0 444 while i<len(v) and v[i] < freq: 445 idx = i 446 i+=1 447 if idx is not None: 448 lower = idx - deltachan 449 upper = idx + deltachan 450 if lower < 0: lower = 0 451 if upper > len(v): upper = len(v) 452 s = slice(lower, upper) 453 y = line._y_orig[s] 454 maxys.append(ma.maximum(y)) 455 peak = max(maxys) 456 self._plotter.vline_with_label(freq, peak, linecat.get_name(row), 379 457 location=loc, rotate=rotate) 380 self._plotter.release() 458 # self._plotter.release() 459 self._plotter.show(hardrefresh=False) 460 381 461 382 462 def save(self, filename=None, orientation=None, dpi=None): … … 619 699 620 700 def _get_label(self, scan, row, mode, userlabel=None): 701 if isinstance(userlabel, list) and len(userlabel) == 0: 702 userlabel = " " 621 703 pms = dict(zip(self._selection.get_pols(),self._selection.get_poltypes())) 622 704 if len(pms): … … 630 712 't': scan._gettime(row) } 631 713 return userlabel or d[mode] 714 -
trunk/python/linecatalog.py
r1150 r1153 103 103 row: the row to retrieve 104 104 """ 105 freq = lcbase.get_frequency( row)106 name = lcbase.get_name( row)105 freq = lcbase.get_frequency(self, row) 106 name = lcbase.get_name(self, row) 107 107 return (freq, name) 108 109 def __len__(self): 110 return self.nrow() 111 112 def __getitem__(self, k): 113 if k < 0: k = self.nrow()-k 114 return self.get_row(k) 115 116 117 118 119 -
trunk/python/scantable.py
r1145 r1153 5 5 from asap import selector 6 6 from asap import NUM 7 from asap import linecatalog 7 8 8 9 class scantable(Scantable): … … 707 708 E.g. 'freqs=[1e9, 2e9]' would mean IF 0 gets restfreq 1e9 and 708 709 IF 1 gets restfreq 2e9. 709 You can also specify the frequencies via known line names710 from the built-in Lovas table. 710 You can also specify the frequencies via a linecatalog/ 711 711 712 Parameters: 712 713 freqs: list of rest frequency values or string idenitfiers … … 738 739 t = type(freqs) 739 740 if isinstance(freqs, int) or isinstance(freqs, float): 740 self._setrestfreqs(freqs, unit)741 self._setrestfreqs(freqs, "",unit) 741 742 elif isinstance(freqs, list) or isinstance(freqs, tuple): 742 743 if isinstance(freqs[-1], int) or isinstance(freqs[-1], float): … … 746 747 sel.set_ifs([i]) 747 748 self._setselection(sel) 748 self._setrestfreqs(freqs[i], unit)749 self._setrestfreqs(freqs[i], "",unit) 749 750 self._setselection(savesel) 750 751 elif isinstance(freqs[-1], str): 751 752 # not yet implemented 752 753 pass 754 elif isinstance(freqs, linecatalog): 755 sel = selector() 756 savesel = self._getselection() 757 for i in xrange(freqs.nrow()): 758 sel.set_ifs([i]) 759 self._setselection(sel) 760 self._setrestfreqs(freqs.get_frequency(i), 761 freqs.get_name(i), "MHz") 762 # ensure that we are not iterating past nIF 763 if i == self.nif()-1: break 764 self._setselection(savesel) 753 765 else: 754 766 return
Note:
See TracChangeset
for help on using the changeset viewer.