Changeset 1698 for branches/alma


Ignore:
Timestamp:
02/12/10 23:31:55 (15 years ago)
Author:
Kana Sugimoto
Message:

New Development: No

JIRA Issue: Yes (CAS-1077)

Ready to Release: Yes

Interface Changes: Yes

What Interface Changed: see the Description

Test Programs: run the new function or try refresh=False

Put in Release Notes: Yes

Module(s): CASA task sdplot()

Description:

  1. A new function, set_data(self, scan, refresh=True), added to the asapplotter class. This function sets a scantable (specified by scan) to be plotted.
  2. A boolean parameter refresh is added to following functions in the asapplotter class:

set_mode, set_layout, set_range, set_legend, set_title, set_ordinate,
set_abcissa, set_colors, set_histogram, set_linestyles, set_font,
set_mask, and set_selection

The plot is replotted based on the new parameter setting(s) only when refresh=True.


File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/alma/python/asapplotter.py

    r1632 r1698  
    7171        self._plotter.hold()
    7272        self._plotter.clear()
    73         from asap import scantable
    7473        if not self._data and not scan:
    7574            msg = "Input is not a scantable"
     
    8079                return
    8180            raise TypeError(msg)
    82         if isinstance(scan, scantable):
    83             if self._data is not None:
    84                 if scan != self._data:
    85                     self._data = scan
    86                     # reset
    87                     self._reset()
    88             else:
    89                 self._data = scan
    90                 self._reset()
    91         # ranges become invalid when unit changes
    92         if self._abcunit and self._abcunit != self._data.get_unit():
    93             self._minmaxx = None
    94             self._minmaxy = None
    95             self._abcunit = self._data.get_unit()
    96             self._datamask = None
     81        if scan: self.set_data(scan,refresh=False)
    9782        self._plot(self._data)
    9883        if self._minmaxy is not None:
     
    152137    # end matplotlib.axes fowarding functions
    153138
    154     def set_mode(self, stacking=None, panelling=None):
     139    def set_data(self, scan, refresh=True):
     140        """
     141        Set a scantable to plot.
     142        Parameters:
     143            scan:      a scantable
     144            refresh:   True (default) or False. If True, the plot is
     145                       replotted based on the new parameter setting(s).
     146                       Otherwise,the parameter(s) are set without replotting.
     147        """
     148        from asap import scantable
     149        if isinstance(scan, scantable):
     150            if self._data is not None:
     151                if scan != self._data:
     152                    self._data = scan
     153                    # reset
     154                    self._reset()
     155            else:
     156                self._data = scan
     157                self._reset()
     158        else:
     159            msg = "Input is not a scantable"
     160            if rcParams['verbose']:
     161                #print msg
     162                asaplog.push( msg )
     163                print_log( 'ERROR' )
     164                return
     165            raise TypeError(msg)
     166
     167        # ranges become invalid when unit changes
     168        if self._abcunit and self._abcunit != self._data.get_unit():
     169            self._minmaxx = None
     170            self._minmaxy = None
     171            self._abcunit = self._data.get_unit()
     172            self._datamask = None
     173        if refresh: self.plot()
     174       
     175
     176    def set_mode(self, stacking=None, panelling=None, refresh=True):
    155177        """
    156178        Set the plots look and feel, i.e. what you want to see on the plot.
     
    160182            panelling:    tell the plotter which variable to plot
    161183                          across multiple panels (default 'scan'
     184            refresh:      True (default) or False. If True, the plot is
     185                          replotted based on the new parameter setting(s).
     186                          Otherwise,the parameter(s) are set without replotting.
    162187        Note:
    163188            Valid modes are:
     
    178203            else:
    179204                raise TypeError(msg)
    180         if self._data: self.plot(self._data)
     205        if refresh and self._data: self.plot(self._data)
    181206        return
    182207
     
    192217        return False
    193218
    194     def set_layout(self,rows=None,cols=None):
     219    def set_layout(self,rows=None,cols=None,refresh=True):
    195220        """
    196221        Set the multi-panel layout, i.e. how many rows and columns plots
     
    199224             rows:   The number of rows of plots
    200225             cols:   The number of columns of plots
     226             refresh:  True (default) or False. If True, the plot is
     227                       replotted based on the new parameter setting(s).
     228                       Otherwise,the parameter(s) are set without replotting.
    201229        Note:
    202230             If no argument is given, the potter reverts to its auto-plot
     
    205233        self._rows = rows
    206234        self._cols = cols
    207         if self._data: self.plot(self._data)
     235        if refresh and self._data: self.plot(self._data)
    208236        return
    209237
     
    219247        return False
    220248
    221     def set_range(self,xstart=None,xend=None,ystart=None,yend=None):
     249    def set_range(self,xstart=None,xend=None,ystart=None,yend=None,refresh=True):
    222250        """
    223251        Set the range of interest on the abcissa of the plot
    224252        Parameters:
    225253            [x,y]start,[x,y]end:  The start and end points of the 'zoom' window
     254            refresh:  True (default) or False. If True, the plot is
     255                      replotted based on the new parameter setting(s).
     256                      Otherwise,the parameter(s) are set without replotting.
    226257        Note:
    227258            These become non-sensical when the unit changes.
     
    237268        else:
    238269            self._minmaxy = [ystart,yend]
    239         if self._data: self.plot(self._data)
     270        if refresh and self._data: self.plot(self._data)
    240271        return
    241272
    242     def set_legend(self, mp=None, fontsize = None, mode = 0):
     273    def set_legend(self, mp=None, fontsize = None, mode = 0, refresh=True):
    243274        """
    244275        Specify a mapping for the legend instead of using the default
     
    264295                        9: upper center
    265296                        10: center
     297            refresh:    True (default) or False. If True, the plot is
     298                        replotted based on the new parameter setting(s).
     299                        Otherwise,the parameter(s) are set without replotting.
    266300
    267301        Example:
     
    278312            from matplotlib import rc as rcp
    279313            rcp('legend', fontsize=fontsize)
    280         if self._data:
    281             self.plot(self._data)
     314        if refresh and self._data: self.plot(self._data)
    282315        return
    283316
    284     def set_title(self, title=None, fontsize=None):
     317    def set_title(self, title=None, fontsize=None, refresh=True):
    285318        """
    286319        Set the title of the plot. If multiple panels are plotted,
    287320        multiple titles have to be specified.
     321        Parameters:
     322            refresh:    True (default) or False. If True, the plot is
     323                        replotted based on the new parameter setting(s).
     324                        Otherwise,the parameter(s) are set without replotting.
    288325        Example:
    289326             # two panels are visible on the plotter
     
    294331            from matplotlib import rc as rcp
    295332            rcp('axes', titlesize=fontsize)
    296         if self._data: self.plot(self._data)
     333        if refresh and self._data: self.plot(self._data)
    297334        return
    298335
    299     def set_ordinate(self, ordinate=None, fontsize=None):
     336    def set_ordinate(self, ordinate=None, fontsize=None, refresh=True):
    300337        """
    301338        Set the y-axis label of the plot. If multiple panels are plotted,
     
    304341            ordinate:    a list of ordinate labels. None (default) let
    305342                         data determine the labels
     343            refresh:     True (default) or False. If True, the plot is
     344                         replotted based on the new parameter setting(s).
     345                         Otherwise,the parameter(s) are set without replotting.
    306346        Example:
    307347             # two panels are visible on the plotter
     
    313353            rcp('axes', labelsize=fontsize)
    314354            rcp('ytick', labelsize=fontsize)
    315         if self._data: self.plot(self._data)
     355        if refresh and self._data: self.plot(self._data)
    316356        return
    317357
    318     def set_abcissa(self, abcissa=None, fontsize=None):
     358    def set_abcissa(self, abcissa=None, fontsize=None, refresh=True):
    319359        """
    320360        Set the x-axis label of the plot. If multiple panels are plotted,
     
    323363            abcissa:     a list of abcissa labels. None (default) let
    324364                         data determine the labels
     365            refresh:     True (default) or False. If True, the plot is
     366                         replotted based on the new parameter setting(s).
     367                         Otherwise,the parameter(s) are set without replotting.
    325368        Example:
    326369             # two panels are visible on the plotter
     
    332375            rcp('axes', labelsize=fontsize)
    333376            rcp('xtick', labelsize=fontsize)
    334         if self._data: self.plot(self._data)
     377        if refresh and self._data: self.plot(self._data)
    335378        return
    336379
    337     def set_colors(self, colmap):
     380    def set_colors(self, colmap, refresh=True):
    338381        """
    339382        Set the colours to be used. The plotter will cycle through
     
    341384        Parameters:
    342385            colmap:     a list of colour names
     386            refresh:    True (default) or False. If True, the plot is
     387                        replotted based on the new parameter setting(s).
     388                        Otherwise,the parameter(s) are set without replotting.
    343389        Example:
    344390             plotter.set_colors("red green blue")
     
    350396            colmap = colmap.split()
    351397        self._plotter.palette(0, colormap=colmap)
    352         if self._data: self.plot(self._data)
     398        if refresh and self._data: self.plot(self._data)
    353399
    354400    # alias for english speakers
    355401    set_colours = set_colors
    356402
    357     def set_histogram(self, hist=True, linewidth=None):
     403    def set_histogram(self, hist=True, linewidth=None, refresh=True):
    358404        """
    359405        Enable/Disable histogram-like plotting.
     
    362408                         is taken from the .asaprc setting
    363409                         plotter.histogram
     410            refresh:     True (default) or False. If True, the plot is
     411                         replotted based on the new parameter setting(s).
     412                         Otherwise,the parameter(s) are set without replotting.
    364413        """
    365414        self._hist = hist
     
    367416            from matplotlib import rc as rcp
    368417            rcp('lines', linewidth=linewidth)
    369         if self._data: self.plot(self._data)
    370 
    371     def set_linestyles(self, linestyles=None, linewidth=None):
     418        if refresh and self._data: self.plot(self._data)
     419
     420    def set_linestyles(self, linestyles=None, linewidth=None, refresh=True):
    372421        """
    373422        Set the linestyles to be used. The plotter will cycle through
     
    379428                             'dashdotdot' and 'dashdashdot' are
    380429                             possible
    381 
     430            refresh:         True (default) or False. If True, the plot is
     431                             replotted based on the new parameter setting(s).
     432                             Otherwise,the parameter(s) are set without replotting.
    382433        Example:
    383434             plotter.set_colors("black")
     
    393444            from matplotlib import rc as rcp
    394445            rcp('lines', linewidth=linewidth)
    395         if self._data: self.plot(self._data)
    396 
    397     def set_font(self, family=None, style=None, weight=None, size=None):
     446        if refresh and self._data: self.plot(self._data)
     447
     448    def set_font(self, family=None, style=None, weight=None, size=None, refresh=True):
    398449        """
    399450        Set font properties.
     
    404455            size:      the 'general' font size, individual elements can be adjusted
    405456                       seperately
     457            refresh:   True (default) or False. If True, the plot is
     458                       replotted based on the new parameter setting(s).
     459                       Otherwise,the parameter(s) are set without replotting.
    406460        """
    407461        from matplotlib import rc as rcp
     
    414468        if isinstance(size, float) or isinstance(size, int):
    415469            rcp('font', size=size)
    416         if self._data: self.plot(self._data)
     470        if refresh and self._data: self.plot(self._data)
    417471
    418472    def plot_lines(self, linecat=None, doppler=0.0, deltachan=10, rotate=90.0,
     
    512566
    513567
    514     def set_mask(self, mask=None, selection=None):
     568    def set_mask(self, mask=None, selection=None, refresh=True):
    515569        """
    516570        Set a plotting mask for a specific polarization.
     
    519573             mask:           a mask from scantable.create_mask
    520574             selection:      the spectra to apply the mask to.
     575             refresh:        True (default) or False. If True, the plot is
     576                             replotted based on the new parameter setting(s).
     577                             Otherwise,the parameter(s) are set without replotting.
    521578        Example:
    522579             select = selector()
     
    549606        else:
    550607            self._maskselection = None
    551         self.plot(self._data)
     608        if refresh: self.plot(self._data)
    552609
    553610    def _slice_indeces(self, data):
     
    733790
    734791    def set_selection(self, selection=None, refresh=True):
     792        """
     793        Parameters:
     794            selection:  a selector object (default unset the selection)
     795            refresh:    True (default) or False. If True, the plot is
     796                        replotted based on the new parameter setting(s).
     797                        Otherwise,the parameter(s) are set without replotting.
     798        """
    735799        self._selection = isinstance(selection,selector) and selection or selector()
    736800        d0 = {'s': 'SCANNO', 'b': 'BEAMNO', 'i':'IFNO',
     
    738802        order = [d0[self._panelling],d0[self._stacking]]
    739803        self._selection.set_order(order)
    740         if self._data and refresh: self.plot(self._data)
     804        if refresh and self._data: self.plot(self._data)
    741805
    742806    def _get_selected_n(self, scan):
Note: See TracChangeset for help on using the changeset viewer.