source: trunk/python/asapplotter.py @ 1164

Last change on this file since 1164 was 1164, checked in by mar637, 18 years ago

fix in plot_lines. have to ignore line when channel is masked

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 28.3 KB
Line 
1from asap import rcParams, print_log, selector
2from asap import NUM
3import matplotlib.axes
4
5class asapplotter:
6    """
7    The ASAP plotter.
8    By default the plotter is set up to plot polarisations
9    'colour stacked' and scantables across panels.
10    Note:
11        Currenly it only plots 'spectra' not Tsys or
12        other variables.
13    """
14    def __init__(self, visible=None):
15        self._visible = rcParams['plotter.gui']
16        if visible is not None:
17            self._visible = visible
18        self._plotter = self._newplotter()
19
20        self._panelling = None
21        self._stacking = None
22        self.set_panelling()
23        self.set_stacking()
24        self._rows = None
25        self._cols = None
26        self._autoplot = False
27        self._minmaxx = None
28        self._minmaxy = None
29        self._datamask = None
30        self._data = None
31        self._lmap = None
32        self._title = None
33        self._ordinate = None
34        self._abcissa = None
35        self._abcunit = None
36        self._usermask = []
37        self._maskselection = None
38        self._selection = selector()
39        self._hist = rcParams['plotter.histogram']
40
41    def _translate(self, instr):
42        keys = "s b i p t".split()
43        if isinstance(instr, str):
44            for key in keys:
45                if instr.lower().startswith(key):
46                    return key
47        return None
48
49    def _newplotter(self):
50        if self._visible:
51            from asap.asaplotgui import asaplotgui as asaplot
52        else:
53            from asap.asaplot import asaplot
54        return asaplot()
55
56
57    def plot(self, scan=None):
58        """
59        Plot a scantable.
60        Parameters:
61            scan:   a scantable
62        Note:
63            If a scantable was specified in a previous call
64            to plot, no argument has to be given to 'replot'
65            NO checking is done that the abcissas of the scantable
66            are consistent e.g. all 'channel' or all 'velocity' etc.
67        """
68        if self._plotter.is_dead:
69            self._plotter = self._newplotter()
70        self._plotter.hold()
71        self._plotter.clear()
72        from asap import scantable
73        if not self._data and not scan:
74            msg = "Input is not a scantable"
75            if rcParams['verbose']:
76                print msg
77                return
78            raise TypeError(msg)
79        if isinstance(scan, scantable):
80            if self._data is not None:
81                if scan != self._data:
82                    self._data = scan
83                    # reset
84                    self._reset()
85            else:
86                self._data = scan
87                self._reset()
88        # ranges become invalid when unit changes
89        if self._abcunit and self._abcunit != self._data.get_unit():
90            self._minmaxx = None
91            self._minmaxy = None
92            self._abcunit = self._data.get_unit()
93            self._datamask = None
94        self._plot(self._data)
95        if self._minmaxy is not None:
96            self._plotter.set_limits(ylim=self._minmaxy)
97        self._plotter.release()
98        self._plotter.tidy()
99        self._plotter.show(hardrefresh=False)
100        print_log()
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
149
150    def set_mode(self, stacking=None, panelling=None):
151        """
152        Set the plots look and feel, i.e. what you want to see on the plot.
153        Parameters:
154            stacking:     tell the plotter which variable to plot
155                          as line color overlays (default 'pol')
156            panelling:    tell the plotter which variable to plot
157                          across multiple panels (default 'scan'
158        Note:
159            Valid modes are:
160                 'beam' 'Beam' 'b':     Beams
161                 'if' 'IF' 'i':         IFs
162                 'pol' 'Pol' 'p':       Polarisations
163                 'scan' 'Scan' 's':     Scans
164                 'time' 'Time' 't':     Times
165        """
166        msg = "Invalid mode"
167        if not self.set_panelling(panelling) or \
168               not self.set_stacking(stacking):
169            if rcParams['verbose']:
170                print msg
171                return
172            else:
173                raise TypeError(msg)
174        if self._data: self.plot(self._data)
175        return
176
177    def set_panelling(self, what=None):
178        mode = what
179        if mode is None:
180             mode = rcParams['plotter.panelling']
181        md = self._translate(mode)
182        if md:
183            self._panelling = md
184            self._title = None
185            return True
186        return False
187
188    def set_layout(self,rows=None,cols=None):
189        """
190        Set the multi-panel layout, i.e. how many rows and columns plots
191        are visible.
192        Parameters:
193             rows:   The number of rows of plots
194             cols:   The number of columns of plots
195        Note:
196             If no argument is given, the potter reverts to its auto-plot
197             behaviour.
198        """
199        self._rows = rows
200        self._cols = cols
201        if self._data: self.plot(self._data)
202        return
203
204    def set_stacking(self, what=None):
205        mode = what
206        if mode is None:
207             mode = rcParams['plotter.stacking']
208        md = self._translate(mode)
209        if md:
210            self._stacking = md
211            self._lmap = None
212            return True
213        return False
214
215    def set_range(self,xstart=None,xend=None,ystart=None,yend=None):
216        """
217        Set the range of interest on the abcissa of the plot
218        Parameters:
219            [x,y]start,[x,y]end:  The start and end points of the 'zoom' window
220        Note:
221            These become non-sensical when the unit changes.
222            use plotter.set_range() without parameters to reset
223
224        """
225        if xstart is None and xend is None:
226            self._minmaxx = None
227        else:
228            self._minmaxx = [xstart,xend]
229        if ystart is None and yend is None:
230            self._minmaxy = None
231        else:
232            self._minmaxy = [ystart,yend]
233        if self._data: self.plot(self._data)
234        return
235
236    def set_legend(self, mp=None, fontsize = None, mode = 0):
237        """
238        Specify a mapping for the legend instead of using the default
239        indices:
240        Parameters:
241            mp:        a list of 'strings'. This should have the same length
242                       as the number of elements on the legend and then maps
243                       to the indeces in order. It is possible to uses latex
244                       math expression. These have to be enclosed in r'',
245                       e.g. r'$x^{2}$'
246            fontsize:  The font size of the label (default None)
247            mode:      where to display the legend
248                       Any other value for loc else disables the legend:
249                        0: auto
250                        1: upper right
251                        2: upper left
252                        3: lower left
253                        4: lower right
254                        5: right
255                        6: center left
256                        7: center right
257                        8: lower center
258                        9: upper center
259                        10: center
260
261        Example:
262             If the data has two IFs/rest frequencies with index 0 and 1
263             for CO and SiO:
264             plotter.set_stacking('i')
265             plotter.set_legend(['CO','SiO'])
266             plotter.plot()
267             plotter.set_legend([r'$^{12}CO$', r'SiO'])
268        """
269        self._lmap = mp
270        self._plotter.legend(mode)
271        if isinstance(fontsize, int):
272            from matplotlib import rc as rcp
273            rcp('legend', fontsize=fontsize)
274        if self._data:
275            self.plot(self._data)
276        return
277
278    def set_title(self, title=None, fontsize=None):
279        """
280        Set the title of the plot. If multiple panels are plotted,
281        multiple titles have to be specified.
282        Example:
283             # two panels are visible on the plotter
284             plotter.set_title(["First Panel","Second Panel"])
285        """
286        self._title = title
287        if isinstance(fontsize, int):
288            from matplotlib import rc as rcp
289            rcp('axes', titlesize=fontsize)
290        if self._data: self.plot(self._data)
291        return
292
293    def set_ordinate(self, ordinate=None, fontsize=None):
294        """
295        Set the y-axis label of the plot. If multiple panels are plotted,
296        multiple labels have to be specified.
297        Parameters:
298            ordinate:    a list of ordinate labels. None (default) let
299                         data determine the labels
300        Example:
301             # two panels are visible on the plotter
302             plotter.set_ordinate(["First Y-Axis","Second Y-Axis"])
303        """
304        self._ordinate = ordinate
305        if isinstance(fontsize, int):
306            from matplotlib import rc as rcp
307            rcp('axes', labelsize=fontsize)
308            rcp('ytick', labelsize=fontsize)
309        if self._data: self.plot(self._data)
310        return
311
312    def set_abcissa(self, abcissa=None, fontsize=None):
313        """
314        Set the x-axis label of the plot. If multiple panels are plotted,
315        multiple labels have to be specified.
316        Parameters:
317            abcissa:     a list of abcissa labels. None (default) let
318                         data determine the labels
319        Example:
320             # two panels are visible on the plotter
321             plotter.set_ordinate(["First X-Axis","Second X-Axis"])
322        """
323        self._abcissa = abcissa
324        if isinstance(fontsize, int):
325            from matplotlib import rc as rcp
326            rcp('axes', labelsize=fontsize)
327            rcp('xtick', labelsize=fontsize)
328        if self._data: self.plot(self._data)
329        return
330
331    def set_colors(self, colormap):
332        """
333        Set the colors to be used. The plotter will cycle through
334        these colors when lines are overlaid (stacking mode).
335        Parameters:
336            colormap:     a list of colour names
337        Example:
338             plotter.set_colors("red green blue")
339             # If for example four lines are overlaid e.g I Q U V
340             # 'I' will be 'red', 'Q' will be 'green', U will be 'blue'
341             # and 'V' will be 'red' again.
342        """
343        if isinstance(colormap,str):
344            colormap = colormap.split()
345        self._plotter.palette(0,colormap=colormap)
346        if self._data: self.plot(self._data)
347
348    def set_histogram(self, hist=True, linewidth=None):
349        """
350        Enable/Disable histogram-like plotting.
351        Parameters:
352            hist:        True (default) or False. The fisrt default
353                         is taken from the .asaprc setting
354                         plotter.histogram
355        """
356        self._hist = hist
357        if isinstance(linewidth, float) or isinstance(linewidth, int):
358            from matplotlib import rc as rcp
359            rcp('lines', linewidth=linewidth)
360        if self._data: self.plot(self._data)
361
362    def set_linestyles(self, linestyles=None, linewidth=None):
363        """
364        Set the linestyles to be used. The plotter will cycle through
365        these linestyles when lines are overlaid (stacking mode) AND
366        only one color has been set.
367        Parameters:
368             linestyles:     a list of linestyles to use.
369                             'line', 'dashed', 'dotted', 'dashdot',
370                             'dashdotdot' and 'dashdashdot' are
371                             possible
372
373        Example:
374             plotter.set_colors("black")
375             plotter.set_linestyles("line dashed dotted dashdot")
376             # If for example four lines are overlaid e.g I Q U V
377             # 'I' will be 'solid', 'Q' will be 'dashed',
378             # U will be 'dotted' and 'V' will be 'dashdot'.
379        """
380        if isinstance(linestyles,str):
381            linestyles = linestyles.split()
382        self._plotter.palette(color=0,linestyle=0,linestyles=linestyles)
383        if isinstance(linewidth, float) or isinstance(linewidth, int):
384            from matplotlib import rc as rcp
385            rcp('lines', linewidth=linewidth)
386        if self._data: self.plot(self._data)
387
388    def set_font(self, family=None, style=None, weight=None, size=None):
389        """
390        Set font properties.
391        Parameters:
392            family:    one of 'sans-serif', 'serif', 'cursive', 'fantasy', 'monospace'
393            style:     one of 'normal' (or 'roman'), 'italic'  or 'oblique'
394            weight:    one of 'normal or 'bold'
395            size:      the 'general' font size, individual elements can be adjusted
396                       seperately
397        """
398        from matplotlib import rc as rcp
399        if isinstance(family, str):
400            rcp('font', family=family)
401        if isinstance(style, str):
402            rcp('font', style=style)
403        if isinstance(weight, str):
404            rcp('font', weight=weight)
405        if isinstance(size, float) or isinstance(size, int):
406            rcp('font', size=size)
407        if self._data: self.plot(self._data)
408
409    def plot_lines(self, linecat=None, offset=0.0, deltachan=10, rotate=0.0,
410                   location=None):
411        """
412        Plot a line catalog.
413        Parameters:
414            linecat:      the linecatalog to plot
415            offset:       the shift in frequency to apply to the frequencies
416            deltachan:    the number of channels to include each side of the
417                          line to determine a local maximum/minimum
418            rotate:       the rotation for the text label
419            location:     the location of the line annotation from the 'top',
420                          'bottom' or alternate (None - the default)
421        """
422        if not self._data: return
423        from asap._asap import linecatalog
424        if not isinstance(linecat, linecatalog): return
425        if not self._data.get_unit().endswith("GHz"): return
426        #self._plotter.hold()
427        from matplotlib.numerix import ma
428        for j in range(len(self._plotter.subplots)):
429            self._plotter.subplot(j)
430            lims = self._plotter.axes.get_xlim()
431            for row in range(linecat.nrow()):
432                freq = linecat.get_frequency(row)/1000.0 + offset
433                if lims[0] < freq < lims[1]:
434                    if location is None:
435                        loc = 'bottom'
436                        if row%2: loc='top'
437                    else: loc = location
438                    maxys = []
439                    for line in self._plotter.axes.lines:
440                        v = line._x
441                        asc = v[0] < v[-1]
442
443                        idx = None
444                        if not asc:
445                            if v[len(v)-1] <= freq <= v[0]:
446                                i = len(v)-1
447                                while i>=0 and v[i] < freq:
448                                    idx = i
449                                    i-=1
450                        else:
451                           if v[0] <= freq <= v[len(v)-1]:
452                                i = 0
453                                while  i<len(v) and v[i] < freq:
454                                    idx = i
455                                    i+=1
456                        if idx is not None:
457                            lower = idx - deltachan
458                            upper = idx + deltachan
459                            if lower < 0: lower = 0
460                            if upper > len(v): upper = len(v)
461                            s = slice(lower, upper)
462                            y = line._y_orig[s]
463                            maxys.append(ma.maximum(y))
464                    if len(maxys):
465                        peak = max(maxys)
466                    else:
467                        print "DEBUG - ignoring line as spectrum was masked at this frequency"
468                        continue
469                    self._plotter.vline_with_label(freq, peak,
470                                                   linecat.get_name(row),
471                                                   location=loc, rotate=rotate)
472        #        self._plotter.release()
473        self._plotter.show(hardrefresh=False)
474
475
476    def save(self, filename=None, orientation=None, dpi=None):
477        """
478        Save the plot to a file. The know formats are 'png', 'ps', 'eps'.
479        Parameters:
480             filename:    The name of the output file. This is optional
481                          and autodetects the image format from the file
482                          suffix. If non filename is specified a file
483                          called 'yyyymmdd_hhmmss.png' is created in the
484                          current directory.
485             orientation: optional parameter for postscript only (not eps).
486                          'landscape', 'portrait' or None (default) are valid.
487                          If None is choosen for 'ps' output, the plot is
488                          automatically oriented to fill the page.
489             dpi:         The dpi of the output non-ps plot
490        """
491        self._plotter.save(filename,orientation,dpi)
492        return
493
494
495    def set_mask(self, mask=None, selection=None):
496        """
497        Set a plotting mask for a specific polarization.
498        This is useful for masking out "noise" Pangle outside a source.
499        Parameters:
500             mask:           a mask from scantable.create_mask
501             selection:      the spectra to apply the mask to.
502        Example:
503             select = selector()
504             select.setpolstrings("Pangle")
505             plotter.set_mask(mymask, select)
506        """
507        if not self._data:
508            msg = "Can only set mask after a first call to plot()"
509            if rcParams['verbose']:
510                print msg
511                return
512            else:
513                raise RuntimeError(msg)
514        if len(mask):
515            if isinstance(mask, list) or isinstance(mask, tuple):
516                self._usermask = array(mask)
517            else:
518                self._usermask = mask
519        if mask is None and selection is None:
520            self._usermask = []
521            self._maskselection = None
522        if isinstance(selection, selector):
523            self._maskselection = {'b': selection.get_beams(),
524                                   's': selection.get_scans(),
525                                   'i': selection.get_ifs(),
526                                   'p': selection.get_pols(),
527                                   't': [] }
528        else:
529            self._maskselection = None
530        self.plot(self._data)
531
532    def _slice_indeces(self, data):
533        mn = self._minmaxx[0]
534        mx = self._minmaxx[1]
535        asc = data[0] < data[-1]
536        start=0
537        end = len(data)-1
538        inc = 1
539        if not asc:
540            start = len(data)-1
541            end = 0
542            inc = -1
543        # find min index
544        while start > 0 and data[start] < mn:
545            start+= inc
546        # find max index
547        while end > 0 and data[end] > mx:
548            end-=inc
549        if end > 0: end +=1
550        if start > end:
551            return end,start
552        return start,end
553
554    def _reset(self):
555        self._usermask = []
556        self._usermaskspectra = None
557        self.set_selection(None, False)
558
559    def _plot(self, scan):
560        savesel = scan.get_selection()
561        sel = savesel +  self._selection
562        d0 = {'s': 'SCANNO', 'b': 'BEAMNO', 'i':'IFNO',
563              'p': 'POLNO', 'c': 'CYCLENO', 't' : 'TIME' }
564        order = [d0[self._panelling],d0[self._stacking]]
565        sel.set_order(order)
566        scan.set_selection(sel)
567        d = {'b': scan.getbeam, 's': scan.getscan,
568             'i': scan.getif, 'p': scan.getpol, 't': scan._gettime }
569
570        polmodes = dict(zip(self._selection.get_pols(),
571                            self._selection.get_poltypes()))
572        # this returns either a tuple of numbers or a length  (ncycles)
573        # convert this into lengths
574        n0,nstack0 = self._get_selected_n(scan)
575        n = len(n0)
576        if isinstance(n0, int): n = n0
577        nstack = len(nstack0)
578        if isinstance(nstack0, int): nstack = nstack0
579        maxpanel, maxstack = 16,8
580        if n > maxpanel or nstack > maxstack:
581            from asap import asaplog
582            maxn = 0
583            if nstack > maxstack: maxn = maxstack
584            if n > maxpanel: maxn = maxpanel
585            msg ="Scan to be plotted contains more than %d selections.\n" \
586                  "Selecting first %d selections..." % (maxn, maxn)
587            asaplog.push(msg)
588            print_log()
589            n = min(n,maxpanel)
590            nstack = min(nstack,maxstack)
591        if n > 1:
592            ganged = rcParams['plotter.ganged']
593            if self._rows and self._cols:
594                n = min(n,self._rows*self._cols)
595                self._plotter.set_panels(rows=self._rows,cols=self._cols,
596                                         nplots=n,ganged=ganged)
597            else:
598                self._plotter.set_panels(rows=n,cols=0,nplots=n,ganged=ganged)
599        else:
600            self._plotter.set_panels()
601        r=0
602        nr = scan.nrow()
603        a0,b0 = -1,-1
604        allxlim = []
605        allylim = []
606        newpanel=True
607        panelcount,stackcount = 0,0
608        while r < nr:
609            a = d[self._panelling](r)
610            b = d[self._stacking](r)
611            if a > a0 and panelcount < n:
612                if n > 1:
613                    self._plotter.subplot(panelcount)
614                self._plotter.palette(0)
615                #title
616                xlab = self._abcissa and self._abcissa[panelcount] \
617                       or scan._getabcissalabel()
618                ylab = self._ordinate and self._ordinate[panelcount] \
619                       or scan._get_ordinate_label()
620                self._plotter.set_axes('xlabel',xlab)
621                self._plotter.set_axes('ylabel',ylab)
622                lbl = self._get_label(scan, r, self._panelling, self._title)
623                if isinstance(lbl, list) or isinstance(lbl, tuple):
624                    if 0 <= panelcount < len(lbl):
625                        lbl = lbl[panelcount]
626                    else:
627                        # get default label
628                        lbl = self._get_label(scan, r, self._panelling, None)
629                self._plotter.set_axes('title',lbl)
630                newpanel = True
631                stackcount =0
632                panelcount += 1
633            if (b > b0 or newpanel) and stackcount < nstack:
634                y = []
635                if len(polmodes):
636                    y = scan._getspectrum(r, polmodes[scan.getpol(r)])
637                else:
638                    y = scan._getspectrum(r)
639                m = scan._getmask(r)
640                from matplotlib.numerix import logical_not, logical_and
641                if self._maskselection and len(self._usermask) == len(m):
642                    if d[self._stacking](r) in self._maskselection[self._stacking]:
643                        m = logical_and(m, self._usermask)
644                x = scan._getabcissa(r)
645                from matplotlib.numerix import ma, array
646                y = ma.masked_array(y,mask=logical_not(array(m,copy=False)))
647                if self._minmaxx is not None:
648                    s,e = self._slice_indeces(x)
649                    x = x[s:e]
650                    y = y[s:e]
651                if len(x) > 1024 and rcParams['plotter.decimate']:
652                    fac = len(x)/1024
653                    x = x[::fac]
654                    y = y[::fac]
655                llbl = self._get_label(scan, r, self._stacking, self._lmap)
656                if isinstance(llbl, list) or isinstance(llbl, tuple):
657                    if 0 <= stackcount < len(llbl):
658                        # use user label
659                        llbl = llbl[stackcount]
660                    else:
661                        # get default label
662                        llbl = self._get_label(scan, r, self._stacking, None)
663                self._plotter.set_line(label=llbl)
664                plotit = self._plotter.plot
665                if self._hist: plotit = self._plotter.hist
666                if len(x) > 0:
667                    plotit(x,y)
668                    xlim= self._minmaxx or [min(x),max(x)]
669                    allxlim += xlim
670                    ylim= self._minmaxy or [ma.minimum(y),ma.maximum(y)]
671                    allylim += ylim
672                stackcount += 1
673                # last in colour stack -> autoscale x
674                if stackcount == nstack:
675                    allxlim.sort()
676                    self._plotter.axes.set_xlim([allxlim[0],allxlim[-1]])
677                    # clear
678                    allxlim =[]
679
680            newpanel = False
681            a0=a
682            b0=b
683            # ignore following rows
684            if (panelcount == n) and (stackcount == nstack):
685                # last panel -> autoscale y if ganged
686                if rcParams['plotter.ganged']:
687                    allylim.sort()
688                    self._plotter.set_limits(ylim=[allylim[0],allylim[-1]])
689                break
690            r+=1 # next row
691        #reset the selector to the scantable's original
692        scan.set_selection(savesel)
693
694    def set_selection(self, selection=None, refresh=True):
695        self._selection = isinstance(selection,selector) and selection or selector()
696        d0 = {'s': 'SCANNO', 'b': 'BEAMNO', 'i':'IFNO',
697              'p': 'POLNO', 'c': 'CYCLENO', 't' : 'TIME' }
698        order = [d0[self._panelling],d0[self._stacking]]
699        self._selection.set_order(order)
700        if self._data and refresh: self.plot(self._data)
701
702    def _get_selected_n(self, scan):
703        d1 = {'b': scan.getbeamnos, 's': scan.getscannos,
704             'i': scan.getifnos, 'p': scan.getpolnos, 't': scan.ncycle }
705        d2 = { 'b': self._selection.get_beams(),
706               's': self._selection.get_scans(),
707               'i': self._selection.get_ifs(),
708               'p': self._selection.get_pols(),
709               't': self._selection.get_cycles() }
710        n =  d2[self._panelling] or d1[self._panelling]()
711        nstack = d2[self._stacking] or d1[self._stacking]()
712        return n,nstack
713
714    def _get_label(self, scan, row, mode, userlabel=None):
715        if isinstance(userlabel, list) and len(userlabel) == 0:
716            userlabel = " "
717        pms = dict(zip(self._selection.get_pols(),self._selection.get_poltypes()))
718        if len(pms):
719            poleval = scan._getpollabel(scan.getpol(row),pms[scan.getpol(row)])
720        else:
721            poleval = scan._getpollabel(scan.getpol(row),scan.poltype())
722        d = {'b': "Beam "+str(scan.getbeam(row)),
723             's': scan._getsourcename(row),
724             'i': "IF"+str(scan.getif(row)),
725             'p': poleval,
726             't': scan._gettime(row) }
727        return userlabel or d[mode]
728
Note: See TracBrowser for help on using the repository browser.