Changeset 82d88d5 in sasview for src/sas/sasgui/plottools


Ignore:
Timestamp:
Mar 6, 2019 6:18:09 PM (5 years ago)
Author:
Paul Kienzle <pkienzle@…>
Branches:
master, magnetic_scatt, release-4.2.2, ticket-1009, ticket-1249
Children:
f923967
Parents:
cb64d86 (diff), f205d3a (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge branch 'master' into py37-sasgui

Location:
src/sas/sasgui/plottools
Files:
12 edited

Legend:

Unmodified
Added
Removed
  • src/sas/sasgui/plottools/PlotPanel.py

    r5251ec6 r82d88d5  
    14341434 
    14351435        """ 
     1436        # TODO: include mask info in plotter 
    14361437        self.data = data 
    14371438        self.qx_data = qx_data 
     
    14511452        else: 
    14521453            output = copy.deepcopy(self.data) 
    1453         # check scale 
     1454        # rescale data if necessary 
    14541455        if self.scale == 'log_{10}': 
    1455             try: 
    1456                 if  self.zmin_2D <= 0  and len(output[output > 0]) > 0: 
    1457                     zmin_temp = self.zmin_2D 
    1458                     output[output > 0] = np.log10(output[output > 0]) 
    1459                     #In log scale Negative values are not correct in general 
    1460                     #output[output<=0] = math.log(np.min(output[output>0])) 
    1461                 elif self.zmin_2D <= 0: 
    1462                     zmin_temp = self.zmin_2D 
    1463                     output[output > 0] = np.zeros(len(output)) 
    1464                     output[output <= 0] = -32 
    1465                 else: 
    1466                     zmin_temp = self.zmin_2D 
    1467                     output[output > 0] = np.log10(output[output > 0]) 
    1468                     #In log scale Negative values are not correct in general 
    1469                     #output[output<=0] = math.log(np.min(output[output>0])) 
    1470             except: 
    1471                 #Too many problems in 2D plot with scale 
    1472                 pass 
    1473  
    1474         else: 
    1475             zmin_temp = self.zmin_2D 
     1456            with np.errstate(all='ignore'): 
     1457                output = np.log10(output) 
     1458            index = np.isfinite(output) 
     1459            if not index.all(): 
     1460                cutoff = (np.min(output[index]) - np.log10(2) 
     1461                          if index.any() else 0.) 
     1462                output[~index] = cutoff 
     1463        # TODO: fix handling of zmin_2D/zmax_2D in _onToggleScale 
     1464        # For now, use default vmin/vmax from data 
     1465        #vmin, vmax = self.zmin_2D, self.zmax_2D 
     1466        vmin, vmax = None, None 
    14761467        self.cmap = cmap 
    14771468        if self.dimension != 3: 
    14781469            #Re-adjust colorbar 
    14791470            self.subplot.figure.subplots_adjust(left=0.2, right=.8, bottom=.2) 
    1480  
    14811471            im = self.subplot.imshow(output, interpolation='nearest', 
    14821472                                     origin='lower', 
    1483                                      vmin=zmin_temp, vmax=self.zmax_2D, 
     1473                                     vmin=vmin, vmax=vmax, 
    14841474                                     cmap=self.cmap, 
    14851475                                     extent=(self.xmin_2D, self.xmax_2D, 
  • src/sas/sasgui/plottools/LineModel.py

    ra26f67f r5251ec6  
    8383        elif x.__class__.__name__ == 'tuple': 
    8484            msg = "Tuples are not allowed as input to BaseComponent models" 
    85             raise ValueError, msg 
     85            raise ValueError(msg) 
    8686        else: 
    8787            return self._line(x) 
     
    105105        elif x.__class__.__name__ == 'tuple': 
    106106            msg = "Tuples are not allowed as input to BaseComponent models" 
    107             raise ValueError, msg 
     107            raise ValueError(msg) 
    108108        else: 
    109109            return self._line(x) 
  • src/sas/sasgui/plottools/__init__.py

    refe730d r5251ec6  
    1 from PlotPanel import PlotPanel 
    2 from plottables import Data1D, Theory1D 
     1from .PlotPanel import PlotPanel 
     2from .plottables import Data1D, Theory1D 
  • src/sas/sasgui/plottools/binder.py

    r20fa5fe r5251ec6  
    2828        return self.artist is not other.artist 
    2929 
    30     def __nonzero__(self): 
     30    def __bool__(self): 
    3131        return self.artist is not None 
     32 
     33    __nonzero__ = __bool__ 
    3234 
    3335 
    3436class BindArtist(object): 
    3537    """ 
     38    Track keyboard modifiers for events. 
    3639    """ 
    37     # Track keyboard modifiers for events. 
    3840    # TODO: Move keyboard modifier support into the backend.  We cannot 
    3941    # TODO: properly support it from outside the windowing system since there 
     
    6567            ] 
    6668        except: 
    67             print("bypassing scroll_event: wrong matplotlib version") 
     69            logger.warn("bypassing scroll_event: wrong matplotlib version") 
    6870            self._connections = [ 
    6971                canvas.mpl_connect('motion_notify_event', self._onMotion), 
     
    7476            ] 
    7577 
     78        # Turn off picker if it hasn't already been done 
     79        try: 
     80            canvas.mpl_disconnect(canvas.button_pick_id) 
     81            canvas.mpl_disconnect(canvas.scroll_pick_id) 
     82        except Exception as exc: 
     83            logger.error(exc) 
     84 
    7685        self._current = None 
    7786        self._actions = {} 
     
    8796        Use clearall() to reset all connections. 
    8897        """ 
    89  
    9098        for h in artists: 
    9199            for a in self.events: 
     
    123131        """ 
    124132        try: 
    125             for cid in self._connections: self.canvas.mpl_disconnect(cid) 
    126         except: 
    127             logger.error("Error disconnection canvas: %s" % sys.exc_value) 
     133            for cid in self._connections: 
     134                self.canvas.mpl_disconnect(cid) 
     135        except Exception as exc: 
     136            logger.error("Error disconnection canvas: %s" % exc) 
    128137        self._connections = [] 
    129138 
     
    172181        sure it applies.  E.g., the callback for 'press' might be: 
    173182            if event.button == 1 and event.shift: process Shift-click 
    174  
    175         TODO: Only receive events with the correct modifiers (e.g., S-click, 
    176         TODO:   or *-click for any modifiers). 
    177         TODO: Only receive button events for the correct button (e.g., click1 
    178         TODO:   release3, or dclick* for any button) 
    179         TODO: Support virtual artist, so that and artist can be flagged as 
    180         TODO:   having a tag list and receive the correct events 
    181         TODO: Support virtual events for binding to button-3 vs shift button-1 
    182         TODO:   without changing callback code 
    183         TODO: Attach multiple callbacks to the same event? 
    184         TODO: Clean up interaction with toolbar modes 
    185         TODO: push/pushclear/pop context so that binding changes for 
    186              the duration 
    187         TODO:   e.g., to support ? context sensitive help 
    188         """ 
     183        """ 
     184        #TODO: Only receive events with the correct modifiers (e.g., S-click, 
     185        #TODO:   or *-click for any modifiers). 
     186        #TODO: Only receive button events for the correct button (e.g., click1 
     187        #TODO:   release3, or dclick* for any button) 
     188        #TODO: Support virtual artist, so that and artist can be flagged as 
     189        #TODO:   having a tag list and receive the correct events 
     190        #TODO: Support virtual events for binding to button-3 vs shift button-1 
     191        #TODO:   without changing callback code 
     192        #TODO: Attach multiple callbacks to the same event? 
     193        #TODO: Clean up interaction with toolbar modes 
     194        #TODO: push/pushclear/pop context so that binding changes for the duration 
     195        #TODO:   e.g., to support ? context sensitive help 
     196 
    189197        # Check that the trigger is valid 
    190198        if trigger not in self._actions: 
    191             raise ValueError, "%s invalid --- valid triggers are %s"\ 
    192                  % (trigger, ", ".join(self.events)) 
     199            raise ValueError("%s invalid --- valid triggers are %s" 
     200                % (trigger, ", ".join(self.events))) 
    193201 
    194202        # Register the trigger callback 
     
    205213        """ 
    206214        if action not in self.events: 
    207             raise ValueError, "Trigger expects " + ", ".join(self.events) 
     215            raise ValueError("Trigger expects " + ", ".join(self.events)) 
    208216 
    209217        # Tag the event with modifiers 
     
    214222        setattr(ev, 'prop', {}) 
    215223 
    216         # Fallback scheme.  If the event does not return false, pass to parent. 
     224        # Fallback scheme. If the event does not return false, pass to parent. 
    217225        processed = False 
    218226        artist, prop = actor.artist, actor.prop 
     
    237245        """ 
    238246        # TODO: sort by zorder of axes then by zorder within axes 
    239         self._artists.sort(cmp=lambda x, y: cmp(y.zorder, x.zorder)) 
     247        self._artists.sort(key=lambda x: x.zorder, reverse=True) 
    240248        found = Selection() 
    241249        for artist in self._artists: 
     
    276284 
    277285            transform = self._hasclick.artist.get_transform() 
    278             # x,y = event.xdata,event.ydata 
     286            #x,y = event.xdata,event.ydata 
    279287            x, y = event.x, event.y 
    280288            try: 
     
    286294                    # #transform ="CompositeGenericTransform" crash 
    287295                    pass 
    288             except: 
    289                 # # CRUFT matplotlib-0.91 support 
     296            except: # CRUFT: matplotlib-0.91 support 
    290297                # # exception for transform ="CompositeGenericTransform" 
    291298                # # crashes also here 
    292299                x, y = transform.inverse_xy_tup((x, y)) 
    293300 
    294             # event.xdata, event.ydata = x, y 
     301            #TODO: why compute (x,y) if it isn't being used? 
     302            #event.xdata, event.ydata = x, y 
    295303            self.trigger(self._hasclick, 'drag', event) 
    296304        else: 
  • src/sas/sasgui/plottools/canvas.py

    r7432acb r5251ec6  
    9797        try: 
    9898            dc.DrawBitmap(self.canvas.bitmap, (0, 0)) 
    99         except: 
    100             logger.error(sys.exc_value) 
     99        except Exception as exc: 
     100            logger.error(exc) 
    101101 
    102102    # restore original figure  resolution 
     
    208208            try: 
    209209                fig.draw(self) 
    210             except ValueError: 
    211                 logger.error(sys.exc_value) 
     210            except ValueError as exc: 
     211                logger.error(exc) 
    212212        else: 
    213213            self._isRendered = False 
  • src/sas/sasgui/plottools/convert_units.py

    ra1b8fee r5251ec6  
    1313    """ 
    1414    if power != 0: 
    15         if string.find(unit, "^") != -1:  # if the unit contains a powerer ^ 
    16             toks = re.split("\^", unit) 
    17             if string.find(toks[0], "/") != -1 or \ 
    18                 string.find(toks[0], "-") != -1: 
     15        if unit.find("^") != -1:  # if the unit contains a powerer ^ 
     16            toks = re.split(r"\^", unit) 
     17            if toks[0].find("/") != -1 or \ 
     18                toks[0].find("-") != -1: 
    1919                if power == 1: 
    2020                    unit = unit 
     
    2222                    unit = "(" + unit + ")" + "^{" + str(power) + "}" 
    2323            else: 
    24                 if string.find(toks[1], "{") != -1:  # if found a { 
     24                if toks[1].find("{") != -1:  # if found a { 
    2525                    find_power_toks = re.split("{", toks[1]) 
    26                     if string.find(find_power_toks[1], "}") != -1:  # found } 
     26                    if find_power_toks[1].find("}") != -1:  # found } 
    2727                        unit_toks = re.split("}", find_power_toks[1]) 
    28                         if string.find(unit_toks[0], ".") != -1: 
     28                        if unit_toks[0].find(".") != -1: 
    2929                            powerer = float(unit_toks[0]) * power 
    30                         elif string.find(unit_toks[0], "/") != -1: 
     30                        elif unit_toks[0].find("/") != -1: 
    3131                            power_toks = re.split("/", unit_toks[0]) 
    3232                            powerer = power * int(power_toks[0])\ 
     
    4444                            unit = toks[0] + "^{" + str(powerer) + "}" 
    4545                else: 
    46                     raise ValueError, "missing } in unit expression" 
     46                    raise ValueError("missing } in unit expression") 
    4747        else:  # no powerer 
    4848            if  power != 1: 
    4949                unit = "(" + unit + ")" + "^{" + str(power) + "}" 
    5050    else: 
    51         raise ValueError, "empty unit ,enter a powerer different from zero" 
     51        raise ValueError("empty unit, enter a power different from zero") 
    5252    return unit 
    5353 
  • src/sas/sasgui/plottools/fitDialog.py

    r2469df7 r5251ec6  
     1import sys 
     2import math 
     3 
    14import wx 
    2 from plottables import Theory1D 
    3 import math 
    45import numpy as np 
    5 import fittings 
    6 import transform 
    7 import sys 
     6 
     7from . import fittings 
     8from . import transform 
     9from .plottables import Theory1D 
    810 
    911# Linear fit panel size 
     
    8688        self.layout() 
    8789        # Receives the type of model for the fitting 
    88         from LineModel import LineModel 
     90        from .LineModel import LineModel 
    8991        self.model = LineModel() 
    9092        # Display the fittings values 
     
    671673                return x 
    672674            else: 
    673                 raise ValueError, "cannot compute log of a negative number" 
     675                raise ValueError("cannot compute log of a negative number") 
    674676 
    675677    def floatInvTransform(self, x): 
     
    734736        except: 
    735737            msg = "LinearFit.set_fit_region: fit range must be floats" 
    736             raise ValueError, msg 
     738            raise ValueError(msg) 
    737739        self.xminFit.SetValue(format_number(xmin)) 
    738740        self.xmaxFit.SetValue(format_number(xmax)) 
  • src/sas/sasgui/plottools/fittings.py

    ra1b8fee r5251ec6  
    101101    # Testing implementation 
    102102    # Fit a Line model 
    103     from LineModel import LineModel 
     103    from .LineModel import LineModel 
    104104    line = LineModel() 
    105105    cstA = Parameter(line, 'A', event.cstA) 
  • src/sas/sasgui/plottools/plottable_interactor.py

    r2469df7 r5251ec6  
    44from __future__ import print_function 
    55 
    6 from BaseInteractor import _BaseInteractor 
     6from .BaseInteractor import _BaseInteractor 
    77 
    88 
  • src/sas/sasgui/plottools/plottables.py

    r2469df7 r5251ec6  
    389389 
    390390        """ 
    391         raise NotImplemented, "Not a valid transform" 
     391        raise NotImplemented("Not a valid transform") 
    392392 
    393393    # Related issues 
     
    689689                msg = "Plottable.View: Given x and dx are not" 
    690690                msg += " of the same length" 
    691                 raise ValueError, msg 
     691                raise ValueError(msg) 
    692692            # Check length of y array 
    693693            if not len(y) == len(x): 
    694694                msg = "Plottable.View: Given y " 
    695695                msg += "and x are not of the same length" 
    696                 raise ValueError, msg 
     696                raise ValueError(msg) 
    697697 
    698698            if dy is not None and not len(dy) == 0 and not len(y) == len(dy): 
    699699                msg = "Plottable.View: Given y and dy are not of the same " 
    700700                msg += "length: len(y)=%s, len(dy)=%s" % (len(y), len(dy)) 
    701                 raise ValueError, msg 
     701                raise ValueError(msg) 
    702702            self.x = [] 
    703703            self.y = [] 
     
    734734                msg = "Plottable.View: transformed x " 
    735735                msg += "and y are not of the same length" 
    736                 raise ValueError, msg 
     736                raise ValueError(msg) 
    737737            if has_err_x and not (len(self.x) == len(self.dx)): 
    738738                msg = "Plottable.View: transformed x and dx" 
    739739                msg += " are not of the same length" 
    740                 raise ValueError, msg 
     740                raise ValueError(msg) 
    741741            if has_err_y and not (len(self.y) == len(self.dy)): 
    742742                msg = "Plottable.View: transformed y" 
    743743                msg += " and dy are not of the same length" 
    744                 raise ValueError, msg 
     744                raise ValueError(msg) 
    745745            # Check that negative values are not plot on x and y axis for 
    746746            # log10 transformation 
     
    812812                        tempy.append(self.y[i]) 
    813813                        tempdy.append(self.dy[i]) 
    814                 except: 
     814                except Exception as exc: 
    815815                    logger.error("check_data_logX: skipping point x %g", self.x[i]) 
    816                     logger.error(sys.exc_value) 
     816                    logger.error(exc) 
    817817            self.x = tempx 
    818818            self.y = tempy 
     
    842842                        tempy.append(self.y[i]) 
    843843                        tempdy.append(self.dy[i]) 
    844                 except: 
     844                except Exception as exc: 
    845845                    logger.error("check_data_logY: skipping point %g", self.y[i]) 
    846                     logger.error(sys.exc_value) 
     846                    logger.error(exc) 
    847847 
    848848            self.x = tempx 
     
    996996            self.zmax = zmax 
    997997        else: 
    998             raise "zmin is greater or equal to zmax " 
     998            raise("zmin is greater or equal to zmax ") 
    999999 
    10001000    def render(self, plot, **kw): 
     
    11081108        Plottable.__init__(self) 
    11091109        msg = "Theory1D is no longer supported, please use Data1D and change symbol.\n" 
    1110         raise DeprecationWarning, msg 
     1110        raise DeprecationWarning(msg) 
    11111111 
    11121112class Fit1D(Plottable): 
  • src/sas/sasgui/plottools/toolbar.py

    r20fa5fe rcb64d86  
    3939    try: save_figure = NavigationToolbar2WxAgg.save 
    4040    except AttributeError: pass 
    41      
     41 
    4242    def _init_toolbar(self): 
    4343        self._parent = self.canvas.GetParent() 
     
    6565                           'Forward', 'Forward navigation view') 
    6666        # todo: get new bitmap 
    67         self.AddCheckTool(self._NTB2_PAN, _load_bitmap('move.png'), 
    68                           shortHelp='Pan', 
    69                           longHelp='Pan with left, zoom with right') 
    70         self.AddCheckTool(self._NTB2_ZOOM, _load_bitmap('zoom_to_rect.png'), 
    71                           shortHelp='Zoom', longHelp='Zoom to rectangle') 
     67        # todo: update with code from matplotlib/backends/backend_wx.py 
     68        if 'phoenix' in wx.PlatformInfo: # wx phoenix >= 4.0.0b2 
     69            self.AddCheckTool(self._NTB2_PAN, "Pan", _load_bitmap('move.png'), 
     70                              shortHelp='Pan', 
     71                              longHelp='Pan with left, zoom with right') 
     72            self.AddCheckTool(self._NTB2_ZOOM, "Zoom", _load_bitmap('zoom_to_rect.png'), 
     73                              shortHelp='Zoom', longHelp='Zoom to rectangle') 
     74        else: 
     75            self.AddCheckTool(self._NTB2_PAN, _load_bitmap('move.png'), 
     76                              shortHelp='Pan', 
     77                              longHelp='Pan with left, zoom with right') 
     78            self.AddCheckTool(self._NTB2_ZOOM, _load_bitmap('zoom_to_rect.png'), 
     79                              shortHelp='Zoom', longHelp='Zoom to rectangle') 
    7280 
    7381        self.AddSeparator() 
  • src/sas/sasgui/plottools/transform.py

    r7432acb r5251ec6  
    2424    """ 
    2525    if not x > 0: 
    26         raise ValueError, "Transformation only accepts positive values." 
     26        raise ValueError("Transformation only accepts positive values.") 
    2727    else: 
    2828        return x 
     
    5050    """ 
    5151    if not x >= 0: 
    52         raise ValueError, "square root of a negative value " 
     52        raise ValueError("square root of a negative value ") 
    5353    else: 
    5454        return math.sqrt(x) 
     
    7676    """ 
    7777    if not x >= 0: 
    78         raise ValueError, "double square root of a negative value " 
     78        raise ValueError("double square root of a negative value ") 
    7979    else: 
    8080        return math.sqrt(math.sqrt(x)) 
     
    9090    """ 
    9191    if not x > 0: 
    92         raise ValueError, "Log(x)of a negative value " 
     92        raise ValueError("Log(x)of a negative value ") 
    9393    else: 
    9494        return math.log(x) 
     
    100100        return 1 / x 
    101101    else: 
    102         raise ValueError, "cannot divide by zero" 
     102        raise ValueError("cannot divide by zero") 
    103103 
    104104 
     
    109109        return 1 / math.sqrt(y) 
    110110    else: 
    111         raise ValueError, "transform.toOneOverSqrtX: cannot be computed" 
     111        raise ValueError("transform.toOneOverSqrtX: cannot be computed") 
    112112 
    113113 
     
    118118        return math.log(y * (x ** 2)) 
    119119    else: 
    120         raise ValueError, "transform.toLogYX2: cannot be computed" 
     120        raise ValueError("transform.toLogYX2: cannot be computed") 
    121121 
    122122 
     
    127127        return math.log(math.pow(x, 4) * y) 
    128128    else: 
    129         raise ValueError, "transform.toLogYX4: input error" 
     129        raise ValueError("transform.toLogYX4: input error") 
    130130 
    131131 
     
    149149    """ 
    150150    if not (x * y) > 0: 
    151         raise ValueError, "Log(X*Y)of a negative value " 
     151        raise ValueError("Log(X*Y)of a negative value ") 
    152152    else: 
    153153        return math.log(x * y) 
     
    211211    else: 
    212212        msg = "transform.errFromX2: can't compute error of negative x" 
    213         raise ValueError, msg 
     213        raise ValueError(msg) 
    214214 
    215215 
     
    245245    else: 
    246246        msg = "transform.errFromX4: can't compute error of negative x" 
    247         raise ValueError, msg 
     247        raise ValueError(msg) 
    248248 
    249249 
     
    264264        msg = "Transformation does not accept" 
    265265        msg += " point that are consistent with zero." 
    266         raise ValueError, msg 
     266        raise ValueError(msg) 
    267267    if x != 0: 
    268268        dx = dx / (x * math.log(10)) 
    269269    else: 
    270         raise ValueError, "errToLogX: divide by zero" 
     270        raise ValueError("errToLogX: divide by zero") 
    271271    return dx 
    272272 
     
    287287        dx = dx / x 
    288288    else: 
    289         raise ValueError, "errToLogX: divide by zero" 
     289        raise ValueError("errToLogX: divide by zero") 
    290290    return dx 
    291291 
     
    312312        msg = "Transformation does not accept point " 
    313313        msg += " that are consistent with zero." 
    314         raise ValueError, msg 
     314        raise ValueError(msg) 
    315315    if x != 0 and y != 0: 
    316316        if dx is None: 
     
    320320        err = (dx / x) ** 2 + (dy / y) ** 2 
    321321    else: 
    322         raise ValueError, "cannot compute this error" 
     322        raise ValueError("cannot compute this error") 
    323323 
    324324    return math.sqrt(math.fabs(err)) 
     
    335335        msg = "Transformation does not accept point" 
    336336        msg += " that are consistent with zero." 
    337         raise ValueError, msg 
     337        raise ValueError(msg) 
    338338    if x > 0 and y > 0: 
    339339        if dx is None: 
     
    343343        err = (2.0 * dx / x) ** 2 + (dy / y) ** 2 
    344344    else: 
    345         raise ValueError, "cannot compute this error" 
     345        raise ValueError("cannot compute this error") 
    346346    return math.sqrt(math.fabs(err)) 
    347347 
     
    357357        err = dx / x ** 2 
    358358    else: 
    359         raise ValueError, "Cannot compute this error" 
     359        raise ValueError("Cannot compute this error") 
    360360    return math.fabs(err) 
    361361 
     
    371371        err = -1 / 2 * math.pow(x, -3.0 / 2.0) * dx 
    372372    else: 
    373         raise ValueError, "Cannot compute this error" 
     373        raise ValueError("Cannot compute this error") 
    374374    return math.fabs(err) 
    375375 
     
    387387        msg = "Transformation does not accept point " 
    388388        msg += " that are consistent with zero." 
    389         raise ValueError, msg 
     389        raise ValueError(msg) 
    390390    if dx is None: 
    391391        dx = 0 
Note: See TracChangeset for help on using the changeset viewer.