Ignore:
Timestamp:
11/11/05 10:01:49 (19 years ago)
Author:
mar637
Message:

create_mask now also handles args[0]=list. auto_quotient checks for conformance between # of ons and offs

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/python/asapplotter.py

    r709 r710  
    1212    """
    1313    def __init__(self, visible=True):
    14        
    15         if visible:
    16             from asap.asaplotgui import asaplotgui as asaplot
    17         else:
    18             from asap.asaplot import asaplot
    19         self._plotter = asaplot()
    20            
     14
     15        self._visible = visible
     16        self._plotter = self._newplotter()
     17
    2118        self._tdict = {'Time':'t','time':'t','t':'t','T':'t'}
    2219        self._bdict = {'Beam':'b','beam':'b','b':'b','B':'b'}
     
    4542        self._minmaxx = None
    4643        self._minmaxy = None
    47         self._datamask = None
     44        self._datamask = None
    4845        self._data = None
    4946        self._lmap = None
     
    5552                        'i':None, 'p':None
    5653                        }
     54        self._usermask = None
     55        self._usermaskspectra = None
     56
     57    def _newplotter(self):
     58        if self._visible:
     59            from asap.asaplotgui import asaplotgui as asaplot
     60        else:
     61            from asap.asaplot import asaplot
     62        return asaplot()
     63
    5764
    5865    def _translate(self, name):
     
    7380            are consistent e.g. all 'channel' or all 'velocity' etc.
    7481        """
    75         if self._plotter.is_dead:
    76             self._plotter = ASAPlot()
     82        if self._plotter.is_dead:
     83            self._plotter = self._newplotter()
    7784        self._plotter.hold()
    7885        self._plotter.clear()
     
    8188                if list(args) != self._data:
    8289                    self._data = list(args)
    83                     # reset cursor
    84                     self.set_cursor(refresh=False)
     90                    # reset
     91                    self._reset()
    8592            else:
    86                 self._data = list(args)
    87                 self.set_cursor(refresh=False)
     93                if isinstance(args[0], list):
     94                    self._data = args[0]
     95                else:
     96                    self._data = list(args)
     97                self._reset()
    8898        # ranges become invalid when unit changes
    8999        if self._abcunit != self._data[0].get_unit():
     
    91101            self._minmaxy = None
    92102            self._abcunit = self._data[0].get_unit()
    93             self._datamask = None
     103            self._datamask = None
    94104        if self._panelling == 't':
    95105            maxrows = 25
     
    125135            ncol = eval(self._cdict.get(colmode))
    126136        if n > 1:
     137            ganged = rcParams['plotter.ganged']
    127138            if self._rows and self._cols:
    128139                n = min(n,self._rows*self._cols)
    129140                self._plotter.set_panels(rows=self._rows,cols=self._cols,
    130                                          nplots=n)
     141                                         nplots=n,ganged=ganged)
    131142            else:
    132                 self._plotter.set_panels(rows=n,cols=0,nplots=n)
     143                self._plotter.set_panels(rows=n,cols=0,nplots=n,ganged=ganged)
    133144        else:
    134145            self._plotter.set_panels()
     
    171182                if self._abcissa: xlab = self._abcissa
    172183                y = None
     184                m = scan._getmask(rowsel)
     185                if self._usermask and self._usermask.count(j):
     186                    m  = logical_and(self._usermask, m)
    173187                if polmode == "stokes":
    174188                    y = scan._getstokesspectrum(rowsel)
     
    184198                    ylab = scan._get_ordinate_label()
    185199                m = scan._getmask(rowsel)
    186                 if self._datamask is not None:
    187                     if len(m) == len(self._datamask):
    188                         m = logical_and(m,self._datamask)
     200                if self._datamask is not None:
     201                    if len(m) == len(self._datamask):
     202                        m = logical_and(m,self._datamask)
    189203                if self._lmap and len(self._lmap) > 0:
    190204                    llab = self._lmap[jj]
     
    200214                    y = y[s:e]
    201215                    m = m[s:e]
     216                if len(x) > 1024 and rcParams['plotter.decimate']:
     217                    fac = len(x)/1024
     218                    x = x[::fac]
     219                    m = m[::fac]
     220                    y = y[::fac]
    202221                self._plotter.plot(x,y,m)
    203222                xlim=[min(x),max(x)]
    204223                if self._minmaxx is not None:
    205                     xlim = self._minmaxx
    206                 self._plotter.axes.set_xlim(xlim)
     224                    xlim = self._minmaxx
     225                self._plotter.axes.set_xlim(xlim)
    207226            self._plotter.set_axes('xlabel',xlab)
    208227            self._plotter.set_axes('ylabel',ylab)
     
    211230
    212231    def _plot_scans(self, scans, colmode):
    213         print "Can only plot one row per scan."
     232        print "Plotting mode is scans across panels. Can only plot one row per scan."
    214233        if colmode == 's':
    215234            return
     
    227246            ncol = eval(self._cdict.get(colmode))
    228247        if n > 1:
     248            ganged = rcParams['plotter.ganged']
    229249            if self._rows and self._cols:
    230250                n = min(n,self._rows*self._cols)
    231251                self._plotter.set_panels(rows=self._rows,cols=self._cols,
    232                                          nplots=n)
     252                                         nplots=n,ganged=ganged)
    233253            else:
    234                 self._plotter.set_panels(rows=n,cols=0,nplots=n)
     254                self._plotter.set_panels(rows=n,cols=0,nplots=n,ganged=ganged)
    235255        else:
    236256            self._plotter.set_panels()
     
    280300                    ylab = scan._get_ordinate_label()
    281301                m = scan._getmask(rowsel)
    282                 if self._datamask is not None:
    283                     if len(m) == len(self._datamask):
    284                         m = logical_and(m,self._datamask)
     302                if self._usermask and self._usermask.count(j):
     303                    m  = logical_and(self._usermask, m)
    285304                if self._lmap and len(self._lmap) > 0:
    286305                    llab = self._lmap[jj]
     
    296315                    y = y[s:e]
    297316                    m = m[s:e]
    298 
     317                if len(x) > 1024 and rcParams['plotter.decimate']:
     318                    fac = len(x)/1024
     319                    x = x[::fac]
     320                    m = m[::fac]
     321                    y = y[::fac]
    299322                self._plotter.plot(x,y,m)
    300323                xlim=[min(x),max(x)]
    301324                if self._minmaxx is not None:
    302                     xlim = self._minmaxx
     325                    xlim = self._minmaxx
    303326                self._plotter.axes.set_xlim(xlim)
    304327
     
    325348            ncol = eval(self._cdict.get(colmode))
    326349        if n > 1:
     350            ganged = rcParams['plotter.ganged']
    327351            if self._rows and self._cols:
    328352                n = min(n,self._rows*self._cols)
    329353                self._plotter.set_panels(rows=self._rows,cols=self._cols,
    330                                          nplots=n)
     354                                         nplots=n,ganged=ganged)
    331355            else:
    332                 self._plotter.set_panels(rows=n,cols=0,nplots=n)
     356                self._plotter.set_panels(rows=n,cols=0,nplots=n,ganged=ganged)
    333357        else:
    334358            self._plotter.set_panels()
     
    390414                    ylab = scan._get_ordinate_label()
    391415                m = scan._getmask(rowsel)
    392                 if self._datamask is not None:
    393                     if len(m) == len(self._datamask):
    394                         m = logical_and(m,self._datamask)
     416                if self._usermask and self._usermask.count(j):
     417                    m  = logical_and(self._usermask, m)
     418
    395419                if colmode == 's' or colmode == 't':
    396420                    if self._title and len(self._title) > 0:
     
    426450                    y = y[s:e]
    427451                    m = m[s:e]
    428 
     452                if len(x) > 1024 and rcParams['plotter.decimate']:
     453                    fac = len(x)/1024
     454                    x = x[::fac]
     455                    m = m[::fac]
     456                    y = y[::fac]
    429457                self._plotter.plot(x,y,m)
    430458                xlim=[min(x),max(x)]
    431459                if self._minmaxx is not None:
    432                     xlim = self._minmaxx
     460                    xlim = self._minmaxx
    433461                self._plotter.axes.set_xlim(xlim)
    434462
     
    445473        Parameters:
    446474            stacking:     tell the plotter which variable to plot
    447                           as line colour overlays (default 'pol')
     475                          as line color overlays (default 'pol')
    448476            panelling:    tell the plotter which variable to plot
    449477                          across multiple panels (default 'scan'
     
    531559             mp:    a list of 'strings'. This should have the same length
    532560                    as the number of elements on the legend and then maps
    533                     to the indeces in order
     561                    to the indeces in order. It is possible to uses latex
     562                    math expression. These have to be enclosed in r'', e.g. r'$x^{2}$'
    534563
    535564        Example:
     
    537566             for CO and SiO:
    538567             plotter.set_stacking('i')
    539              plotter.set_legend_map(['CO','SiO'])
     568             plotter.set_legend(['CO','SiO'])
    540569             plotter.plot()
     570             plotter.set_legend([r'$^{12}CO$', r'SiO'])
    541571        """
    542572        self._lmap = mp
     
    545575
    546576    def set_title(self, title=None):
     577        """
     578        Set the title of the plot. If multiple panels are plotted,
     579        multiple titles have to be specified.
     580        Example:
     581             # two panels are visible on the plotter
     582             plotter.set_title(["First Panel","Second Panel"])
     583        """
    547584        self._title = title
    548585        if self._data: self.plot()
     
    550587
    551588    def set_ordinate(self, ordinate=None):
     589        """
     590        Set the y-axis label of the plot. If multiple panels are plotted,
     591        multiple labels have to be specified.
     592        Example:
     593             # two panels are visible on the plotter
     594             plotter.set_ordinate(["First Y-Axis","Second Y-Axis"])
     595        """
    552596        self._ordinate = ordinate
    553597        if self._data: self.plot()
     
    555599
    556600    def set_abcissa(self, abcissa=None):
     601        """
     602        Set the x-axis label of the plot. If multiple panels are plotted,
     603        multiple labels have to be specified.
     604        Example:
     605             # two panels are visible on the plotter
     606             plotter.set_ordinate(["First X-Axis","Second X-Axis"])
     607        """
    557608        self._abcissa = abcissa
    558609        if self._data: self.plot()
    559610        return
    560611
    561     def save(self, filename=None, orientation=None,dpi=None):
     612    def set_colors(self, colormap):
     613        """
     614        Set the colors to be used. The plotter will cycle through
     615        these colors when lines are overlaid (stacking mode).
     616        Example:
     617             plotter.set_colors("red green blue")
     618             # If for example four lines are overlaid e.g I Q U V
     619             # 'I' will be 'red', 'Q' will be 'green', U will be 'blue'
     620             # and 'V' will be 'red' again.
     621        """
     622        if isinstance(colormap,str):
     623            colormap = colormap.split()
     624        self._plotter.palette(0,colormap=colormap)
     625        if self._data: self.plot()
     626
     627    def set_linestyles(self, linestyles):
     628        """
     629        Parameters:
     630             linestyles:     a list of linestyles to use.
     631                             'line', 'dashed', 'dotted', 'dashdot',
     632                             'dashdotdot' and 'dashdashdot' are
     633                             possible
     634
     635        Set the linestyles to be used. The plotter will cycle through
     636        these linestyles when lines are overlaid (stacking mode) AND
     637        only one color has been set.
     638        Example:
     639             plotter.set_colors("black")
     640             plotter.set_linestyles("line dashed dotted dashdot")
     641             # If for example four lines are overlaid e.g I Q U V
     642             # 'I' will be 'solid', 'Q' will be 'dashed',
     643             # U will be 'dotted' and 'V' will be 'dashdot'.
     644        """
     645        if isinstance(linestyles,str):
     646            linestyles = linestyles.split()
     647        self._plotter.palette(color=0,linestyle=0,linestyles=linestyles)
     648        if self._data: self.plot()
     649
     650    def save(self, filename=None, orientation=None, dpi=None):
    562651        """
    563652        Save the plot to a file. The know formats are 'png', 'ps', 'eps'.
     
    572661                          If None is choosen for 'ps' output, the plot is
    573662                          automatically oriented to fill the page.
     663             dpi:         The dpi of the output non-ps plot
    574664        """
    575665        self._plotter.save(filename,orientation,dpi)
     
    640730        dstokes2 = {"I":0,"Plinear":1,"Pangle":2,"V":3}
    641731        draw = {"XX":0, "YY":1,"Real(XY)":2, "Imag(XY)":3}
    642         dcirc = { "RR":0,"LL":1}#,"Real(RL)":2,"Image(RL)":3}
     732        dcirc = { "RR":0,"LL":1}#,"Real(RL)":2,"Imag(RL)":3}
    643733
    644734        if pol is None:
     
    677767        if self._data and refresh: self.plot()
    678768
     769    def set_mask(self, mask=None, pol=None):
     770        if not self._data:
     771            print "Can only set cursor after a first call to plot()"
     772            return
     773        if isinstance(mask, array):
     774            self._usermask = mask
     775        if isinstance(mask, list):
     776            self._usermask = array(mask)
     777        if mask is None and pol is None:
     778            self._usermask = None
     779            self._usermaskspectra = None
     780
     781        dstokes = {"I":0,"Q":1,"U":2,"V":3}
     782        dstokes2 = {"I":0,"Plinear":1,"Pangle":2,"V":3}
     783        draw = {"XX":0, "YY":1,"Real(XY)":2, "Imag(XY)":3}
     784        dcirc = { "RR":0,"LL":1}#,"Real(RL)":2,"Imag(RL)":3}
     785        if isinstance(pol, str):
     786            pol = pol.split()
     787        if isinstance(pol, list):
     788            if isinstance(pol[0], str):
     789                pass
     790            else:
     791                cpos = self._cursor[self._stacking]
     792                self._usermaskspectra =filter(lambda i: filter(lambda j: j==i ,cpos),pol)
     793        else:
     794            return
     795        self.plot()
     796
    679797    def _get_pollabel(self, scan, polmode):
    680798        tlab = ""
     
    711829        return start,end
    712830
    713 #if __name__ == '__main__':
    714 #    plotter = asapplotter()
     831    def _reset(self):
     832        self._usermask = None
     833        self._usermaskspectra = None
     834        self.set_cursor(refresh=False)
Note: See TracChangeset for help on using the changeset viewer.