Changeset 914ba0a in sasview for src/sas/sasgui/plottools


Ignore:
Timestamp:
May 2, 2017 3:58:01 PM (8 years ago)
Author:
Paul Kienzle <pkienzle@…>
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.
Message:

merge with master

Location:
src/sas/sasgui/plottools
Files:
1 added
15 edited

Legend:

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

    rd7bb526 r959eb01  
    11#!/usr/bin/env python 
    22""" 
    3 Provide Line function (y= A + Bx) 
     3Provide 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  
     5assumed (y= mx+b) or in this nomenclature (y=Ax + B). This lead to some 
     6contortions in the code and worse incorrect calculations until now for at least 
     7some of the functions.  This seemed the easiest to fix particularly since this 
     8function should disappear in a future iteration (see notes in fitDialog) 
     9 
     10PDB   July 10, 2016 
     11 
    412""" 
    513 
     
    1018    Class that evaluates a linear model. 
    1119 
    12     f(x) = A + Bx 
     20    f(x) = Ax + B 
    1321 
    1422    List of default parameters: 
    15     A = 0.0 
    16     B = 0.0 
     23    A = 1.0 
     24    B = 1.0 
    1725    """ 
    1826 
     
    5361 
    5462        """ 
    55         return  self.params['A'] + (x * self.params['B']) 
     63        return  (self.params['A'] * x) + self.params['B'] 
    5664 
    5765    def run(self, x=0.0): 
    5866        """ 
    5967        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  
    6074 
    6175        :param x: simple value 
     
    7488    def runXY(self, x=0.0): 
    7589        """ 
    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  
    7796 
    7897        :param x: simple value 
  • src/sas/sasgui/plottools/PlotPanel.py

    r16b769b ra1b8fee  
    22    Plot panel. 
    33""" 
     4from __future__ import print_function 
     5 
    46import logging 
    57import traceback 
     
    1517import os 
    1618import transform 
    17 from plottables import Data1D 
    1819#TODO: make the plottables interactive 
    1920from binder import BindArtist 
     
    3031DEFAULT_CMAP = pylab.cm.jet 
    3132import copy 
    32 import numpy 
     33import numpy as np 
    3334 
    3435from sas.sasgui.guiframe.events import StatusEvent 
    3536from .toolbar import NavigationToolBar, PlotPrintout, bind 
    3637 
     38logger = logging.getLogger(__name__) 
     39 
    3740def show_tree(obj, d=0): 
    3841    """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__)) 
    4043    if 'get_children' in dir(obj): 
    4144        for a in obj.get_children(): show_tree(a, d + 1) 
     
    151154        #List of texts currently on the plot 
    152155        self.textList = [] 
     156        self.selectedText = None 
    153157        #User scale 
    154         if xtransform != None: 
     158        if xtransform is not None: 
    155159            self.xLabel = xtransform 
    156160        else: 
    157161            self.xLabel = "log10(x)" 
    158         if ytransform != None: 
     162        if ytransform is not None: 
    159163            self.yLabel = ytransform 
    160164        else: 
     
    190194 
    191195        # new data for the fit 
     196        from sas.sasgui.guiframe.dataFitting import Data1D 
    192197        self.fit_result = Data1D(x=[], y=[], dy=None) 
    193198        self.fit_result.symbol = 13 
     
    352357            self.leftdown = True 
    353358            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: 
    355365                self.xInit, self.yInit = event.xdata, event.ydata 
    356366                try: 
     
    373383            self.mousemotion = False 
    374384            self.leftup = True 
     385            self.selectedText = None 
    375386 
    376387        #release the legend 
     
    383394        Set legend alpha 
    384395        """ 
    385         if self.legend != None: 
     396        if self.legend is not None: 
    386397            self.legend.legendPatch.set_alpha(alpha) 
    387398 
     
    409420        """ 
    410421        ax = event.inaxes 
    411         if ax == None: 
     422        if ax is None: 
    412423            return 
    413424        # Event occurred inside a plotting area 
     
    445456        """ 
    446457        self.cusor_line(event) 
    447         if self.gotLegend == 1: 
     458        if self.gotLegend == 1 and self.leftdown: 
    448459            self._on_legend_motion(event) 
    449460            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 
    450474        if self.enable_toolbar: 
    451475            #Disable dragging without the toolbar to allow zooming with toolbar 
     
    454478        if self.leftdown == True and self.mousemotion == True: 
    455479            ax = event.inaxes 
    456             if ax != None:  # the dragging is perform inside the figure 
     480            if ax is not None:  # the dragging is perform inside the figure 
    457481                self.xFinal, self.yFinal = event.xdata, event.ydata 
    458482                # Check whether this is the first point 
    459                 if self.xInit == None: 
     483                if self.xInit is None: 
    460484                    self.xInit = self.xFinal 
    461485                    self.yInit = self.yFinal 
     
    554578        step = event.step 
    555579 
    556         if ax != None: 
     580        if ax is not None: 
    557581            # Event occurred inside a plotting area 
    558582            lo, hi = ax.get_xlim() 
     
    646670                dlg.setFitRange(self.xminView, self.xmaxView, 
    647671                                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 
    648681            dlg.ShowModal() 
    649682 
     
    708741                if dial.ShowModal() == wx.ID_OK: 
    709742                    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) 
    730743                    self._onEVT_FUNC_PROPERTY() 
    731744                dial.Destroy() 
     
    924937        # reset postion 
    925938        self.position = None 
    926         if self.graph.selected_plottable != None: 
     939        if self.graph.selected_plottable is not None: 
    927940            self.graph.selected_plottable = None 
    928941 
     
    948961                                              prop=FontProperties(size=10), 
    949962                                              loc=self.legendLoc) 
    950             if self.legend != None: 
     963            if self.legend is not None: 
    951964                self.legend.set_picker(self.legend_picker) 
    952965                self.legend.set_axes(self.subplot) 
     
    978991                                          prop=FontProperties(size=10), 
    979992                                          loc=self.legendLoc) 
    980         if self.legend != None: 
     993        if self.legend is not None: 
    981994            self.legend.set_picker(self.legend_picker) 
    982995            self.legend.set_axes(self.subplot) 
     
    9991012        pos_x = 0 
    10001013        pos_y = 0 
    1001         if self.position != None: 
     1014        if self.position is not None: 
    10021015            pos_x, pos_y = self.position 
    10031016        else: 
     
    10241037                    self.subplot.figure.canvas.draw_idle() 
    10251038            except: 
    1026                 if self.parent != None: 
     1039                if self.parent is not None: 
    10271040                    msg = "Add Text: Error. Check your property values..." 
    10281041                    wx.PostEvent(self.parent, StatusEvent(status=msg)) 
     
    10581071            self.xaxis_tick = xaxis_font 
    10591072 
    1060         if self.data != None: 
     1073        if self.data is not None: 
    10611074            # 2D 
    10621075            self.xaxis(self.xaxis_label, self.xaxis_unit, \ 
     
    11051118            self.yaxis_tick = yaxis_font 
    11061119 
    1107         if self.data != None: 
     1120        if self.data is not None: 
    11081121            # 2D 
    11091122            self.yaxis(self.yaxis_label, self.yaxis_unit, \ 
     
    11441157                label_temp = textdial.getText() 
    11451158                if label_temp.count("\%s" % "\\") > 0: 
    1146                     if self.parent != None: 
     1159                    if self.parent is not None: 
    11471160                        msg = "Add Label: Error. Can not use double '\\' " 
    11481161                        msg += "characters..." 
     
    11511164                    label = label_temp 
    11521165            except: 
    1153                 if self.parent != None: 
     1166                if self.parent is not None: 
    11541167                    msg = "Add Label: Error. Check your property values..." 
    11551168                    wx.PostEvent(self.parent, StatusEvent(status=msg)) 
     
    11691182        num_text = len(self.textList) 
    11701183        if num_text < 1: 
    1171             if self.parent != None: 
     1184            if self.parent is not None: 
    11721185                msg = "Remove Text: Nothing to remove.  " 
    11731186                wx.PostEvent(self.parent, StatusEvent(status=msg)) 
     
    11791192            text_remove = txt.get_text() 
    11801193            txt.remove() 
    1181             if self.parent != None: 
     1194            if self.parent is not None: 
    11821195                msg = "Removed Text: '%s'. " % text_remove 
    11831196                wx.PostEvent(self.parent, StatusEvent(status=msg)) 
    11841197        except: 
    1185             if self.parent != None: 
     1198            if self.parent is not None: 
    11861199                msg = "Remove Text: Error occurred. " 
    11871200                wx.PostEvent(self.parent, StatusEvent(status=msg)) 
     
    12061219 
    12071220        # Properties defined by plot 
    1208          
     1221 
    12091222        # Ricardo: 
    1210         # A empty label "$$" will prevent the panel from displaying!  
    1211          
     1223        # A empty label "$$" will prevent the panel from displaying! 
    12121224        if prop["xlabel"]: 
    12131225            self.subplot.set_xlabel(r"$%s$"%prop["xlabel"]) 
     
    12151227            self.subplot.set_ylabel(r"$%s$"%prop["ylabel"]) 
    12161228        self.subplot.set_title(prop["title"]) 
    1217          
     1229 
    12181230 
    12191231    def clear(self): 
     
    12401252                                        prop=FontProperties(size=10), 
    12411253                                        loc=self.legendLoc) 
    1242                 if self.legend != None: 
     1254                if self.legend is not None: 
    12431255                    self.legend.set_picker(self.legend_picker) 
    12441256                    self.legend.set_axes(self.subplot) 
     
    12691281        if font: 
    12701282            self.subplot.set_xlabel(label, fontproperties=font, color=color) 
    1271             if t_font != None: 
     1283            if t_font is not None: 
    12721284                for tick in self.subplot.xaxis.get_major_ticks(): 
    12731285                    tick.label.set_fontproperties(t_font) 
     
    12901302        if font: 
    12911303            self.subplot.set_ylabel(label, fontproperties=font, color=color) 
    1292             if t_font != None: 
     1304            if t_font is not None: 
    12931305                for tick_label in self.subplot.get_yticklabels(): 
    12941306                    tick_label.set_fontproperties(t_font) 
     
    13171329        from plottable_interactor import PointInteractor 
    13181330        p = PointInteractor(self, self.subplot, zorder=zorder, id=id) 
    1319         if p.markersize != None: 
     1331        if p.markersize is not None: 
    13201332            markersize = p.markersize 
    13211333        p.points(x, y, dx=dx, dy=dy, color=color, symbol=symbol, zorder=zorder, 
     
    13531365 
    13541366        # 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(()): 
    13561368            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(()): 
    13581370            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: 
    13601372            self.subplot.plot(x, y, color=self._color(color), 
    13611373                              marker=self._symbol(symbol), 
     
    13931405        if self.scale == 'log_{10}': 
    13941406            self.scale = 'linear' 
    1395             if not self.zmin_2D is None: 
     1407            if self.zmin_2D is not None: 
    13961408                zmin_2D_temp = math.pow(10, self.zmin_2D) 
    1397             if not self.zmax_2D is None: 
     1409            if self.zmax_2D is not None: 
    13981410                zmax_2D_temp = math.pow(10, self.zmax_2D) 
    13991411        else: 
    14001412            self.scale = 'log_{10}' 
    1401             if not self.zmin_2D is None: 
     1413            if self.zmin_2D is not None: 
    14021414                # min log value: no log(negative) 
    14031415                if self.zmin_2D <= 0: 
     
    14051417                else: 
    14061418                    zmin_2D_temp = math.log10(self.zmin_2D) 
    1407             if not self.zmax_2D is None: 
     1419            if self.zmax_2D is not None: 
    14081420                zmax_2D_temp = math.log10(self.zmax_2D) 
    14091421 
     
    14331445        c = self._color(color) 
    14341446        # If we don't have any data, skip. 
    1435         if self.data == None: 
     1447        if self.data is None: 
    14361448            return 
    14371449        if self.data.ndim == 1: 
     
    14441456                if  self.zmin_2D <= 0  and len(output[output > 0]) > 0: 
    14451457                    zmin_temp = self.zmin_2D 
    1446                     output[output > 0] = numpy.log10(output[output > 0]) 
     1458                    output[output > 0] = np.log10(output[output > 0]) 
    14471459                    #In log scale Negative values are not correct in general 
    1448                     #output[output<=0] = math.log(numpy.min(output[output>0])) 
     1460                    #output[output<=0] = math.log(np.min(output[output>0])) 
    14491461                elif self.zmin_2D <= 0: 
    14501462                    zmin_temp = self.zmin_2D 
    1451                     output[output > 0] = numpy.zeros(len(output)) 
     1463                    output[output > 0] = np.zeros(len(output)) 
    14521464                    output[output <= 0] = -32 
    14531465                else: 
    14541466                    zmin_temp = self.zmin_2D 
    1455                     output[output > 0] = numpy.log10(output[output > 0]) 
     1467                    output[output > 0] = np.log10(output[output > 0]) 
    14561468                    #In log scale Negative values are not correct in general 
    1457                     #output[output<=0] = math.log(numpy.min(output[output>0])) 
     1469                    #output[output<=0] = math.log(np.min(output[output>0])) 
    14581470            except: 
    14591471                #Too many problems in 2D plot with scale 
     
    14841496            X = self.x_bins[0:-1] 
    14851497            Y = self.y_bins[0:-1] 
    1486             X, Y = numpy.meshgrid(X, Y) 
     1498            X, Y = np.meshgrid(X, Y) 
    14871499 
    14881500            try: 
     
    14981510                    from mpl_toolkits.mplot3d import Axes3D 
    14991511                except: 
    1500                     logging.error("PlotPanel could not import Axes3D") 
     1512                    logger.error("PlotPanel could not import Axes3D") 
    15011513                self.subplot.figure.clear() 
    15021514                ax = Axes3D(self.subplot.figure) 
     
    15091521            self.subplot.set_axis_off() 
    15101522 
    1511         if cbax == None: 
     1523        if cbax is None: 
    15121524            ax.set_frame_on(False) 
    15131525            cb = self.subplot.figure.colorbar(im, shrink=0.8, aspect=20) 
     
    15311543        """ 
    15321544        # 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 \ 
    15341546                or self.qx_data.ndim != 1 or self.qy_data.ndim != 1: 
    15351547            # do we need deepcopy here? 
     
    15471559        # 1d array to use for weighting the data point averaging 
    15481560        #when they fall into a same bin. 
    1549         weights_data = numpy.ones([self.data.size]) 
     1561        weights_data = np.ones([self.data.size]) 
    15501562        # get histogram of ones w/len(data); this will provide 
    15511563        #the weights of data on each bins 
    1552         weights, xedges, yedges = numpy.histogram2d(x=self.qy_data, 
     1564        weights, xedges, yedges = np.histogram2d(x=self.qy_data, 
    15531565                                                    y=self.qx_data, 
    15541566                                                    bins=[self.y_bins, self.x_bins], 
    15551567                                                    weights=weights_data) 
    15561568        # get histogram of data, all points into a bin in a way of summing 
    1557         image, xedges, yedges = numpy.histogram2d(x=self.qy_data, 
     1569        image, xedges, yedges = np.histogram2d(x=self.qy_data, 
    15581570                                                  y=self.qx_data, 
    15591571                                                  bins=[self.y_bins, self.x_bins], 
    15601572                                                  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: 
    15621574        # If weight == 1, there is only one data point in the bin so 
    15631575        # that no normalization is required. 
     
    15731585        # do while loop until all vacant bins are filled up up 
    15741586        #to loop = max_loop 
    1575         while not(numpy.isfinite(image[weights == 0])).all(): 
     1587        while not(np.isfinite(image[weights == 0])).all(): 
    15761588            if loop >= max_loop:  # this protects never-ending loop 
    15771589                break 
     
    15911603        """ 
    15921604        # 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 \ 
    15941606                or self.qx_data.ndim != 1 or self.qy_data.ndim != 1: 
    15951607            # do we need deepcopy here? 
     
    16221634 
    16231635        # store x and y bin centers in q space 
    1624         x_bins = numpy.linspace(xmin, xmax, npix_x) 
    1625         y_bins = numpy.linspace(ymin, ymax, npix_y) 
     1636        x_bins = np.linspace(xmin, xmax, npix_x) 
     1637        y_bins = np.linspace(ymin, ymax, npix_y) 
    16261638 
    16271639        #set x_bins and y_bins 
     
    16421654        """ 
    16431655        # No image matrix given 
    1644         if image == None or numpy.ndim(image) != 2 \ 
    1645                 or numpy.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: 
    16471659            return image 
    16481660        # Get bin size in y and x directions 
    16491661        len_y = len(image) 
    16501662        len_x = len(image[1]) 
    1651         temp_image = numpy.zeros([len_y, len_x]) 
    1652         weit = numpy.zeros([len_y, len_x]) 
     1663        temp_image = np.zeros([len_y, len_x]) 
     1664        weit = np.zeros([len_y, len_x]) 
    16531665        # do for-loop for all pixels 
    16541666        for n_y in range(len(image)): 
    16551667            for n_x in range(len(image[1])): 
    16561668                # find only null pixels 
    1657                 if weights[n_y][n_x] > 0 or numpy.isfinite(image[n_y][n_x]): 
     1669                if weights[n_y][n_x] > 0 or np.isfinite(image[n_y][n_x]): 
    16581670                    continue 
    16591671                else: 
    16601672                    # find 4 nearest neighbors 
    16611673                    # check where or not it is at the corner 
    1662                     if n_y != 0 and numpy.isfinite(image[n_y - 1][n_x]): 
     1674                    if n_y != 0 and np.isfinite(image[n_y - 1][n_x]): 
    16631675                        temp_image[n_y][n_x] += image[n_y - 1][n_x] 
    16641676                        weit[n_y][n_x] += 1 
    1665                     if n_x != 0 and numpy.isfinite(image[n_y][n_x - 1]): 
     1677                    if n_x != 0 and np.isfinite(image[n_y][n_x - 1]): 
    16661678                        temp_image[n_y][n_x] += image[n_y][n_x - 1] 
    16671679                        weit[n_y][n_x] += 1 
    1668                     if n_y != len_y - 1 and numpy.isfinite(image[n_y + 1][n_x]): 
     1680                    if n_y != len_y - 1 and np.isfinite(image[n_y + 1][n_x]): 
    16691681                        temp_image[n_y][n_x] += image[n_y + 1][n_x] 
    16701682                        weit[n_y][n_x] += 1 
    1671                     if n_x != len_x - 1 and numpy.isfinite(image[n_y][n_x + 1]): 
     1683                    if n_x != len_x - 1 and np.isfinite(image[n_y][n_x + 1]): 
    16721684                        temp_image[n_y][n_x] += image[n_y][n_x + 1] 
    16731685                        weit[n_y][n_x] += 1 
    16741686                    # go 4 next nearest neighbors when no non-zero 
    16751687                    # 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]): 
    16781690                        temp_image[n_y][n_x] += image[n_y - 1][n_x - 1] 
    16791691                        weit[n_y][n_x] += 1 
    16801692                    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]): 
    16821694                        temp_image[n_y][n_x] += image[n_y + 1][n_x - 1] 
    16831695                        weit[n_y][n_x] += 1 
    16841696                    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]): 
    16861698                        temp_image[n_y][n_x] += image[n_y - 1][n_x + 1] 
    16871699                        weit[n_y][n_x] += 1 
    16881700                    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]): 
    16901702                        temp_image[n_y][n_x] += image[n_y + 1][n_x + 1] 
    16911703                        weit[n_y][n_x] += 1 
     
    17411753        if remove_fit: 
    17421754            self.graph.delete(self.fit_result) 
     1755            if hasattr(self, 'plots'): 
     1756                if 'fit' in self.plots.keys(): 
     1757                    del self.plots['fit'] 
    17431758        self.ly = None 
    17441759        self.q_ctrl = None 
     
    17541769        _yscale = 'linear' 
    17551770        for item in list: 
     1771            if item.id == 'fit': 
     1772                continue 
    17561773            item.setLabel(self.xLabel, self.yLabel) 
    1757  
    17581774            # control axis labels from the panel itself 
    17591775            yname, yunits = item.get_yaxis() 
    1760             if self.yaxis_label != None: 
     1776            if self.yaxis_label is not None: 
    17611777                yname = self.yaxis_label 
    17621778                yunits = self.yaxis_unit 
     
    17651781                self.yaxis_unit = yunits 
    17661782            xname, xunits = item.get_xaxis() 
    1767             if self.xaxis_label != None: 
     1783            if self.xaxis_label is not None: 
    17681784                xname = self.xaxis_label 
    17691785                xunits = self.xaxis_unit 
     
    17851801            if self.xLabel == "ln(x)": 
    17861802                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) 
    17881804            if self.xLabel == "log10(x)": 
    17891805                item.transformX(transform.toX_pos, transform.errToX_pos) 
     
    17971813            if self.yLabel == "ln(y)": 
    17981814                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) 
    18001816            if self.yLabel == "y": 
    18011817                item.transformY(transform.toX, transform.errToX) 
     
    18131829                yunits = convert_unit(-1, yunits) 
    18141830                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)) 
    18151836            if self.yLabel == "y*x^(4)": 
    18161837                item.transformY(transform.toYX4, transform.errToYX4) 
     
    18261847            if self.yLabel == "ln(y*x)": 
    18271848                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), 
    18291850                                              "%s%s" % (yunits, self.xaxis_unit)) 
    18301851            if self.yLabel == "ln(y*x^(2))": 
     
    18441865                self.graph._yaxis_transformed("%s \ \ %s^{4}" % (yname, xname), 
    18451866                                              "%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)) 
    18591867            item.transformView() 
    18601868 
     
    18941902 
    18951903        """ 
     1904        xlim = self.subplot.get_xlim() 
     1905        ylim = self.subplot.get_ylim() 
     1906 
    18961907        # Saving value to redisplay in Fit Dialog when it is opened again 
    18971908        self.Avalue, self.Bvalue, self.ErrAvalue, \ 
     
    19171928        self.graph.render(self) 
    19181929        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) 
    19191939        self.subplot.figure.canvas.draw_idle() 
    19201940 
     
    19221942        """ 
    19231943        """ 
    1924         if self.parent == None: 
     1944        if self.parent is None: 
    19251945            return 
    19261946        # get current caption 
     
    19962016            self.toolbar.copy_figure(self.canvas) 
    19972017        except: 
    1998             print "Error in copy Image" 
     2018            print("Error in copy Image") 
    19992019 
    20002020 
  • src/sas/sasgui/plottools/PropertyDialog.py

    rd7bb526 r959eb01  
    2323        iy += 1 
    2424        ix = 1 
    25         self.xvalue = wx.ComboBox(self, -1) 
     25        self.xvalue = wx.ComboBox(self, -1, style=wx.CB_READONLY) 
    2626        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) 
    2828 
    2929        ix += 2 
    30         self.yvalue = wx.ComboBox(self, -1) 
     30        self.yvalue = wx.ComboBox(self, -1, style=wx.CB_READONLY) 
    3131        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) 
    3333 
    3434        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) 
    3637        x_size += self.view.GetSize()[0] 
    3738        self.view.SetMinSize((160, 30)) 
     
    6465        self.yvalue.Insert("ln(y)", 2) 
    6566        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) 
    7375        # type of view or model used 
    7476        self.view.SetValue("--") 
     
    8385        self.Centre() 
    8486 
     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 
    85106    def setValues(self, x, y, view): 
    86107        """ 
  • src/sas/sasgui/plottools/TextDialog.py

    rd7bb526 r7432acb  
    4141        style_box = wx.BoxSizer(wx.HORIZONTAL) 
    4242        # tcA 
    43         if unit != None: 
     43        if unit is not None: 
    4444            styles = wx.TAB_TRAVERSAL 
    4545            height = -1 
     
    130130                       0, wx.TOP, 5) 
    131131        family_box.Add(self.font_size, 0, 0) 
    132         if unit_box != None: 
     132        if unit_box is not None: 
    133133            family_box.Add((_BOX_WIDTH / 2, -1)) 
    134134            family_box.Add(tick_label_text, 0, 0) 
     
    159159        text_box.Add(self.text_string) 
    160160        vbox.Add(text_box, 0, wx.EXPAND, 15) 
    161         if unit_box != None: 
     161        if unit_box is not None: 
    162162            unit_box.Add(unit_text, 0, 0) 
    163163            unit_box.Add(self.unit_ctrl, 0, 0) 
  • src/sas/sasgui/plottools/arrow3d.py

    rd7bb526 r7432acb  
    2929        self.base = base 
    3030 
    31         if base != None: 
     31        if base is not None: 
    3232            # To turn the updating off during dragging 
    3333            base.canvas.mpl_connect('button_press_event', self.on_left_down) 
  • src/sas/sasgui/plottools/binder.py

    rd7bb526 ra1b8fee  
    22Extension to MPL to support the binding of artists to key/mouse events. 
    33""" 
     4from __future__ import print_function 
     5 
    46import sys 
    57import logging 
     8 
     9logger = logging.getLogger(__name__) 
    610 
    711class Selection(object): 
     
    6165            ] 
    6266        except: 
    63             print "bypassing scroll_event: wrong matplotlib version" 
     67            print("bypassing scroll_event: wrong matplotlib version") 
    6468            self._connections = [ 
    6569                canvas.mpl_connect('motion_notify_event', self._onMotion), 
     
    121125            for cid in self._connections: self.canvas.mpl_disconnect(cid) 
    122126        except: 
    123             logging.error("Error disconnection canvas: %s" % sys.exc_value) 
     127            logger.error("Error disconnection canvas: %s" % sys.exc_value) 
    124128        self._connections = [] 
    125129 
  • src/sas/sasgui/plottools/canvas.py

    rd7bb526 r7432acb  
    1111from matplotlib.backends.backend_wx import RendererWx 
    1212 
     13logger = logging.getLogger(__name__) 
     14 
    1315 
    1416def draw_image(self, x, y, im, bbox, clippath=None, clippath_trans=None): 
     
    9698            dc.DrawBitmap(self.canvas.bitmap, (0, 0)) 
    9799        except: 
    98             logging.error(sys.exc_value) 
     100            logger.error(sys.exc_value) 
    99101 
    100102    # restore original figure  resolution 
     
    151153        """ 
    152154        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: 
    154156            self.panel.legend._loc = self.panel.legend_pos_loc 
    155157        self.idletimer.Restart(5, *args, **kwargs)  # Delay by 5 ms 
     
    207209                fig.draw(self) 
    208210            except ValueError: 
    209                 logging.error(sys.exc_value) 
     211                logger.error(sys.exc_value) 
    210212        else: 
    211213            self._isRendered = False 
  • src/sas/sasgui/plottools/convert_units.py

    rd7bb526 ra1b8fee  
    33    This is a cleaned up version of unitConverter.py 
    44""" 
     5from __future__ import print_function 
     6 
    57import re 
    68import string 
     
    6870    unit8 = "m/s^{4}"  #         x^2               (m/s^{4})^{2} 
    6971 
    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  
    22from plottables import Theory1D 
    33import math 
    4 import numpy 
     4import numpy as np 
    55import fittings 
    66import transform 
     
    2020def format_number(value, high=False): 
    2121    """ 
    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. 
    2324    """ 
    2425    try: 
     
    4041        """ 
    4142        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 
    4363        """ 
    4464        wx.Dialog.__init__(self, parent, title=title, 
     
    5070        # Registered owner for close event 
    5171        self._registered_close = None 
    52  
    5372        # dialog panel self call function to plot the fitting function 
     73        # calls the calling PlotPanel method onFitDisplay 
    5474        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 
    5677        self.plottable = plottable 
     78        # is this a Guinier fit 
    5779        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 
    5982        self.xLabel, self.yLabel, self.Avalue, self.Bvalue, \ 
    6083               self.ErrAvalue, self.ErrBvalue, self.Chivalue = self.transform() 
    6184 
    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 
    63150        vbox = wx.BoxSizer(wx.VERTICAL) 
    64151        sizer = wx.GridBagSizer(5, 5) 
     152        sizer_button = wx.BoxSizer(wx.HORIZONTAL) 
     153         
     154        #size of string boxes in pixels 
    65155        _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)) 
    68159        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)) 
    70161        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)) 
    72163        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)) 
    74165        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)) 
    76167        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)) 
    78169        msg = "Enter the minimum value on " 
    79170        msg += "the x-axis to be included in the fit." 
    80171        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)) 
    82173        msg = "Enter the maximum value on " 
    83174        msg += " the x-axis to be included in the fit." 
    84175        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)) 
    86177        msg = "Minimum value on the x-axis for the plotted data." 
    87178        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)) 
    89180        msg = "Maximum value on the x-axis for the plotted data." 
    90181        self.initXmax.SetToolTipString(msg) 
     
    98189        self.initXmax.SetBackgroundColour(_BACKGROUND_COLOR) 
    99190 
    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 
    101194        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) 
    108195        if RG_ON: 
    109196            if (self.yLabel == "ln(y)" or self.yLabel == "ln(y*x)") and \ 
     
    112199            if (self.xLabel == "x^(4)") and (self.yLabel == "y*x^(4)"): 
    113200                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" 
    116208        if self.bg_on: 
    117209            param_a = 'Background (= Parameter a)' 
    118210        else: 
    119211            param_a = 'Parameter a' 
    120         vbox.Add(sizer) 
     212 
     213 
     214        #Now set this all up in the GridBagSizer sizer 
    121215        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 
    123220        sizer.Add(wx.StaticText(self, -1, explanation), (iy, ix), 
    124221                  (1, 1), wx.LEFT | wx.EXPAND | wx.ADJUST_MINSIZE, 15) 
    125         iy += 2 
     222        iy += 1 
    126223        sizer.Add(wx.StaticText(self, -1, param_a), (iy, ix), 
    127224                  (1, 1), wx.LEFT | wx.EXPAND | wx.ADJUST_MINSIZE, 15) 
     
    281378                      wx.LEFT | wx.EXPAND | wx.ADJUST_MINSIZE, 0) 
    282379 
     380        #Now add some space before the separation line 
    283381        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) 
    288392        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) 
    290395        sizer_button.Add(self.btClose, 0, 
    291396                         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) 
    292401        vbox.Add(sizer_button, 0, wx.EXPAND | wx.BOTTOM | wx.TOP, 10) 
    293402 
    294         sizer.Add(self.btFit, (iy, ix), (1, 1), wx.LEFT | wx.ADJUST_MINSIZE, 0) 
    295403        # panel.SetSizer(sizer) 
    296404        self.SetSizer(vbox) 
    297405        self.Centre() 
    298         # Receives the type of model for the fitting 
    299         from LineModel import LineModel 
    300         self.model = LineModel() 
    301         # Display the fittings values 
    302         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 dialog 
    308         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.dy 
    330             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)) 
    347406 
    348407    def register_close(self, owner): 
     
    371430        the button Fit.Computes chisqr , 
    372431        A and B parameters of the best linear fit y=Ax +B 
    373         Push a plottable to 
     432        Push a plottable to the caller 
    374433        """ 
    375434        tempx = [] 
     
    389448                xmin = xminView 
    390449                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))) 
    391454                # Store the transformed values of view x, y,dy 
    392455                # in variables  before the fit 
     
    419482 
    420483                if self.xLabel.lower() == "log10(x)": 
    421                     tempdy = numpy.asarray(tempdy) 
     484                    tempdy = np.asarray(tempdy) 
    422485                    tempdy[tempdy == 0] = 1 
    423486                    chisqr, out, cov = fittings.sasfit(self.model, 
     
    428491                                                       math.log10(xmax)) 
    429492                else: 
    430                     tempdy = numpy.asarray(tempdy) 
     493                    tempdy = np.asarray(tempdy) 
    431494                    tempdy[tempdy == 0] = 1 
    432495                    chisqr, out, cov = fittings.sasfit(self.model, 
     
    439502 
    440503                # Check that cov and out are iterable before displaying them 
    441                 if cov == None: 
     504                if cov is None: 
    442505                    errA = 0.0 
    443506                    errB = 0.0 
     
    445508                    errA = math.sqrt(cov[0][0]) 
    446509                    errB = math.sqrt(cov[1][1]) 
    447                 if out == None: 
     510                if out is None: 
    448511                    cstA = 0.0 
    449512                    cstB = 0.0 
     
    485548                    tempy.append(y_model) 
    486549                # Set the fit parameter display when  FitDialog is opened again 
    487                 self.Avalue = cstB 
    488                 self.Bvalue = cstA 
     550                self.Avalue = cstA 
     551                self.Bvalue = cstB 
    489552                self.ErrAvalue = errA 
    490553                self.ErrBvalue = errB 
     
    494557 
    495558                # Display the fitting value on the Fit Dialog 
    496                 self._onsetValues(cstB, cstA, errA, errB, chisqr) 
     559                self._onsetValues(cstA, cstB, errA, errB, chisqr) 
    497560 
    498561    def _onsetValues(self, cstA, cstB, errA, errB, Chi): 
     
    501564        """ 
    502565        rg = None 
     566        _diam = None 
    503567        self.tcA.SetValue(format_number(cstA)) 
    504568        self.tcB.SetValue(format_number(cstB)) 
     
    508572        if self.rg_on: 
    509573            if self.Rg_tctr.IsShown(): 
    510                 rg = numpy.sqrt(-3 * float(cstA)) 
     574                rg = np.sqrt(-3 * float(cstA)) 
    511575                value = format_number(rg) 
    512576                self.Rg_tctr.SetValue(value) 
    513577                if self.I0_tctr.IsShown(): 
    514                     val = numpy.exp(cstB) 
     578                    val = np.exp(cstB) 
    515579                    self.I0_tctr.SetValue(format_number(val)) 
    516580            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)) 
    519583                else: 
    520584                    value = '' 
    521585                self.Rgerr_tctr.SetValue(value) 
    522586                if self.I0err_tctr.IsShown(): 
    523                     val = numpy.abs(numpy.exp(cstB) - numpy.exp(cstB + errB)) 
     587                    val = np.abs(np.exp(cstB) * errB) 
    524588                    self.I0err_tctr.SetValue(format_number(val)) 
    525589            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) 
    528593                self.Diameter_tctr.SetValue(value) 
    529594            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) 
    532597                else: 
    533598                    value = '' 
    534599                self.Diametererr_tctr.SetValue(value) 
    535600            if self.RgQmin_tctr.IsShown(): 
    536                 value = format_number(rg * self.mini) 
     601                value = format_number(rg * self.floatInvTransform(self.mini)) 
    537602                self.RgQmin_tctr.SetValue(value) 
    538603            if self.RgQmax_tctr.IsShown(): 
    539                 value = format_number(rg * self.maxi) 
     604                value = format_number(rg * self.floatInvTransform(self.maxi)) 
    540605                self.RgQmax_tctr.SetValue(value) 
    541606 
     
    610675    def floatInvTransform(self, x): 
    611676        """ 
    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. 
    614681 
    615682        """ 
     
    617684        # functionality work without rewritting the whole code 
    618685        # 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)": 
    620689            return math.sqrt(x) 
     690        elif self.xLabel == "x^(4)": 
     691            return math.sqrt(math.sqrt(x)) 
    621692        elif self.xLabel == "log10(x)": 
    622693            return math.pow(10, x) 
    623694        elif self.xLabel == "ln(x)": 
    624695            return math.exp(x) 
     696        elif self.xLabel == "log10(x^(4))": 
     697            return math.sqrt(math.sqrt(math.pow(10, x))) 
    625698        return x 
    626699 
  • src/sas/sasgui/plottools/fittings.py

    rd7bb526 ra1b8fee  
    11""" 
     2This module is used to fit a set of x,y data to a model passed to it. It is 
     3used to calculate the slope and intercepts for the linearized fits.  Two things 
     4should be noted: 
     5 
     6First, this fitting module uses the NLLSQ module of SciPy rather than a linear 
     7fit.  This along with a few other modules could probably be removed if we 
     8move to a linear regression approach. 
     9 
     10Second, this infrastructure does not allow for resolution smearing of the  
     11the models.  Hence the results are not that accurate even for pinhole 
     12collimation of SANS but may be good for SAXS.  It is completely wrong for  
     13slit smeared data.  
     14 
    215""" 
     16from __future__ import print_function 
     17 
    318from scipy import optimize 
    419 
     
    621class Parameter(object): 
    722    """ 
    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. 
    925    """ 
    1026    def __init__(self, model, name, value=None): 
    1127        self.model = model 
    1228        self.name = name 
    13         if not value == None: 
     29        if value is not None: 
    1430            self.model.setParam(self.name, value) 
    1531 
     
    92108    chisqr, out, cov = sasfit(line, [cstA, cstB], event.x, y, 0) 
    93109    # print "Output parameters:", out 
    94     print "The right answer is [70.0, 1.0]" 
    95     print chisqr, out, cov 
     110    print("The right answer is [70.0, 1.0]") 
     111    print(chisqr, out, cov) 
  • src/sas/sasgui/plottools/plottable_interactor.py

    rd7bb526 ra1b8fee  
    22    This module allows more interaction with the plot 
    33""" 
     4from __future__ import print_function 
     5 
    46from BaseInteractor import _BaseInteractor 
     7 
    58 
    69class PointInteractor(_BaseInteractor): 
     
    5053            l_width = markersize * 0.4 
    5154            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: 
    5659            markersize = self.markersize 
    5760        # 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(()): 
    5962            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(()): 
    6164            dy = nx.vstack((y - dy[0], dy[1] - y)).transpose() 
    6265 
    63         if dx == None and dy == None: 
     66        if dx is None and dy is None: 
    6467            # zorder = 1 
    6568            self.marker = self.axes.plot(x, y, color=self.color, 
     
    100103        """ 
    101104        """ 
    102         if not self.marker == None: 
     105        if self.marker is not None: 
    103106            self.base.connect.clear([self.marker]) 
    104107        self.color = self._color(color) 
     
    115118        """ 
    116119        """ 
    117         if not self.marker == None: 
     120        if self.marker is not None: 
    118121            self.base.connect.clear([self.marker]) 
    119122        self.color = self._color(color) 
     
    133136        """ 
    134137        """ 
    135         if not self.marker == None: 
     138        if self.marker is not None: 
    136139            self.base.connect.clear([self.marker]) 
    137140        self.color = self._color(color) 
     
    156159 
    157160    def clear(self): 
    158         print "plottable_interactor.clear()" 
     161        print("plottable_interactor.clear()") 
    159162 
    160163    def _on_click(self, evt): 
  • src/sas/sasgui/plottools/plottables.py

    rcd54205 r45dffa69  
    4343# Support for ancient python versions 
    4444import copy 
    45 import numpy 
     45import numpy as np 
    4646import sys 
    4747import logging 
     48 
     49logger = logging.getLogger(__name__) 
    4850 
    4951if 'any' not in dir(__builtins__): 
     
    212214                self.color += plottable.colors() 
    213215                self.plottables[plottable] = self.color 
     216                plottable.custom_color = self.color 
    214217 
    215218    def changed(self): 
     
    226229            if p.hidden == True: 
    227230                continue 
    228             if not p.x == None: 
     231            if p.x is not None: 
    229232                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: 
    231234                        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: 
    233236                        max_value = x_i 
    234237        return min_value, max_value 
     
    559562        Returns True if there is no data stored in the plottable 
    560563        """ 
    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): 
    563566            return True 
    564567        return False 
     
    676679        # Sanity check 
    677680        # 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): 
    683686                msg = "Plottable.View: Given x and dx are not" 
    684687                msg += " of the same length" 
     
    690693                raise ValueError, msg 
    691694 
    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): 
    693696                msg = "Plottable.View: Given y and dy are not of the same " 
    694697                msg += "length: len(y)=%s, len(dy)=%s" % (len(y), len(dy)) 
     
    705708                self.dy = None 
    706709            if not has_err_x: 
    707                 dx = numpy.zeros(len(x)) 
     710                dx = np.zeros(len(x)) 
    708711            if not has_err_y: 
    709                 dy = numpy.zeros(len(y)) 
     712                dy = np.zeros(len(y)) 
    710713            for i in range(len(x)): 
    711714                try: 
     
    794797        tempy = [] 
    795798        tempdy = [] 
    796         if self.dx == None: 
    797             self.dx = numpy.zeros(len(self.x)) 
    798         if self.dy == None: 
    799             self.dy = numpy.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)) 
    800803        if self.xLabel == "log10(x)": 
    801804            for i in range(len(self.x)): 
     
    807810                        tempdy.append(self.dy[i]) 
    808811                except: 
    809                     logging.error("check_data_logX: skipping point x %g", self.x[i]) 
    810                     logging.error(sys.exc_value) 
     812                    logger.error("check_data_logX: skipping point x %g", self.x[i]) 
     813                    logger.error(sys.exc_value) 
    811814            self.x = tempx 
    812815            self.y = tempy 
     
    824827        tempy = [] 
    825828        tempdy = [] 
    826         if self.dx == None: 
    827             self.dx = numpy.zeros(len(self.x)) 
    828         if self.dy == None: 
    829             self.dy = numpy.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)) 
    830833        if self.yLabel == "log10(y)": 
    831834            for i in range(len(self.x)): 
     
    837840                        tempdy.append(self.dy[i]) 
    838841                except: 
    839                     logging.error("check_data_logY: skipping point %g", self.y[i]) 
    840                     logging.error(sys.exc_value) 
     842                    logger.error("check_data_logY: skipping point %g", self.y[i]) 
     843                    logger.error(sys.exc_value) 
    841844 
    842845            self.x = tempx 
     
    857860        tempy = [] 
    858861        tempdy = [] 
    859         if self.dx == None: 
    860             self.dx = numpy.zeros(len(self.x)) 
    861         if self.dy == None: 
    862             self.dy = numpy.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: 
    864867            for i in range(len(self.x)): 
    865868                if self.x[i] >= xmin and self.x[i] <= xmax: 
     
    10221025    """ 
    10231026 
    1024     def __init__(self, x, y, dx=None, dy=None): 
     1027    def __init__(self, x, y, dx=None, dy=None, lam=None, dlam=None): 
    10251028        """ 
    10261029        Draw points specified by x[i],y[i] in the current color/symbol. 
     
    10361039        self.x = x 
    10371040        self.y = y 
     1041        self.lam = lam 
    10381042        self.dx = dx 
    10391043        self.dy = dy 
     1044        self.dlam = dlam 
    10401045        self.source = None 
    10411046        self.detector = None 
     
    12011206        """ 
    12021207        """ 
    1203         if  self._chisq == None: 
     1208        if  self._chisq is None: 
    12041209            chisqTxt = r'$\chi^2=$' 
    12051210        else: 
     
    12251230 
    12261231def sample_graph(): 
    1227     import numpy as nx 
     1232    import numpy as np 
    12281233 
    12291234    # Construct a simple graph 
    12301235    if False: 
    1231         x = nx.array([1, 2, 3, 4, 5, 6], 'd') 
    1232         y = nx.array([4, 5, 6, 5, 4, 5], 'd') 
    1233         dy = nx.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]) 
    12341239    else: 
    1235         x = nx.linspace(0, 1., 10000) 
    1236         y = nx.sin(2 * nx.pi * x * 2.8) 
    1237         dy = nx.sqrt(100 * nx.abs(y)) / 100 
     1240        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 
    12381243    data = Data1D(x, y, dy=dy) 
    12391244    data.xaxis('distance', 'm') 
  • src/sas/sasgui/plottools/toolbar.py

    rd7bb526 r959eb01  
    66from matplotlib.backends.backend_wx import _load_bitmap 
    77import logging 
     8 
     9logger = logging.getLogger(__name__) 
    810 
    911# Event binding code changed after version 2.5 
     
    9496            self._parent.onToolContextMenu(event=event) 
    9597        except: 
    96             logging.error("Plot toolbar could not show menu") 
     98            logger.error("Plot toolbar could not show menu") 
    9799 
    98100    def context_menu(self, event): 
     
    122124        except: 
    123125            import traceback 
    124             logging.error(traceback.format_exc()) 
     126            logger.error(traceback.format_exc()) 
    125127 
    126128    def copy_figure(self, event): 
  • src/sas/sasgui/plottools/transform.py

    rd7bb526 r7432acb  
    162162 
    163163    """ 
    164     if dx == None: 
     164    if dx is None: 
    165165        dx = 0 
    166166    return dx 
     
    175175 
    176176    """ 
    177     if dx == None: 
     177    if dx is None: 
    178178        dx = 0 
    179179    return dx 
     
    188188 
    189189    """ 
    190     if  dx != None: 
     190    if  dx is not None: 
    191191        err = 2 * x * dx 
    192192        return math.fabs(err) 
     
    204204    """ 
    205205    if x > 0: 
    206         if dx != None: 
     206        if dx is not None: 
    207207            err = dx / (2 * math.sqrt(x)) 
    208208        else: 
     
    222222 
    223223    """ 
    224     if dx != None: 
     224    if dx is not None: 
    225225        err = 4 * math.pow(x, 3) * dx 
    226226        return math.fabs(err) 
     
    238238    """ 
    239239    if x > 0: 
    240         if dx != None: 
     240        if dx is not None: 
    241241            err = dx / (4 * math.pow(x, 3 / 4)) 
    242242        else: 
     
    256256 
    257257    """ 
    258     if dx == None: 
     258    if dx is None: 
    259259        dx = 0 
    260260 
     
    280280 
    281281    """ 
    282     if dx == None: 
     282    if dx is None: 
    283283        dx = 0 
    284284 
     
    291291 
    292292 
    293 def errToYX2(x, y, dx=None, dy=None): 
    294     """ 
    295     """ 
    296     if dx == None: 
    297         dx = 0 
    298     if dy == None: 
     293def errToYX2(y, x, dy=None, dx=None): 
     294    """ 
     295    """ 
     296    if dx is None: 
     297        dx = 0 
     298    if dy is None: 
    299299        dy = 0 
    300300    err = math.sqrt((2 * x * y * dx) ** 2 + ((x ** 2) * dy) ** 2) 
     
    314314        raise ValueError, msg 
    315315    if x != 0 and y != 0: 
    316         if dx == None: 
     316        if dx is None: 
    317317            dx = 0 
    318         if dy == None: 
     318        if dy is None: 
    319319            dy = 0 
    320320        err = (dx / x) ** 2 + (dy / y) ** 2 
     
    325325 
    326326 
    327 def errToLogYX2(x, y, dx=None, dy=None): 
     327def errToLogYX2(y, x, dy=None, dx=None): 
    328328    """ 
    329329    calculate error of Log(yx**2) 
     
    337337        raise ValueError, msg 
    338338    if x > 0 and y > 0: 
    339         if dx == None: 
     339        if dx is None: 
    340340            dx = 0 
    341         if dy == None: 
     341        if dy is None: 
    342342            dy = 0 
    343343        err = (2.0 * dx / x) ** 2 + (dy / y) ** 2 
     
    353353    """ 
    354354    if x != 0: 
    355         if dx == None: 
     355        if dx is None: 
    356356            dx = 0 
    357357        err = dx / x ** 2 
     
    367367    """ 
    368368    if x > 0: 
    369         if dx == None: 
     369        if dx is None: 
    370370            dx = 0 
    371371        err = -1 / 2 * math.pow(x, -3.0 / 2.0) * dx 
     
    375375 
    376376 
    377 def errToLogYX4(x, y=None, dx=None, dy=None): 
     377def errToLogYX4(y, x, dy=None, dx=None): 
    378378    """ 
    379379    error for ln(y*x^(4)) 
     
    388388        msg += " that are consistent with zero." 
    389389        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: 
    393393        dy = 0 
    394394    err = math.sqrt((4.0 * dx / x) ** 2 + (dy / y) ** 2) 
     
    396396 
    397397 
    398 def errToYX4(x, y=None, dx=None, dy=None): 
     398def errToYX4(y, x, dy=None, dx=None): 
    399399    """ 
    400400    error for (y*x^(4)) 
     
    406406    # within errors 
    407407 
    408     if dx == None: 
    409         dx = 0 
    410     if dy == None: 
     408    if dx is None: 
     409        dx = 0 
     410    if dy is None: 
    411411        dy = 0 
    412412    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 config 
    21from PlotPanel import PlotPanel 
    32from plottables import Data1D, Theory1D 
Note: See TracChangeset for help on using the changeset viewer.