Changeset 9a5097c in sasview for src/sas/sascalc/data_util


Ignore:
Timestamp:
Mar 26, 2017 11: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/sascalc/data_util
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • src/sas/sascalc/data_util/err1d.py

    rb699768 r9a5097c  
    88""" 
    99from __future__ import division  # Get true division 
    10 import numpy 
     10import numpy as np 
    1111 
    1212 
     
    5959def exp(X, varX): 
    6060    """Exponentiation with error propagation""" 
    61     Z = numpy.exp(X) 
     61    Z = np.exp(X) 
    6262    varZ = varX * Z**2 
    6363    return Z, varZ 
     
    6666def log(X, varX): 
    6767    """Logarithm with error propagation""" 
    68     Z = numpy.log(X) 
     68    Z = np.log(X) 
    6969    varZ = varX / X**2 
    7070    return Z, varZ 
     
    7373# def pow(X,varX, Y,varY): 
    7474#    Z = X**Y 
    75 #    varZ = (Y**2 * varX/X**2 + varY * numpy.log(X)**2) * Z**2 
     75#    varZ = (Y**2 * varX/X**2 + varY * np.log(X)**2) * Z**2 
    7676#    return Z,varZ 
    7777# 
  • src/sas/sascalc/data_util/formatnum.py

    rb699768 r9a5097c  
    4040 
    4141import math 
    42 import numpy 
     42import numpy as np 
    4343__all__ = ['format_uncertainty', 'format_uncertainty_pm', 
    4444           'format_uncertainty_compact'] 
     
    102102    """ 
    103103    # Handle indefinite value 
    104     if numpy.isinf(value): 
     104    if np.isinf(value): 
    105105        return "inf" if value > 0 else "-inf" 
    106     if numpy.isnan(value): 
     106    if np.isnan(value): 
    107107        return "NaN" 
    108108 
    109109    # Handle indefinite uncertainty 
    110     if uncertainty is None or uncertainty <= 0 or numpy.isnan(uncertainty): 
     110    if uncertainty is None or uncertainty <= 0 or np.isnan(uncertainty): 
    111111        return "%g" % value 
    112     if numpy.isinf(uncertainty): 
     112    if np.isinf(uncertainty): 
    113113        if compact: 
    114114            return "%.2g(inf)" % value 
     
    279279 
    280280    # non-finite values 
    281     assert value_str(-numpy.inf,None) == "-inf" 
    282     assert value_str(numpy.inf,None) == "inf" 
    283     assert value_str(numpy.NaN,None) == "NaN" 
     281    assert value_str(-np.inf,None) == "-inf" 
     282    assert value_str(np.inf,None) == "inf" 
     283    assert value_str(np.NaN,None) == "NaN" 
    284284     
    285285    # bad or missing uncertainty 
    286     assert value_str(-1.23567,numpy.NaN) == "-1.23567" 
    287     assert value_str(-1.23567,-numpy.inf) == "-1.23567" 
     286    assert value_str(-1.23567,np.NaN) == "-1.23567" 
     287    assert value_str(-1.23567,-np.inf) == "-1.23567" 
    288288    assert value_str(-1.23567,-0.1) == "-1.23567" 
    289289    assert value_str(-1.23567,0) == "-1.23567" 
    290290    assert value_str(-1.23567,None) == "-1.23567" 
    291     assert value_str(-1.23567,numpy.inf) == "-1.2(inf)" 
     291    assert value_str(-1.23567,np.inf) == "-1.2(inf)" 
    292292 
    293293def test_pm(): 
     
    410410 
    411411    # non-finite values 
    412     assert value_str(-numpy.inf,None) == "-inf" 
    413     assert value_str(numpy.inf,None) == "inf" 
    414     assert value_str(numpy.NaN,None) == "NaN" 
     412    assert value_str(-np.inf,None) == "-inf" 
     413    assert value_str(np.inf,None) == "inf" 
     414    assert value_str(np.NaN,None) == "NaN" 
    415415     
    416416    # bad or missing uncertainty 
    417     assert value_str(-1.23567,numpy.NaN) == "-1.23567" 
    418     assert value_str(-1.23567,-numpy.inf) == "-1.23567" 
     417    assert value_str(-1.23567,np.NaN) == "-1.23567" 
     418    assert value_str(-1.23567,-np.inf) == "-1.23567" 
    419419    assert value_str(-1.23567,-0.1) == "-1.23567" 
    420420    assert value_str(-1.23567,0) == "-1.23567" 
    421421    assert value_str(-1.23567,None) == "-1.23567" 
    422     assert value_str(-1.23567,numpy.inf) == "-1.2 +/- inf" 
     422    assert value_str(-1.23567,np.inf) == "-1.2 +/- inf" 
    423423 
    424424def test_default(): 
  • src/sas/sascalc/data_util/qsmearing.py

    r775e0b7 r9a5097c  
    99#copyright 2008, University of Tennessee 
    1010###################################################################### 
    11 import numpy 
    1211import math 
    1312import logging 
     
    6059    if data.dx is not None and data.isSesans: 
    6160        #if data.dx[0] > 0.0: 
    62         if numpy.size(data.dx[data.dx <= 0]) == 0: 
     61        if np.size(data.dx[data.dx <= 0]) == 0: 
    6362            _found_sesans = True 
    6463        # if data.dx[0] <= 0.0: 
    65         if numpy.size(data.dx[data.dx <= 0]) > 0: 
     64        if np.size(data.dx[data.dx <= 0]) > 0: 
    6665            raise ValueError('one or more of your dx values are negative, please check the data file!') 
    6766 
     
    121120        self.resolution = resolution 
    122121        if offset is None: 
    123             offset = numpy.searchsorted(self.resolution.q_calc, self.resolution.q[0]) 
     122            offset = np.searchsorted(self.resolution.q_calc, self.resolution.q[0]) 
    124123        self.offset = offset 
    125124 
     
    137136        start, end = first_bin + self.offset, last_bin + self.offset 
    138137        q_calc = self.resolution.q_calc 
    139         iq_calc = numpy.empty_like(q_calc) 
     138        iq_calc = np.empty_like(q_calc) 
    140139        if start > 0: 
    141140            iq_calc[:start] = self.model.evalDistribution(q_calc[:start]) 
     
    157156        """ 
    158157        q = self.resolution.q 
    159         first = numpy.searchsorted(q, q_min) 
    160         last = numpy.searchsorted(q, q_max) 
     158        first = np.searchsorted(q, q_min) 
     159        last = np.searchsorted(q, q_max) 
    161160        return first, min(last,len(q)-1) 
    162161 
  • src/sas/sascalc/data_util/uncertainty.py

    rb699768 r9a5097c  
    1717from __future__ import division 
    1818 
    19 import numpy 
     19import numpy as np 
    2020import err1d 
    2121from formatnum import format_uncertainty 
     
    2727class Uncertainty(object): 
    2828    # Make standard deviation available 
    29     def _getdx(self): return numpy.sqrt(self.variance) 
     29    def _getdx(self): return np.sqrt(self.variance) 
    3030    def _setdx(self,dx):  
    3131        # Direct operation 
     
    144144        return self 
    145145    def __abs__(self): 
    146         return Uncertainty(numpy.abs(self.x),self.variance) 
     146        return Uncertainty(np.abs(self.x),self.variance) 
    147147 
    148148    def __str__(self): 
    149         #return str(self.x)+" +/- "+str(numpy.sqrt(self.variance)) 
    150         if numpy.isscalar(self.x): 
    151             return format_uncertainty(self.x,numpy.sqrt(self.variance)) 
     149        #return str(self.x)+" +/- "+str(np.sqrt(self.variance)) 
     150        if np.isscalar(self.x): 
     151            return format_uncertainty(self.x,np.sqrt(self.variance)) 
    152152        else: 
    153153            return [format_uncertainty(v,dv)  
    154                     for v,dv in zip(self.x,numpy.sqrt(self.variance))] 
     154                    for v,dv in zip(self.x,np.sqrt(self.variance))] 
    155155    def __repr__(self): 
    156156        return "Uncertainty(%s,%s)"%(str(self.x),str(self.variance)) 
     
    287287    # =============== vector operations ================ 
    288288    # Slicing 
    289     z = Uncertainty(numpy.array([1,2,3,4,5]),numpy.array([2,1,2,3,2])) 
     289    z = Uncertainty(np.array([1,2,3,4,5]),np.array([2,1,2,3,2])) 
    290290    assert z[2].x == 3 and z[2].variance == 2 
    291291    assert (z[2:4].x == [3,4]).all() 
    292292    assert (z[2:4].variance == [2,3]).all() 
    293     z[2:4] = Uncertainty(numpy.array([8,7]),numpy.array([4,5])) 
     293    z[2:4] = Uncertainty(np.array([8,7]),np.array([4,5])) 
    294294    assert z[2].x == 8 and z[2].variance == 4 
    295     A = Uncertainty(numpy.array([a.x]*2),numpy.array([a.variance]*2)) 
    296     B = Uncertainty(numpy.array([b.x]*2),numpy.array([b.variance]*2)) 
     295    A = Uncertainty(np.array([a.x]*2),np.array([a.variance]*2)) 
     296    B = Uncertainty(np.array([b.x]*2),np.array([b.variance]*2)) 
    297297 
    298298    # TODO complete tests of copy and inplace operations for vectors and slices. 
Note: See TracChangeset for help on using the changeset viewer.