Changeset 82d88d5 in sasview for src/sas/sasgui/plottools
- Timestamp:
- Mar 6, 2019 6:18:09 PM (5 years ago)
- 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. - Location:
- src/sas/sasgui/plottools
- Files:
-
- 12 edited
Legend:
- Unmodified
- Added
- Removed
-
src/sas/sasgui/plottools/PlotPanel.py
r5251ec6 r82d88d5 1434 1434 1435 1435 """ 1436 # TODO: include mask info in plotter 1436 1437 self.data = data 1437 1438 self.qx_data = qx_data … … 1451 1452 else: 1452 1453 output = copy.deepcopy(self.data) 1453 # check scale1454 # rescale data if necessary 1454 1455 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 1476 1467 self.cmap = cmap 1477 1468 if self.dimension != 3: 1478 1469 #Re-adjust colorbar 1479 1470 self.subplot.figure.subplots_adjust(left=0.2, right=.8, bottom=.2) 1480 1481 1471 im = self.subplot.imshow(output, interpolation='nearest', 1482 1472 origin='lower', 1483 vmin= zmin_temp, vmax=self.zmax_2D,1473 vmin=vmin, vmax=vmax, 1484 1474 cmap=self.cmap, 1485 1475 extent=(self.xmin_2D, self.xmax_2D, -
src/sas/sasgui/plottools/LineModel.py
ra26f67f r5251ec6 83 83 elif x.__class__.__name__ == 'tuple': 84 84 msg = "Tuples are not allowed as input to BaseComponent models" 85 raise ValueError , msg85 raise ValueError(msg) 86 86 else: 87 87 return self._line(x) … … 105 105 elif x.__class__.__name__ == 'tuple': 106 106 msg = "Tuples are not allowed as input to BaseComponent models" 107 raise ValueError , msg107 raise ValueError(msg) 108 108 else: 109 109 return self._line(x) -
src/sas/sasgui/plottools/__init__.py
refe730d r5251ec6 1 from PlotPanel import PlotPanel2 from plottables import Data1D, Theory1D1 from .PlotPanel import PlotPanel 2 from .plottables import Data1D, Theory1D -
src/sas/sasgui/plottools/binder.py
r20fa5fe r5251ec6 28 28 return self.artist is not other.artist 29 29 30 def __ nonzero__(self):30 def __bool__(self): 31 31 return self.artist is not None 32 33 __nonzero__ = __bool__ 32 34 33 35 34 36 class BindArtist(object): 35 37 """ 38 Track keyboard modifiers for events. 36 39 """ 37 # Track keyboard modifiers for events.38 40 # TODO: Move keyboard modifier support into the backend. We cannot 39 41 # TODO: properly support it from outside the windowing system since there … … 65 67 ] 66 68 except: 67 print("bypassing scroll_event: wrong matplotlib version")69 logger.warn("bypassing scroll_event: wrong matplotlib version") 68 70 self._connections = [ 69 71 canvas.mpl_connect('motion_notify_event', self._onMotion), … … 74 76 ] 75 77 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 76 85 self._current = None 77 86 self._actions = {} … … 87 96 Use clearall() to reset all connections. 88 97 """ 89 90 98 for h in artists: 91 99 for a in self.events: … … 123 131 """ 124 132 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) 128 137 self._connections = [] 129 138 … … 172 181 sure it applies. E.g., the callback for 'press' might be: 173 182 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 189 197 # Check that the trigger is valid 190 198 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))) 193 201 194 202 # Register the trigger callback … … 205 213 """ 206 214 if action not in self.events: 207 raise ValueError , "Trigger expects " + ", ".join(self.events)215 raise ValueError("Trigger expects " + ", ".join(self.events)) 208 216 209 217 # Tag the event with modifiers … … 214 222 setattr(ev, 'prop', {}) 215 223 216 # Fallback scheme. 224 # Fallback scheme. If the event does not return false, pass to parent. 217 225 processed = False 218 226 artist, prop = actor.artist, actor.prop … … 237 245 """ 238 246 # 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) 240 248 found = Selection() 241 249 for artist in self._artists: … … 276 284 277 285 transform = self._hasclick.artist.get_transform() 278 # 286 #x,y = event.xdata,event.ydata 279 287 x, y = event.x, event.y 280 288 try: … … 286 294 # #transform ="CompositeGenericTransform" crash 287 295 pass 288 except: 289 # # CRUFT matplotlib-0.91 support 296 except: # CRUFT: matplotlib-0.91 support 290 297 # # exception for transform ="CompositeGenericTransform" 291 298 # # crashes also here 292 299 x, y = transform.inverse_xy_tup((x, y)) 293 300 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 295 303 self.trigger(self._hasclick, 'drag', event) 296 304 else: -
src/sas/sasgui/plottools/canvas.py
r7432acb r5251ec6 97 97 try: 98 98 dc.DrawBitmap(self.canvas.bitmap, (0, 0)) 99 except :100 logger.error( sys.exc_value)99 except Exception as exc: 100 logger.error(exc) 101 101 102 102 # restore original figure resolution … … 208 208 try: 209 209 fig.draw(self) 210 except ValueError :211 logger.error( sys.exc_value)210 except ValueError as exc: 211 logger.error(exc) 212 212 else: 213 213 self._isRendered = False -
src/sas/sasgui/plottools/convert_units.py
ra1b8fee r5251ec6 13 13 """ 14 14 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: 19 19 if power == 1: 20 20 unit = unit … … 22 22 unit = "(" + unit + ")" + "^{" + str(power) + "}" 23 23 else: 24 if string.find(toks[1],"{") != -1: # if found a {24 if toks[1].find("{") != -1: # if found a { 25 25 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 } 27 27 unit_toks = re.split("}", find_power_toks[1]) 28 if string.find(unit_toks[0],".") != -1:28 if unit_toks[0].find(".") != -1: 29 29 powerer = float(unit_toks[0]) * power 30 elif string.find(unit_toks[0],"/") != -1:30 elif unit_toks[0].find("/") != -1: 31 31 power_toks = re.split("/", unit_toks[0]) 32 32 powerer = power * int(power_toks[0])\ … … 44 44 unit = toks[0] + "^{" + str(powerer) + "}" 45 45 else: 46 raise ValueError , "missing } in unit expression"46 raise ValueError("missing } in unit expression") 47 47 else: # no powerer 48 48 if power != 1: 49 49 unit = "(" + unit + ")" + "^{" + str(power) + "}" 50 50 else: 51 raise ValueError , "empty unit ,enter a powerer different from zero"51 raise ValueError("empty unit, enter a power different from zero") 52 52 return unit 53 53 -
src/sas/sasgui/plottools/fitDialog.py
r2469df7 r5251ec6 1 import sys 2 import math 3 1 4 import wx 2 from plottables import Theory1D3 import math4 5 import numpy as np 5 import fittings 6 import transform 7 import sys 6 7 from . import fittings 8 from . import transform 9 from .plottables import Theory1D 8 10 9 11 # Linear fit panel size … … 86 88 self.layout() 87 89 # Receives the type of model for the fitting 88 from LineModel import LineModel90 from .LineModel import LineModel 89 91 self.model = LineModel() 90 92 # Display the fittings values … … 671 673 return x 672 674 else: 673 raise ValueError , "cannot compute log of a negative number"675 raise ValueError("cannot compute log of a negative number") 674 676 675 677 def floatInvTransform(self, x): … … 734 736 except: 735 737 msg = "LinearFit.set_fit_region: fit range must be floats" 736 raise ValueError , msg738 raise ValueError(msg) 737 739 self.xminFit.SetValue(format_number(xmin)) 738 740 self.xmaxFit.SetValue(format_number(xmax)) -
src/sas/sasgui/plottools/fittings.py
ra1b8fee r5251ec6 101 101 # Testing implementation 102 102 # Fit a Line model 103 from LineModel import LineModel103 from .LineModel import LineModel 104 104 line = LineModel() 105 105 cstA = Parameter(line, 'A', event.cstA) -
src/sas/sasgui/plottools/plottable_interactor.py
r2469df7 r5251ec6 4 4 from __future__ import print_function 5 5 6 from BaseInteractor import _BaseInteractor6 from .BaseInteractor import _BaseInteractor 7 7 8 8 -
src/sas/sasgui/plottools/plottables.py
r2469df7 r5251ec6 389 389 390 390 """ 391 raise NotImplemented , "Not a valid transform"391 raise NotImplemented("Not a valid transform") 392 392 393 393 # Related issues … … 689 689 msg = "Plottable.View: Given x and dx are not" 690 690 msg += " of the same length" 691 raise ValueError , msg691 raise ValueError(msg) 692 692 # Check length of y array 693 693 if not len(y) == len(x): 694 694 msg = "Plottable.View: Given y " 695 695 msg += "and x are not of the same length" 696 raise ValueError , msg696 raise ValueError(msg) 697 697 698 698 if dy is not None and not len(dy) == 0 and not len(y) == len(dy): 699 699 msg = "Plottable.View: Given y and dy are not of the same " 700 700 msg += "length: len(y)=%s, len(dy)=%s" % (len(y), len(dy)) 701 raise ValueError , msg701 raise ValueError(msg) 702 702 self.x = [] 703 703 self.y = [] … … 734 734 msg = "Plottable.View: transformed x " 735 735 msg += "and y are not of the same length" 736 raise ValueError , msg736 raise ValueError(msg) 737 737 if has_err_x and not (len(self.x) == len(self.dx)): 738 738 msg = "Plottable.View: transformed x and dx" 739 739 msg += " are not of the same length" 740 raise ValueError , msg740 raise ValueError(msg) 741 741 if has_err_y and not (len(self.y) == len(self.dy)): 742 742 msg = "Plottable.View: transformed y" 743 743 msg += " and dy are not of the same length" 744 raise ValueError , msg744 raise ValueError(msg) 745 745 # Check that negative values are not plot on x and y axis for 746 746 # log10 transformation … … 812 812 tempy.append(self.y[i]) 813 813 tempdy.append(self.dy[i]) 814 except :814 except Exception as exc: 815 815 logger.error("check_data_logX: skipping point x %g", self.x[i]) 816 logger.error( sys.exc_value)816 logger.error(exc) 817 817 self.x = tempx 818 818 self.y = tempy … … 842 842 tempy.append(self.y[i]) 843 843 tempdy.append(self.dy[i]) 844 except :844 except Exception as exc: 845 845 logger.error("check_data_logY: skipping point %g", self.y[i]) 846 logger.error( sys.exc_value)846 logger.error(exc) 847 847 848 848 self.x = tempx … … 996 996 self.zmax = zmax 997 997 else: 998 raise "zmin is greater or equal to zmax "998 raise("zmin is greater or equal to zmax ") 999 999 1000 1000 def render(self, plot, **kw): … … 1108 1108 Plottable.__init__(self) 1109 1109 msg = "Theory1D is no longer supported, please use Data1D and change symbol.\n" 1110 raise DeprecationWarning , msg1110 raise DeprecationWarning(msg) 1111 1111 1112 1112 class Fit1D(Plottable): -
src/sas/sasgui/plottools/toolbar.py
r20fa5fe rcb64d86 39 39 try: save_figure = NavigationToolbar2WxAgg.save 40 40 except AttributeError: pass 41 41 42 42 def _init_toolbar(self): 43 43 self._parent = self.canvas.GetParent() … … 65 65 'Forward', 'Forward navigation view') 66 66 # 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') 72 80 73 81 self.AddSeparator() -
src/sas/sasgui/plottools/transform.py
r7432acb r5251ec6 24 24 """ 25 25 if not x > 0: 26 raise ValueError , "Transformation only accepts positive values."26 raise ValueError("Transformation only accepts positive values.") 27 27 else: 28 28 return x … … 50 50 """ 51 51 if not x >= 0: 52 raise ValueError , "square root of a negative value "52 raise ValueError("square root of a negative value ") 53 53 else: 54 54 return math.sqrt(x) … … 76 76 """ 77 77 if not x >= 0: 78 raise ValueError , "double square root of a negative value "78 raise ValueError("double square root of a negative value ") 79 79 else: 80 80 return math.sqrt(math.sqrt(x)) … … 90 90 """ 91 91 if not x > 0: 92 raise ValueError , "Log(x)of a negative value "92 raise ValueError("Log(x)of a negative value ") 93 93 else: 94 94 return math.log(x) … … 100 100 return 1 / x 101 101 else: 102 raise ValueError , "cannot divide by zero"102 raise ValueError("cannot divide by zero") 103 103 104 104 … … 109 109 return 1 / math.sqrt(y) 110 110 else: 111 raise ValueError , "transform.toOneOverSqrtX: cannot be computed"111 raise ValueError("transform.toOneOverSqrtX: cannot be computed") 112 112 113 113 … … 118 118 return math.log(y * (x ** 2)) 119 119 else: 120 raise ValueError , "transform.toLogYX2: cannot be computed"120 raise ValueError("transform.toLogYX2: cannot be computed") 121 121 122 122 … … 127 127 return math.log(math.pow(x, 4) * y) 128 128 else: 129 raise ValueError , "transform.toLogYX4: input error"129 raise ValueError("transform.toLogYX4: input error") 130 130 131 131 … … 149 149 """ 150 150 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 ") 152 152 else: 153 153 return math.log(x * y) … … 211 211 else: 212 212 msg = "transform.errFromX2: can't compute error of negative x" 213 raise ValueError , msg213 raise ValueError(msg) 214 214 215 215 … … 245 245 else: 246 246 msg = "transform.errFromX4: can't compute error of negative x" 247 raise ValueError , msg247 raise ValueError(msg) 248 248 249 249 … … 264 264 msg = "Transformation does not accept" 265 265 msg += " point that are consistent with zero." 266 raise ValueError , msg266 raise ValueError(msg) 267 267 if x != 0: 268 268 dx = dx / (x * math.log(10)) 269 269 else: 270 raise ValueError , "errToLogX: divide by zero"270 raise ValueError("errToLogX: divide by zero") 271 271 return dx 272 272 … … 287 287 dx = dx / x 288 288 else: 289 raise ValueError , "errToLogX: divide by zero"289 raise ValueError("errToLogX: divide by zero") 290 290 return dx 291 291 … … 312 312 msg = "Transformation does not accept point " 313 313 msg += " that are consistent with zero." 314 raise ValueError , msg314 raise ValueError(msg) 315 315 if x != 0 and y != 0: 316 316 if dx is None: … … 320 320 err = (dx / x) ** 2 + (dy / y) ** 2 321 321 else: 322 raise ValueError , "cannot compute this error"322 raise ValueError("cannot compute this error") 323 323 324 324 return math.sqrt(math.fabs(err)) … … 335 335 msg = "Transformation does not accept point" 336 336 msg += " that are consistent with zero." 337 raise ValueError , msg337 raise ValueError(msg) 338 338 if x > 0 and y > 0: 339 339 if dx is None: … … 343 343 err = (2.0 * dx / x) ** 2 + (dy / y) ** 2 344 344 else: 345 raise ValueError , "cannot compute this error"345 raise ValueError("cannot compute this error") 346 346 return math.sqrt(math.fabs(err)) 347 347 … … 357 357 err = dx / x ** 2 358 358 else: 359 raise ValueError , "Cannot compute this error"359 raise ValueError("Cannot compute this error") 360 360 return math.fabs(err) 361 361 … … 371 371 err = -1 / 2 * math.pow(x, -3.0 / 2.0) * dx 372 372 else: 373 raise ValueError , "Cannot compute this error"373 raise ValueError("Cannot compute this error") 374 374 return math.fabs(err) 375 375 … … 387 387 msg = "Transformation does not accept point " 388 388 msg += " that are consistent with zero." 389 raise ValueError , msg389 raise ValueError(msg) 390 390 if dx is None: 391 391 dx = 0
Note: See TracChangeset
for help on using the changeset viewer.