Changeset ed2276f in sasview for src/sas/sascalc/dataloader


Ignore:
Timestamp:
Apr 4, 2017 12:00:18 PM (7 years ago)
Author:
GitHub <noreply@…>
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:
7b15990
Parents:
9a5097c (diff), 571bf4b (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.
git-author:
Andrew Jackson <andrew.jackson@…> (04/04/17 12:00:18)
git-committer:
GitHub <noreply@…> (04/04/17 12:00:18)
Message:

Merge branch 'master' into numpy_import

Location:
src/sas/sascalc/dataloader
Files:
11 edited

Legend:

Unmodified
Added
Removed
  • src/sas/sascalc/dataloader/manipulations.py

    r9a5097c red2276f  
    8080 
    8181    """ 
    82     if data2d.data == None or data2d.x_bins == None or data2d.y_bins == None: 
     82    if data2d.data is None or data2d.x_bins is None or data2d.y_bins is None: 
    8383        raise ValueError, "Can't convert this data: data=None..." 
    8484    new_x = np.tile(data2d.x_bins, (len(data2d.y_bins), 1)) 
     
    9292    if data2d.err_data == None or np.any(data2d.err_data <= 0): 
    9393        new_err_data = np.sqrt(np.abs(new_data)) 
     94 
    9495    else: 
    9596        new_err_data = data2d.err_data.flatten() 
  • src/sas/sascalc/dataloader/readers/IgorReader.py

    r9a5097c red2276f  
    1313############################################################################# 
    1414import os 
     15 
    1516import numpy as np 
    1617import math 
    1718#import logging 
     19 
    1820from sas.sascalc.dataloader.data_info import Data2D 
    1921from sas.sascalc.dataloader.data_info import Detector 
     
    4042        """ Read file """ 
    4143        if not os.path.isfile(filename): 
    42             raise ValueError, \ 
    43             "Specified file %s is not a regular file" % filename 
    44          
    45         # Read file 
    46         f = open(filename, 'r') 
    47         buf = f.read() 
    48          
    49         # Instantiate data object 
     44            raise ValueError("Specified file %s is not a regular " 
     45                             "file" % filename) 
     46         
    5047        output = Data2D() 
     48 
    5149        output.filename = os.path.basename(filename) 
    5250        detector = Detector() 
    53         if len(output.detector) > 0: 
    54             print str(output.detector[0]) 
     51        if len(output.detector): 
     52            print(str(output.detector[0])) 
    5553        output.detector.append(detector) 
    56                  
    57         # Get content 
    58         dataStarted = False 
    59          
    60         lines = buf.split('\n') 
    61         itot = 0 
    62         x = [] 
    63         y = [] 
    64          
    65         ncounts = 0 
    66          
    67         xmin = None 
    68         xmax = None 
    69         ymin = None 
    70         ymax = None 
    71          
    72         i_x = 0 
    73         i_y = -1 
    74         i_tot_row = 0 
    75          
    76         isInfo = False 
    77         isCenter = False 
    78         
    79         data_conv_q = None 
    80         data_conv_i = None 
    81          
    82         if has_converter == True and output.Q_unit != '1/A': 
     54 
     55        data_conv_q = data_conv_i = None 
     56         
     57        if has_converter and output.Q_unit != '1/A': 
    8358            data_conv_q = Converter('1/A') 
    8459            # Test it 
    8560            data_conv_q(1.0, output.Q_unit) 
    8661             
    87         if has_converter == True and output.I_unit != '1/cm': 
     62        if has_converter and output.I_unit != '1/cm': 
    8863            data_conv_i = Converter('1/cm') 
    8964            # Test it 
    9065            data_conv_i(1.0, output.I_unit) 
    91           
     66 
    9267        for line in lines: 
    9368             
     
    12095        output.data = np.zeros([size_x, size_y]) 
    12196        output.err_data = np.zeros([size_x, size_y]) 
    122       
    123         #Read Header and 2D data 
    124         for line in lines: 
    125             # Find setup info line 
    126             if isInfo: 
    127                 isInfo = False 
    128                 line_toks = line.split() 
    129                 # Wavelength in Angstrom 
    130                 try: 
    131                     wavelength = float(line_toks[1]) 
    132                 except: 
    133                     msg = "IgorReader: can't read this file, missing wavelength" 
    134                     raise ValueError, msg 
    135                 # Distance in meters 
    136                 try: 
    137                     distance = float(line_toks[3]) 
    138                 except: 
    139                     msg = "IgorReader: can't read this file, missing distance" 
    140                     raise ValueError, msg 
    141                  
    142                 # Distance in meters 
    143                 try: 
    144                     transmission = float(line_toks[4]) 
    145                 except: 
    146                     msg = "IgorReader: can't read this file, " 
    147                     msg += "missing transmission" 
    148                     raise ValueError, msg 
    149                                              
    150             if line.count("LAMBDA") > 0: 
    151                 isInfo = True 
    152                  
    153             # Find center info line 
    154             if isCenter: 
    155                 isCenter = False 
    156                 line_toks = line.split() 
    157                  
    158                 # Center in bin number: Must substrate 1 because 
    159                 #the index starts from 1 
    160                 center_x = float(line_toks[0]) - 1 
    161                 center_y = float(line_toks[1]) - 1 
    162  
    163             if line.count("BCENT") > 0: 
    164                 isCenter = True 
    165                  
    166             # Find data start 
    167             if line.count("***")>0: 
    168                 dataStarted = True 
    169                  
    170                 # Check that we have all the info 
    171                 if wavelength == None \ 
    172                     or distance == None \ 
    173                     or center_x == None \ 
    174                     or center_y == None: 
    175                     msg = "IgorReader:Missing information in data file" 
    176                     raise ValueError, msg 
    177                  
    178             if dataStarted == True: 
    179                 try: 
    180                     value = float(line) 
    181                 except: 
    182                     # Found a non-float entry, skip it 
    183                     continue 
    184                  
    185                 # Get bin number 
    186                 if math.fmod(itot, i_tot_row) == 0: 
    187                     i_x = 0 
    188                     i_y += 1 
    189                 else: 
    190                     i_x += 1 
    191                      
    192                 output.data[i_y][i_x] = value 
    193                 ncounts += 1 
    194                  
    195                 # Det 640 x 640 mm 
    196                 # Q = 4pi/lambda sin(theta/2) 
    197                 # Bin size is 0.5 cm  
    198                 #REmoved +1 from theta = (i_x-center_x+1)*0.5 / distance 
    199                 # / 100.0 and  
    200                 #REmoved +1 from theta = (i_y-center_y+1)*0.5 / 
    201                 # distance / 100.0 
    202                 #ToDo: Need  complete check if the following 
    203                 # covert process is consistent with fitting.py. 
    204                 theta = (i_x - center_x) * 0.5 / distance / 100.0 
    205                 qx = 4.0 * math.pi / wavelength * math.sin(theta/2.0) 
    206  
    207                 if has_converter == True and output.Q_unit != '1/A': 
    208                     qx = data_conv_q(qx, units=output.Q_unit) 
    209  
    210                 if xmin == None or qx < xmin: 
    211                     xmin = qx 
    212                 if xmax == None or qx > xmax: 
    213                     xmax = qx 
    214                  
    215                 theta = (i_y - center_y) * 0.5 / distance / 100.0 
    216                 qy = 4.0 * math.pi / wavelength * math.sin(theta / 2.0) 
    217  
    218                 if has_converter == True and output.Q_unit != '1/A': 
    219                     qy = data_conv_q(qy, units=output.Q_unit) 
    220                  
    221                 if ymin == None or qy < ymin: 
    222                     ymin = qy 
    223                 if ymax == None or qy > ymax: 
    224                     ymax = qy 
    225                  
    226                 if not qx in x: 
    227                     x.append(qx) 
    228                 if not qy in y: 
    229                     y.append(qy) 
    230                  
    231                 itot += 1 
    232                    
    233                    
     97   
     98        data_row = 0 
     99        wavelength = distance = center_x = center_y = None 
     100        dataStarted = isInfo = isCenter = False 
     101 
     102        with open(filename, 'r') as f: 
     103            for line in f: 
     104                data_row += 1 
     105                # Find setup info line 
     106                if isInfo: 
     107                    isInfo = False 
     108                    line_toks = line.split() 
     109                    # Wavelength in Angstrom 
     110                    try: 
     111                        wavelength = float(line_toks[1]) 
     112                    except ValueError: 
     113                        msg = "IgorReader: can't read this file, missing wavelength" 
     114                        raise ValueError(msg) 
     115                    # Distance in meters 
     116                    try: 
     117                        distance = float(line_toks[3]) 
     118                    except ValueError: 
     119                        msg = "IgorReader: can't read this file, missing distance" 
     120                        raise ValueError(msg) 
     121 
     122                    # Distance in meters 
     123                    try: 
     124                        transmission = float(line_toks[4]) 
     125                    except: 
     126                        msg = "IgorReader: can't read this file, " 
     127                        msg += "missing transmission" 
     128                        raise ValueError(msg) 
     129 
     130                if line.count("LAMBDA"): 
     131                    isInfo = True 
     132 
     133                # Find center info line 
     134                if isCenter: 
     135                    isCenter = False 
     136                    line_toks = line.split() 
     137 
     138                    # Center in bin number: Must subtract 1 because 
     139                    # the index starts from 1 
     140                    center_x = float(line_toks[0]) - 1 
     141                    center_y = float(line_toks[1]) - 1 
     142 
     143                if line.count("BCENT"): 
     144                    isCenter = True 
     145 
     146                # Find data start 
     147                if line.count("***"): 
     148                    # now have to continue to blank line 
     149                    dataStarted = True 
     150 
     151                    # Check that we have all the info 
     152                    if (wavelength is None 
     153                            or distance is None 
     154                            or center_x is None 
     155                            or center_y is None): 
     156                        msg = "IgorReader:Missing information in data file" 
     157                        raise ValueError(msg) 
     158 
     159                if dataStarted: 
     160                    if len(line.rstrip()): 
     161                        continue 
     162                    else: 
     163                        break 
     164 
     165        # The data is loaded in row major order (last index changing most 
     166        # rapidly). However, the original data is in column major order (first 
     167        # index changing most rapidly). The swap to column major order is done 
     168        # in reader2D_converter at the end of this method. 
     169        data = np.loadtxt(filename, skiprows=data_row) 
     170        size_x = size_y = int(np.rint(np.sqrt(data.size))) 
     171        output.data = np.reshape(data, (size_x, size_y)) 
     172        output.err_data = np.zeros_like(output.data) 
     173 
     174        # Det 640 x 640 mm 
     175        # Q = 4 * pi/lambda * sin(theta/2) 
     176        # Bin size is 0.5 cm 
     177        # Removed +1 from theta = (i_x - center_x + 1)*0.5 / distance 
     178        # / 100.0 and 
     179        # Removed +1 from theta = (i_y - center_y + 1)*0.5 / 
     180        # distance / 100.0 
     181        # ToDo: Need  complete check if the following 
     182        # convert process is consistent with fitting.py. 
     183 
     184        # calculate qx, qy bin centers of each pixel in the image 
     185        theta = (np.arange(size_x) - center_x) * 0.5 / distance / 100. 
     186        qx = 4 * np.pi / wavelength * np.sin(theta/2) 
     187 
     188        theta = (np.arange(size_y) - center_y) * 0.5 / distance / 100. 
     189        qy = 4 * np.pi / wavelength * np.sin(theta/2) 
     190 
     191        if has_converter and output.Q_unit != '1/A': 
     192            qx = data_conv_q(qx, units=output.Q_unit) 
     193            qy = data_conv_q(qx, units=output.Q_unit) 
     194 
     195        xmax = np.max(qx) 
     196        xmin = np.min(qx) 
     197        ymax = np.max(qy) 
     198        ymin = np.min(qy) 
     199 
     200        # calculate edge offset in q. 
    234201        theta = 0.25 / distance / 100.0 
    235         xstep = 4.0 * math.pi / wavelength * math.sin(theta / 2.0) 
     202        xstep = 4.0 * np.pi / wavelength * np.sin(theta / 2.0) 
    236203         
    237204        theta = 0.25 / distance / 100.0 
    238         ystep = 4.0 * math.pi/ wavelength * math.sin(theta / 2.0) 
     205        ystep = 4.0 * np.pi/ wavelength * np.sin(theta / 2.0) 
    239206         
    240207        # Store all data ###################################### 
    241208        # Store wavelength 
    242         if has_converter == True and output.source.wavelength_unit != 'A': 
     209        if has_converter and output.source.wavelength_unit != 'A': 
    243210            conv = Converter('A') 
    244211            wavelength = conv(wavelength, units=output.source.wavelength_unit) 
     
    246213 
    247214        # Store distance 
    248         if has_converter == True and detector.distance_unit != 'm': 
     215        if has_converter and detector.distance_unit != 'm': 
    249216            conv = Converter('m') 
    250217            distance = conv(distance, units=detector.distance_unit) 
     
    254221        output.sample.transmission = transmission 
    255222         
    256         # Store pixel size 
     223        # Store pixel size (mm) 
    257224        pixel = 5.0 
    258         if has_converter == True and detector.pixel_size_unit != 'mm': 
     225        if has_converter and detector.pixel_size_unit != 'mm': 
    259226            conv = Converter('mm') 
    260227            pixel = conv(pixel, units=detector.pixel_size_unit) 
     
    267234         
    268235        # Store limits of the image (2D array) 
    269         xmin = xmin - xstep / 2.0 
    270         xmax = xmax + xstep / 2.0 
    271         ymin = ymin - ystep / 2.0 
    272         ymax = ymax + ystep / 2.0 
    273         if has_converter == True and output.Q_unit != '1/A': 
     236        xmin -= xstep / 2.0 
     237        xmax += xstep / 2.0 
     238        ymin -= ystep / 2.0 
     239        ymax += ystep / 2.0 
     240        if has_converter and output.Q_unit != '1/A': 
    274241            xmin = data_conv_q(xmin, units=output.Q_unit) 
    275242            xmax = data_conv_q(xmax, units=output.Q_unit) 
     
    282249         
    283250        # Store x and y axis bin centers 
    284         output.x_bins = x 
    285         output.y_bins = y 
     251        output.x_bins = qx.tolist() 
     252        output.y_bins = qy.tolist() 
    286253         
    287254        # Units 
  • src/sas/sascalc/dataloader/readers/cansas_reader.py

    rc221349 r8434365  
    930930            self._write_data(datainfo, entry_node) 
    931931        # Transmission Spectrum Info 
    932         self._write_trans_spectrum(datainfo, entry_node) 
     932        # TODO: fix the writer to linearize all data, including T_spectrum 
     933        # self._write_trans_spectrum(datainfo, entry_node) 
    933934        # Sample info 
    934935        self._write_sample_info(datainfo, entry_node) 
  • src/sas/sascalc/dataloader/data_info.py

    r2ffe241 r9a5097c  
    2323#from sas.guitools.plottables import Data1D as plottable_1D 
    2424from sas.sascalc.data_util.uncertainty import Uncertainty 
    25 import numpy 
     25import numpy as np 
    2626import math 
    2727 
     
    5151 
    5252    def __init__(self, x, y, dx=None, dy=None, dxl=None, dxw=None, lam=None, dlam=None): 
    53         self.x = numpy.asarray(x) 
    54         self.y = numpy.asarray(y) 
     53        self.x = np.asarray(x) 
     54        self.y = np.asarray(y) 
    5555        if dx is not None: 
    56             self.dx = numpy.asarray(dx) 
     56            self.dx = np.asarray(dx) 
    5757        if dy is not None: 
    58             self.dy = numpy.asarray(dy) 
     58            self.dy = np.asarray(dy) 
    5959        if dxl is not None: 
    60             self.dxl = numpy.asarray(dxl) 
     60            self.dxl = np.asarray(dxl) 
    6161        if dxw is not None: 
    62             self.dxw = numpy.asarray(dxw) 
     62            self.dxw = np.asarray(dxw) 
    6363        if lam is not None: 
    64             self.lam = numpy.asarray(lam) 
     64            self.lam = np.asarray(lam) 
    6565        if dlam is not None: 
    66             self.dlam = numpy.asarray(dlam) 
     66            self.dlam = np.asarray(dlam) 
    6767 
    6868    def xaxis(self, label, unit): 
     
    109109                 qy_data=None, q_data=None, mask=None, 
    110110                 dqx_data=None, dqy_data=None): 
    111         self.data = numpy.asarray(data) 
    112         self.qx_data = numpy.asarray(qx_data) 
    113         self.qy_data = numpy.asarray(qy_data) 
    114         self.q_data = numpy.asarray(q_data) 
    115         self.mask = numpy.asarray(mask) 
    116         self.err_data = numpy.asarray(err_data) 
     111        self.data = np.asarray(data) 
     112        self.qx_data = np.asarray(qx_data) 
     113        self.qy_data = np.asarray(qy_data) 
     114        self.q_data = np.asarray(q_data) 
     115        self.mask = np.asarray(mask) 
     116        self.err_data = np.asarray(err_data) 
    117117        if dqx_data is not None: 
    118             self.dqx_data = numpy.asarray(dqx_data) 
     118            self.dqx_data = np.asarray(dqx_data) 
    119119        if dqy_data is not None: 
    120             self.dqy_data = numpy.asarray(dqy_data) 
     120            self.dqy_data = np.asarray(dqy_data) 
    121121 
    122122    def xaxis(self, label, unit): 
     
    734734        """ 
    735735        def _check(v): 
    736             if (v.__class__ == list or v.__class__ == numpy.ndarray) \ 
     736            if (v.__class__ == list or v.__class__ == np.ndarray) \ 
    737737                and len(v) > 0 and min(v) > 0: 
    738738                return True 
     
    752752 
    753753        if clone is None or not issubclass(clone.__class__, Data1D): 
    754             x = numpy.zeros(length) 
    755             dx = numpy.zeros(length) 
    756             y = numpy.zeros(length) 
    757             dy = numpy.zeros(length) 
    758             lam = numpy.zeros(length) 
    759             dlam = numpy.zeros(length) 
     754            x = np.zeros(length) 
     755            dx = np.zeros(length) 
     756            y = np.zeros(length) 
     757            dy = np.zeros(length) 
     758            lam = np.zeros(length) 
     759            dlam = np.zeros(length) 
    760760            clone = Data1D(x, y, lam=lam, dx=dx, dy=dy, dlam=dlam) 
    761761 
     
    806806            dy_other = other.dy 
    807807            if other.dy == None or (len(other.dy) != len(other.y)): 
    808                 dy_other = numpy.zeros(len(other.y)) 
     808                dy_other = np.zeros(len(other.y)) 
    809809 
    810810        # Check that we have errors, otherwise create zero vector 
    811811        dy = self.dy 
    812812        if self.dy == None or (len(self.dy) != len(self.y)): 
    813             dy = numpy.zeros(len(self.y)) 
     813            dy = np.zeros(len(self.y)) 
    814814 
    815815        return dy, dy_other 
     
    824824            result.dxw = None 
    825825        else: 
    826             result.dxw = numpy.zeros(len(self.x)) 
     826            result.dxw = np.zeros(len(self.x)) 
    827827        if self.dxl == None: 
    828828            result.dxl = None 
    829829        else: 
    830             result.dxl = numpy.zeros(len(self.x)) 
     830            result.dxl = np.zeros(len(self.x)) 
    831831 
    832832        for i in range(len(self.x)): 
     
    886886            result.dy = None 
    887887        else: 
    888             result.dy = numpy.zeros(len(self.x) + len(other.x)) 
     888            result.dy = np.zeros(len(self.x) + len(other.x)) 
    889889        if self.dx == None or other.dx is None: 
    890890            result.dx = None 
    891891        else: 
    892             result.dx = numpy.zeros(len(self.x) + len(other.x)) 
     892            result.dx = np.zeros(len(self.x) + len(other.x)) 
    893893        if self.dxw == None or other.dxw is None: 
    894894            result.dxw = None 
    895895        else: 
    896             result.dxw = numpy.zeros(len(self.x) + len(other.x)) 
     896            result.dxw = np.zeros(len(self.x) + len(other.x)) 
    897897        if self.dxl == None or other.dxl is None: 
    898898            result.dxl = None 
    899899        else: 
    900             result.dxl = numpy.zeros(len(self.x) + len(other.x)) 
    901  
    902         result.x = numpy.append(self.x, other.x) 
     900            result.dxl = np.zeros(len(self.x) + len(other.x)) 
     901 
     902        result.x = np.append(self.x, other.x) 
    903903        #argsorting 
    904         ind = numpy.argsort(result.x) 
     904        ind = np.argsort(result.x) 
    905905        result.x = result.x[ind] 
    906         result.y = numpy.append(self.y, other.y) 
     906        result.y = np.append(self.y, other.y) 
    907907        result.y = result.y[ind] 
    908908        if result.dy != None: 
    909             result.dy = numpy.append(self.dy, other.dy) 
     909            result.dy = np.append(self.dy, other.dy) 
    910910            result.dy = result.dy[ind] 
    911911        if result.dx is not None: 
    912             result.dx = numpy.append(self.dx, other.dx) 
     912            result.dx = np.append(self.dx, other.dx) 
    913913            result.dx = result.dx[ind] 
    914914        if result.dxw is not None: 
    915             result.dxw = numpy.append(self.dxw, other.dxw) 
     915            result.dxw = np.append(self.dxw, other.dxw) 
    916916            result.dxw = result.dxw[ind] 
    917917        if result.dxl is not None: 
    918             result.dxl = numpy.append(self.dxl, other.dxl) 
     918            result.dxl = np.append(self.dxl, other.dxl) 
    919919            result.dxl = result.dxl[ind] 
    920920        return result 
     
    970970 
    971971        if clone is None or not issubclass(clone.__class__, Data2D): 
    972             data = numpy.zeros(length) 
    973             err_data = numpy.zeros(length) 
    974             qx_data = numpy.zeros(length) 
    975             qy_data = numpy.zeros(length) 
    976             q_data = numpy.zeros(length) 
    977             mask = numpy.zeros(length) 
     972            data = np.zeros(length) 
     973            err_data = np.zeros(length) 
     974            qx_data = np.zeros(length) 
     975            qy_data = np.zeros(length) 
     976            q_data = np.zeros(length) 
     977            mask = np.zeros(length) 
    978978            dqx_data = None 
    979979            dqy_data = None 
     
    10311031            if other.err_data == None or \ 
    10321032                (len(other.err_data) != len(other.data)): 
    1033                 err_other = numpy.zeros(len(other.data)) 
     1033                err_other = np.zeros(len(other.data)) 
    10341034 
    10351035        # Check that we have errors, otherwise create zero vector 
     
    10371037        if self.err_data == None or \ 
    10381038            (len(self.err_data) != len(self.data)): 
    1039             err = numpy.zeros(len(other.data)) 
     1039            err = np.zeros(len(other.data)) 
    10401040        return err, err_other 
    10411041 
     
    10491049        # First, check the data compatibility 
    10501050        dy, dy_other = self._validity_check(other) 
    1051         result = self.clone_without_data(numpy.size(self.data)) 
     1051        result = self.clone_without_data(np.size(self.data)) 
    10521052        if self.dqx_data == None or self.dqy_data == None: 
    10531053            result.dqx_data = None 
    10541054            result.dqy_data = None 
    10551055        else: 
    1056             result.dqx_data = numpy.zeros(len(self.data)) 
    1057             result.dqy_data = numpy.zeros(len(self.data)) 
    1058         for i in range(numpy.size(self.data)): 
     1056            result.dqx_data = np.zeros(len(self.data)) 
     1057            result.dqy_data = np.zeros(len(self.data)) 
     1058        for i in range(np.size(self.data)): 
    10591059            result.data[i] = self.data[i] 
    10601060            if self.err_data is not None and \ 
    1061                 numpy.size(self.data) == numpy.size(self.err_data): 
     1061                            np.size(self.data) == np.size(self.err_data): 
    10621062                result.err_data[i] = self.err_data[i] 
    10631063            if self.dqx_data is not None: 
     
    11181118        # First, check the data compatibility 
    11191119        self._validity_check_union(other) 
    1120         result = self.clone_without_data(numpy.size(self.data) + \ 
    1121                                          numpy.size(other.data)) 
     1120        result = self.clone_without_data(np.size(self.data) + \ 
     1121                                         np.size(other.data)) 
    11221122        result.xmin = self.xmin 
    11231123        result.xmax = self.xmax 
     
    11291129            result.dqy_data = None 
    11301130        else: 
    1131             result.dqx_data = numpy.zeros(len(self.data) + \ 
    1132                                          numpy.size(other.data)) 
    1133             result.dqy_data = numpy.zeros(len(self.data) + \ 
    1134                                          numpy.size(other.data)) 
    1135  
    1136         result.data = numpy.append(self.data, other.data) 
    1137         result.qx_data = numpy.append(self.qx_data, other.qx_data) 
    1138         result.qy_data = numpy.append(self.qy_data, other.qy_data) 
    1139         result.q_data = numpy.append(self.q_data, other.q_data) 
    1140         result.mask = numpy.append(self.mask, other.mask) 
     1131            result.dqx_data = np.zeros(len(self.data) + \ 
     1132                                       np.size(other.data)) 
     1133            result.dqy_data = np.zeros(len(self.data) + \ 
     1134                                       np.size(other.data)) 
     1135 
     1136        result.data = np.append(self.data, other.data) 
     1137        result.qx_data = np.append(self.qx_data, other.qx_data) 
     1138        result.qy_data = np.append(self.qy_data, other.qy_data) 
     1139        result.q_data = np.append(self.q_data, other.q_data) 
     1140        result.mask = np.append(self.mask, other.mask) 
    11411141        if result.err_data is not None: 
    1142             result.err_data = numpy.append(self.err_data, other.err_data) 
     1142            result.err_data = np.append(self.err_data, other.err_data) 
    11431143        if self.dqx_data is not None: 
    1144             result.dqx_data = numpy.append(self.dqx_data, other.dqx_data) 
     1144            result.dqx_data = np.append(self.dqx_data, other.dqx_data) 
    11451145        if self.dqy_data is not None: 
    1146             result.dqy_data = numpy.append(self.dqy_data, other.dqy_data) 
     1146            result.dqy_data = np.append(self.dqy_data, other.dqy_data) 
    11471147 
    11481148        return result 
  • src/sas/sascalc/dataloader/readers/abs_reader.py

    rb699768 r9a5097c  
    99###################################################################### 
    1010 
    11 import numpy 
     11import numpy as np 
    1212import os 
    1313from sas.sascalc.dataloader.data_info import Data1D 
     
    5353                buff = input_f.read() 
    5454                lines = buff.split('\n') 
    55                 x  = numpy.zeros(0) 
    56                 y  = numpy.zeros(0) 
    57                 dy = numpy.zeros(0) 
    58                 dx = numpy.zeros(0) 
     55                x  = np.zeros(0) 
     56                y  = np.zeros(0) 
     57                dy = np.zeros(0) 
     58                dx = np.zeros(0) 
    5959                output = Data1D(x, y, dy=dy, dx=dx) 
    6060                detector = Detector() 
     
    204204                                _dy = data_conv_i(_dy, units=output.y_unit) 
    205205                            
    206                             x = numpy.append(x, _x) 
    207                             y = numpy.append(y, _y) 
    208                             dy = numpy.append(dy, _dy) 
    209                             dx = numpy.append(dx, _dx) 
     206                            x = np.append(x, _x) 
     207                            y = np.append(y, _y) 
     208                            dy = np.append(dy, _dy) 
     209                            dx = np.append(dx, _dx) 
    210210                             
    211211                        except: 
  • src/sas/sascalc/dataloader/readers/ascii_reader.py

    rd2471870 r9a5097c  
    1414 
    1515 
    16 import numpy 
     16import numpy as np 
    1717import os 
    1818from sas.sascalc.dataloader.data_info import Data1D 
     
    6969 
    7070                # Arrays for data storage 
    71                 tx = numpy.zeros(0) 
    72                 ty = numpy.zeros(0) 
    73                 tdy = numpy.zeros(0) 
    74                 tdx = numpy.zeros(0) 
     71                tx = np.zeros(0) 
     72                ty = np.zeros(0) 
     73                tdy = np.zeros(0) 
     74                tdx = np.zeros(0) 
    7575 
    7676                # The first good line of data will define whether 
     
    140140                            is_data == False: 
    141141                            try: 
    142                                 tx = numpy.zeros(0) 
    143                                 ty = numpy.zeros(0) 
    144                                 tdy = numpy.zeros(0) 
    145                                 tdx = numpy.zeros(0) 
     142                                tx = np.zeros(0) 
     143                                ty = np.zeros(0) 
     144                                tdy = np.zeros(0) 
     145                                tdx = np.zeros(0) 
    146146                            except: 
    147147                                pass 
    148148 
    149149                        if has_error_dy == True: 
    150                             tdy = numpy.append(tdy, _dy) 
     150                            tdy = np.append(tdy, _dy) 
    151151                        if has_error_dx == True: 
    152                             tdx = numpy.append(tdx, _dx) 
    153                         tx = numpy.append(tx, _x) 
    154                         ty = numpy.append(ty, _y) 
     152                            tdx = np.append(tdx, _dx) 
     153                        tx = np.append(tx, _x) 
     154                        ty = np.append(ty, _y) 
    155155 
    156156                        #To remember the # of columns on the current line 
     
    188188                #Let's re-order the data to make cal. 
    189189                # curve look better some cases 
    190                 ind = numpy.lexsort((ty, tx)) 
    191                 x = numpy.zeros(len(tx)) 
    192                 y = numpy.zeros(len(ty)) 
    193                 dy = numpy.zeros(len(tdy)) 
    194                 dx = numpy.zeros(len(tdx)) 
     190                ind = np.lexsort((ty, tx)) 
     191                x = np.zeros(len(tx)) 
     192                y = np.zeros(len(ty)) 
     193                dy = np.zeros(len(tdy)) 
     194                dx = np.zeros(len(tdx)) 
    195195                output = Data1D(x, y, dy=dy, dx=dx) 
    196196                self.filename = output.filename = basename 
     
    212212                output.y = y[x != 0] 
    213213                output.dy = dy[x != 0] if has_error_dy == True\ 
    214                     else numpy.zeros(len(output.y)) 
     214                    else np.zeros(len(output.y)) 
    215215                output.dx = dx[x != 0] if has_error_dx == True\ 
    216                     else numpy.zeros(len(output.x)) 
     216                    else np.zeros(len(output.x)) 
    217217 
    218218                output.xaxis("\\rm{Q}", 'A^{-1}') 
  • src/sas/sascalc/dataloader/readers/danse_reader.py

    rb699768 r9a5097c  
    1515import os 
    1616import sys 
    17 import numpy 
     17import numpy as np 
    1818import logging 
    1919from sas.sascalc.dataloader.data_info import Data2D, Detector 
     
    7979            output.detector.append(detector) 
    8080             
    81             output.data = numpy.zeros([size_x,size_y]) 
    82             output.err_data = numpy.zeros([size_x, size_y]) 
     81            output.data = np.zeros([size_x,size_y]) 
     82            output.err_data = np.zeros([size_x, size_y]) 
    8383             
    8484            data_conv_q = None 
  • src/sas/sascalc/dataloader/readers/hfir1d_reader.py

    rb699768 r9a5097c  
    99#copyright 2008, University of Tennessee 
    1010###################################################################### 
    11 import numpy 
     11import numpy as np 
    1212import os 
    1313from sas.sascalc.dataloader.data_info import Data1D 
     
    5252                buff = input_f.read() 
    5353                lines = buff.split('\n') 
    54                 x = numpy.zeros(0) 
    55                 y = numpy.zeros(0) 
    56                 dx = numpy.zeros(0) 
    57                 dy = numpy.zeros(0) 
     54                x = np.zeros(0) 
     55                y = np.zeros(0) 
     56                dx = np.zeros(0) 
     57                dy = np.zeros(0) 
    5858                output = Data1D(x, y, dx=dx, dy=dy) 
    5959                self.filename = output.filename = basename 
     
    8888                            _dy = data_conv_i(_dy, units=output.y_unit) 
    8989                                                     
    90                         x = numpy.append(x, _x) 
    91                         y = numpy.append(y, _y) 
    92                         dx = numpy.append(dx, _dx) 
    93                         dy = numpy.append(dy, _dy) 
     90                        x = np.append(x, _x) 
     91                        y = np.append(y, _y) 
     92                        dx = np.append(dx, _dx) 
     93                        dy = np.append(dy, _dy) 
    9494                    except: 
    9595                        # Couldn't parse this line, skip it  
  • src/sas/sascalc/dataloader/readers/red2d_reader.py

    rb699768 r9a5097c  
    1010###################################################################### 
    1111import os 
    12 import numpy 
     12import numpy as np 
    1313import math 
    1414from sas.sascalc.dataloader.data_info import Data2D, Detector 
     
    198198                break 
    199199        # Make numpy array to remove header lines using index 
    200         lines_array = numpy.array(lines) 
     200        lines_array = np.array(lines) 
    201201 
    202202        # index for lines_array 
    203         lines_index = numpy.arange(len(lines)) 
     203        lines_index = np.arange(len(lines)) 
    204204         
    205205        # get the data lines 
     
    225225 
    226226        # numpy array form 
    227         data_array = numpy.array(data_list1) 
     227        data_array = np.array(data_list1) 
    228228        # Redimesion based on the row_num and col_num, 
    229229        #otherwise raise an error. 
     
    235235        ## Get the all data: Let's HARDcoding; Todo find better way 
    236236        # Defaults 
    237         dqx_data = numpy.zeros(0) 
    238         dqy_data = numpy.zeros(0) 
    239         err_data = numpy.ones(row_num) 
    240         qz_data = numpy.zeros(row_num) 
    241         mask = numpy.ones(row_num, dtype=bool) 
     237        dqx_data = np.zeros(0) 
     238        dqy_data = np.zeros(0) 
     239        err_data = np.ones(row_num) 
     240        qz_data = np.zeros(row_num) 
     241        mask = np.ones(row_num, dtype=bool) 
    242242        # Get from the array 
    243243        qx_data = data_point[0] 
     
    254254            dqy_data = data_point[(5 + ver)] 
    255255        #if col_num > (6 + ver): mask[data_point[(6 + ver)] < 1] = False 
    256         q_data = numpy.sqrt(qx_data*qx_data+qy_data*qy_data+qz_data*qz_data) 
     256        q_data = np.sqrt(qx_data*qx_data+qy_data*qy_data+qz_data*qz_data) 
    257257            
    258258        # Extra protection(it is needed for some data files):  
     
    262262   
    263263        # Store limits of the image in q space 
    264         xmin = numpy.min(qx_data) 
    265         xmax = numpy.max(qx_data) 
    266         ymin = numpy.min(qy_data) 
    267         ymax = numpy.max(qy_data) 
     264        xmin = np.min(qx_data) 
     265        xmax = np.max(qx_data) 
     266        ymin = np.min(qy_data) 
     267        ymax = np.max(qy_data) 
    268268 
    269269        # units 
     
    287287         
    288288        # store x and y axis bin centers in q space 
    289         x_bins = numpy.arange(xmin, xmax + xstep, xstep) 
    290         y_bins = numpy.arange(ymin, ymax + ystep, ystep) 
     289        x_bins = np.arange(xmin, xmax + xstep, xstep) 
     290        y_bins = np.arange(ymin, ymax + ystep, ystep) 
    291291        
    292292        # get the limits of q values 
     
    300300        output.data = data 
    301301        if (err_data == 1).all(): 
    302             output.err_data = numpy.sqrt(numpy.abs(data)) 
     302            output.err_data = np.sqrt(np.abs(data)) 
    303303            output.err_data[output.err_data == 0.0] = 1.0 
    304304        else: 
     
    335335                # tranfer the comp. to cartesian coord. for newer version. 
    336336                if ver != 1: 
    337                     diag = numpy.sqrt(qx_data * qx_data + qy_data * qy_data) 
     337                    diag = np.sqrt(qx_data * qx_data + qy_data * qy_data) 
    338338                    cos_th = qx_data / diag 
    339339                    sin_th = qy_data / diag 
    340                     output.dqx_data = numpy.sqrt((dqx_data * cos_th) * \ 
     340                    output.dqx_data = np.sqrt((dqx_data * cos_th) * \ 
    341341                                                 (dqx_data * cos_th) \ 
    342342                                                 + (dqy_data * sin_th) * \ 
    343343                                                  (dqy_data * sin_th)) 
    344                     output.dqy_data = numpy.sqrt((dqx_data * sin_th) * \ 
     344                    output.dqy_data = np.sqrt((dqx_data * sin_th) * \ 
    345345                                                 (dqx_data * sin_th) \ 
    346346                                                 + (dqy_data * cos_th) * \ 
  • src/sas/sascalc/dataloader/readers/sesans_reader.py

    r7caf3e5 r9a5097c  
    66    Jurrian Bakker  
    77""" 
    8 import numpy 
     8import numpy as np 
    99import os 
    1010from sas.sascalc.dataloader.data_info import Data1D 
     
    6060                buff = input_f.read() 
    6161                lines = buff.splitlines() 
    62                 x  = numpy.zeros(0) 
    63                 y  = numpy.zeros(0) 
    64                 dy = numpy.zeros(0) 
    65                 lam  = numpy.zeros(0) 
    66                 dlam = numpy.zeros(0) 
    67                 dx = numpy.zeros(0) 
     62                x  = np.zeros(0) 
     63                y  = np.zeros(0) 
     64                dy = np.zeros(0) 
     65                lam  = np.zeros(0) 
     66                dlam = np.zeros(0) 
     67                dx = np.zeros(0) 
    6868                 
    6969               #temp. space to sort data 
    70                 tx  = numpy.zeros(0) 
    71                 ty  = numpy.zeros(0) 
    72                 tdy = numpy.zeros(0) 
    73                 tlam  = numpy.zeros(0) 
    74                 tdlam = numpy.zeros(0) 
    75                 tdx = numpy.zeros(0) 
     70                tx  = np.zeros(0) 
     71                ty  = np.zeros(0) 
     72                tdy = np.zeros(0) 
     73                tlam  = np.zeros(0) 
     74                tdlam = np.zeros(0) 
     75                tdx = np.zeros(0) 
    7676                output = Data1D(x=x, y=y, lam=lam, dy=dy, dx=dx, dlam=dlam, isSesans=True) 
    7777                self.filename = output.filename = basename 
     
    128128 
    129129                x,y,lam,dy,dx,dlam = [ 
    130                    numpy.asarray(v, 'double') 
     130                    np.asarray(v, 'double') 
    131131                   for v in (x,y,lam,dy,dx,dlam) 
    132132                ] 
  • src/sas/sascalc/dataloader/readers/tiff_reader.py

    rb699768 r9a5097c  
    1313import logging 
    1414import os 
    15 import numpy 
     15import numpy as np 
    1616from sas.sascalc.dataloader.data_info import Data2D 
    1717from sas.sascalc.dataloader.manipulations import reader2D_converter 
     
    5656 
    5757        # Initiazed the output data object 
    58         output.data = numpy.zeros([im.size[0], im.size[1]]) 
    59         output.err_data = numpy.zeros([im.size[0], im.size[1]]) 
    60         output.mask = numpy.ones([im.size[0], im.size[1]], dtype=bool) 
     58        output.data = np.zeros([im.size[0], im.size[1]]) 
     59        output.err_data = np.zeros([im.size[0], im.size[1]]) 
     60        output.mask = np.ones([im.size[0], im.size[1]], dtype=bool) 
    6161         
    6262        # Initialize 
     
    9494        output.x_bins = x_vals 
    9595        output.y_bins = y_vals 
    96         output.qx_data = numpy.array(x_vals) 
    97         output.qy_data = numpy.array(y_vals) 
     96        output.qx_data = np.array(x_vals) 
     97        output.qy_data = np.array(y_vals) 
    9898        output.xmin = 0 
    9999        output.xmax = im.size[0] - 1 
Note: See TracChangeset for help on using the changeset viewer.