Changeset c416a17 in sasview for src/sas/sasgui/plottools


Ignore:
Timestamp:
May 26, 2017 7:41:44 AM (8 years ago)
Author:
Piotr Rozyczko <rozyczko@…>
Branches:
ESS_GUI, ESS_GUI_Docs, ESS_GUI_batch_fitting, ESS_GUI_bumps_abstraction, ESS_GUI_iss1116, ESS_GUI_iss879, ESS_GUI_iss959, ESS_GUI_opencl, ESS_GUI_ordering, ESS_GUI_sync_sascalc
Children:
c1e380e
Parents:
6964d44 (diff), 7132e49 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge branch 'master' into ESS_GUI

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

Legend:

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

    re3ae090 r959eb01  
    88function should disappear in a future iteration (see notes in fitDialog) 
    99 
    10                 -PDB   July 10, 2016 
     10PDB   July 10, 2016 
     11 
    1112""" 
    1213 
     
    7071        runXY is when the if statement is true. I however cannot see what that 
    7172        function is for.  It needs to be documented here or removed. 
    72         -PDB 7/10/16  
     73        PDB 7/10/16  
    7374 
    7475        :param x: simple value 
     
    9293        but the only difference between this and run is when the if  
    9394        statement is true. I however cannot see what that function 
    94         is for.  It needs to be documented here or removed. -PDB 7/10/16  
     95        is for.  It needs to be documented here or removed. PDB 7/10/16  
    9596 
    9697        :param x: simple value 
  • src/sas/sasgui/plottools/PlotPanel.py

    r9687d58 ra1b8fee  
    22    Plot panel. 
    33""" 
     4from __future__ import print_function 
     5 
    46import logging 
    57import traceback 
     
    1012matplotlib.interactive(False) 
    1113#Use the WxAgg back end. The Wx one takes too long to render 
    12 #matplotlib.use('WXAgg') 
     14matplotlib.use('WXAgg') 
    1315from matplotlib.backends.backend_wxagg import FigureCanvasWxAgg 
    1416from matplotlib.figure import Figure 
     
    2931DEFAULT_CMAP = pylab.cm.jet 
    3032import copy 
    31 import numpy 
     33import numpy as np 
    3234 
    3335from sas.sasgui.guiframe.events import StatusEvent 
    3436from .toolbar import NavigationToolBar, PlotPrintout, bind 
    3537 
     38logger = logging.getLogger(__name__) 
     39 
    3640def show_tree(obj, d=0): 
    3741    """Handy function for displaying a tree of graph objects""" 
    38     print "%s%s" % ("-"*d, obj.__class__.__name__) 
     42    print("%s%s" % ("-"*d, obj.__class__.__name__)) 
    3943    if 'get_children' in dir(obj): 
    4044        for a in obj.get_children(): show_tree(a, d + 1) 
     
    152156        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: 
     
    358362                    return 
    359363 
    360             if ax != None: 
     364            if ax is not None: 
    361365                self.xInit, self.yInit = event.xdata, event.ydata 
    362366                try: 
     
    390394        Set legend alpha 
    391395        """ 
    392         if self.legend != None: 
     396        if self.legend is not None: 
    393397            self.legend.legendPatch.set_alpha(alpha) 
    394398 
     
    416420        """ 
    417421        ax = event.inaxes 
    418         if ax == None: 
     422        if ax is None: 
    419423            return 
    420424        # Event occurred inside a plotting area 
     
    459463            # User has clicked on text and is dragging 
    460464            ax = event.inaxes 
    461             if ax != None: 
     465            if ax is not None: 
    462466                # Only move text if mouse is within axes 
    463467                self.selectedText.set_position((event.xdata, event.ydata)) 
     
    474478        if self.leftdown == True and self.mousemotion == True: 
    475479            ax = event.inaxes 
    476             if ax != None:  # the dragging is perform inside the figure 
     480            if ax is not None:  # the dragging is perform inside the figure 
    477481                self.xFinal, self.yFinal = event.xdata, event.ydata 
    478482                # Check whether this is the first point 
    479                 if self.xInit == None: 
     483                if self.xInit is None: 
    480484                    self.xInit = self.xFinal 
    481485                    self.yInit = self.yFinal 
     
    574578        step = event.step 
    575579 
    576         if ax != None: 
     580        if ax is not None: 
    577581            # Event occurred inside a plotting area 
    578582            lo, hi = ax.get_xlim() 
     
    933937        # reset postion 
    934938        self.position = None 
    935         if self.graph.selected_plottable != None: 
     939        if self.graph.selected_plottable is not None: 
    936940            self.graph.selected_plottable = None 
    937941 
     
    957961                                              prop=FontProperties(size=10), 
    958962                                              loc=self.legendLoc) 
    959             if self.legend != None: 
     963            if self.legend is not None: 
    960964                self.legend.set_picker(self.legend_picker) 
    961965                self.legend.set_axes(self.subplot) 
     
    987991                                          prop=FontProperties(size=10), 
    988992                                          loc=self.legendLoc) 
    989         if self.legend != None: 
     993        if self.legend is not None: 
    990994            self.legend.set_picker(self.legend_picker) 
    991995            self.legend.set_axes(self.subplot) 
     
    10081012        pos_x = 0 
    10091013        pos_y = 0 
    1010         if self.position != None: 
     1014        if self.position is not None: 
    10111015            pos_x, pos_y = self.position 
    10121016        else: 
     
    10331037                    self.subplot.figure.canvas.draw_idle() 
    10341038            except: 
    1035                 if self.parent != None: 
     1039                if self.parent is not None: 
    10361040                    msg = "Add Text: Error. Check your property values..." 
    10371041                    wx.PostEvent(self.parent, StatusEvent(status=msg)) 
     
    10671071            self.xaxis_tick = xaxis_font 
    10681072 
    1069         if self.data != None: 
     1073        if self.data is not None: 
    10701074            # 2D 
    10711075            self.xaxis(self.xaxis_label, self.xaxis_unit, \ 
     
    11141118            self.yaxis_tick = yaxis_font 
    11151119 
    1116         if self.data != None: 
     1120        if self.data is not None: 
    11171121            # 2D 
    11181122            self.yaxis(self.yaxis_label, self.yaxis_unit, \ 
     
    11531157                label_temp = textdial.getText() 
    11541158                if label_temp.count("\%s" % "\\") > 0: 
    1155                     if self.parent != None: 
     1159                    if self.parent is not None: 
    11561160                        msg = "Add Label: Error. Can not use double '\\' " 
    11571161                        msg += "characters..." 
     
    11601164                    label = label_temp 
    11611165            except: 
    1162                 if self.parent != None: 
     1166                if self.parent is not None: 
    11631167                    msg = "Add Label: Error. Check your property values..." 
    11641168                    wx.PostEvent(self.parent, StatusEvent(status=msg)) 
     
    11781182        num_text = len(self.textList) 
    11791183        if num_text < 1: 
    1180             if self.parent != None: 
     1184            if self.parent is not None: 
    11811185                msg = "Remove Text: Nothing to remove.  " 
    11821186                wx.PostEvent(self.parent, StatusEvent(status=msg)) 
     
    11881192            text_remove = txt.get_text() 
    11891193            txt.remove() 
    1190             if self.parent != None: 
     1194            if self.parent is not None: 
    11911195                msg = "Removed Text: '%s'. " % text_remove 
    11921196                wx.PostEvent(self.parent, StatusEvent(status=msg)) 
    11931197        except: 
    1194             if self.parent != None: 
     1198            if self.parent is not None: 
    11951199                msg = "Remove Text: Error occurred. " 
    11961200                wx.PostEvent(self.parent, StatusEvent(status=msg)) 
     
    12481252                                        prop=FontProperties(size=10), 
    12491253                                        loc=self.legendLoc) 
    1250                 if self.legend != None: 
     1254                if self.legend is not None: 
    12511255                    self.legend.set_picker(self.legend_picker) 
    12521256                    self.legend.set_axes(self.subplot) 
     
    12771281        if font: 
    12781282            self.subplot.set_xlabel(label, fontproperties=font, color=color) 
    1279             if t_font != None: 
     1283            if t_font is not None: 
    12801284                for tick in self.subplot.xaxis.get_major_ticks(): 
    12811285                    tick.label.set_fontproperties(t_font) 
     
    12981302        if font: 
    12991303            self.subplot.set_ylabel(label, fontproperties=font, color=color) 
    1300             if t_font != None: 
     1304            if t_font is not None: 
    13011305                for tick_label in self.subplot.get_yticklabels(): 
    13021306                    tick_label.set_fontproperties(t_font) 
     
    13251329        from plottable_interactor import PointInteractor 
    13261330        p = PointInteractor(self, self.subplot, zorder=zorder, id=id) 
    1327         if p.markersize != None: 
     1331        if p.markersize is not None: 
    13281332            markersize = p.markersize 
    13291333        p.points(x, y, dx=dx, dy=dy, color=color, symbol=symbol, zorder=zorder, 
     
    13611365 
    13621366        # Convert tuple (lo,hi) to array [(x-lo),(hi-x)] 
    1363         if dx != None and type(dx) == type(()): 
     1367        if dx is not None and type(dx) == type(()): 
    13641368            dx = nx.vstack((x - dx[0], dx[1] - x)).transpose() 
    1365         if dy != None and type(dy) == type(()): 
     1369        if dy is not None and type(dy) == type(()): 
    13661370            dy = nx.vstack((y - dy[0], dy[1] - y)).transpose() 
    1367         if dx == None and dy == None: 
     1371        if dx is None and dy is None: 
    13681372            self.subplot.plot(x, y, color=self._color(color), 
    13691373                              marker=self._symbol(symbol), 
     
    14011405        if self.scale == 'log_{10}': 
    14021406            self.scale = 'linear' 
    1403             if not self.zmin_2D is None: 
     1407            if self.zmin_2D is not None: 
    14041408                zmin_2D_temp = math.pow(10, self.zmin_2D) 
    1405             if not self.zmax_2D is None: 
     1409            if self.zmax_2D is not None: 
    14061410                zmax_2D_temp = math.pow(10, self.zmax_2D) 
    14071411        else: 
    14081412            self.scale = 'log_{10}' 
    1409             if not self.zmin_2D is None: 
     1413            if self.zmin_2D is not None: 
    14101414                # min log value: no log(negative) 
    14111415                if self.zmin_2D <= 0: 
     
    14131417                else: 
    14141418                    zmin_2D_temp = math.log10(self.zmin_2D) 
    1415             if not self.zmax_2D is None: 
     1419            if self.zmax_2D is not None: 
    14161420                zmax_2D_temp = math.log10(self.zmax_2D) 
    14171421 
     
    14411445        c = self._color(color) 
    14421446        # If we don't have any data, skip. 
    1443         if self.data == None: 
     1447        if self.data is None: 
    14441448            return 
    14451449        if self.data.ndim == 1: 
     
    14521456                if  self.zmin_2D <= 0  and len(output[output > 0]) > 0: 
    14531457                    zmin_temp = self.zmin_2D 
    1454                     output[output > 0] = numpy.log10(output[output > 0]) 
     1458                    output[output > 0] = np.log10(output[output > 0]) 
    14551459                    #In log scale Negative values are not correct in general 
    1456                     #output[output<=0] = math.log(numpy.min(output[output>0])) 
     1460                    #output[output<=0] = math.log(np.min(output[output>0])) 
    14571461                elif self.zmin_2D <= 0: 
    14581462                    zmin_temp = self.zmin_2D 
    1459                     output[output > 0] = numpy.zeros(len(output)) 
     1463                    output[output > 0] = np.zeros(len(output)) 
    14601464                    output[output <= 0] = -32 
    14611465                else: 
    14621466                    zmin_temp = self.zmin_2D 
    1463                     output[output > 0] = numpy.log10(output[output > 0]) 
     1467                    output[output > 0] = np.log10(output[output > 0]) 
    14641468                    #In log scale Negative values are not correct in general 
    1465                     #output[output<=0] = math.log(numpy.min(output[output>0])) 
     1469                    #output[output<=0] = math.log(np.min(output[output>0])) 
    14661470            except: 
    14671471                #Too many problems in 2D plot with scale 
     
    14921496            X = self.x_bins[0:-1] 
    14931497            Y = self.y_bins[0:-1] 
    1494             X, Y = numpy.meshgrid(X, Y) 
     1498            X, Y = np.meshgrid(X, Y) 
    14951499 
    14961500            try: 
     
    15061510                    from mpl_toolkits.mplot3d import Axes3D 
    15071511                except: 
    1508                     logging.error("PlotPanel could not import Axes3D") 
     1512                    logger.error("PlotPanel could not import Axes3D") 
    15091513                self.subplot.figure.clear() 
    15101514                ax = Axes3D(self.subplot.figure) 
     
    15171521            self.subplot.set_axis_off() 
    15181522 
    1519         if cbax == None: 
     1523        if cbax is None: 
    15201524            ax.set_frame_on(False) 
    15211525            cb = self.subplot.figure.colorbar(im, shrink=0.8, aspect=20) 
     
    15391543        """ 
    15401544        # No qx or qy given in a vector format 
    1541         if self.qx_data == None or self.qy_data == None \ 
     1545        if self.qx_data is None or self.qy_data is None \ 
    15421546                or self.qx_data.ndim != 1 or self.qy_data.ndim != 1: 
    15431547            # do we need deepcopy here? 
     
    15551559        # 1d array to use for weighting the data point averaging 
    15561560        #when they fall into a same bin. 
    1557         weights_data = numpy.ones([self.data.size]) 
     1561        weights_data = np.ones([self.data.size]) 
    15581562        # get histogram of ones w/len(data); this will provide 
    15591563        #the weights of data on each bins 
    1560         weights, xedges, yedges = numpy.histogram2d(x=self.qy_data, 
     1564        weights, xedges, yedges = np.histogram2d(x=self.qy_data, 
    15611565                                                    y=self.qx_data, 
    15621566                                                    bins=[self.y_bins, self.x_bins], 
    15631567                                                    weights=weights_data) 
    15641568        # get histogram of data, all points into a bin in a way of summing 
    1565         image, xedges, yedges = numpy.histogram2d(x=self.qy_data, 
     1569        image, xedges, yedges = np.histogram2d(x=self.qy_data, 
    15661570                                                  y=self.qx_data, 
    15671571                                                  bins=[self.y_bins, self.x_bins], 
     
    15811585        # do while loop until all vacant bins are filled up up 
    15821586        #to loop = max_loop 
    1583         while not(numpy.isfinite(image[weights == 0])).all(): 
     1587        while not(np.isfinite(image[weights == 0])).all(): 
    15841588            if loop >= max_loop:  # this protects never-ending loop 
    15851589                break 
     
    15991603        """ 
    16001604        # No qx or qy given in a vector format 
    1601         if self.qx_data == None or self.qy_data == None \ 
     1605        if self.qx_data is None or self.qy_data is None \ 
    16021606                or self.qx_data.ndim != 1 or self.qy_data.ndim != 1: 
    16031607            # do we need deepcopy here? 
     
    16301634 
    16311635        # store x and y bin centers in q space 
    1632         x_bins = numpy.linspace(xmin, xmax, npix_x) 
    1633         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) 
    16341638 
    16351639        #set x_bins and y_bins 
     
    16501654        """ 
    16511655        # No image matrix given 
    1652         if image == None or numpy.ndim(image) != 2 \ 
    1653                 or numpy.isfinite(image).all() \ 
    1654                 or weights == None: 
     1656        if image is None or np.ndim(image) != 2 \ 
     1657                or np.isfinite(image).all() \ 
     1658                or weights is None: 
    16551659            return image 
    16561660        # Get bin size in y and x directions 
    16571661        len_y = len(image) 
    16581662        len_x = len(image[1]) 
    1659         temp_image = numpy.zeros([len_y, len_x]) 
    1660         weit = numpy.zeros([len_y, len_x]) 
     1663        temp_image = np.zeros([len_y, len_x]) 
     1664        weit = np.zeros([len_y, len_x]) 
    16611665        # do for-loop for all pixels 
    16621666        for n_y in range(len(image)): 
    16631667            for n_x in range(len(image[1])): 
    16641668                # find only null pixels 
    1665                 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]): 
    16661670                    continue 
    16671671                else: 
    16681672                    # find 4 nearest neighbors 
    16691673                    # check where or not it is at the corner 
    1670                     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]): 
    16711675                        temp_image[n_y][n_x] += image[n_y - 1][n_x] 
    16721676                        weit[n_y][n_x] += 1 
    1673                     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]): 
    16741678                        temp_image[n_y][n_x] += image[n_y][n_x - 1] 
    16751679                        weit[n_y][n_x] += 1 
    1676                     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]): 
    16771681                        temp_image[n_y][n_x] += image[n_y + 1][n_x] 
    16781682                        weit[n_y][n_x] += 1 
    1679                     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]): 
    16801684                        temp_image[n_y][n_x] += image[n_y][n_x + 1] 
    16811685                        weit[n_y][n_x] += 1 
    16821686                    # go 4 next nearest neighbors when no non-zero 
    16831687                    # neighbor exists 
    1684                     if n_y != 0 and n_x != 0 and\ 
    1685                          numpy.isfinite(image[n_y - 1][n_x - 1]): 
     1688                    if n_y != 0 and n_x != 0 and \ 
     1689                            np.isfinite(image[n_y - 1][n_x - 1]): 
    16861690                        temp_image[n_y][n_x] += image[n_y - 1][n_x - 1] 
    16871691                        weit[n_y][n_x] += 1 
    16881692                    if n_y != len_y - 1 and n_x != 0 and \ 
    1689                         numpy.isfinite(image[n_y + 1][n_x - 1]): 
     1693                            np.isfinite(image[n_y + 1][n_x - 1]): 
    16901694                        temp_image[n_y][n_x] += image[n_y + 1][n_x - 1] 
    16911695                        weit[n_y][n_x] += 1 
    16921696                    if n_y != len_y and n_x != len_x - 1 and \ 
    1693                         numpy.isfinite(image[n_y - 1][n_x + 1]): 
     1697                            np.isfinite(image[n_y - 1][n_x + 1]): 
    16941698                        temp_image[n_y][n_x] += image[n_y - 1][n_x + 1] 
    16951699                        weit[n_y][n_x] += 1 
    16961700                    if n_y != len_y - 1 and n_x != len_x - 1 and \ 
    1697                         numpy.isfinite(image[n_y + 1][n_x + 1]): 
     1701                            np.isfinite(image[n_y + 1][n_x + 1]): 
    16981702                        temp_image[n_y][n_x] += image[n_y + 1][n_x + 1] 
    16991703                        weit[n_y][n_x] += 1 
     
    17701774            # control axis labels from the panel itself 
    17711775            yname, yunits = item.get_yaxis() 
    1772             if self.yaxis_label != None: 
     1776            if self.yaxis_label is not None: 
    17731777                yname = self.yaxis_label 
    17741778                yunits = self.yaxis_unit 
     
    17771781                self.yaxis_unit = yunits 
    17781782            xname, xunits = item.get_xaxis() 
    1779             if self.xaxis_label != None: 
     1783            if self.xaxis_label is not None: 
    17801784                xname = self.xaxis_label 
    17811785                xunits = self.xaxis_unit 
     
    19381942        """ 
    19391943        """ 
    1940         if self.parent == None: 
     1944        if self.parent is None: 
    19411945            return 
    19421946        # get current caption 
     
    20122016            self.toolbar.copy_figure(self.canvas) 
    20132017        except: 
    2014             print "Error in copy Image" 
     2018            print("Error in copy Image") 
    20152019 
    20162020 
  • 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

    re3ae090 r7432acb  
    22from plottables import Theory1D 
    33import math 
    4 import numpy 
     4import numpy as np 
    55import fittings 
    66import transform 
     
    9595 
    9696        # Set default value of parameter in the dialog panel 
    97         if self.Avalue == None: 
     97        if self.Avalue is None: 
    9898            self.tcA.SetValue(format_number(self.default_A)) 
    9999        else: 
    100100            self.tcA.SetLabel(format_number(self.Avalue)) 
    101         if self.Bvalue == None: 
     101        if self.Bvalue is None: 
    102102            self.tcB.SetValue(format_number(self.default_B)) 
    103103        else: 
    104104            self.tcB.SetLabel(format_number(self.Bvalue)) 
    105         if self.ErrAvalue == None: 
     105        if self.ErrAvalue is None: 
    106106            self.tcErrA.SetLabel(format_number(0.0)) 
    107107        else: 
    108108            self.tcErrA.SetLabel(format_number(self.ErrAvalue)) 
    109         if self.ErrBvalue == None: 
     109        if self.ErrBvalue is None: 
    110110            self.tcErrB.SetLabel(format_number(0.0)) 
    111111        else: 
    112112            self.tcErrB.SetLabel(format_number(self.ErrBvalue)) 
    113         if self.Chivalue == None: 
     113        if self.Chivalue is None: 
    114114            self.tcChi.SetLabel(format_number(0.0)) 
    115115        else: 
     
    482482 
    483483                if self.xLabel.lower() == "log10(x)": 
    484                     tempdy = numpy.asarray(tempdy) 
     484                    tempdy = np.asarray(tempdy) 
    485485                    tempdy[tempdy == 0] = 1 
    486486                    chisqr, out, cov = fittings.sasfit(self.model, 
     
    491491                                                       math.log10(xmax)) 
    492492                else: 
    493                     tempdy = numpy.asarray(tempdy) 
     493                    tempdy = np.asarray(tempdy) 
    494494                    tempdy[tempdy == 0] = 1 
    495495                    chisqr, out, cov = fittings.sasfit(self.model, 
     
    502502 
    503503                # Check that cov and out are iterable before displaying them 
    504                 if cov == None: 
     504                if cov is None: 
    505505                    errA = 0.0 
    506506                    errB = 0.0 
     
    508508                    errA = math.sqrt(cov[0][0]) 
    509509                    errB = math.sqrt(cov[1][1]) 
    510                 if out == None: 
     510                if out is None: 
    511511                    cstA = 0.0 
    512512                    cstB = 0.0 
     
    572572        if self.rg_on: 
    573573            if self.Rg_tctr.IsShown(): 
    574                 rg = numpy.sqrt(-3 * float(cstA)) 
     574                rg = np.sqrt(-3 * float(cstA)) 
    575575                value = format_number(rg) 
    576576                self.Rg_tctr.SetValue(value) 
    577577                if self.I0_tctr.IsShown(): 
    578                     val = numpy.exp(cstB) 
     578                    val = np.exp(cstB) 
    579579                    self.I0_tctr.SetValue(format_number(val)) 
    580580            if self.Rgerr_tctr.IsShown(): 
    581                 if rg != None and rg != 0: 
     581                if rg is not None and rg != 0: 
    582582                    value = format_number(3 * float(errA) / (2 * rg)) 
    583583                else: 
     
    585585                self.Rgerr_tctr.SetValue(value) 
    586586                if self.I0err_tctr.IsShown(): 
    587                     val = numpy.abs(numpy.exp(cstB) * errB) 
     587                    val = np.abs(np.exp(cstB) * errB) 
    588588                    self.I0err_tctr.SetValue(format_number(val)) 
    589589            if self.Diameter_tctr.IsShown(): 
    590                 rg = numpy.sqrt(-2 * float(cstA)) 
    591                 _diam = 4 * numpy.sqrt(-float(cstA)) 
     590                rg = np.sqrt(-2 * float(cstA)) 
     591                _diam = 4 * np.sqrt(-float(cstA)) 
    592592                value = format_number(_diam) 
    593593                self.Diameter_tctr.SetValue(value) 
    594594            if self.Diametererr_tctr.IsShown(): 
    595                 if rg != None and rg != 0: 
     595                if rg is not None and rg != 0: 
    596596                    value = format_number(8 * float(errA) / _diam) 
    597597                else: 
  • src/sas/sasgui/plottools/fittings.py

    re3ae090 ra1b8fee  
    1414 
    1515""" 
     16from __future__ import print_function 
     17 
    1618from scipy import optimize 
    1719 
     
    2527        self.model = model 
    2628        self.name = name 
    27         if not value == None: 
     29        if value is not None: 
    2830            self.model.setParam(self.name, value) 
    2931 
     
    106108    chisqr, out, cov = sasfit(line, [cstA, cstB], event.x, y, 0) 
    107109    # print "Output parameters:", out 
    108     print "The right answer is [70.0, 1.0]" 
    109     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

    r9687d58 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__): 
     
    227229            if p.hidden == True: 
    228230                continue 
    229             if not p.x == None: 
     231            if p.x is not None: 
    230232                for x_i in p.x: 
    231                     if min_value == None or x_i < min_value: 
     233                    if min_value is None or x_i < min_value: 
    232234                        min_value = x_i 
    233                     if max_value == None or x_i > max_value: 
     235                    if max_value is None or x_i > max_value: 
    234236                        max_value = x_i 
    235237        return min_value, max_value 
     
    560562        Returns True if there is no data stored in the plottable 
    561563        """ 
    562         if not self.x == None and len(self.x) == 0 \ 
    563             and not self.y == None and len(self.y) == 0: 
     564        if (self.x is not None and len(self.x) == 0 
     565            and self.y is not None and len(self.y) == 0): 
    564566            return True 
    565567        return False 
     
    681683 
    682684        if(x is not None) and (y is not None): 
    683             if not dx is None and not len(dx) == 0 and not len(x) == len(dx): 
     685            if dx is not None and not len(dx) == 0 and not len(x) == len(dx): 
    684686                msg = "Plottable.View: Given x and dx are not" 
    685687                msg += " of the same length" 
     
    691693                raise ValueError, msg 
    692694 
    693             if not dy is 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): 
    694696                msg = "Plottable.View: Given y and dy are not of the same " 
    695697                msg += "length: len(y)=%s, len(dy)=%s" % (len(y), len(dy)) 
     
    706708                self.dy = None 
    707709            if not has_err_x: 
    708                 dx = numpy.zeros(len(x)) 
     710                dx = np.zeros(len(x)) 
    709711            if not has_err_y: 
    710                 dy = numpy.zeros(len(y)) 
     712                dy = np.zeros(len(y)) 
    711713            for i in range(len(x)): 
    712714                try: 
     
    795797        tempy = [] 
    796798        tempdy = [] 
    797         if self.dx == None: 
    798             self.dx = numpy.zeros(len(self.x)) 
    799         if self.dy == None: 
    800             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)) 
    801803        if self.xLabel == "log10(x)": 
    802804            for i in range(len(self.x)): 
     
    808810                        tempdy.append(self.dy[i]) 
    809811                except: 
    810                     logging.error("check_data_logX: skipping point x %g", self.x[i]) 
    811                     logging.error(sys.exc_value) 
     812                    logger.error("check_data_logX: skipping point x %g", self.x[i]) 
     813                    logger.error(sys.exc_value) 
    812814            self.x = tempx 
    813815            self.y = tempy 
     
    825827        tempy = [] 
    826828        tempdy = [] 
    827         if self.dx == None: 
    828             self.dx = numpy.zeros(len(self.x)) 
    829         if self.dy == None: 
    830             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)) 
    831833        if self.yLabel == "log10(y)": 
    832834            for i in range(len(self.x)): 
     
    838840                        tempdy.append(self.dy[i]) 
    839841                except: 
    840                     logging.error("check_data_logY: skipping point %g", self.y[i]) 
    841                     logging.error(sys.exc_value) 
     842                    logger.error("check_data_logY: skipping point %g", self.y[i]) 
     843                    logger.error(sys.exc_value) 
    842844 
    843845            self.x = tempx 
     
    858860        tempy = [] 
    859861        tempdy = [] 
    860         if self.dx == None: 
    861             self.dx = numpy.zeros(len(self.x)) 
    862         if self.dy == None: 
    863             self.dy = numpy.zeros(len(self.y)) 
    864         if xmin != None and xmax != None: 
     862        if self.dx is None: 
     863            self.dx = np.zeros(len(self.x)) 
     864        if self.dy is None: 
     865            self.dy = np.zeros(len(self.y)) 
     866        if xmin is not None and xmax is not None: 
    865867            for i in range(len(self.x)): 
    866868                if self.x[i] >= xmin and self.x[i] <= xmax: 
     
    10231025    """ 
    10241026 
    1025     def __init__(self, x, y, dx=None, dy=None): 
     1027    def __init__(self, x, y, dx=None, dy=None, lam=None, dlam=None): 
    10261028        """ 
    10271029        Draw points specified by x[i],y[i] in the current color/symbol. 
     
    10371039        self.x = x 
    10381040        self.y = y 
     1041        self.lam = lam 
    10391042        self.dx = dx 
    10401043        self.dy = dy 
     1044        self.dlam = dlam 
    10411045        self.source = None 
    10421046        self.detector = None 
     
    12021206        """ 
    12031207        """ 
    1204         if  self._chisq == None: 
     1208        if  self._chisq is None: 
    12051209            chisqTxt = r'$\chi^2=$' 
    12061210        else: 
     
    12261230 
    12271231def sample_graph(): 
    1228     import numpy as nx 
     1232    import numpy as np 
    12291233 
    12301234    # Construct a simple graph 
    12311235    if False: 
    1232         x = nx.array([1, 2, 3, 4, 5, 6], 'd') 
    1233         y = nx.array([4, 5, 6, 5, 4, 5], 'd') 
    1234         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]) 
    12351239    else: 
    1236         x = nx.linspace(0, 1., 10000) 
    1237         y = nx.sin(2 * nx.pi * x * 2.8) 
    1238         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 
    12391243    data = Data1D(x, y, dy=dy) 
    12401244    data.xaxis('distance', 'm') 
  • src/sas/sasgui/plottools/toolbar.py

    r092a3d9 rc416a17  
    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 
     
    3537 
    3638    # CRUFT: mpl 1.1 uses save rather than save_figure 
    37     #try: save_figure = NavigationToolbar2WxAgg.save 
    38     #except AttributeError: pass 
     39    try: save_figure = NavigationToolbar2WxAgg.save 
     40    except AttributeError: pass 
    3941     
    4042    def _init_toolbar(self): 
     
    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): 
     
    169171    wx.TheClipboard.SetData(bmp) 
    170172    wx.TheClipboard.Close() 
    171  
    172  
  • src/sas/sasgui/plottools/transform.py

    r821c330 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 
     
    294294    """ 
    295295    """ 
    296     if dx == None: 
    297         dx = 0 
    298     if dy == None: 
     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 
     
    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 
     
    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) 
     
    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/config.py

    rd7bb526 r092a3d9  
    3030__all__ = [] 
    3131 
    32 plot_version = "0.98" 
    33 plot_backend = "WXAgg" 
     32#plot_version = "0.98" 
     33#plot_backend = "WXAgg" 
     34plot_backend = "Qt4Agg" 
    3435 
    3536# Sort out matplotlib version 
    3637import matplotlib 
    37 try: 
    38     import pkg_resources 
    39     pkg_resources.require("matplotlib>=" + plot_version) 
    40 except: 
    41     from distutils.version import LooseVersion as Version 
    42     if Version(matplotlib.__version__) < Version(plot_version): 
    43         msg = "Matplotlib version must be %s or newer" % (plot_version, ) 
    44         raise ImportError(msg) 
     38#try: 
     39#    import pkg_resources 
     40#    pkg_resources.require("matplotlib>=" + plot_version) 
     41#except: 
     42#    from distutils.version import LooseVersion as Version 
     43#    if Version(matplotlib.__version__) < Version(plot_version): 
     44#        msg = "Matplotlib version must be %s or newer" % (plot_version, ) 
     45#        raise ImportError(msg) 
    4546 
    4647# Sort out matplotlib backend 
     
    5152elif matplotlib.get_backend() != plot_backend: 
    5253    # if a backend has already been selected, make sure it is the correct one. 
    53     raise ImportError("Matplotlib not using backend " + plot_backend) 
     54    #raise ImportError("Matplotlib not using backend " + plot_backend) 
     55    pass 
    5456 
    5557# set global plot style 
     
    5860matplotlib.rcParams[param] = 0.05 
    5961matplotlib.rcParams['legend.numpoints'] = 1 
     62#matplotlib.rcParams['interactive'] = True 
     63 
    6064 
    6165# this should happen after initial matplotlib configuration 
    62 from .toolbar import NavigationToolBar 
    63 from matplotlib.backends import backend_wxagg 
    64 backend_wxagg.NavigationToolbar2WxAgg = NavigationToolBar 
     66#from .toolbar import NavigationToolBar 
     67#from matplotlib.backends import backend_wxagg 
     68#backend_wxagg.NavigationToolbar2WxAgg = NavigationToolBar 
    6569 
    6670# CRUFT: bumps 0.7.5.6 and older uses wrong toolbar 
    67 backend_wxagg.NavigationToolbar2Wx = NavigationToolBar 
     71#backend_wxagg.NavigationToolbar2Wx = NavigationToolBar 
Note: See TracChangeset for help on using the changeset viewer.