Changeset 9a5097c in sasview for src/sas/sasgui/plottools


Ignore:
Timestamp:
Mar 26, 2017 9:33:16 PM (7 years ago)
Author:
andyfaff
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, costrafo411, magnetic_scatt, release-4.2.2, ticket-1009, ticket-1094-headless, ticket-1242-2d-resolution, ticket-1243, ticket-1249, ticket885, unittest-saveload
Children:
ed2276f
Parents:
9146ed9
Message:

MAINT: import numpy as np

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

Legend:

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

    r198fa76 r9a5097c  
    2929DEFAULT_CMAP = pylab.cm.jet 
    3030import copy 
    31 import numpy 
     31import numpy as np 
    3232 
    3333from sas.sasgui.guiframe.events import StatusEvent 
     
    14521452                if  self.zmin_2D <= 0  and len(output[output > 0]) > 0: 
    14531453                    zmin_temp = self.zmin_2D 
    1454                     output[output > 0] = numpy.log10(output[output > 0]) 
     1454                    output[output > 0] = np.log10(output[output > 0]) 
    14551455                    #In log scale Negative values are not correct in general 
    1456                     #output[output<=0] = math.log(numpy.min(output[output>0])) 
     1456                    #output[output<=0] = math.log(np.min(output[output>0])) 
    14571457                elif self.zmin_2D <= 0: 
    14581458                    zmin_temp = self.zmin_2D 
    1459                     output[output > 0] = numpy.zeros(len(output)) 
     1459                    output[output > 0] = np.zeros(len(output)) 
    14601460                    output[output <= 0] = -32 
    14611461                else: 
    14621462                    zmin_temp = self.zmin_2D 
    1463                     output[output > 0] = numpy.log10(output[output > 0]) 
     1463                    output[output > 0] = np.log10(output[output > 0]) 
    14641464                    #In log scale Negative values are not correct in general 
    1465                     #output[output<=0] = math.log(numpy.min(output[output>0])) 
     1465                    #output[output<=0] = math.log(np.min(output[output>0])) 
    14661466            except: 
    14671467                #Too many problems in 2D plot with scale 
     
    14921492            X = self.x_bins[0:-1] 
    14931493            Y = self.y_bins[0:-1] 
    1494             X, Y = numpy.meshgrid(X, Y) 
     1494            X, Y = np.meshgrid(X, Y) 
    14951495 
    14961496            try: 
     
    15551555        # 1d array to use for weighting the data point averaging 
    15561556        #when they fall into a same bin. 
    1557         weights_data = numpy.ones([self.data.size]) 
     1557        weights_data = np.ones([self.data.size]) 
    15581558        # get histogram of ones w/len(data); this will provide 
    15591559        #the weights of data on each bins 
    1560         weights, xedges, yedges = numpy.histogram2d(x=self.qy_data, 
     1560        weights, xedges, yedges = np.histogram2d(x=self.qy_data, 
    15611561                                                    y=self.qx_data, 
    15621562                                                    bins=[self.y_bins, self.x_bins], 
    15631563                                                    weights=weights_data) 
    15641564        # get histogram of data, all points into a bin in a way of summing 
    1565         image, xedges, yedges = numpy.histogram2d(x=self.qy_data, 
     1565        image, xedges, yedges = np.histogram2d(x=self.qy_data, 
    15661566                                                  y=self.qx_data, 
    15671567                                                  bins=[self.y_bins, self.x_bins], 
     
    15811581        # do while loop until all vacant bins are filled up up 
    15821582        #to loop = max_loop 
    1583         while not(numpy.isfinite(image[weights == 0])).all(): 
     1583        while not(np.isfinite(image[weights == 0])).all(): 
    15841584            if loop >= max_loop:  # this protects never-ending loop 
    15851585                break 
     
    16301630 
    16311631        # 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) 
     1632        x_bins = np.linspace(xmin, xmax, npix_x) 
     1633        y_bins = np.linspace(ymin, ymax, npix_y) 
    16341634 
    16351635        #set x_bins and y_bins 
     
    16501650        """ 
    16511651        # No image matrix given 
    1652         if image == None or numpy.ndim(image) != 2 \ 
    1653                 or numpy.isfinite(image).all() \ 
     1652        if image == None or np.ndim(image) != 2 \ 
     1653                or np.isfinite(image).all() \ 
    16541654                or weights == None: 
    16551655            return image 
     
    16571657        len_y = len(image) 
    16581658        len_x = len(image[1]) 
    1659         temp_image = numpy.zeros([len_y, len_x]) 
    1660         weit = numpy.zeros([len_y, len_x]) 
     1659        temp_image = np.zeros([len_y, len_x]) 
     1660        weit = np.zeros([len_y, len_x]) 
    16611661        # do for-loop for all pixels 
    16621662        for n_y in range(len(image)): 
    16631663            for n_x in range(len(image[1])): 
    16641664                # find only null pixels 
    1665                 if weights[n_y][n_x] > 0 or numpy.isfinite(image[n_y][n_x]): 
     1665                if weights[n_y][n_x] > 0 or np.isfinite(image[n_y][n_x]): 
    16661666                    continue 
    16671667                else: 
    16681668                    # find 4 nearest neighbors 
    16691669                    # check where or not it is at the corner 
    1670                     if n_y != 0 and numpy.isfinite(image[n_y - 1][n_x]): 
     1670                    if n_y != 0 and np.isfinite(image[n_y - 1][n_x]): 
    16711671                        temp_image[n_y][n_x] += image[n_y - 1][n_x] 
    16721672                        weit[n_y][n_x] += 1 
    1673                     if n_x != 0 and numpy.isfinite(image[n_y][n_x - 1]): 
     1673                    if n_x != 0 and np.isfinite(image[n_y][n_x - 1]): 
    16741674                        temp_image[n_y][n_x] += image[n_y][n_x - 1] 
    16751675                        weit[n_y][n_x] += 1 
    1676                     if n_y != len_y - 1 and numpy.isfinite(image[n_y + 1][n_x]): 
     1676                    if n_y != len_y - 1 and np.isfinite(image[n_y + 1][n_x]): 
    16771677                        temp_image[n_y][n_x] += image[n_y + 1][n_x] 
    16781678                        weit[n_y][n_x] += 1 
    1679                     if n_x != len_x - 1 and numpy.isfinite(image[n_y][n_x + 1]): 
     1679                    if n_x != len_x - 1 and np.isfinite(image[n_y][n_x + 1]): 
    16801680                        temp_image[n_y][n_x] += image[n_y][n_x + 1] 
    16811681                        weit[n_y][n_x] += 1 
    16821682                    # go 4 next nearest neighbors when no non-zero 
    16831683                    # neighbor exists 
    1684                     if n_y != 0 and n_x != 0 and\ 
    1685                          numpy.isfinite(image[n_y - 1][n_x - 1]): 
     1684                    if n_y != 0 and n_x != 0 and \ 
     1685                            np.isfinite(image[n_y - 1][n_x - 1]): 
    16861686                        temp_image[n_y][n_x] += image[n_y - 1][n_x - 1] 
    16871687                        weit[n_y][n_x] += 1 
    16881688                    if n_y != len_y - 1 and n_x != 0 and \ 
    1689                         numpy.isfinite(image[n_y + 1][n_x - 1]): 
     1689                            np.isfinite(image[n_y + 1][n_x - 1]): 
    16901690                        temp_image[n_y][n_x] += image[n_y + 1][n_x - 1] 
    16911691                        weit[n_y][n_x] += 1 
    16921692                    if n_y != len_y and n_x != len_x - 1 and \ 
    1693                         numpy.isfinite(image[n_y - 1][n_x + 1]): 
     1693                            np.isfinite(image[n_y - 1][n_x + 1]): 
    16941694                        temp_image[n_y][n_x] += image[n_y - 1][n_x + 1] 
    16951695                        weit[n_y][n_x] += 1 
    16961696                    if n_y != len_y - 1 and n_x != len_x - 1 and \ 
    1697                         numpy.isfinite(image[n_y + 1][n_x + 1]): 
     1697                            np.isfinite(image[n_y + 1][n_x + 1]): 
    16981698                        temp_image[n_y][n_x] += image[n_y + 1][n_x + 1] 
    16991699                        weit[n_y][n_x] += 1 
  • src/sas/sasgui/plottools/fitDialog.py

    rdd5bf63 r9a5097c  
    22from plottables import Theory1D 
    33import math 
    4 import numpy 
     4import numpy as np 
    55import fittings 
    66import transform 
     
    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, 
     
    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(): 
     
    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) 
  • src/sas/sasgui/plottools/plottables.py

    ra9f579c r9a5097c  
    4343# Support for ancient python versions 
    4444import copy 
    45 import numpy 
     45import numpy as np 
    4646import sys 
    4747import logging 
     
    706706                self.dy = None 
    707707            if not has_err_x: 
    708                 dx = numpy.zeros(len(x)) 
     708                dx = np.zeros(len(x)) 
    709709            if not has_err_y: 
    710                 dy = numpy.zeros(len(y)) 
     710                dy = np.zeros(len(y)) 
    711711            for i in range(len(x)): 
    712712                try: 
     
    796796        tempdy = [] 
    797797        if self.dx == None: 
    798             self.dx = numpy.zeros(len(self.x)) 
     798            self.dx = np.zeros(len(self.x)) 
    799799        if self.dy == None: 
    800             self.dy = numpy.zeros(len(self.y)) 
     800            self.dy = np.zeros(len(self.y)) 
    801801        if self.xLabel == "log10(x)": 
    802802            for i in range(len(self.x)): 
     
    826826        tempdy = [] 
    827827        if self.dx == None: 
    828             self.dx = numpy.zeros(len(self.x)) 
     828            self.dx = np.zeros(len(self.x)) 
    829829        if self.dy == None: 
    830             self.dy = numpy.zeros(len(self.y)) 
     830            self.dy = np.zeros(len(self.y)) 
    831831        if self.yLabel == "log10(y)": 
    832832            for i in range(len(self.x)): 
     
    859859        tempdy = [] 
    860860        if self.dx == None: 
    861             self.dx = numpy.zeros(len(self.x)) 
     861            self.dx = np.zeros(len(self.x)) 
    862862        if self.dy == None: 
    863             self.dy = numpy.zeros(len(self.y)) 
     863            self.dy = np.zeros(len(self.y)) 
    864864        if xmin != None and xmax != None: 
    865865            for i in range(len(self.x)): 
     
    12281228 
    12291229def sample_graph(): 
    1230     import numpy as nx 
     1230    import numpy as np 
    12311231 
    12321232    # Construct a simple graph 
    12331233    if False: 
    1234         x = nx.array([1, 2, 3, 4, 5, 6], 'd') 
    1235         y = nx.array([4, 5, 6, 5, 4, 5], 'd') 
    1236         dy = nx.array([0.2, 0.3, 0.1, 0.2, 0.9, 0.3]) 
     1234        x = np.array([1, 2, 3, 4, 5, 6], 'd') 
     1235        y = np.array([4, 5, 6, 5, 4, 5], 'd') 
     1236        dy = np.array([0.2, 0.3, 0.1, 0.2, 0.9, 0.3]) 
    12371237    else: 
    1238         x = nx.linspace(0, 1., 10000) 
    1239         y = nx.sin(2 * nx.pi * x * 2.8) 
    1240         dy = nx.sqrt(100 * nx.abs(y)) / 100 
     1238        x = np.linspace(0, 1., 10000) 
     1239        y = np.sin(2 * np.pi * x * 2.8) 
     1240        dy = np.sqrt(100 * np.abs(y)) / 100 
    12411241    data = Data1D(x, y, dy=dy) 
    12421242    data.xaxis('distance', 'm') 
Note: See TracChangeset for help on using the changeset viewer.