Changeset c416a17 in sasview for src/sas/sasgui/plottools
- Timestamp:
- May 26, 2017 7:41:44 AM (8 years ago)
- Branches:
- ESS_GUI, ESS_GUI_Docs, ESS_GUI_batch_fitting, ESS_GUI_bumps_abstraction, ESS_GUI_iss1116, ESS_GUI_iss879, ESS_GUI_iss959, ESS_GUI_opencl, ESS_GUI_ordering, ESS_GUI_sync_sascalc
- Children:
- c1e380e
- Parents:
- 6964d44 (diff), 7132e49 (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:
-
- 14 edited
Legend:
- Unmodified
- Added
- Removed
-
src/sas/sasgui/plottools/LineModel.py
re3ae090 r959eb01 8 8 function should disappear in a future iteration (see notes in fitDialog) 9 9 10 -PDB July 10, 2016 10 PDB July 10, 2016 11 11 12 """ 12 13 … … 70 71 runXY is when the if statement is true. I however cannot see what that 71 72 function is for. It needs to be documented here or removed. 72 -PDB 7/10/1673 PDB 7/10/16 73 74 74 75 :param x: simple value … … 92 93 but the only difference between this and run is when the if 93 94 statement is true. I however cannot see what that function 94 is for. It needs to be documented here or removed. -PDB 7/10/1695 is for. It needs to be documented here or removed. PDB 7/10/16 95 96 96 97 :param x: simple value -
src/sas/sasgui/plottools/PlotPanel.py
r9687d58 ra1b8fee 2 2 Plot panel. 3 3 """ 4 from __future__ import print_function 5 4 6 import logging 5 7 import traceback … … 10 12 matplotlib.interactive(False) 11 13 #Use the WxAgg back end. The Wx one takes too long to render 12 #matplotlib.use('WXAgg')14 matplotlib.use('WXAgg') 13 15 from matplotlib.backends.backend_wxagg import FigureCanvasWxAgg 14 16 from matplotlib.figure import Figure … … 29 31 DEFAULT_CMAP = pylab.cm.jet 30 32 import copy 31 import numpy 33 import numpy as np 32 34 33 35 from sas.sasgui.guiframe.events import StatusEvent 34 36 from .toolbar import NavigationToolBar, PlotPrintout, bind 35 37 38 logger = logging.getLogger(__name__) 39 36 40 def show_tree(obj, d=0): 37 41 """Handy function for displaying a tree of graph objects""" 38 print "%s%s" % ("-"*d, obj.__class__.__name__)42 print("%s%s" % ("-"*d, obj.__class__.__name__)) 39 43 if 'get_children' in dir(obj): 40 44 for a in obj.get_children(): show_tree(a, d + 1) … … 152 156 self.selectedText = None 153 157 #User scale 154 if xtransform !=None:158 if xtransform is not None: 155 159 self.xLabel = xtransform 156 160 else: 157 161 self.xLabel = "log10(x)" 158 if ytransform !=None:162 if ytransform is not None: 159 163 self.yLabel = ytransform 160 164 else: … … 358 362 return 359 363 360 if ax !=None:364 if ax is not None: 361 365 self.xInit, self.yInit = event.xdata, event.ydata 362 366 try: … … 390 394 Set legend alpha 391 395 """ 392 if self.legend !=None:396 if self.legend is not None: 393 397 self.legend.legendPatch.set_alpha(alpha) 394 398 … … 416 420 """ 417 421 ax = event.inaxes 418 if ax ==None:422 if ax is None: 419 423 return 420 424 # Event occurred inside a plotting area … … 459 463 # User has clicked on text and is dragging 460 464 ax = event.inaxes 461 if ax !=None:465 if ax is not None: 462 466 # Only move text if mouse is within axes 463 467 self.selectedText.set_position((event.xdata, event.ydata)) … … 474 478 if self.leftdown == True and self.mousemotion == True: 475 479 ax = event.inaxes 476 if ax !=None: # the dragging is perform inside the figure480 if ax is not None: # the dragging is perform inside the figure 477 481 self.xFinal, self.yFinal = event.xdata, event.ydata 478 482 # Check whether this is the first point 479 if self.xInit ==None:483 if self.xInit is None: 480 484 self.xInit = self.xFinal 481 485 self.yInit = self.yFinal … … 574 578 step = event.step 575 579 576 if ax !=None:580 if ax is not None: 577 581 # Event occurred inside a plotting area 578 582 lo, hi = ax.get_xlim() … … 933 937 # reset postion 934 938 self.position = None 935 if self.graph.selected_plottable !=None:939 if self.graph.selected_plottable is not None: 936 940 self.graph.selected_plottable = None 937 941 … … 957 961 prop=FontProperties(size=10), 958 962 loc=self.legendLoc) 959 if self.legend !=None:963 if self.legend is not None: 960 964 self.legend.set_picker(self.legend_picker) 961 965 self.legend.set_axes(self.subplot) … … 987 991 prop=FontProperties(size=10), 988 992 loc=self.legendLoc) 989 if self.legend !=None:993 if self.legend is not None: 990 994 self.legend.set_picker(self.legend_picker) 991 995 self.legend.set_axes(self.subplot) … … 1008 1012 pos_x = 0 1009 1013 pos_y = 0 1010 if self.position !=None:1014 if self.position is not None: 1011 1015 pos_x, pos_y = self.position 1012 1016 else: … … 1033 1037 self.subplot.figure.canvas.draw_idle() 1034 1038 except: 1035 if self.parent !=None:1039 if self.parent is not None: 1036 1040 msg = "Add Text: Error. Check your property values..." 1037 1041 wx.PostEvent(self.parent, StatusEvent(status=msg)) … … 1067 1071 self.xaxis_tick = xaxis_font 1068 1072 1069 if self.data !=None:1073 if self.data is not None: 1070 1074 # 2D 1071 1075 self.xaxis(self.xaxis_label, self.xaxis_unit, \ … … 1114 1118 self.yaxis_tick = yaxis_font 1115 1119 1116 if self.data !=None:1120 if self.data is not None: 1117 1121 # 2D 1118 1122 self.yaxis(self.yaxis_label, self.yaxis_unit, \ … … 1153 1157 label_temp = textdial.getText() 1154 1158 if label_temp.count("\%s" % "\\") > 0: 1155 if self.parent !=None:1159 if self.parent is not None: 1156 1160 msg = "Add Label: Error. Can not use double '\\' " 1157 1161 msg += "characters..." … … 1160 1164 label = label_temp 1161 1165 except: 1162 if self.parent !=None:1166 if self.parent is not None: 1163 1167 msg = "Add Label: Error. Check your property values..." 1164 1168 wx.PostEvent(self.parent, StatusEvent(status=msg)) … … 1178 1182 num_text = len(self.textList) 1179 1183 if num_text < 1: 1180 if self.parent !=None:1184 if self.parent is not None: 1181 1185 msg = "Remove Text: Nothing to remove. " 1182 1186 wx.PostEvent(self.parent, StatusEvent(status=msg)) … … 1188 1192 text_remove = txt.get_text() 1189 1193 txt.remove() 1190 if self.parent !=None:1194 if self.parent is not None: 1191 1195 msg = "Removed Text: '%s'. " % text_remove 1192 1196 wx.PostEvent(self.parent, StatusEvent(status=msg)) 1193 1197 except: 1194 if self.parent !=None:1198 if self.parent is not None: 1195 1199 msg = "Remove Text: Error occurred. " 1196 1200 wx.PostEvent(self.parent, StatusEvent(status=msg)) … … 1248 1252 prop=FontProperties(size=10), 1249 1253 loc=self.legendLoc) 1250 if self.legend !=None:1254 if self.legend is not None: 1251 1255 self.legend.set_picker(self.legend_picker) 1252 1256 self.legend.set_axes(self.subplot) … … 1277 1281 if font: 1278 1282 self.subplot.set_xlabel(label, fontproperties=font, color=color) 1279 if t_font !=None:1283 if t_font is not None: 1280 1284 for tick in self.subplot.xaxis.get_major_ticks(): 1281 1285 tick.label.set_fontproperties(t_font) … … 1298 1302 if font: 1299 1303 self.subplot.set_ylabel(label, fontproperties=font, color=color) 1300 if t_font !=None:1304 if t_font is not None: 1301 1305 for tick_label in self.subplot.get_yticklabels(): 1302 1306 tick_label.set_fontproperties(t_font) … … 1325 1329 from plottable_interactor import PointInteractor 1326 1330 p = PointInteractor(self, self.subplot, zorder=zorder, id=id) 1327 if p.markersize !=None:1331 if p.markersize is not None: 1328 1332 markersize = p.markersize 1329 1333 p.points(x, y, dx=dx, dy=dy, color=color, symbol=symbol, zorder=zorder, … … 1361 1365 1362 1366 # Convert tuple (lo,hi) to array [(x-lo),(hi-x)] 1363 if dx !=None and type(dx) == type(()):1367 if dx is not None and type(dx) == type(()): 1364 1368 dx = nx.vstack((x - dx[0], dx[1] - x)).transpose() 1365 if dy !=None and type(dy) == type(()):1369 if dy is not None and type(dy) == type(()): 1366 1370 dy = nx.vstack((y - dy[0], dy[1] - y)).transpose() 1367 if dx == None and dy ==None:1371 if dx is None and dy is None: 1368 1372 self.subplot.plot(x, y, color=self._color(color), 1369 1373 marker=self._symbol(symbol), … … 1401 1405 if self.scale == 'log_{10}': 1402 1406 self.scale = 'linear' 1403 if not self.zmin_2D isNone:1407 if self.zmin_2D is not None: 1404 1408 zmin_2D_temp = math.pow(10, self.zmin_2D) 1405 if not self.zmax_2D isNone:1409 if self.zmax_2D is not None: 1406 1410 zmax_2D_temp = math.pow(10, self.zmax_2D) 1407 1411 else: 1408 1412 self.scale = 'log_{10}' 1409 if not self.zmin_2D isNone:1413 if self.zmin_2D is not None: 1410 1414 # min log value: no log(negative) 1411 1415 if self.zmin_2D <= 0: … … 1413 1417 else: 1414 1418 zmin_2D_temp = math.log10(self.zmin_2D) 1415 if not self.zmax_2D isNone:1419 if self.zmax_2D is not None: 1416 1420 zmax_2D_temp = math.log10(self.zmax_2D) 1417 1421 … … 1441 1445 c = self._color(color) 1442 1446 # If we don't have any data, skip. 1443 if self.data ==None:1447 if self.data is None: 1444 1448 return 1445 1449 if self.data.ndim == 1: … … 1452 1456 if self.zmin_2D <= 0 and len(output[output > 0]) > 0: 1453 1457 zmin_temp = self.zmin_2D 1454 output[output > 0] = n umpy.log10(output[output > 0])1458 output[output > 0] = np.log10(output[output > 0]) 1455 1459 #In log scale Negative values are not correct in general 1456 #output[output<=0] = math.log(n umpy.min(output[output>0]))1460 #output[output<=0] = math.log(np.min(output[output>0])) 1457 1461 elif self.zmin_2D <= 0: 1458 1462 zmin_temp = self.zmin_2D 1459 output[output > 0] = n umpy.zeros(len(output))1463 output[output > 0] = np.zeros(len(output)) 1460 1464 output[output <= 0] = -32 1461 1465 else: 1462 1466 zmin_temp = self.zmin_2D 1463 output[output > 0] = n umpy.log10(output[output > 0])1467 output[output > 0] = np.log10(output[output > 0]) 1464 1468 #In log scale Negative values are not correct in general 1465 #output[output<=0] = math.log(n umpy.min(output[output>0]))1469 #output[output<=0] = math.log(np.min(output[output>0])) 1466 1470 except: 1467 1471 #Too many problems in 2D plot with scale … … 1492 1496 X = self.x_bins[0:-1] 1493 1497 Y = self.y_bins[0:-1] 1494 X, Y = n umpy.meshgrid(X, Y)1498 X, Y = np.meshgrid(X, Y) 1495 1499 1496 1500 try: … … 1506 1510 from mpl_toolkits.mplot3d import Axes3D 1507 1511 except: 1508 logg ing.error("PlotPanel could not import Axes3D")1512 logger.error("PlotPanel could not import Axes3D") 1509 1513 self.subplot.figure.clear() 1510 1514 ax = Axes3D(self.subplot.figure) … … 1517 1521 self.subplot.set_axis_off() 1518 1522 1519 if cbax ==None:1523 if cbax is None: 1520 1524 ax.set_frame_on(False) 1521 1525 cb = self.subplot.figure.colorbar(im, shrink=0.8, aspect=20) … … 1539 1543 """ 1540 1544 # No qx or qy given in a vector format 1541 if self.qx_data == None or self.qy_data ==None \1545 if self.qx_data is None or self.qy_data is None \ 1542 1546 or self.qx_data.ndim != 1 or self.qy_data.ndim != 1: 1543 1547 # do we need deepcopy here? … … 1555 1559 # 1d array to use for weighting the data point averaging 1556 1560 #when they fall into a same bin. 1557 weights_data = n umpy.ones([self.data.size])1561 weights_data = np.ones([self.data.size]) 1558 1562 # get histogram of ones w/len(data); this will provide 1559 1563 #the weights of data on each bins 1560 weights, xedges, yedges = n umpy.histogram2d(x=self.qy_data,1564 weights, xedges, yedges = np.histogram2d(x=self.qy_data, 1561 1565 y=self.qx_data, 1562 1566 bins=[self.y_bins, self.x_bins], 1563 1567 weights=weights_data) 1564 1568 # get histogram of data, all points into a bin in a way of summing 1565 image, xedges, yedges = n umpy.histogram2d(x=self.qy_data,1569 image, xedges, yedges = np.histogram2d(x=self.qy_data, 1566 1570 y=self.qx_data, 1567 1571 bins=[self.y_bins, self.x_bins], … … 1581 1585 # do while loop until all vacant bins are filled up up 1582 1586 #to loop = max_loop 1583 while not(n umpy.isfinite(image[weights == 0])).all():1587 while not(np.isfinite(image[weights == 0])).all(): 1584 1588 if loop >= max_loop: # this protects never-ending loop 1585 1589 break … … 1599 1603 """ 1600 1604 # No qx or qy given in a vector format 1601 if self.qx_data == None or self.qy_data ==None \1605 if self.qx_data is None or self.qy_data is None \ 1602 1606 or self.qx_data.ndim != 1 or self.qy_data.ndim != 1: 1603 1607 # do we need deepcopy here? … … 1630 1634 1631 1635 # store x and y bin centers in q space 1632 x_bins = n umpy.linspace(xmin, xmax, npix_x)1633 y_bins = n umpy.linspace(ymin, ymax, npix_y)1636 x_bins = np.linspace(xmin, xmax, npix_x) 1637 y_bins = np.linspace(ymin, ymax, npix_y) 1634 1638 1635 1639 #set x_bins and y_bins … … 1650 1654 """ 1651 1655 # No image matrix given 1652 if image == None or numpy.ndim(image) != 2 \1653 or n umpy.isfinite(image).all() \1654 or weights ==None:1656 if image is None or np.ndim(image) != 2 \ 1657 or np.isfinite(image).all() \ 1658 or weights is None: 1655 1659 return image 1656 1660 # Get bin size in y and x directions 1657 1661 len_y = len(image) 1658 1662 len_x = len(image[1]) 1659 temp_image = n umpy.zeros([len_y, len_x])1660 weit = n umpy.zeros([len_y, len_x])1663 temp_image = np.zeros([len_y, len_x]) 1664 weit = np.zeros([len_y, len_x]) 1661 1665 # do for-loop for all pixels 1662 1666 for n_y in range(len(image)): 1663 1667 for n_x in range(len(image[1])): 1664 1668 # find only null pixels 1665 if weights[n_y][n_x] > 0 or n umpy.isfinite(image[n_y][n_x]):1669 if weights[n_y][n_x] > 0 or np.isfinite(image[n_y][n_x]): 1666 1670 continue 1667 1671 else: 1668 1672 # find 4 nearest neighbors 1669 1673 # check where or not it is at the corner 1670 if n_y != 0 and n umpy.isfinite(image[n_y - 1][n_x]):1674 if n_y != 0 and np.isfinite(image[n_y - 1][n_x]): 1671 1675 temp_image[n_y][n_x] += image[n_y - 1][n_x] 1672 1676 weit[n_y][n_x] += 1 1673 if n_x != 0 and n umpy.isfinite(image[n_y][n_x - 1]):1677 if n_x != 0 and np.isfinite(image[n_y][n_x - 1]): 1674 1678 temp_image[n_y][n_x] += image[n_y][n_x - 1] 1675 1679 weit[n_y][n_x] += 1 1676 if n_y != len_y - 1 and n umpy.isfinite(image[n_y + 1][n_x]):1680 if n_y != len_y - 1 and np.isfinite(image[n_y + 1][n_x]): 1677 1681 temp_image[n_y][n_x] += image[n_y + 1][n_x] 1678 1682 weit[n_y][n_x] += 1 1679 if n_x != len_x - 1 and n umpy.isfinite(image[n_y][n_x + 1]):1683 if n_x != len_x - 1 and np.isfinite(image[n_y][n_x + 1]): 1680 1684 temp_image[n_y][n_x] += image[n_y][n_x + 1] 1681 1685 weit[n_y][n_x] += 1 1682 1686 # go 4 next nearest neighbors when no non-zero 1683 1687 # neighbor exists 1684 if n_y != 0 and n_x != 0 and \1685 numpy.isfinite(image[n_y - 1][n_x - 1]):1688 if n_y != 0 and n_x != 0 and \ 1689 np.isfinite(image[n_y - 1][n_x - 1]): 1686 1690 temp_image[n_y][n_x] += image[n_y - 1][n_x - 1] 1687 1691 weit[n_y][n_x] += 1 1688 1692 if n_y != len_y - 1 and n_x != 0 and \ 1689 numpy.isfinite(image[n_y + 1][n_x - 1]):1693 np.isfinite(image[n_y + 1][n_x - 1]): 1690 1694 temp_image[n_y][n_x] += image[n_y + 1][n_x - 1] 1691 1695 weit[n_y][n_x] += 1 1692 1696 if n_y != len_y and n_x != len_x - 1 and \ 1693 numpy.isfinite(image[n_y - 1][n_x + 1]):1697 np.isfinite(image[n_y - 1][n_x + 1]): 1694 1698 temp_image[n_y][n_x] += image[n_y - 1][n_x + 1] 1695 1699 weit[n_y][n_x] += 1 1696 1700 if n_y != len_y - 1 and n_x != len_x - 1 and \ 1697 numpy.isfinite(image[n_y + 1][n_x + 1]):1701 np.isfinite(image[n_y + 1][n_x + 1]): 1698 1702 temp_image[n_y][n_x] += image[n_y + 1][n_x + 1] 1699 1703 weit[n_y][n_x] += 1 … … 1770 1774 # control axis labels from the panel itself 1771 1775 yname, yunits = item.get_yaxis() 1772 if self.yaxis_label !=None:1776 if self.yaxis_label is not None: 1773 1777 yname = self.yaxis_label 1774 1778 yunits = self.yaxis_unit … … 1777 1781 self.yaxis_unit = yunits 1778 1782 xname, xunits = item.get_xaxis() 1779 if self.xaxis_label !=None:1783 if self.xaxis_label is not None: 1780 1784 xname = self.xaxis_label 1781 1785 xunits = self.xaxis_unit … … 1938 1942 """ 1939 1943 """ 1940 if self.parent ==None:1944 if self.parent is None: 1941 1945 return 1942 1946 # get current caption … … 2012 2016 self.toolbar.copy_figure(self.canvas) 2013 2017 except: 2014 print "Error in copy Image"2018 print("Error in copy Image") 2015 2019 2016 2020 -
src/sas/sasgui/plottools/TextDialog.py
rd7bb526 r7432acb 41 41 style_box = wx.BoxSizer(wx.HORIZONTAL) 42 42 # tcA 43 if unit !=None:43 if unit is not None: 44 44 styles = wx.TAB_TRAVERSAL 45 45 height = -1 … … 130 130 0, wx.TOP, 5) 131 131 family_box.Add(self.font_size, 0, 0) 132 if unit_box !=None:132 if unit_box is not None: 133 133 family_box.Add((_BOX_WIDTH / 2, -1)) 134 134 family_box.Add(tick_label_text, 0, 0) … … 159 159 text_box.Add(self.text_string) 160 160 vbox.Add(text_box, 0, wx.EXPAND, 15) 161 if unit_box !=None:161 if unit_box is not None: 162 162 unit_box.Add(unit_text, 0, 0) 163 163 unit_box.Add(self.unit_ctrl, 0, 0) -
src/sas/sasgui/plottools/arrow3d.py
rd7bb526 r7432acb 29 29 self.base = base 30 30 31 if base !=None:31 if base is not None: 32 32 # To turn the updating off during dragging 33 33 base.canvas.mpl_connect('button_press_event', self.on_left_down) -
src/sas/sasgui/plottools/binder.py
rd7bb526 ra1b8fee 2 2 Extension to MPL to support the binding of artists to key/mouse events. 3 3 """ 4 from __future__ import print_function 5 4 6 import sys 5 7 import logging 8 9 logger = logging.getLogger(__name__) 6 10 7 11 class Selection(object): … … 61 65 ] 62 66 except: 63 print "bypassing scroll_event: wrong matplotlib version"67 print("bypassing scroll_event: wrong matplotlib version") 64 68 self._connections = [ 65 69 canvas.mpl_connect('motion_notify_event', self._onMotion), … … 121 125 for cid in self._connections: self.canvas.mpl_disconnect(cid) 122 126 except: 123 logg ing.error("Error disconnection canvas: %s" % sys.exc_value)127 logger.error("Error disconnection canvas: %s" % sys.exc_value) 124 128 self._connections = [] 125 129 -
src/sas/sasgui/plottools/canvas.py
rd7bb526 r7432acb 11 11 from matplotlib.backends.backend_wx import RendererWx 12 12 13 logger = logging.getLogger(__name__) 14 13 15 14 16 def draw_image(self, x, y, im, bbox, clippath=None, clippath_trans=None): … … 96 98 dc.DrawBitmap(self.canvas.bitmap, (0, 0)) 97 99 except: 98 logg ing.error(sys.exc_value)100 logger.error(sys.exc_value) 99 101 100 102 # restore original figure resolution … … 151 153 """ 152 154 self.panel.subplot.grid(self.panel.grid_on) 153 if self.panel.legend !=None and self.panel.legend_pos_loc:155 if self.panel.legend is not None and self.panel.legend_pos_loc: 154 156 self.panel.legend._loc = self.panel.legend_pos_loc 155 157 self.idletimer.Restart(5, *args, **kwargs) # Delay by 5 ms … … 207 209 fig.draw(self) 208 210 except ValueError: 209 logg ing.error(sys.exc_value)211 logger.error(sys.exc_value) 210 212 else: 211 213 self._isRendered = False -
src/sas/sasgui/plottools/convert_units.py
rd7bb526 ra1b8fee 3 3 This is a cleaned up version of unitConverter.py 4 4 """ 5 from __future__ import print_function 6 5 7 import re 6 8 import string … … 68 70 unit8 = "m/s^{4}" # x^2 (m/s^{4})^{2} 69 71 70 print "this unit1 %s ,its powerer %s , and value %s" % (unit1, 1, convert_unit(1, unit1))71 print "this unit2 %s ,its powerer %s , and value %s" % (unit2, 1, convert_unit(1, unit2))72 print "this unit3 %s ,its powerer %s , and value %s" % (unit3, 2, convert_unit(2, unit3))73 print "this unit4 %s ,its powerer %s , and value %s" % (unit4, -1, convert_unit(-1, unit4))74 print "this unit5 %s ,its powerer %s , and value %s" % (unit5, 2, convert_unit(2, unit5))75 print "this unit6 %s ,its powerer %s , and value %s" % (unit6, 2, convert_unit(2, unit6))76 print "this unit7 %s ,its powerer %s , and value %s" % (unit7, -1, convert_unit(-1, unit7))77 print "this unit8 %s ,its powerer %s , and value %s" % (unit8, 2, convert_unit(2, unit8))78 print "this unit9 %s ,its powerer %s , and value %s" % (unit9, 2, convert_unit(2, unit9))72 print("this unit1 %s ,its powerer %s , and value %s" % (unit1, 1, convert_unit(1, unit1))) 73 print("this unit2 %s ,its powerer %s , and value %s" % (unit2, 1, convert_unit(1, unit2))) 74 print("this unit3 %s ,its powerer %s , and value %s" % (unit3, 2, convert_unit(2, unit3))) 75 print("this unit4 %s ,its powerer %s , and value %s" % (unit4, -1, convert_unit(-1, unit4))) 76 print("this unit5 %s ,its powerer %s , and value %s" % (unit5, 2, convert_unit(2, unit5))) 77 print("this unit6 %s ,its powerer %s , and value %s" % (unit6, 2, convert_unit(2, unit6))) 78 print("this unit7 %s ,its powerer %s , and value %s" % (unit7, -1, convert_unit(-1, unit7))) 79 print("this unit8 %s ,its powerer %s , and value %s" % (unit8, 2, convert_unit(2, unit8))) 80 print("this unit9 %s ,its powerer %s , and value %s" % (unit9, 2, convert_unit(2, unit9))) -
src/sas/sasgui/plottools/fitDialog.py
re3ae090 r7432acb 2 2 from plottables import Theory1D 3 3 import math 4 import numpy 4 import numpy as np 5 5 import fittings 6 6 import transform … … 95 95 96 96 # Set default value of parameter in the dialog panel 97 if self.Avalue ==None:97 if self.Avalue is None: 98 98 self.tcA.SetValue(format_number(self.default_A)) 99 99 else: 100 100 self.tcA.SetLabel(format_number(self.Avalue)) 101 if self.Bvalue ==None:101 if self.Bvalue is None: 102 102 self.tcB.SetValue(format_number(self.default_B)) 103 103 else: 104 104 self.tcB.SetLabel(format_number(self.Bvalue)) 105 if self.ErrAvalue ==None:105 if self.ErrAvalue is None: 106 106 self.tcErrA.SetLabel(format_number(0.0)) 107 107 else: 108 108 self.tcErrA.SetLabel(format_number(self.ErrAvalue)) 109 if self.ErrBvalue ==None:109 if self.ErrBvalue is None: 110 110 self.tcErrB.SetLabel(format_number(0.0)) 111 111 else: 112 112 self.tcErrB.SetLabel(format_number(self.ErrBvalue)) 113 if self.Chivalue ==None:113 if self.Chivalue is None: 114 114 self.tcChi.SetLabel(format_number(0.0)) 115 115 else: … … 482 482 483 483 if self.xLabel.lower() == "log10(x)": 484 tempdy = n umpy.asarray(tempdy)484 tempdy = np.asarray(tempdy) 485 485 tempdy[tempdy == 0] = 1 486 486 chisqr, out, cov = fittings.sasfit(self.model, … … 491 491 math.log10(xmax)) 492 492 else: 493 tempdy = n umpy.asarray(tempdy)493 tempdy = np.asarray(tempdy) 494 494 tempdy[tempdy == 0] = 1 495 495 chisqr, out, cov = fittings.sasfit(self.model, … … 502 502 503 503 # Check that cov and out are iterable before displaying them 504 if cov ==None:504 if cov is None: 505 505 errA = 0.0 506 506 errB = 0.0 … … 508 508 errA = math.sqrt(cov[0][0]) 509 509 errB = math.sqrt(cov[1][1]) 510 if out ==None:510 if out is None: 511 511 cstA = 0.0 512 512 cstB = 0.0 … … 572 572 if self.rg_on: 573 573 if self.Rg_tctr.IsShown(): 574 rg = n umpy.sqrt(-3 * float(cstA))574 rg = np.sqrt(-3 * float(cstA)) 575 575 value = format_number(rg) 576 576 self.Rg_tctr.SetValue(value) 577 577 if self.I0_tctr.IsShown(): 578 val = n umpy.exp(cstB)578 val = np.exp(cstB) 579 579 self.I0_tctr.SetValue(format_number(val)) 580 580 if self.Rgerr_tctr.IsShown(): 581 if rg !=None and rg != 0:581 if rg is not None and rg != 0: 582 582 value = format_number(3 * float(errA) / (2 * rg)) 583 583 else: … … 585 585 self.Rgerr_tctr.SetValue(value) 586 586 if self.I0err_tctr.IsShown(): 587 val = n umpy.abs(numpy.exp(cstB) * errB)587 val = np.abs(np.exp(cstB) * errB) 588 588 self.I0err_tctr.SetValue(format_number(val)) 589 589 if self.Diameter_tctr.IsShown(): 590 rg = n umpy.sqrt(-2 * float(cstA))591 _diam = 4 * n umpy.sqrt(-float(cstA))590 rg = np.sqrt(-2 * float(cstA)) 591 _diam = 4 * np.sqrt(-float(cstA)) 592 592 value = format_number(_diam) 593 593 self.Diameter_tctr.SetValue(value) 594 594 if self.Diametererr_tctr.IsShown(): 595 if rg !=None and rg != 0:595 if rg is not None and rg != 0: 596 596 value = format_number(8 * float(errA) / _diam) 597 597 else: -
src/sas/sasgui/plottools/fittings.py
re3ae090 ra1b8fee 14 14 15 15 """ 16 from __future__ import print_function 17 16 18 from scipy import optimize 17 19 … … 25 27 self.model = model 26 28 self.name = name 27 if not value ==None:29 if value is not None: 28 30 self.model.setParam(self.name, value) 29 31 … … 106 108 chisqr, out, cov = sasfit(line, [cstA, cstB], event.x, y, 0) 107 109 # print "Output parameters:", out 108 print "The right answer is [70.0, 1.0]"109 print chisqr, out, cov110 print("The right answer is [70.0, 1.0]") 111 print(chisqr, out, cov) -
src/sas/sasgui/plottools/plottable_interactor.py
rd7bb526 ra1b8fee 2 2 This module allows more interaction with the plot 3 3 """ 4 from __future__ import print_function 5 4 6 from BaseInteractor import _BaseInteractor 7 5 8 6 9 class PointInteractor(_BaseInteractor): … … 50 53 l_width = markersize * 0.4 51 54 return self.step(x=x, y=y, color=color, label=label, width=l_width) 52 if not self.marker ==None:53 self.base.connect.clear([self.marker]) 54 self.color = self._color(color) 55 if self.markersize !=None:55 if self.marker is not None: 56 self.base.connect.clear([self.marker]) 57 self.color = self._color(color) 58 if self.markersize is not None: 56 59 markersize = self.markersize 57 60 # Convert tuple (lo,hi) to array [(x-lo),(hi-x)] 58 if dx !=None and type(dx) == type(()):61 if dx is not None and type(dx) == type(()): 59 62 dx = nx.vstack((x - dx[0], dx[1] - x)).transpose() 60 if dy !=None and type(dy) == type(()):63 if dy is not None and type(dy) == type(()): 61 64 dy = nx.vstack((y - dy[0], dy[1] - y)).transpose() 62 65 63 if dx == None and dy ==None:66 if dx is None and dy is None: 64 67 # zorder = 1 65 68 self.marker = self.axes.plot(x, y, color=self.color, … … 100 103 """ 101 104 """ 102 if not self.marker ==None:105 if self.marker is not None: 103 106 self.base.connect.clear([self.marker]) 104 107 self.color = self._color(color) … … 115 118 """ 116 119 """ 117 if not self.marker ==None:120 if self.marker is not None: 118 121 self.base.connect.clear([self.marker]) 119 122 self.color = self._color(color) … … 133 136 """ 134 137 """ 135 if not self.marker ==None:138 if self.marker is not None: 136 139 self.base.connect.clear([self.marker]) 137 140 self.color = self._color(color) … … 156 159 157 160 def clear(self): 158 print "plottable_interactor.clear()"161 print("plottable_interactor.clear()") 159 162 160 163 def _on_click(self, evt): -
src/sas/sasgui/plottools/plottables.py
r9687d58 r45dffa69 43 43 # Support for ancient python versions 44 44 import copy 45 import numpy 45 import numpy as np 46 46 import sys 47 47 import logging 48 49 logger = logging.getLogger(__name__) 48 50 49 51 if 'any' not in dir(__builtins__): … … 227 229 if p.hidden == True: 228 230 continue 229 if not p.x ==None:231 if p.x is not None: 230 232 for x_i in p.x: 231 if min_value ==None or x_i < min_value:233 if min_value is None or x_i < min_value: 232 234 min_value = x_i 233 if max_value ==None or x_i > max_value:235 if max_value is None or x_i > max_value: 234 236 max_value = x_i 235 237 return min_value, max_value … … 560 562 Returns True if there is no data stored in the plottable 561 563 """ 562 if not self.x == None and len(self.x) == 0 \563 and not self.y == None and len(self.y) == 0:564 if (self.x is not None and len(self.x) == 0 565 and self.y is not None and len(self.y) == 0): 564 566 return True 565 567 return False … … 681 683 682 684 if(x is not None) and (y is not None): 683 if not dx isNone and not len(dx) == 0 and not len(x) == len(dx):685 if dx is not None and not len(dx) == 0 and not len(x) == len(dx): 684 686 msg = "Plottable.View: Given x and dx are not" 685 687 msg += " of the same length" … … 691 693 raise ValueError, msg 692 694 693 if not dy isNone and not len(dy) == 0 and not len(y) == len(dy):695 if dy is not None and not len(dy) == 0 and not len(y) == len(dy): 694 696 msg = "Plottable.View: Given y and dy are not of the same " 695 697 msg += "length: len(y)=%s, len(dy)=%s" % (len(y), len(dy)) … … 706 708 self.dy = None 707 709 if not has_err_x: 708 dx = n umpy.zeros(len(x))710 dx = np.zeros(len(x)) 709 711 if not has_err_y: 710 dy = n umpy.zeros(len(y))712 dy = np.zeros(len(y)) 711 713 for i in range(len(x)): 712 714 try: … … 795 797 tempy = [] 796 798 tempdy = [] 797 if self.dx ==None:798 self.dx = n umpy.zeros(len(self.x))799 if self.dy ==None:800 self.dy = n umpy.zeros(len(self.y))799 if self.dx is None: 800 self.dx = np.zeros(len(self.x)) 801 if self.dy is None: 802 self.dy = np.zeros(len(self.y)) 801 803 if self.xLabel == "log10(x)": 802 804 for i in range(len(self.x)): … … 808 810 tempdy.append(self.dy[i]) 809 811 except: 810 logg ing.error("check_data_logX: skipping point x %g", self.x[i])811 logg ing.error(sys.exc_value)812 logger.error("check_data_logX: skipping point x %g", self.x[i]) 813 logger.error(sys.exc_value) 812 814 self.x = tempx 813 815 self.y = tempy … … 825 827 tempy = [] 826 828 tempdy = [] 827 if self.dx ==None:828 self.dx = n umpy.zeros(len(self.x))829 if self.dy ==None:830 self.dy = n umpy.zeros(len(self.y))829 if self.dx is None: 830 self.dx = np.zeros(len(self.x)) 831 if self.dy is None: 832 self.dy = np.zeros(len(self.y)) 831 833 if self.yLabel == "log10(y)": 832 834 for i in range(len(self.x)): … … 838 840 tempdy.append(self.dy[i]) 839 841 except: 840 logg ing.error("check_data_logY: skipping point %g", self.y[i])841 logg ing.error(sys.exc_value)842 logger.error("check_data_logY: skipping point %g", self.y[i]) 843 logger.error(sys.exc_value) 842 844 843 845 self.x = tempx … … 858 860 tempy = [] 859 861 tempdy = [] 860 if self.dx ==None:861 self.dx = n umpy.zeros(len(self.x))862 if self.dy ==None:863 self.dy = n umpy.zeros(len(self.y))864 if xmin != None and xmax !=None:862 if self.dx is None: 863 self.dx = np.zeros(len(self.x)) 864 if self.dy is None: 865 self.dy = np.zeros(len(self.y)) 866 if xmin is not None and xmax is not None: 865 867 for i in range(len(self.x)): 866 868 if self.x[i] >= xmin and self.x[i] <= xmax: … … 1023 1025 """ 1024 1026 1025 def __init__(self, x, y, dx=None, dy=None ):1027 def __init__(self, x, y, dx=None, dy=None, lam=None, dlam=None): 1026 1028 """ 1027 1029 Draw points specified by x[i],y[i] in the current color/symbol. … … 1037 1039 self.x = x 1038 1040 self.y = y 1041 self.lam = lam 1039 1042 self.dx = dx 1040 1043 self.dy = dy 1044 self.dlam = dlam 1041 1045 self.source = None 1042 1046 self.detector = None … … 1202 1206 """ 1203 1207 """ 1204 if self._chisq ==None:1208 if self._chisq is None: 1205 1209 chisqTxt = r'$\chi^2=$' 1206 1210 else: … … 1226 1230 1227 1231 def sample_graph(): 1228 import numpy as n x1232 import numpy as np 1229 1233 1230 1234 # Construct a simple graph 1231 1235 if False: 1232 x = n x.array([1, 2, 3, 4, 5, 6], 'd')1233 y = n x.array([4, 5, 6, 5, 4, 5], 'd')1234 dy = n x.array([0.2, 0.3, 0.1, 0.2, 0.9, 0.3])1236 x = np.array([1, 2, 3, 4, 5, 6], 'd') 1237 y = np.array([4, 5, 6, 5, 4, 5], 'd') 1238 dy = np.array([0.2, 0.3, 0.1, 0.2, 0.9, 0.3]) 1235 1239 else: 1236 x = n x.linspace(0, 1., 10000)1237 y = n x.sin(2 * nx.pi * x * 2.8)1238 dy = n x.sqrt(100 * nx.abs(y)) / 1001240 x = np.linspace(0, 1., 10000) 1241 y = np.sin(2 * np.pi * x * 2.8) 1242 dy = np.sqrt(100 * np.abs(y)) / 100 1239 1243 data = Data1D(x, y, dy=dy) 1240 1244 data.xaxis('distance', 'm') -
src/sas/sasgui/plottools/toolbar.py
r092a3d9 rc416a17 6 6 from matplotlib.backends.backend_wx import _load_bitmap 7 7 import logging 8 9 logger = logging.getLogger(__name__) 8 10 9 11 # Event binding code changed after version 2.5 … … 35 37 36 38 # CRUFT: mpl 1.1 uses save rather than save_figure 37 #try: save_figure = NavigationToolbar2WxAgg.save38 #except AttributeError: pass39 try: save_figure = NavigationToolbar2WxAgg.save 40 except AttributeError: pass 39 41 40 42 def _init_toolbar(self): … … 94 96 self._parent.onToolContextMenu(event=event) 95 97 except: 96 logg ing.error("Plot toolbar could not show menu")98 logger.error("Plot toolbar could not show menu") 97 99 98 100 def context_menu(self, event): … … 122 124 except: 123 125 import traceback 124 logg ing.error(traceback.format_exc())126 logger.error(traceback.format_exc()) 125 127 126 128 def copy_figure(self, event): … … 169 171 wx.TheClipboard.SetData(bmp) 170 172 wx.TheClipboard.Close() 171 172 -
src/sas/sasgui/plottools/transform.py
r821c330 r7432acb 162 162 163 163 """ 164 if dx ==None:164 if dx is None: 165 165 dx = 0 166 166 return dx … … 175 175 176 176 """ 177 if dx ==None:177 if dx is None: 178 178 dx = 0 179 179 return dx … … 188 188 189 189 """ 190 if dx !=None:190 if dx is not None: 191 191 err = 2 * x * dx 192 192 return math.fabs(err) … … 204 204 """ 205 205 if x > 0: 206 if dx !=None:206 if dx is not None: 207 207 err = dx / (2 * math.sqrt(x)) 208 208 else: … … 222 222 223 223 """ 224 if dx !=None:224 if dx is not None: 225 225 err = 4 * math.pow(x, 3) * dx 226 226 return math.fabs(err) … … 238 238 """ 239 239 if x > 0: 240 if dx !=None:240 if dx is not None: 241 241 err = dx / (4 * math.pow(x, 3 / 4)) 242 242 else: … … 256 256 257 257 """ 258 if dx ==None:258 if dx is None: 259 259 dx = 0 260 260 … … 280 280 281 281 """ 282 if dx ==None:282 if dx is None: 283 283 dx = 0 284 284 … … 294 294 """ 295 295 """ 296 if dx ==None:297 dx = 0 298 if dy ==None:296 if dx is None: 297 dx = 0 298 if dy is None: 299 299 dy = 0 300 300 err = math.sqrt((2 * x * y * dx) ** 2 + ((x ** 2) * dy) ** 2) … … 314 314 raise ValueError, msg 315 315 if x != 0 and y != 0: 316 if dx ==None:316 if dx is None: 317 317 dx = 0 318 if dy ==None:318 if dy is None: 319 319 dy = 0 320 320 err = (dx / x) ** 2 + (dy / y) ** 2 … … 337 337 raise ValueError, msg 338 338 if x > 0 and y > 0: 339 if dx ==None:339 if dx is None: 340 340 dx = 0 341 if dy ==None:341 if dy is None: 342 342 dy = 0 343 343 err = (2.0 * dx / x) ** 2 + (dy / y) ** 2 … … 353 353 """ 354 354 if x != 0: 355 if dx ==None:355 if dx is None: 356 356 dx = 0 357 357 err = dx / x ** 2 … … 367 367 """ 368 368 if x > 0: 369 if dx ==None:369 if dx is None: 370 370 dx = 0 371 371 err = -1 / 2 * math.pow(x, -3.0 / 2.0) * dx … … 388 388 msg += " that are consistent with zero." 389 389 raise ValueError, msg 390 if dx ==None:391 dx = 0 392 if dy ==None:390 if dx is None: 391 dx = 0 392 if dy is None: 393 393 dy = 0 394 394 err = math.sqrt((4.0 * dx / x) ** 2 + (dy / y) ** 2) … … 406 406 # within errors 407 407 408 if dx ==None:409 dx = 0 410 if dy ==None:408 if dx is None: 409 dx = 0 410 if dy is None: 411 411 dy = 0 412 412 err = math.sqrt((dy * pow(x, 4)) ** 2 + (4 * y * dx * math.pow(x, 3)) ** 2) -
src/sas/sasgui/plottools/config.py
rd7bb526 r092a3d9 30 30 __all__ = [] 31 31 32 plot_version = "0.98" 33 plot_backend = "WXAgg" 32 #plot_version = "0.98" 33 #plot_backend = "WXAgg" 34 plot_backend = "Qt4Agg" 34 35 35 36 # Sort out matplotlib version 36 37 import matplotlib 37 try:38 import pkg_resources39 pkg_resources.require("matplotlib>=" + plot_version)40 except:41 from distutils.version import LooseVersion as Version42 if Version(matplotlib.__version__) < Version(plot_version):43 msg = "Matplotlib version must be %s or newer" % (plot_version, )44 raise ImportError(msg)38 #try: 39 # import pkg_resources 40 # pkg_resources.require("matplotlib>=" + plot_version) 41 #except: 42 # from distutils.version import LooseVersion as Version 43 # if Version(matplotlib.__version__) < Version(plot_version): 44 # msg = "Matplotlib version must be %s or newer" % (plot_version, ) 45 # raise ImportError(msg) 45 46 46 47 # Sort out matplotlib backend … … 51 52 elif matplotlib.get_backend() != plot_backend: 52 53 # if a backend has already been selected, make sure it is the correct one. 53 raise ImportError("Matplotlib not using backend " + plot_backend) 54 #raise ImportError("Matplotlib not using backend " + plot_backend) 55 pass 54 56 55 57 # set global plot style … … 58 60 matplotlib.rcParams[param] = 0.05 59 61 matplotlib.rcParams['legend.numpoints'] = 1 62 #matplotlib.rcParams['interactive'] = True 63 60 64 61 65 # this should happen after initial matplotlib configuration 62 from .toolbar import NavigationToolBar63 from matplotlib.backends import backend_wxagg64 backend_wxagg.NavigationToolbar2WxAgg = NavigationToolBar66 #from .toolbar import NavigationToolBar 67 #from matplotlib.backends import backend_wxagg 68 #backend_wxagg.NavigationToolbar2WxAgg = NavigationToolBar 65 69 66 70 # CRUFT: bumps 0.7.5.6 and older uses wrong toolbar 67 backend_wxagg.NavigationToolbar2Wx = NavigationToolBar71 #backend_wxagg.NavigationToolbar2Wx = NavigationToolBar
Note: See TracChangeset
for help on using the changeset viewer.