source: tags/Release2.1.0b/python/asapplotter.py @ 1218

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

fixed typo in axhspan

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