Changeset 2698


Ignore:
Timestamp:
12/15/12 21:37:52 (12 years ago)
Author:
Kana Sugimoto
Message:

New Development: No

JIRA Issue: No

Ready for Test: Yes

Interface Changes: No

What Interface Changed:

Test Programs:

Put in Release Notes: No

Module(s):

Description:

perparation for refactoring. chaged order of methods in code.


File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/python/asapplotter.py

    r2697 r2698  
    4949        self._inikwg = kwargs
    5050
     51        # plot settings
     52        self._colormap = None
     53        self._linestyles = None
     54        self._fp = FontProperties()
     55        self._rows = None
     56        self._cols = None
     57        self._minmaxx = None
     58        self._minmaxy = None
     59        self._margins = self.set_margin(refresh=False)
     60        self._legendloc = None
     61        # scantable plot settings
    5162        self._panelling = None
    5263        self._stacking = None
    5364        self.set_panelling()
    5465        self.set_stacking()
    55         self._rows = None
    56         self._cols = None
    57         self._minmaxx = None
    58         self._minmaxy = None
    59         self._datamask = None
     66        self._hist = rcParams['plotter.histogram']
     67        # scantable dependent settings
    6068        self._data = None
     69        self._abcunit = None
     70        self._headtext = {'string': None, 'textobj': None}
     71        self._selection = selector()
     72        self._usermask = []
     73        self._maskselection = None
     74        self._offset = None
    6175        self._lmap = None
    6276        self._title = None
    6377        self._ordinate = None
    6478        self._abcissa = None
    65         self._abcunit = None
    66         self._usermask = []
    67         self._maskselection = None
    68         self._selection = selector()
    69         self._hist = rcParams['plotter.histogram']
    70         self._fp = FontProperties()
    71         self._margins = self.set_margin(refresh=False)
    72         self._offset = None
     79        # cursors for page iteration
    7380        self._startrow = 0
    7481        self._ipanel = -1
    7582        self._panelrows = []
    76         self._headtext={'string': None, 'textobj': None}
    77         self._colormap = None
    78         self._linestyles = None
    79         self._legendloc = None
    8083
    8184    def _translate(self, instr):
     
    178181
    179182
    180     @asaplog_post_dec
    181     def plot(self, scan=None):
    182         """
    183         Plot a scantable.
    184         Parameters:
    185             scan:   a scantable
    186         Note:
    187             If a scantable was specified in a previous call
    188             to plot, no argument has to be given to 'replot'
    189             NO checking is done that the abcissas of the scantable
    190             are consistent e.g. all 'channel' or all 'velocity' etc.
    191         """
    192         if not self._data and not scan:
    193             msg = "Input is not a scantable"
    194             raise TypeError(msg)
    195 
    196         self._assert_plotter(action="reload")
    197         self._plotter.hold()
    198         self._reset_counter()
    199         #self._plotter.clear()
    200         if scan:
    201             self.set_data(scan, refresh=False)
    202         self._plotter.palette(color=0,colormap=self._colormap,
    203                               linestyle=0,linestyles=self._linestyles)
    204         self._plotter.legend(self._legendloc)
    205         self._plot(self._data)
    206         if self._minmaxy is not None:
    207             self._plotter.set_limits(ylim=self._minmaxy)
    208         if self.casabar_exists(): self._plotter.figmgr.casabar.enable_button()
    209         self._plotter.release()
    210         self._plotter.tidy()
    211         self._plotter.show(hardrefresh=False)
    212         return
    213 
    214183    def gca(self):
    215184        errmsg = "No axis to retun. Need to plot first."
     
    224193
    225194        self._plotter.figure.show()
     195
     196    def save(self, filename=None, orientation=None, dpi=None):
     197        """
     198        Save the plot to a file. The known formats are 'png', 'ps', 'eps'.
     199        Parameters:
     200             filename:    The name of the output file. This is optional
     201                          and autodetects the image format from the file
     202                          suffix. If non filename is specified a file
     203                          called 'yyyymmdd_hhmmss.png' is created in the
     204                          current directory.
     205             orientation: optional parameter for postscript only (not eps).
     206                          'landscape', 'portrait' or None (default) are valid.
     207                          If None is choosen for 'ps' output, the plot is
     208                          automatically oriented to fill the page.
     209             dpi:         The dpi of the output non-ps plot
     210        """
     211        errmsg = "Cannot save figure. Need to plot first."
     212        self._assert_plotter(action="halt",errmsg=errmsg)
     213       
     214        self._plotter.save(filename,orientation,dpi)
     215        return
    226216
    227217    def create_mask(self, nwin=1, panel=0, color=None):
     
    389379    # end matplotlib.axes fowarding functions
    390380
     381    # forwards to matplotlib.Figure.text
     382    def figtext(self, *args, **kwargs):
     383        """
     384        Add text to figure at location x,y (relative 0-1 coords).
     385        This method forwards *args and **kwargs to a Matplotlib method,
     386        matplotlib.Figure.text.
     387        See the method help for detailed information.
     388        """
     389        self._assert_plotter(action="reload")
     390        self._plotter.text(*args, **kwargs)
     391    # end matplotlib.Figure.text forwarding function
     392
     393    # plot setttings
    391394    @asaplog_post_dec
    392395    def set_data(self, scan, refresh=True):
     
    422425            self._minmaxy = None
    423426            self._abcunit = self._data.get_unit()
    424             self._datamask = None
    425427        if refresh: self.plot()
    426428
     
    459461        return
    460462
     463    def set_stacking(self, what=None):
     464        """Set the 'stacking' mode i.e. which type of spectra should be
     465        overlayed.
     466        """
     467        mode = what
     468        if mode is None:
     469             mode = rcParams['plotter.stacking']
     470        md = self._translate(mode)
     471        if md:
     472            self._stacking = md
     473            self._lmap = None
     474            # new mode is set. need to reset counters for multi page plotting
     475            self._reset_counters()
     476            return True
     477        return False
     478
    461479    def set_panelling(self, what=None):
    462480        """Set the 'panelling' mode i.e. which type of spectra should be
     
    471489            self._panelling = md
    472490            self._title = None
    473             #if md == 'r':
    474             #    self._stacking = '_r'
    475             # you need to reset counters for multi page plotting
     491            # new mode is set. need to reset counters for multi page plotting
    476492            self._reset_counters()
    477493            return True
     
    496512        if refresh and self._data: self.plot(self._data)
    497513        return
    498 
    499     def set_stacking(self, what=None):
    500         """Set the 'stacking' mode i.e. which type of spectra should be
    501         overlayed.
    502         """
    503         mode = what
    504         if mode is None:
    505              mode = rcParams['plotter.stacking']
    506         md = self._translate(mode)
    507         if md:
    508             self._stacking = md
    509             self._lmap = None
    510             #if md == 'r':
    511             #    self._panelling = '_r'
    512             # you need to reset counters for multi page plotting
    513             self._reset_counters()
    514             return True
    515         return False
    516 
    517     def _reset_counters(self):
    518         self._startrow = 0
    519         self._ipanel = -1
    520         self._panelrows = []
    521514
    522515    def set_range(self,xstart=None,xend=None,ystart=None,yend=None,refresh=True, offset=None):
     
    860853
    861854
    862     def save(self, filename=None, orientation=None, dpi=None):
    863         """
    864         Save the plot to a file. The known formats are 'png', 'ps', 'eps'.
    865         Parameters:
    866              filename:    The name of the output file. This is optional
    867                           and autodetects the image format from the file
    868                           suffix. If non filename is specified a file
    869                           called 'yyyymmdd_hhmmss.png' is created in the
    870                           current directory.
    871              orientation: optional parameter for postscript only (not eps).
    872                           'landscape', 'portrait' or None (default) are valid.
    873                           If None is choosen for 'ps' output, the plot is
    874                           automatically oriented to fill the page.
    875              dpi:         The dpi of the output non-ps plot
    876         """
    877         errmsg = "Cannot save figure. Need to plot first."
    878         self._assert_plotter(action="halt",errmsg=errmsg)
    879        
    880         self._plotter.save(filename,orientation,dpi)
    881         return
     855    def set_selection(self, selection=None, refresh=True, **kw):
     856        """
     857        Parameters:
     858            selection:  a selector object (default unset the selection)
     859            refresh:    True (default) or False. If True, the plot is
     860                        replotted based on the new parameter setting(s).
     861                        Otherwise,the parameter(s) are set without replotting.
     862        """
     863        if selection is None:
     864            # reset
     865            if len(kw) == 0:
     866                self._selection = selector()
     867            else:
     868                # try keywords
     869                for k in kw:
     870                    if k not in selector.fields:
     871                        raise KeyError("Invalid selection key '%s', valid keys are %s" % (k, selector.fields))
     872                self._selection = selector(**kw)
     873        elif isinstance(selection, selector):
     874            self._selection = selection
     875        else:
     876            raise TypeError("'selection' is not of type selector")
     877
     878        order = self._get_sortstring([self._panelling,self._stacking])
     879        if order:
     880            self._selection.set_order(order)
     881        if refresh and self._data:
     882            self.plot()
    882883
    883884    @asaplog_post_dec
     
    953954            return start,end
    954955
     956    # reset methods
    955957    def _reset(self):
    956958        self._usermask = []
     
    970972        if self.casabar_exists():
    971973            self._plotter.figmgr.casabar.set_pagecounter(1)
     974
     975    def _reset_counters(self):
     976        self._startrow = 0
     977        self._ipanel = -1
     978        self._panelrows = []
     979
     980    # scantable plot methods
     981    @asaplog_post_dec
     982    def plot(self, scan=None):
     983        """
     984        Plot a scantable.
     985        Parameters:
     986            scan:   a scantable
     987        Note:
     988            If a scantable was specified in a previous call
     989            to plot, no argument has to be given to 'replot'
     990            NO checking is done that the abcissas of the scantable
     991            are consistent e.g. all 'channel' or all 'velocity' etc.
     992        """
     993        if not self._data and not scan:
     994            msg = "Input is not a scantable"
     995            raise TypeError(msg)
     996
     997        self._assert_plotter(action="reload")
     998        self._plotter.hold()
     999        self._reset_counter()
     1000        #self._plotter.clear()
     1001        if scan:
     1002            self.set_data(scan, refresh=False)
     1003        self._plotter.palette(color=0,colormap=self._colormap,
     1004                              linestyle=0,linestyles=self._linestyles)
     1005        self._plotter.legend(self._legendloc)
     1006        self._plot(self._data)
     1007        if self._minmaxy is not None:
     1008            self._plotter.set_limits(ylim=self._minmaxy)
     1009        if self.casabar_exists(): self._plotter.figmgr.casabar.enable_button()
     1010        self._plotter.release()
     1011        self._plotter.tidy()
     1012        self._plotter.show(hardrefresh=False)
     1013        return
    9721014
    9731015    def _plot(self, scan):
     
    11901232        #temporary switch-off for older matplotlib
    11911233        #if self._fp is not None:
    1192         if self._fp is not None and getattr(self._plotter.figure,'findobj',False):
     1234        if self._fp is not None and \
     1235               getattr(self._plotter.figure,'findobj',False):
    11931236            for o in self._plotter.figure.findobj(Text):
    11941237                if not self._headtext['textobj'] or \
     
    12121255            return lsorts
    12131256        return None
    1214 
    1215     def set_selection(self, selection=None, refresh=True, **kw):
    1216         """
    1217         Parameters:
    1218             selection:  a selector object (default unset the selection)
    1219             refresh:    True (default) or False. If True, the plot is
    1220                         replotted based on the new parameter setting(s).
    1221                         Otherwise,the parameter(s) are set without replotting.
    1222         """
    1223         if selection is None:
    1224             # reset
    1225             if len(kw) == 0:
    1226                 self._selection = selector()
    1227             else:
    1228                 # try keywords
    1229                 for k in kw:
    1230                     if k not in selector.fields:
    1231                         raise KeyError("Invalid selection key '%s', valid keys are %s" % (k, selector.fields))
    1232                 self._selection = selector(**kw)
    1233         elif isinstance(selection, selector):
    1234             self._selection = selection
    1235         else:
    1236             raise TypeError("'selection' is not of type selector")
    1237 
    1238         order = self._get_sortstring([self._panelling,self._stacking])
    1239         if order:
    1240             self._selection.set_order(order)
    1241         if refresh and self._data:
    1242             self.plot()
    12431257
    12441258    def _get_selected_n(self, scan):
     
    15731587        #    self._minmaxy = None
    15741588        #    self._abcunit = self._data.get_unit()
    1575         #    self._datamask = None
    15761589
    15771590        self._assert_plotter(action="reload")
     
    16361649        if len(x) > 0:
    16371650            plotit(x,y)
    1638 
    1639 
    1640     # forwards to matplotlib.Figure.text
    1641     def figtext(self, *args, **kwargs):
    1642         """
    1643         Add text to figure at location x,y (relative 0-1 coords).
    1644         This method forwards *args and **kwargs to a Matplotlib method,
    1645         matplotlib.Figure.text.
    1646         See the method help for detailed information.
    1647         """
    1648         self._assert_plotter(action="reload")
    1649         self._plotter.text(*args, **kwargs)
    1650     # end matplotlib.Figure.text forwarding function
    16511651
    16521652
Note: See TracChangeset for help on using the changeset viewer.