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

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

removed commented out statements

  • 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        from matplotlib.numerix import ma
434        for j in range(len(self._plotter.subplots)):
435            self._plotter.subplot(j)
436            lims = self._plotter.axes.get_xlim()
437            for row in range(linecat.nrow()):
438                restf = linecat.get_frequency(row)/1000.0
439                c = 299792.458
440                freq = restf*(1.0-doppler/c)
441                if lims[0] < freq < lims[1]:
442                    if location is None:
443                        loc = 'bottom'
444                        if row%2: loc='top'
445                    else: loc = location
446                    maxys = []
447                    for line in self._plotter.axes.lines:
448                        v = line._x
449                        asc = v[0] < v[-1]
450
451                        idx = None
452                        if not asc:
453                            if v[len(v)-1] <= freq <= v[0]:
454                                i = len(v)-1
455                                while i>=0 and v[i] < freq:
456                                    idx = i
457                                    i-=1
458                        else:
459                           if v[0] <= freq <= v[len(v)-1]:
460                                i = 0
461                                while  i<len(v) and v[i] < freq:
462                                    idx = i
463                                    i+=1
464                        if idx is not None:
465                            lower = idx - deltachan
466                            upper = idx + deltachan
467                            if lower < 0: lower = 0
468                            if upper > len(v): upper = len(v)
469                            s = slice(lower, upper)
470                            y = line._y[s]
471                            maxy = ma.maximum(y)
472                            if isinstance( maxy, float):
473                                maxys.append(maxy)
474                    if len(maxys):
475                        peak = max(maxys)
476                        if peak > self._plotter.axes.get_ylim()[1]:
477                            loc = 'bottom'
478                    else:
479                        continue
480                    self._plotter.vline_with_label(freq, peak,
481                                                   linecat.get_name(row),
482                                                   location=loc, rotate=rotate)
483        self._plotter.show(hardrefresh=False)
484
485
486    def save(self, filename=None, orientation=None, dpi=None):
487        """
488        Save the plot to a file. The know formats are 'png', 'ps', 'eps'.
489        Parameters:
490             filename:    The name of the output file. This is optional
491                          and autodetects the image format from the file
492                          suffix. If non filename is specified a file
493                          called 'yyyymmdd_hhmmss.png' is created in the
494                          current directory.
495             orientation: optional parameter for postscript only (not eps).
496                          'landscape', 'portrait' or None (default) are valid.
497                          If None is choosen for 'ps' output, the plot is
498                          automatically oriented to fill the page.
499             dpi:         The dpi of the output non-ps plot
500        """
501        self._plotter.save(filename,orientation,dpi)
502        return
503
504
505    def set_mask(self, mask=None, selection=None):
506        """
507        Set a plotting mask for a specific polarization.
508        This is useful for masking out "noise" Pangle outside a source.
509        Parameters:
510             mask:           a mask from scantable.create_mask
511             selection:      the spectra to apply the mask to.
512        Example:
513             select = selector()
514             select.setpolstrings("Pangle")
515             plotter.set_mask(mymask, select)
516        """
517        if not self._data:
518            msg = "Can only set mask after a first call to plot()"
519            if rcParams['verbose']:
520                print msg
521                return
522            else:
523                raise RuntimeError(msg)
524        if len(mask):
525            if isinstance(mask, list) or isinstance(mask, tuple):
526                self._usermask = array(mask)
527            else:
528                self._usermask = mask
529        if mask is None and selection is None:
530            self._usermask = []
531            self._maskselection = None
532        if isinstance(selection, selector):
533            self._maskselection = {'b': selection.get_beams(),
534                                   's': selection.get_scans(),
535                                   'i': selection.get_ifs(),
536                                   'p': selection.get_pols(),
537                                   't': [] }
538        else:
539            self._maskselection = None
540        self.plot(self._data)
541
542    def _slice_indeces(self, data):
543        mn = self._minmaxx[0]
544        mx = self._minmaxx[1]
545        asc = data[0] < data[-1]
546        start=0
547        end = len(data)-1
548        inc = 1
549        if not asc:
550            start = len(data)-1
551            end = 0
552            inc = -1
553        # find min index
554        while start > 0 and data[start] < mn:
555            start+= inc
556        # find max index
557        while end > 0 and data[end] > mx:
558            end-=inc
559        if end > 0: end +=1
560        if start > end:
561            return end,start
562        return start,end
563
564    def _reset(self):
565        self._usermask = []
566        self._usermaskspectra = None
567        self.set_selection(None, False)
568
569    def _plot(self, scan):
570        savesel = scan.get_selection()
571        sel = savesel +  self._selection
572        d0 = {'s': 'SCANNO', 'b': 'BEAMNO', 'i':'IFNO',
573              'p': 'POLNO', 'c': 'CYCLENO', 't' : 'TIME' }
574        order = [d0[self._panelling],d0[self._stacking]]
575        sel.set_order(order)
576        scan.set_selection(sel)
577        d = {'b': scan.getbeam, 's': scan.getscan,
578             'i': scan.getif, 'p': scan.getpol, 't': scan._gettime }
579
580        polmodes = dict(zip(self._selection.get_pols(),
581                            self._selection.get_poltypes()))
582        # this returns either a tuple of numbers or a length  (ncycles)
583        # convert this into lengths
584        n0,nstack0 = self._get_selected_n(scan)
585        if isinstance(n0, int): n = n0
586        else: n = len(n0)
587        if isinstance(nstack0, int): nstack = nstack0
588        else: nstack = len(nstack0)
589        maxpanel, maxstack = 16,8
590        if n > maxpanel or nstack > maxstack:
591            from asap import asaplog
592            maxn = 0
593            if nstack > maxstack: maxn = maxstack
594            if n > maxpanel: maxn = maxpanel
595            msg ="Scan to be plotted contains more than %d selections.\n" \
596                  "Selecting first %d selections..." % (maxn, maxn)
597            asaplog.push(msg)
598            print_log()
599            n = min(n,maxpanel)
600            nstack = min(nstack,maxstack)
601        if n > 1:
602            ganged = rcParams['plotter.ganged']
603            if self._rows and self._cols:
604                n = min(n,self._rows*self._cols)
605                self._plotter.set_panels(rows=self._rows,cols=self._cols,
606                                         nplots=n,ganged=ganged)
607            else:
608                self._plotter.set_panels(rows=n,cols=0,nplots=n,ganged=ganged)
609        else:
610            self._plotter.set_panels()
611        r=0
612        nr = scan.nrow()
613        a0,b0 = -1,-1
614        allxlim = []
615        allylim = []
616        newpanel=True
617        panelcount,stackcount = 0,0
618        while r < nr:
619            a = d[self._panelling](r)
620            b = d[self._stacking](r)
621            if a > a0 and panelcount < n:
622                if n > 1:
623                    self._plotter.subplot(panelcount)
624                self._plotter.palette(0)
625                #title
626                xlab = self._abcissa and self._abcissa[panelcount] \
627                       or scan._getabcissalabel()
628                ylab = self._ordinate and self._ordinate[panelcount] \
629                       or scan._get_ordinate_label()
630                self._plotter.set_axes('xlabel',xlab)
631                self._plotter.set_axes('ylabel',ylab)
632                lbl = self._get_label(scan, r, self._panelling, self._title)
633                if isinstance(lbl, list) or isinstance(lbl, tuple):
634                    if 0 <= panelcount < len(lbl):
635                        lbl = lbl[panelcount]
636                    else:
637                        # get default label
638                        lbl = self._get_label(scan, r, self._panelling, None)
639                self._plotter.set_axes('title',lbl)
640                newpanel = True
641                stackcount =0
642                panelcount += 1
643            if (b > b0 or newpanel) and stackcount < nstack:
644                y = []
645                if len(polmodes):
646                    y = scan._getspectrum(r, polmodes[scan.getpol(r)])
647                else:
648                    y = scan._getspectrum(r)
649                m = scan._getmask(r)
650                from matplotlib.numerix import logical_not, logical_and
651                if self._maskselection and len(self._usermask) == len(m):
652                    if d[self._stacking](r) in self._maskselection[self._stacking]:
653                        m = logical_and(m, self._usermask)
654                x = scan._getabcissa(r)
655                from matplotlib.numerix import ma, array
656                y = ma.masked_array(y,mask=logical_not(array(m,copy=False)))
657                if self._minmaxx is not None:
658                    s,e = self._slice_indeces(x)
659                    x = x[s:e]
660                    y = y[s:e]
661                if len(x) > 1024 and rcParams['plotter.decimate']:
662                    fac = len(x)/1024
663                    x = x[::fac]
664                    y = y[::fac]
665                llbl = self._get_label(scan, r, self._stacking, self._lmap)
666                if isinstance(llbl, list) or isinstance(llbl, tuple):
667                    if 0 <= stackcount < len(llbl):
668                        # use user label
669                        llbl = llbl[stackcount]
670                    else:
671                        # get default label
672                        llbl = self._get_label(scan, r, self._stacking, None)
673                self._plotter.set_line(label=llbl)
674                plotit = self._plotter.plot
675                if self._hist: plotit = self._plotter.hist
676                if len(x) > 0:
677                    plotit(x,y)
678                    xlim= self._minmaxx or [min(x),max(x)]
679                    allxlim += xlim
680                    ylim= self._minmaxy or [ma.minimum(y),ma.maximum(y)]
681                    allylim += ylim
682                stackcount += 1
683                # last in colour stack -> autoscale x
684                if stackcount == nstack:
685                    allxlim.sort()
686                    self._plotter.axes.set_xlim([allxlim[0],allxlim[-1]])
687                    # clear
688                    allxlim =[]
689
690            newpanel = False
691            a0=a
692            b0=b
693            # ignore following rows
694            if (panelcount == n) and (stackcount == nstack):
695                # last panel -> autoscale y if ganged
696                if rcParams['plotter.ganged']:
697                    allylim.sort()
698                    self._plotter.set_limits(ylim=[allylim[0],allylim[-1]])
699                break
700            r+=1 # next row
701        #reset the selector to the scantable's original
702        scan.set_selection(savesel)
703
704    def set_selection(self, selection=None, refresh=True):
705        self._selection = isinstance(selection,selector) and selection or selector()
706        d0 = {'s': 'SCANNO', 'b': 'BEAMNO', 'i':'IFNO',
707              'p': 'POLNO', 'c': 'CYCLENO', 't' : 'TIME' }
708        order = [d0[self._panelling],d0[self._stacking]]
709        self._selection.set_order(order)
710        if self._data and refresh: self.plot(self._data)
711
712    def _get_selected_n(self, scan):
713        d1 = {'b': scan.getbeamnos, 's': scan.getscannos,
714             'i': scan.getifnos, 'p': scan.getpolnos, 't': scan.ncycle }
715        d2 = { 'b': self._selection.get_beams(),
716               's': self._selection.get_scans(),
717               'i': self._selection.get_ifs(),
718               'p': self._selection.get_pols(),
719               't': self._selection.get_cycles() }
720        n =  d2[self._panelling] or d1[self._panelling]()
721        nstack = d2[self._stacking] or d1[self._stacking]()
722        return n,nstack
723
724    def _get_label(self, scan, row, mode, userlabel=None):
725        if isinstance(userlabel, list) and len(userlabel) == 0:
726            userlabel = " "
727        pms = dict(zip(self._selection.get_pols(),self._selection.get_poltypes()))
728        if len(pms):
729            poleval = scan._getpollabel(scan.getpol(row),pms[scan.getpol(row)])
730        else:
731            poleval = scan._getpollabel(scan.getpol(row),scan.poltype())
732        d = {'b': "Beam "+str(scan.getbeam(row)),
733             's': scan._getsourcename(row),
734             'i': "IF"+str(scan.getif(row)),
735             'p': poleval,
736             't': str(scan.get_time(row)) }
737        return userlabel or d[mode]
738
Note: See TracBrowser for help on using the repository browser.