Changeset 914ba0a in sasview for src/sas/sasgui/plottools
- Timestamp:
- May 2, 2017 3:58:01 PM (8 years ago)
- Branches:
- master, 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, magnetic_scatt, release-4.2.2, ticket-1009, ticket-1094-headless, ticket-1242-2d-resolution, ticket-1243, ticket-1249, ticket885, unittest-saveload
- Children:
- d66dbcc
- Parents:
- 74d9780 (diff), 658dd57 (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:
-
- 1 added
- 15 edited
Legend:
- Unmodified
- Added
- Removed
-
src/sas/sasgui/plottools/LineModel.py
rd7bb526 r959eb01 1 1 #!/usr/bin/env python 2 2 """ 3 Provide Line function (y= A + Bx) 3 Provide Line function (y= Ax + B). Until July 10, 2016 this function provided 4 (y= A + Bx). This however was contrary to all the other code using it which 5 assumed (y= mx+b) or in this nomenclature (y=Ax + B). This lead to some 6 contortions in the code and worse incorrect calculations until now for at least 7 some of the functions. This seemed the easiest to fix particularly since this 8 function should disappear in a future iteration (see notes in fitDialog) 9 10 PDB July 10, 2016 11 4 12 """ 5 13 … … 10 18 Class that evaluates a linear model. 11 19 12 f(x) = A + Bx20 f(x) = Ax + B 13 21 14 22 List of default parameters: 15 A = 0.016 B = 0.023 A = 1.0 24 B = 1.0 17 25 """ 18 26 … … 53 61 54 62 """ 55 return self.params['A'] + (x * self.params['B'])63 return (self.params['A'] * x) + self.params['B'] 56 64 57 65 def run(self, x=0.0): 58 66 """ 59 67 Evaluate the model 68 69 :note: This is the function called by fitDialog to calculate the 70 the y(xmin) and y(xmax), but the only difference between this and 71 runXY is when the if statement is true. I however cannot see what that 72 function is for. It needs to be documented here or removed. 73 PDB 7/10/16 60 74 61 75 :param x: simple value … … 74 88 def runXY(self, x=0.0): 75 89 """ 76 Evaluate the model 90 Evaluate the model. 91 92 :note: This is to be what is called by fitDialog for the actual fit 93 but the only difference between this and run is when the if 94 statement is true. I however cannot see what that function 95 is for. It needs to be documented here or removed. PDB 7/10/16 77 96 78 97 :param x: simple value -
src/sas/sasgui/plottools/PlotPanel.py
r16b769b ra1b8fee 2 2 Plot panel. 3 3 """ 4 from __future__ import print_function 5 4 6 import logging 5 7 import traceback … … 15 17 import os 16 18 import transform 17 from plottables import Data1D18 19 #TODO: make the plottables interactive 19 20 from binder import BindArtist … … 30 31 DEFAULT_CMAP = pylab.cm.jet 31 32 import copy 32 import numpy 33 import numpy as np 33 34 34 35 from sas.sasgui.guiframe.events import StatusEvent 35 36 from .toolbar import NavigationToolBar, PlotPrintout, bind 36 37 38 logger = logging.getLogger(__name__) 39 37 40 def show_tree(obj, d=0): 38 41 """Handy function for displaying a tree of graph objects""" 39 print "%s%s" % ("-"*d, obj.__class__.__name__)42 print("%s%s" % ("-"*d, obj.__class__.__name__)) 40 43 if 'get_children' in dir(obj): 41 44 for a in obj.get_children(): show_tree(a, d + 1) … … 151 154 #List of texts currently on the plot 152 155 self.textList = [] 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: … … 190 194 191 195 # new data for the fit 196 from sas.sasgui.guiframe.dataFitting import Data1D 192 197 self.fit_result = Data1D(x=[], y=[], dy=None) 193 198 self.fit_result.symbol = 13 … … 352 357 self.leftdown = True 353 358 ax = event.inaxes 354 if ax != None: 359 for text in self.textList: 360 if text.contains(event)[0]: # If user has clicked on text 361 self.selectedText = text 362 return 363 364 if ax is not None: 355 365 self.xInit, self.yInit = event.xdata, event.ydata 356 366 try: … … 373 383 self.mousemotion = False 374 384 self.leftup = True 385 self.selectedText = None 375 386 376 387 #release the legend … … 383 394 Set legend alpha 384 395 """ 385 if self.legend !=None:396 if self.legend is not None: 386 397 self.legend.legendPatch.set_alpha(alpha) 387 398 … … 409 420 """ 410 421 ax = event.inaxes 411 if ax ==None:422 if ax is None: 412 423 return 413 424 # Event occurred inside a plotting area … … 445 456 """ 446 457 self.cusor_line(event) 447 if self.gotLegend == 1 :458 if self.gotLegend == 1 and self.leftdown: 448 459 self._on_legend_motion(event) 449 460 return 461 462 if self.leftdown and self.selectedText is not None: 463 # User has clicked on text and is dragging 464 ax = event.inaxes 465 if ax is not None: 466 # Only move text if mouse is within axes 467 self.selectedText.set_position((event.xdata, event.ydata)) 468 self._dragHelper(0, 0) 469 else: 470 # User has dragged outside of axes 471 self.selectedText = None 472 return 473 450 474 if self.enable_toolbar: 451 475 #Disable dragging without the toolbar to allow zooming with toolbar … … 454 478 if self.leftdown == True and self.mousemotion == True: 455 479 ax = event.inaxes 456 if ax !=None: # the dragging is perform inside the figure480 if ax is not None: # the dragging is perform inside the figure 457 481 self.xFinal, self.yFinal = event.xdata, event.ydata 458 482 # Check whether this is the first point 459 if self.xInit ==None:483 if self.xInit is None: 460 484 self.xInit = self.xFinal 461 485 self.yInit = self.yFinal … … 554 578 step = event.step 555 579 556 if ax !=None:580 if ax is not None: 557 581 # Event occurred inside a plotting area 558 582 lo, hi = ax.get_xlim() … … 646 670 dlg.setFitRange(self.xminView, self.xmaxView, 647 671 self.xmin, self.xmax) 672 else: 673 xlim = self.subplot.get_xlim() 674 ylim = self.subplot.get_ylim() 675 dlg.setFitRange(xlim[0], xlim[1], ylim[0], ylim[1]) 676 # It would be nice for this to NOT be modal (i.e. Show). 677 # Not sure about other ramifications - for example 678 # if a second linear fit is started before the first is closed. 679 # consider for future - being able to work on the plot while 680 # seing the fit values would be very nice -- PDB 7/10/16 648 681 dlg.ShowModal() 649 682 … … 708 741 if dial.ShowModal() == wx.ID_OK: 709 742 self.xLabel, self.yLabel, self.viewModel = dial.getValues() 710 if self.viewModel == "Linear y vs x":711 self.xLabel = "x"712 self.yLabel = "y"713 self.viewModel = "--"714 dial.setValues(self.xLabel, self.yLabel, self.viewModel)715 if self.viewModel == "Guinier lny vs x^(2)":716 self.xLabel = "x^(2)"717 self.yLabel = "ln(y)"718 self.viewModel = "--"719 dial.setValues(self.xLabel, self.yLabel, self.viewModel)720 if self.viewModel == "XS Guinier ln(y*x) vs x^(2)":721 self.xLabel = "x^(2)"722 self.yLabel = "ln(y*x)"723 self.viewModel = "--"724 dial.setValues(self.xLabel, self.yLabel, self.viewModel)725 if self.viewModel == "Porod y*x^(4) vs x^(4)":726 self.xLabel = "x^(4)"727 self.yLabel = "y*x^(4)"728 self.viewModel = "--"729 dial.setValues(self.xLabel, self.yLabel, self.viewModel)730 743 self._onEVT_FUNC_PROPERTY() 731 744 dial.Destroy() … … 924 937 # reset postion 925 938 self.position = None 926 if self.graph.selected_plottable !=None:939 if self.graph.selected_plottable is not None: 927 940 self.graph.selected_plottable = None 928 941 … … 948 961 prop=FontProperties(size=10), 949 962 loc=self.legendLoc) 950 if self.legend !=None:963 if self.legend is not None: 951 964 self.legend.set_picker(self.legend_picker) 952 965 self.legend.set_axes(self.subplot) … … 978 991 prop=FontProperties(size=10), 979 992 loc=self.legendLoc) 980 if self.legend !=None:993 if self.legend is not None: 981 994 self.legend.set_picker(self.legend_picker) 982 995 self.legend.set_axes(self.subplot) … … 999 1012 pos_x = 0 1000 1013 pos_y = 0 1001 if self.position !=None:1014 if self.position is not None: 1002 1015 pos_x, pos_y = self.position 1003 1016 else: … … 1024 1037 self.subplot.figure.canvas.draw_idle() 1025 1038 except: 1026 if self.parent !=None:1039 if self.parent is not None: 1027 1040 msg = "Add Text: Error. Check your property values..." 1028 1041 wx.PostEvent(self.parent, StatusEvent(status=msg)) … … 1058 1071 self.xaxis_tick = xaxis_font 1059 1072 1060 if self.data !=None:1073 if self.data is not None: 1061 1074 # 2D 1062 1075 self.xaxis(self.xaxis_label, self.xaxis_unit, \ … … 1105 1118 self.yaxis_tick = yaxis_font 1106 1119 1107 if self.data !=None:1120 if self.data is not None: 1108 1121 # 2D 1109 1122 self.yaxis(self.yaxis_label, self.yaxis_unit, \ … … 1144 1157 label_temp = textdial.getText() 1145 1158 if label_temp.count("\%s" % "\\") > 0: 1146 if self.parent !=None:1159 if self.parent is not None: 1147 1160 msg = "Add Label: Error. Can not use double '\\' " 1148 1161 msg += "characters..." … … 1151 1164 label = label_temp 1152 1165 except: 1153 if self.parent !=None:1166 if self.parent is not None: 1154 1167 msg = "Add Label: Error. Check your property values..." 1155 1168 wx.PostEvent(self.parent, StatusEvent(status=msg)) … … 1169 1182 num_text = len(self.textList) 1170 1183 if num_text < 1: 1171 if self.parent !=None:1184 if self.parent is not None: 1172 1185 msg = "Remove Text: Nothing to remove. " 1173 1186 wx.PostEvent(self.parent, StatusEvent(status=msg)) … … 1179 1192 text_remove = txt.get_text() 1180 1193 txt.remove() 1181 if self.parent !=None:1194 if self.parent is not None: 1182 1195 msg = "Removed Text: '%s'. " % text_remove 1183 1196 wx.PostEvent(self.parent, StatusEvent(status=msg)) 1184 1197 except: 1185 if self.parent !=None:1198 if self.parent is not None: 1186 1199 msg = "Remove Text: Error occurred. " 1187 1200 wx.PostEvent(self.parent, StatusEvent(status=msg)) … … 1206 1219 1207 1220 # Properties defined by plot 1208 1221 1209 1222 # Ricardo: 1210 # A empty label "$$" will prevent the panel from displaying! 1211 1223 # A empty label "$$" will prevent the panel from displaying! 1212 1224 if prop["xlabel"]: 1213 1225 self.subplot.set_xlabel(r"$%s$"%prop["xlabel"]) … … 1215 1227 self.subplot.set_ylabel(r"$%s$"%prop["ylabel"]) 1216 1228 self.subplot.set_title(prop["title"]) 1217 1229 1218 1230 1219 1231 def clear(self): … … 1240 1252 prop=FontProperties(size=10), 1241 1253 loc=self.legendLoc) 1242 if self.legend !=None:1254 if self.legend is not None: 1243 1255 self.legend.set_picker(self.legend_picker) 1244 1256 self.legend.set_axes(self.subplot) … … 1269 1281 if font: 1270 1282 self.subplot.set_xlabel(label, fontproperties=font, color=color) 1271 if t_font !=None:1283 if t_font is not None: 1272 1284 for tick in self.subplot.xaxis.get_major_ticks(): 1273 1285 tick.label.set_fontproperties(t_font) … … 1290 1302 if font: 1291 1303 self.subplot.set_ylabel(label, fontproperties=font, color=color) 1292 if t_font !=None:1304 if t_font is not None: 1293 1305 for tick_label in self.subplot.get_yticklabels(): 1294 1306 tick_label.set_fontproperties(t_font) … … 1317 1329 from plottable_interactor import PointInteractor 1318 1330 p = PointInteractor(self, self.subplot, zorder=zorder, id=id) 1319 if p.markersize !=None:1331 if p.markersize is not None: 1320 1332 markersize = p.markersize 1321 1333 p.points(x, y, dx=dx, dy=dy, color=color, symbol=symbol, zorder=zorder, … … 1353 1365 1354 1366 # Convert tuple (lo,hi) to array [(x-lo),(hi-x)] 1355 if dx !=None and type(dx) == type(()):1367 if dx is not None and type(dx) == type(()): 1356 1368 dx = nx.vstack((x - dx[0], dx[1] - x)).transpose() 1357 if dy !=None and type(dy) == type(()):1369 if dy is not None and type(dy) == type(()): 1358 1370 dy = nx.vstack((y - dy[0], dy[1] - y)).transpose() 1359 if dx == None and dy ==None:1371 if dx is None and dy is None: 1360 1372 self.subplot.plot(x, y, color=self._color(color), 1361 1373 marker=self._symbol(symbol), … … 1393 1405 if self.scale == 'log_{10}': 1394 1406 self.scale = 'linear' 1395 if not self.zmin_2D isNone:1407 if self.zmin_2D is not None: 1396 1408 zmin_2D_temp = math.pow(10, self.zmin_2D) 1397 if not self.zmax_2D isNone:1409 if self.zmax_2D is not None: 1398 1410 zmax_2D_temp = math.pow(10, self.zmax_2D) 1399 1411 else: 1400 1412 self.scale = 'log_{10}' 1401 if not self.zmin_2D isNone:1413 if self.zmin_2D is not None: 1402 1414 # min log value: no log(negative) 1403 1415 if self.zmin_2D <= 0: … … 1405 1417 else: 1406 1418 zmin_2D_temp = math.log10(self.zmin_2D) 1407 if not self.zmax_2D isNone:1419 if self.zmax_2D is not None: 1408 1420 zmax_2D_temp = math.log10(self.zmax_2D) 1409 1421 … … 1433 1445 c = self._color(color) 1434 1446 # If we don't have any data, skip. 1435 if self.data ==None:1447 if self.data is None: 1436 1448 return 1437 1449 if self.data.ndim == 1: … … 1444 1456 if self.zmin_2D <= 0 and len(output[output > 0]) > 0: 1445 1457 zmin_temp = self.zmin_2D 1446 output[output > 0] = n umpy.log10(output[output > 0])1458 output[output > 0] = np.log10(output[output > 0]) 1447 1459 #In log scale Negative values are not correct in general 1448 #output[output<=0] = math.log(n umpy.min(output[output>0]))1460 #output[output<=0] = math.log(np.min(output[output>0])) 1449 1461 elif self.zmin_2D <= 0: 1450 1462 zmin_temp = self.zmin_2D 1451 output[output > 0] = n umpy.zeros(len(output))1463 output[output > 0] = np.zeros(len(output)) 1452 1464 output[output <= 0] = -32 1453 1465 else: 1454 1466 zmin_temp = self.zmin_2D 1455 output[output > 0] = n umpy.log10(output[output > 0])1467 output[output > 0] = np.log10(output[output > 0]) 1456 1468 #In log scale Negative values are not correct in general 1457 #output[output<=0] = math.log(n umpy.min(output[output>0]))1469 #output[output<=0] = math.log(np.min(output[output>0])) 1458 1470 except: 1459 1471 #Too many problems in 2D plot with scale … … 1484 1496 X = self.x_bins[0:-1] 1485 1497 Y = self.y_bins[0:-1] 1486 X, Y = n umpy.meshgrid(X, Y)1498 X, Y = np.meshgrid(X, Y) 1487 1499 1488 1500 try: … … 1498 1510 from mpl_toolkits.mplot3d import Axes3D 1499 1511 except: 1500 logg ing.error("PlotPanel could not import Axes3D")1512 logger.error("PlotPanel could not import Axes3D") 1501 1513 self.subplot.figure.clear() 1502 1514 ax = Axes3D(self.subplot.figure) … … 1509 1521 self.subplot.set_axis_off() 1510 1522 1511 if cbax ==None:1523 if cbax is None: 1512 1524 ax.set_frame_on(False) 1513 1525 cb = self.subplot.figure.colorbar(im, shrink=0.8, aspect=20) … … 1531 1543 """ 1532 1544 # No qx or qy given in a vector format 1533 if self.qx_data == None or self.qy_data ==None \1545 if self.qx_data is None or self.qy_data is None \ 1534 1546 or self.qx_data.ndim != 1 or self.qy_data.ndim != 1: 1535 1547 # do we need deepcopy here? … … 1547 1559 # 1d array to use for weighting the data point averaging 1548 1560 #when they fall into a same bin. 1549 weights_data = n umpy.ones([self.data.size])1561 weights_data = np.ones([self.data.size]) 1550 1562 # get histogram of ones w/len(data); this will provide 1551 1563 #the weights of data on each bins 1552 weights, xedges, yedges = n umpy.histogram2d(x=self.qy_data,1564 weights, xedges, yedges = np.histogram2d(x=self.qy_data, 1553 1565 y=self.qx_data, 1554 1566 bins=[self.y_bins, self.x_bins], 1555 1567 weights=weights_data) 1556 1568 # get histogram of data, all points into a bin in a way of summing 1557 image, xedges, yedges = n umpy.histogram2d(x=self.qy_data,1569 image, xedges, yedges = np.histogram2d(x=self.qy_data, 1558 1570 y=self.qx_data, 1559 1571 bins=[self.y_bins, self.x_bins], 1560 1572 weights=self.data) 1561 # Now, normalize the image by weights only for weights>1: 1573 # Now, normalize the image by weights only for weights>1: 1562 1574 # If weight == 1, there is only one data point in the bin so 1563 1575 # that no normalization is required. … … 1573 1585 # do while loop until all vacant bins are filled up up 1574 1586 #to loop = max_loop 1575 while not(n umpy.isfinite(image[weights == 0])).all():1587 while not(np.isfinite(image[weights == 0])).all(): 1576 1588 if loop >= max_loop: # this protects never-ending loop 1577 1589 break … … 1591 1603 """ 1592 1604 # No qx or qy given in a vector format 1593 if self.qx_data == None or self.qy_data ==None \1605 if self.qx_data is None or self.qy_data is None \ 1594 1606 or self.qx_data.ndim != 1 or self.qy_data.ndim != 1: 1595 1607 # do we need deepcopy here? … … 1622 1634 1623 1635 # store x and y bin centers in q space 1624 x_bins = n umpy.linspace(xmin, xmax, npix_x)1625 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) 1626 1638 1627 1639 #set x_bins and y_bins … … 1642 1654 """ 1643 1655 # No image matrix given 1644 if image == None or numpy.ndim(image) != 2 \1645 or n umpy.isfinite(image).all() \1646 or weights ==None:1656 if image is None or np.ndim(image) != 2 \ 1657 or np.isfinite(image).all() \ 1658 or weights is None: 1647 1659 return image 1648 1660 # Get bin size in y and x directions 1649 1661 len_y = len(image) 1650 1662 len_x = len(image[1]) 1651 temp_image = n umpy.zeros([len_y, len_x])1652 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]) 1653 1665 # do for-loop for all pixels 1654 1666 for n_y in range(len(image)): 1655 1667 for n_x in range(len(image[1])): 1656 1668 # find only null pixels 1657 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]): 1658 1670 continue 1659 1671 else: 1660 1672 # find 4 nearest neighbors 1661 1673 # check where or not it is at the corner 1662 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]): 1663 1675 temp_image[n_y][n_x] += image[n_y - 1][n_x] 1664 1676 weit[n_y][n_x] += 1 1665 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]): 1666 1678 temp_image[n_y][n_x] += image[n_y][n_x - 1] 1667 1679 weit[n_y][n_x] += 1 1668 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]): 1669 1681 temp_image[n_y][n_x] += image[n_y + 1][n_x] 1670 1682 weit[n_y][n_x] += 1 1671 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]): 1672 1684 temp_image[n_y][n_x] += image[n_y][n_x + 1] 1673 1685 weit[n_y][n_x] += 1 1674 1686 # go 4 next nearest neighbors when no non-zero 1675 1687 # neighbor exists 1676 if n_y != 0 and n_x != 0 and \1677 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]): 1678 1690 temp_image[n_y][n_x] += image[n_y - 1][n_x - 1] 1679 1691 weit[n_y][n_x] += 1 1680 1692 if n_y != len_y - 1 and n_x != 0 and \ 1681 numpy.isfinite(image[n_y + 1][n_x - 1]):1693 np.isfinite(image[n_y + 1][n_x - 1]): 1682 1694 temp_image[n_y][n_x] += image[n_y + 1][n_x - 1] 1683 1695 weit[n_y][n_x] += 1 1684 1696 if n_y != len_y and n_x != len_x - 1 and \ 1685 numpy.isfinite(image[n_y - 1][n_x + 1]):1697 np.isfinite(image[n_y - 1][n_x + 1]): 1686 1698 temp_image[n_y][n_x] += image[n_y - 1][n_x + 1] 1687 1699 weit[n_y][n_x] += 1 1688 1700 if n_y != len_y - 1 and n_x != len_x - 1 and \ 1689 numpy.isfinite(image[n_y + 1][n_x + 1]):1701 np.isfinite(image[n_y + 1][n_x + 1]): 1690 1702 temp_image[n_y][n_x] += image[n_y + 1][n_x + 1] 1691 1703 weit[n_y][n_x] += 1 … … 1741 1753 if remove_fit: 1742 1754 self.graph.delete(self.fit_result) 1755 if hasattr(self, 'plots'): 1756 if 'fit' in self.plots.keys(): 1757 del self.plots['fit'] 1743 1758 self.ly = None 1744 1759 self.q_ctrl = None … … 1754 1769 _yscale = 'linear' 1755 1770 for item in list: 1771 if item.id == 'fit': 1772 continue 1756 1773 item.setLabel(self.xLabel, self.yLabel) 1757 1758 1774 # control axis labels from the panel itself 1759 1775 yname, yunits = item.get_yaxis() 1760 if self.yaxis_label !=None:1776 if self.yaxis_label is not None: 1761 1777 yname = self.yaxis_label 1762 1778 yunits = self.yaxis_unit … … 1765 1781 self.yaxis_unit = yunits 1766 1782 xname, xunits = item.get_xaxis() 1767 if self.xaxis_label !=None:1783 if self.xaxis_label is not None: 1768 1784 xname = self.xaxis_label 1769 1785 xunits = self.xaxis_unit … … 1785 1801 if self.xLabel == "ln(x)": 1786 1802 item.transformX(transform.toLogX, transform.errToLogX) 1787 self.graph._xaxis_transformed("\ln \\ %s" % xname, "%s" % xunits)1803 self.graph._xaxis_transformed("\ln{(%s)}" % xname, "%s" % xunits) 1788 1804 if self.xLabel == "log10(x)": 1789 1805 item.transformX(transform.toX_pos, transform.errToX_pos) … … 1797 1813 if self.yLabel == "ln(y)": 1798 1814 item.transformY(transform.toLogX, transform.errToLogX) 1799 self.graph._yaxis_transformed("\ln \\ %s" % yname, "%s" % yunits)1815 self.graph._yaxis_transformed("\ln{(%s)}" % yname, "%s" % yunits) 1800 1816 if self.yLabel == "y": 1801 1817 item.transformY(transform.toX, transform.errToX) … … 1813 1829 yunits = convert_unit(-1, yunits) 1814 1830 self.graph._yaxis_transformed("1/%s" % yname, "%s" % yunits) 1831 if self.yLabel == "y*x^(2)": 1832 item.transformY(transform.toYX2, transform.errToYX2) 1833 xunits = convert_unit(2, self.xaxis_unit) 1834 self.graph._yaxis_transformed("%s \ \ %s^{2}" % (yname, xname), 1835 "%s%s" % (yunits, xunits)) 1815 1836 if self.yLabel == "y*x^(4)": 1816 1837 item.transformY(transform.toYX4, transform.errToYX4) … … 1826 1847 if self.yLabel == "ln(y*x)": 1827 1848 item.transformY(transform.toLogXY, transform.errToLogXY) 1828 self.graph._yaxis_transformed("\ln (%s \ \ %s)" % (yname, xname),1849 self.graph._yaxis_transformed("\ln{(%s \ \ %s)}" % (yname, xname), 1829 1850 "%s%s" % (yunits, self.xaxis_unit)) 1830 1851 if self.yLabel == "ln(y*x^(2))": … … 1844 1865 self.graph._yaxis_transformed("%s \ \ %s^{4}" % (yname, xname), 1845 1866 "%s%s" % (yunits, xunits)) 1846 if self.viewModel == "Guinier lny vs x^(2)":1847 item.transformX(transform.toX2, transform.errToX2)1848 xunits = convert_unit(2, xunits)1849 self.graph._xaxis_transformed("%s^{2}" % xname, "%s" % xunits)1850 item.transformY(transform.toLogX, transform.errToLogX)1851 self.graph._yaxis_transformed("\ln\ \ %s" % yname, "%s" % yunits)1852 if self.viewModel == "Porod y*x^(4) vs x^(4)":1853 item.transformX(transform.toX4, transform.errToX4)1854 xunits = convert_unit(4, self.xaxis_unit)1855 self.graph._xaxis_transformed("%s^{4}" % xname, "%s" % xunits)1856 item.transformY(transform.toYX4, transform.errToYX4)1857 self.graph._yaxis_transformed("%s \ \ %s^{4}" % (yname, xname),1858 "%s%s" % (yunits, xunits))1859 1867 item.transformView() 1860 1868 … … 1894 1902 1895 1903 """ 1904 xlim = self.subplot.get_xlim() 1905 ylim = self.subplot.get_ylim() 1906 1896 1907 # Saving value to redisplay in Fit Dialog when it is opened again 1897 1908 self.Avalue, self.Bvalue, self.ErrAvalue, \ … … 1917 1928 self.graph.render(self) 1918 1929 self._offset_graph() 1930 if hasattr(self, 'plots'): 1931 # Used by Plotter1D 1932 fit_id = 'fit' 1933 self.fit_result.id = fit_id 1934 self.fit_result.title = 'Fit' 1935 self.fit_result.name = 'Fit' 1936 self.plots[fit_id] = self.fit_result 1937 self.subplot.set_xlim(xlim) 1938 self.subplot.set_ylim(ylim) 1919 1939 self.subplot.figure.canvas.draw_idle() 1920 1940 … … 1922 1942 """ 1923 1943 """ 1924 if self.parent ==None:1944 if self.parent is None: 1925 1945 return 1926 1946 # get current caption … … 1996 2016 self.toolbar.copy_figure(self.canvas) 1997 2017 except: 1998 print "Error in copy Image"2018 print("Error in copy Image") 1999 2019 2000 2020 -
src/sas/sasgui/plottools/PropertyDialog.py
rd7bb526 r959eb01 23 23 iy += 1 24 24 ix = 1 25 self.xvalue = wx.ComboBox(self, -1 )25 self.xvalue = wx.ComboBox(self, -1, style=wx.CB_READONLY) 26 26 x_size += self.xvalue.GetSize()[0] 27 sizer.Add(self.xvalue, (iy, ix), (1, 1), wx. EXPAND | wx.ADJUST_MINSIZE, 0)27 sizer.Add(self.xvalue, (iy, ix), (1, 1), wx.ADJUST_MINSIZE, 0) 28 28 29 29 ix += 2 30 self.yvalue = wx.ComboBox(self, -1 )30 self.yvalue = wx.ComboBox(self, -1, style=wx.CB_READONLY) 31 31 x_size += self.yvalue.GetSize()[0] 32 sizer.Add(self.yvalue, (iy, ix), (1, 1), wx. EXPAND | wx.ADJUST_MINSIZE, 0)32 sizer.Add(self.yvalue, (iy, ix), (1, 1), wx.ADJUST_MINSIZE, 0) 33 33 34 34 ix += 2 35 self.view = wx.ComboBox(self, -1) 35 self.view = wx.ComboBox(self, -1, style=wx.CB_READONLY) 36 self.view.Bind(wx.EVT_COMBOBOX, self.viewChanged) 36 37 x_size += self.view.GetSize()[0] 37 38 self.view.SetMinSize((160, 30)) … … 64 65 self.yvalue.Insert("ln(y)", 2) 65 66 self.yvalue.Insert("y^(2)", 3) 66 self.yvalue.Insert("y*x^(4)", 4) 67 self.yvalue.Insert("1/sqrt(y)", 5) 68 self.yvalue.Insert("log10(y)", 6) 69 self.yvalue.Insert("ln(y*x)", 7) 70 self.yvalue.Insert("ln(y*x^(2))", 8) 71 self.yvalue.Insert("ln(y*x^(4))", 9) 72 self.yvalue.Insert("log10(y*x^(4))", 10) 67 self.yvalue.Insert("y*x^(2)", 4) 68 self.yvalue.Insert("y*x^(4)", 5) 69 self.yvalue.Insert("1/sqrt(y)", 6) 70 self.yvalue.Insert("log10(y)", 7) 71 self.yvalue.Insert("ln(y*x)", 8) 72 self.yvalue.Insert("ln(y*x^(2))", 9) 73 self.yvalue.Insert("ln(y*x^(4))", 10) 74 self.yvalue.Insert("log10(y*x^(4))", 11) 73 75 # type of view or model used 74 76 self.view.SetValue("--") … … 83 85 self.Centre() 84 86 87 def viewChanged(self, event): 88 event.Skip() 89 view = self.view.GetValue() 90 if view == "Linear y vs x": 91 self.xvalue.SetValue("x") 92 self.yvalue.SetValue("y") 93 elif view == "Guinier lny vs x^(2)": 94 self.xvalue.SetValue("x^(2)") 95 self.yvalue.SetValue("ln(y)") 96 elif view == "XS Guinier ln(y*x) vs x^(2)": 97 self.xvalue.SetValue("x^(2)") 98 self.yvalue.SetValue("ln(y*x)") 99 elif view == "Porod y*x^(4) vs x^(4)": 100 self.xvalue.SetValue("x^(4)") 101 self.yvalue.SetValue("y*x^(4)") 102 elif view == "Kratky y*x^(2) vs x": 103 self.xvalue.SetValue("x") 104 self.yvalue.SetValue("y*x^(2)") 105 85 106 def setValues(self, x, y, view): 86 107 """ -
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
rd7bb526 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 … … 20 20 def format_number(value, high=False): 21 21 """ 22 Return a float in a standardized, human-readable formatted string 22 Return a float in a standardized, human-readable formatted string. 23 This is used to output readable (e.g. x.xxxe-y) values to the panel. 23 24 """ 24 25 try: … … 40 41 """ 41 42 Dialog window pops- up when select Linear fit on Context menu 42 Displays fitting parameters 43 Displays fitting parameters. This class handles the linearized 44 fitting and derives and displays specialized output parameters based 45 on the scale choice of the plot calling it. 46 47 :note1: The fitting is currently a bit convoluted as besides using 48 plottools.transform.py to handle all the conversions, it uses 49 LineModel to define a linear model and calculate a number of 50 things like residuals etc as well as the function itself given an x 51 value. It also uses fittings.py to set up the defined LineModel for 52 fitting and then send it to the SciPy NLLSQ method. As these are by 53 definition "linear nodels" it would make more sense to just call 54 a linear solver such as scipy.stats.linregress or bumps.wsolve directly. 55 This would considerably simplify the code and remove the need I think 56 for LineModel.py and possibly fittins.py altogether. -PDB 7/10/16 57 58 :note2: The linearized fits do not take resolution into account. This 59 means that for poor resolution such as slit smearing the answers will 60 be completely wrong --- Rg would be OK but I0 would be orders of 61 magnitude off. Eventually we should fix this to account properly for 62 resolution. -PDB 7/10/16 43 63 """ 44 64 wx.Dialog.__init__(self, parent, title=title, … … 50 70 # Registered owner for close event 51 71 self._registered_close = None 52 53 72 # dialog panel self call function to plot the fitting function 73 # calls the calling PlotPanel method onFitDisplay 54 74 self.push_data = push_data 55 # dialog self plottable 75 # dialog self plottable - basically the plot we are working with 76 # passed in by the caller 56 77 self.plottable = plottable 78 # is this a Guinier fit 57 79 self.rg_on = False 58 # Receive transformations of x and y 80 # Receive transformations of x and y - basically transform is passed 81 # as caller method that returns its current value for these 59 82 self.xLabel, self.yLabel, self.Avalue, self.Bvalue, \ 60 83 self.ErrAvalue, self.ErrBvalue, self.Chivalue = self.transform() 61 84 62 # Dialog interface 85 # Now set up the dialog interface 86 self.layout() 87 # Receives the type of model for the fitting 88 from LineModel import LineModel 89 self.model = LineModel() 90 # Display the fittings values 91 self.default_A = self.model.getParam('A') 92 self.default_B = self.model.getParam('B') 93 self.cstA = fittings.Parameter(self.model, 'A', self.default_A) 94 self.cstB = fittings.Parameter(self.model, 'B', self.default_B) 95 96 # Set default value of parameter in the dialog panel 97 if self.Avalue is None: 98 self.tcA.SetValue(format_number(self.default_A)) 99 else: 100 self.tcA.SetLabel(format_number(self.Avalue)) 101 if self.Bvalue is None: 102 self.tcB.SetValue(format_number(self.default_B)) 103 else: 104 self.tcB.SetLabel(format_number(self.Bvalue)) 105 if self.ErrAvalue is None: 106 self.tcErrA.SetLabel(format_number(0.0)) 107 else: 108 self.tcErrA.SetLabel(format_number(self.ErrAvalue)) 109 if self.ErrBvalue is None: 110 self.tcErrB.SetLabel(format_number(0.0)) 111 else: 112 self.tcErrB.SetLabel(format_number(self.ErrBvalue)) 113 if self.Chivalue is None: 114 self.tcChi.SetLabel(format_number(0.0)) 115 else: 116 self.tcChi.SetLabel(format_number(self.Chivalue)) 117 if self.plottable.x != []: 118 # store the values of View in self.x,self.y,self.dx,self.dy 119 self.x, self.y, self.dx, \ 120 self.dy = self.plottable.returnValuesOfView() 121 try: 122 self.mini = self.floatForwardTransform(min(self.x)) 123 except: 124 self.mini = "Invalid" 125 try: 126 self.maxi = self.floatForwardTransform(max(self.x)) 127 except: 128 self.maxi = "Invalid" 129 130 self.initXmin.SetValue(format_number(min(self.plottable.x))) 131 self.initXmax.SetValue(format_number(max(self.plottable.x))) 132 self.mini = min(self.x) 133 self.maxi = max(self.x) 134 self.xminFit.SetValue(format_number(self.mini)) 135 self.xmaxFit.SetValue(format_number(self.maxi)) 136 137 def layout(self): 138 """ 139 Sets up the panel layout for the linear fit including all the 140 labels, text entry boxes, and buttons. 141 142 """ 143 144 # set up sizers first. 145 # vbox is the panel sizer and is a vertical sizer 146 # The first element of the panel is sizer which is a gridbagsizer 147 # and contains most of the text fields 148 # this is followed by a line separator added to vbox 149 # and finally the sizer_button (a horizontal sizer) adds the buttons 63 150 vbox = wx.BoxSizer(wx.VERTICAL) 64 151 sizer = wx.GridBagSizer(5, 5) 152 sizer_button = wx.BoxSizer(wx.HORIZONTAL) 153 154 #size of string boxes in pixels 65 155 _BOX_WIDTH = 100 66 67 self.tcA = wx.TextCtrl(self, -1, size=(_BOX_WIDTH, 20)) 156 _BOX_HEIGHT = 20 157 #now set up all the text fields 158 self.tcA = wx.TextCtrl(self, -1, size=(_BOX_WIDTH, _BOX_HEIGHT)) 68 159 self.tcA.SetToolTipString("Fit value for the slope parameter.") 69 self.tcErrA = wx.TextCtrl(self, -1, size=(_BOX_WIDTH, 20))160 self.tcErrA = wx.TextCtrl(self, -1, size=(_BOX_WIDTH, _BOX_HEIGHT)) 70 161 self.tcErrA.SetToolTipString("Error on the slope parameter.") 71 self.tcB = wx.TextCtrl(self, -1, size=(_BOX_WIDTH, 20))162 self.tcB = wx.TextCtrl(self, -1, size=(_BOX_WIDTH, _BOX_HEIGHT)) 72 163 self.tcA.SetToolTipString("Fit value for the constant parameter.") 73 self.tcErrB = wx.TextCtrl(self, -1, size=(_BOX_WIDTH, 20))164 self.tcErrB = wx.TextCtrl(self, -1, size=(_BOX_WIDTH, _BOX_HEIGHT)) 74 165 self.tcErrB.SetToolTipString("Error on the constant parameter.") 75 self.tcChi = wx.TextCtrl(self, -1, size=(_BOX_WIDTH, 20))166 self.tcChi = wx.TextCtrl(self, -1, size=(_BOX_WIDTH, _BOX_HEIGHT)) 76 167 self.tcChi.SetToolTipString("Chi^2 over degrees of freedom.") 77 self.xminFit = wx.TextCtrl(self, -1, size=(_BOX_WIDTH, 20))168 self.xminFit = wx.TextCtrl(self, -1, size=(_BOX_WIDTH, _BOX_HEIGHT)) 78 169 msg = "Enter the minimum value on " 79 170 msg += "the x-axis to be included in the fit." 80 171 self.xminFit.SetToolTipString(msg) 81 self.xmaxFit = wx.TextCtrl(self, -1, size=(_BOX_WIDTH, 20))172 self.xmaxFit = wx.TextCtrl(self, -1, size=(_BOX_WIDTH, _BOX_HEIGHT)) 82 173 msg = "Enter the maximum value on " 83 174 msg += " the x-axis to be included in the fit." 84 175 self.xmaxFit.SetToolTipString(msg) 85 self.initXmin = wx.TextCtrl(self, -1, size=(_BOX_WIDTH, 20))176 self.initXmin = wx.TextCtrl(self, -1, size=(_BOX_WIDTH, _BOX_HEIGHT)) 86 177 msg = "Minimum value on the x-axis for the plotted data." 87 178 self.initXmin.SetToolTipString(msg) 88 self.initXmax = wx.TextCtrl(self, -1, size=(_BOX_WIDTH, 20))179 self.initXmax = wx.TextCtrl(self, -1, size=(_BOX_WIDTH, _BOX_HEIGHT)) 89 180 msg = "Maximum value on the x-axis for the plotted data." 90 181 self.initXmax.SetToolTipString(msg) … … 98 189 self.initXmax.SetBackgroundColour(_BACKGROUND_COLOR) 99 190 100 # Buttons on the bottom 191 #set some flags for specific types of fits like Guinier (Rg) and 192 #Porod (bg) -- this will determine WHAT boxes show up in the 193 #sizer layout and depends on the active axis transform 101 194 self.bg_on = False 102 self.static_line_1 = wx.StaticLine(self, -1)103 self.btFit = wx.Button(self, -1, 'Fit')104 self.btFit.Bind(wx.EVT_BUTTON, self._onFit)105 self.btFit.SetToolTipString("Perform fit.")106 self.btClose = wx.Button(self, wx.ID_CANCEL, 'Close')107 self.btClose.Bind(wx.EVT_BUTTON, self._on_close)108 195 if RG_ON: 109 196 if (self.yLabel == "ln(y)" or self.yLabel == "ln(y*x)") and \ … … 112 199 if (self.xLabel == "x^(4)") and (self.yLabel == "y*x^(4)"): 113 200 self.bg_on = True 114 # Intro 115 explanation = "Perform fit for y(x) = ax + b" 201 202 # Finally set up static text strings 203 warning = "WARNING! Resolution is NOT accounted for. \n" 204 warning += "Thus slit smeared data will give very wrong answers!" 205 self.textwarn = wx.StaticText(self, -1, warning) 206 self.textwarn.SetForegroundColour(wx.RED) 207 explanation = "Perform fit for y(x) = ax + b \n" 116 208 if self.bg_on: 117 209 param_a = 'Background (= Parameter a)' 118 210 else: 119 211 param_a = 'Parameter a' 120 vbox.Add(sizer) 212 213 214 #Now set this all up in the GridBagSizer sizer 121 215 ix = 0 122 iy = 1 216 iy = 0 217 sizer.Add(self.textwarn, (iy, ix), 218 (2, 3), wx.LEFT | wx.EXPAND | wx.ADJUST_MINSIZE, 15) 219 iy += 2 123 220 sizer.Add(wx.StaticText(self, -1, explanation), (iy, ix), 124 221 (1, 1), wx.LEFT | wx.EXPAND | wx.ADJUST_MINSIZE, 15) 125 iy += 2222 iy += 1 126 223 sizer.Add(wx.StaticText(self, -1, param_a), (iy, ix), 127 224 (1, 1), wx.LEFT | wx.EXPAND | wx.ADJUST_MINSIZE, 15) … … 281 378 wx.LEFT | wx.EXPAND | wx.ADJUST_MINSIZE, 0) 282 379 380 #Now add some space before the separation line 283 381 iy += 1 284 ix = 1 285 286 vbox.Add(self.static_line_1, 0, wx.EXPAND, 0) 287 sizer_button = wx.BoxSizer(wx.HORIZONTAL) 382 ix = 0 383 sizer.Add((20,20), (iy, ix), (1, 1), 384 wx.LEFT | wx.EXPAND | wx.ADJUST_MINSIZE, 0) 385 386 # Buttons on the bottom 387 self.btFit = wx.Button(self, -1, 'Fit') 388 self.btFit.Bind(wx.EVT_BUTTON, self._onFit) 389 self.btFit.SetToolTipString("Perform fit.") 390 self.btClose = wx.Button(self, wx.ID_CANCEL, 'Close') 391 self.btClose.Bind(wx.EVT_BUTTON, self._on_close) 288 392 sizer_button.Add((20, 20), 1, wx.EXPAND | wx.ADJUST_MINSIZE, 0) 289 sizer_button.Add(self.btFit, 0, wx.LEFT | wx.RIGHT | wx.ADJUST_MINSIZE, 10) 393 sizer_button.Add(self.btFit, 0, 394 wx.LEFT | wx.RIGHT | wx.ADJUST_MINSIZE, 10) 290 395 sizer_button.Add(self.btClose, 0, 291 396 wx.LEFT | wx.RIGHT | wx.ADJUST_MINSIZE, 10) 397 398 vbox.Add(sizer) 399 self.static_line_1 = wx.StaticLine(self, -1) 400 vbox.Add(self.static_line_1, 0, wx.EXPAND, 0) 292 401 vbox.Add(sizer_button, 0, wx.EXPAND | wx.BOTTOM | wx.TOP, 10) 293 402 294 sizer.Add(self.btFit, (iy, ix), (1, 1), wx.LEFT | wx.ADJUST_MINSIZE, 0)295 403 # panel.SetSizer(sizer) 296 404 self.SetSizer(vbox) 297 405 self.Centre() 298 # Receives the type of model for the fitting299 from LineModel import LineModel300 self.model = LineModel()301 # Display the fittings values302 self.default_A = self.model.getParam('A')303 self.default_B = self.model.getParam('B')304 self.cstA = fittings.Parameter(self.model, 'A', self.default_A)305 self.cstB = fittings.Parameter(self.model, 'B', self.default_B)306 307 # Set default value of parameter in fit dialog308 if self.Avalue == None:309 self.tcA.SetValue(format_number(self.default_A))310 else:311 self.tcA.SetLabel(format_number(self.Avalue))312 if self.Bvalue == None:313 self.tcB.SetValue(format_number(self.default_B))314 else:315 self.tcB.SetLabel(format_number(self.Bvalue))316 if self.ErrAvalue == None:317 self.tcErrA.SetLabel(format_number(0.0))318 else:319 self.tcErrA.SetLabel(format_number(self.ErrAvalue))320 if self.ErrBvalue == None:321 self.tcErrB.SetLabel(format_number(0.0))322 else:323 self.tcErrB.SetLabel(format_number(self.ErrBvalue))324 if self.Chivalue == None:325 self.tcChi.SetLabel(format_number(0.0))326 else:327 self.tcChi.SetLabel(format_number(self.Chivalue))328 if self.plottable.x != []:329 # store the values of View in self.x,self.y,self.dx,self.dy330 self.x, self.y, self.dx, \331 self.dy = self.plottable.returnValuesOfView()332 try:333 self.mini = self.floatForwardTransform(min(self.x))334 except:335 self.mini = "Invalid"336 try:337 self.maxi = self.floatForwardTransform(max(self.x))338 except:339 self.maxi = "Invalid"340 341 self.initXmin.SetValue(format_number(min(self.plottable.x)))342 self.initXmax.SetValue(format_number(max(self.plottable.x)))343 self.mini = min(self.x)344 self.maxi = max(self.x)345 self.xminFit.SetValue(format_number(self.mini))346 self.xmaxFit.SetValue(format_number(self.maxi))347 406 348 407 def register_close(self, owner): … … 371 430 the button Fit.Computes chisqr , 372 431 A and B parameters of the best linear fit y=Ax +B 373 Push a plottable to 432 Push a plottable to the caller 374 433 """ 375 434 tempx = [] … … 389 448 xmin = xminView 390 449 xmax = xmaxView 450 # Set the qmin and qmax in the panel that matches the 451 # transformed min and max 452 self.initXmin.SetValue(format_number(self.floatInvTransform(xmin))) 453 self.initXmax.SetValue(format_number(self.floatInvTransform(xmax))) 391 454 # Store the transformed values of view x, y,dy 392 455 # in variables before the fit … … 419 482 420 483 if self.xLabel.lower() == "log10(x)": 421 tempdy = n umpy.asarray(tempdy)484 tempdy = np.asarray(tempdy) 422 485 tempdy[tempdy == 0] = 1 423 486 chisqr, out, cov = fittings.sasfit(self.model, … … 428 491 math.log10(xmax)) 429 492 else: 430 tempdy = n umpy.asarray(tempdy)493 tempdy = np.asarray(tempdy) 431 494 tempdy[tempdy == 0] = 1 432 495 chisqr, out, cov = fittings.sasfit(self.model, … … 439 502 440 503 # Check that cov and out are iterable before displaying them 441 if cov ==None:504 if cov is None: 442 505 errA = 0.0 443 506 errB = 0.0 … … 445 508 errA = math.sqrt(cov[0][0]) 446 509 errB = math.sqrt(cov[1][1]) 447 if out ==None:510 if out is None: 448 511 cstA = 0.0 449 512 cstB = 0.0 … … 485 548 tempy.append(y_model) 486 549 # Set the fit parameter display when FitDialog is opened again 487 self.Avalue = cst B488 self.Bvalue = cst A550 self.Avalue = cstA 551 self.Bvalue = cstB 489 552 self.ErrAvalue = errA 490 553 self.ErrBvalue = errB … … 494 557 495 558 # Display the fitting value on the Fit Dialog 496 self._onsetValues(cst B, cstA, errA, errB, chisqr)559 self._onsetValues(cstA, cstB, errA, errB, chisqr) 497 560 498 561 def _onsetValues(self, cstA, cstB, errA, errB, Chi): … … 501 564 """ 502 565 rg = None 566 _diam = None 503 567 self.tcA.SetValue(format_number(cstA)) 504 568 self.tcB.SetValue(format_number(cstB)) … … 508 572 if self.rg_on: 509 573 if self.Rg_tctr.IsShown(): 510 rg = n umpy.sqrt(-3 * float(cstA))574 rg = np.sqrt(-3 * float(cstA)) 511 575 value = format_number(rg) 512 576 self.Rg_tctr.SetValue(value) 513 577 if self.I0_tctr.IsShown(): 514 val = n umpy.exp(cstB)578 val = np.exp(cstB) 515 579 self.I0_tctr.SetValue(format_number(val)) 516 580 if self.Rgerr_tctr.IsShown(): 517 if rg !=None and rg != 0:518 value = format_number(3 * float( cstA) / (2 * rg))581 if rg is not None and rg != 0: 582 value = format_number(3 * float(errA) / (2 * rg)) 519 583 else: 520 584 value = '' 521 585 self.Rgerr_tctr.SetValue(value) 522 586 if self.I0err_tctr.IsShown(): 523 val = n umpy.abs(numpy.exp(cstB) - numpy.exp(cstB + errB))587 val = np.abs(np.exp(cstB) * errB) 524 588 self.I0err_tctr.SetValue(format_number(val)) 525 589 if self.Diameter_tctr.IsShown(): 526 rg = 4 * numpy.sqrt(-float(cstA)) 527 value = format_number(rg) 590 rg = np.sqrt(-2 * float(cstA)) 591 _diam = 4 * np.sqrt(-float(cstA)) 592 value = format_number(_diam) 528 593 self.Diameter_tctr.SetValue(value) 529 594 if self.Diametererr_tctr.IsShown(): 530 if rg !=None and rg != 0:531 value = format_number(8 * float( cstA) / rg)595 if rg is not None and rg != 0: 596 value = format_number(8 * float(errA) / _diam) 532 597 else: 533 598 value = '' 534 599 self.Diametererr_tctr.SetValue(value) 535 600 if self.RgQmin_tctr.IsShown(): 536 value = format_number(rg * self. mini)601 value = format_number(rg * self.floatInvTransform(self.mini)) 537 602 self.RgQmin_tctr.SetValue(value) 538 603 if self.RgQmax_tctr.IsShown(): 539 value = format_number(rg * self. maxi)604 value = format_number(rg * self.floatInvTransform(self.maxi)) 540 605 self.RgQmax_tctr.SetValue(value) 541 606 … … 610 675 def floatInvTransform(self, x): 611 676 """ 612 transform a float.It is use to determine the x.View min and x.View 613 max for values not in x 677 transform a float.It is used to determine the x.View min and x.View 678 max for values not in x. Also used to properly calculate RgQmin, 679 RgQmax and to update qmin and qmax in the linear range boxes on the 680 panel. 614 681 615 682 """ … … 617 684 # functionality work without rewritting the whole code 618 685 # with good design (which really should be done...). 619 if self.xLabel == "x^(2)": 686 if self.xLabel == "x": 687 return x 688 elif self.xLabel == "x^(2)": 620 689 return math.sqrt(x) 690 elif self.xLabel == "x^(4)": 691 return math.sqrt(math.sqrt(x)) 621 692 elif self.xLabel == "log10(x)": 622 693 return math.pow(10, x) 623 694 elif self.xLabel == "ln(x)": 624 695 return math.exp(x) 696 elif self.xLabel == "log10(x^(4))": 697 return math.sqrt(math.sqrt(math.pow(10, x))) 625 698 return x 626 699 -
src/sas/sasgui/plottools/fittings.py
rd7bb526 ra1b8fee 1 1 """ 2 This module is used to fit a set of x,y data to a model passed to it. It is 3 used to calculate the slope and intercepts for the linearized fits. Two things 4 should be noted: 5 6 First, this fitting module uses the NLLSQ module of SciPy rather than a linear 7 fit. This along with a few other modules could probably be removed if we 8 move to a linear regression approach. 9 10 Second, this infrastructure does not allow for resolution smearing of the 11 the models. Hence the results are not that accurate even for pinhole 12 collimation of SANS but may be good for SAXS. It is completely wrong for 13 slit smeared data. 14 2 15 """ 16 from __future__ import print_function 17 3 18 from scipy import optimize 4 19 … … 6 21 class Parameter(object): 7 22 """ 8 Class to handle model parameters 23 Class to handle model parameters - sets the parameters and their 24 initial value from the model based to it. 9 25 """ 10 26 def __init__(self, model, name, value=None): 11 27 self.model = model 12 28 self.name = name 13 if not value ==None:29 if value is not None: 14 30 self.model.setParam(self.name, value) 15 31 … … 92 108 chisqr, out, cov = sasfit(line, [cstA, cstB], event.x, y, 0) 93 109 # print "Output parameters:", out 94 print "The right answer is [70.0, 1.0]"95 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
rcd54205 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__): … … 212 214 self.color += plottable.colors() 213 215 self.plottables[plottable] = self.color 216 plottable.custom_color = self.color 214 217 215 218 def changed(self): … … 226 229 if p.hidden == True: 227 230 continue 228 if not p.x ==None:231 if p.x is not None: 229 232 for x_i in p.x: 230 if min_value ==None or x_i < min_value:233 if min_value is None or x_i < min_value: 231 234 min_value = x_i 232 if max_value ==None or x_i > max_value:235 if max_value is None or x_i > max_value: 233 236 max_value = x_i 234 237 return min_value, max_value … … 559 562 Returns True if there is no data stored in the plottable 560 563 """ 561 if not self.x == None and len(self.x) == 0 \562 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): 563 566 return True 564 567 return False … … 676 679 # Sanity check 677 680 # Do the transofrmation only when x and y are empty 678 has_err_x = not (dx ==None or len(dx) == 0)679 has_err_y = not (dy ==None or len(dy) == 0)680 681 if(x != None) and (y !=None):682 if not dx ==None and not len(dx) == 0 and not len(x) == len(dx):681 has_err_x = not (dx is None or len(dx) == 0) 682 has_err_y = not (dy is None or len(dy) == 0) 683 684 if(x is not None) and (y is not None): 685 if dx is not None and not len(dx) == 0 and not len(x) == len(dx): 683 686 msg = "Plottable.View: Given x and dx are not" 684 687 msg += " of the same length" … … 690 693 raise ValueError, msg 691 694 692 if not dy ==None 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): 693 696 msg = "Plottable.View: Given y and dy are not of the same " 694 697 msg += "length: len(y)=%s, len(dy)=%s" % (len(y), len(dy)) … … 705 708 self.dy = None 706 709 if not has_err_x: 707 dx = n umpy.zeros(len(x))710 dx = np.zeros(len(x)) 708 711 if not has_err_y: 709 dy = n umpy.zeros(len(y))712 dy = np.zeros(len(y)) 710 713 for i in range(len(x)): 711 714 try: … … 794 797 tempy = [] 795 798 tempdy = [] 796 if self.dx ==None:797 self.dx = n umpy.zeros(len(self.x))798 if self.dy ==None:799 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)) 800 803 if self.xLabel == "log10(x)": 801 804 for i in range(len(self.x)): … … 807 810 tempdy.append(self.dy[i]) 808 811 except: 809 logg ing.error("check_data_logX: skipping point x %g", self.x[i])810 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) 811 814 self.x = tempx 812 815 self.y = tempy … … 824 827 tempy = [] 825 828 tempdy = [] 826 if self.dx ==None:827 self.dx = n umpy.zeros(len(self.x))828 if self.dy ==None:829 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)) 830 833 if self.yLabel == "log10(y)": 831 834 for i in range(len(self.x)): … … 837 840 tempdy.append(self.dy[i]) 838 841 except: 839 logg ing.error("check_data_logY: skipping point %g", self.y[i])840 logg ing.error(sys.exc_value)842 logger.error("check_data_logY: skipping point %g", self.y[i]) 843 logger.error(sys.exc_value) 841 844 842 845 self.x = tempx … … 857 860 tempy = [] 858 861 tempdy = [] 859 if self.dx ==None:860 self.dx = n umpy.zeros(len(self.x))861 if self.dy ==None:862 self.dy = n umpy.zeros(len(self.y))863 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: 864 867 for i in range(len(self.x)): 865 868 if self.x[i] >= xmin and self.x[i] <= xmax: … … 1022 1025 """ 1023 1026 1024 def __init__(self, x, y, dx=None, dy=None ):1027 def __init__(self, x, y, dx=None, dy=None, lam=None, dlam=None): 1025 1028 """ 1026 1029 Draw points specified by x[i],y[i] in the current color/symbol. … … 1036 1039 self.x = x 1037 1040 self.y = y 1041 self.lam = lam 1038 1042 self.dx = dx 1039 1043 self.dy = dy 1044 self.dlam = dlam 1040 1045 self.source = None 1041 1046 self.detector = None … … 1201 1206 """ 1202 1207 """ 1203 if self._chisq ==None:1208 if self._chisq is None: 1204 1209 chisqTxt = r'$\chi^2=$' 1205 1210 else: … … 1225 1230 1226 1231 def sample_graph(): 1227 import numpy as n x1232 import numpy as np 1228 1233 1229 1234 # Construct a simple graph 1230 1235 if False: 1231 x = n x.array([1, 2, 3, 4, 5, 6], 'd')1232 y = n x.array([4, 5, 6, 5, 4, 5], 'd')1233 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]) 1234 1239 else: 1235 x = n x.linspace(0, 1., 10000)1236 y = n x.sin(2 * nx.pi * x * 2.8)1237 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 1238 1243 data = Data1D(x, y, dy=dy) 1239 1244 data.xaxis('distance', 'm') -
src/sas/sasgui/plottools/toolbar.py
rd7bb526 r959eb01 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 … … 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): -
src/sas/sasgui/plottools/transform.py
rd7bb526 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 … … 291 291 292 292 293 def errToYX2( x, y, dx=None, dy=None):294 """ 295 """ 296 if dx ==None:297 dx = 0 298 if dy ==None:293 def errToYX2(y, x, dy=None, dx=None): 294 """ 295 """ 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 … … 325 325 326 326 327 def errToLogYX2( x, y, dx=None, dy=None):327 def errToLogYX2(y, x, dy=None, dx=None): 328 328 """ 329 329 calculate error of Log(yx**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 … … 375 375 376 376 377 def errToLogYX4( x, y=None, dx=None, dy=None):377 def errToLogYX4(y, x, dy=None, dx=None): 378 378 """ 379 379 error for ln(y*x^(4)) … … 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) … … 396 396 397 397 398 def errToYX4( x, y=None, dx=None, dy=None):398 def errToYX4(y, x, dy=None, dx=None): 399 399 """ 400 400 error for (y*x^(4)) … … 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/__init__.py
rd7bb526 refe730d 1 import config2 1 from PlotPanel import PlotPanel 3 2 from plottables import Data1D, Theory1D
Note: See TracChangeset
for help on using the changeset viewer.