Changeset 2531


Ignore:
Timestamp:
Mar 13, 2006, 11:57:44 AM (18 years ago)
Author:
ole
Message:

Investigating feasibility of scipy as an alternative to Numeric

Location:
inundation/utilities
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • inundation/utilities/numerical_tools.py

    r2526 r2531  
    44"""
    55
    6 import Numeric
    7 
    8 
     6
     7#Establish which Numeric package to use
     8#(this should move to somewhere central)
     9try:
     10    from scipy import ArrayType, array, sum, innerproduct, ravel, sqrt   
     11except:
     12    print 'Could not find scipy - using Numeric'
     13    from Numeric import ArrayType, array, sum, innerproduct, ravel, sqrt
     14   
    915
    1016def angle(v):
     
    1420
    1521    from math import acos, pi, sqrt
    16     from Numeric import sum, array
    1722
    1823    l = sqrt( sum (array(v)**2))
     
    7277    """Mean value of a vector
    7378    """
    74     return(float(Numeric.sum(x))/len(x))
     79    return(float(sum(x))/len(x))
    7580
    7681
     
    9095    cy = y - mean(y) 
    9196
    92     p = Numeric.innerproduct(cx,cy)/N
     97    p = innerproduct(cx,cy)/N
    9398    return(p)
    9499
     
    130135    """
    131136 
    132     y = Numeric.ravel(x)
    133     p = Numeric.sqrt(Numeric.innerproduct(y,y))
     137    y = ravel(x)
     138    p = sqrt(innerproduct(y,y))
    134139    return p
    135140   
     
    168173    This function is necessary as array(A) can cause memory overflow.
    169174    """
    170 
    171     from Numeric import ArrayType, array
    172175
    173176    if typecode is None:
  • inundation/utilities/polygon.py

    r2378 r2531  
    44"""
    55
     6
     7try:
     8    from scipy import Float, Int, zeros, ones, array, concatenate, reshape, dot
     9except:
     10    print 'Could not find scipy - using Numeric'
     11    from Numeric import Float, Int, zeros, ones, array, concatenate, reshape, dot
     12   
     13
     14from math import sqrt
    615from utilities.numerical_tools import ensure_numeric
     16
    717
    818def point_on_line(x, y, x0, y0, x1, y1):
     
    1424
    1525    """
    16 
    17     from Numeric import array, dot, allclose
    18     from math import sqrt
    1926
    2027    a = array([x - x0, y - y0])
     
    4653    """
    4754
    48     from Numeric import array, Float, reshape
    49 
    5055    if verbose: print 'Checking input to inside_polygon'
     56   
    5157    try:
    5258        points = ensure_numeric(points, Float)
     59    except NameError, e:
     60        raise NameError, e
    5361    except:
    5462        msg = 'Points could not be converted to Numeric array'
     
    5765    try:
    5866        polygon = ensure_numeric(polygon, Float)
     67    except NameError, e:
     68        raise NameError, e       
    5969    except:
    6070        msg = 'Polygon %s could not be converted to Numeric array' %(str(polygon))
     
    8898    """
    8999
    90     from Numeric import array, Float, reshape
    91 
    92100    if verbose: print 'Checking input to outside_polygon'
    93101    try:
    94102        points = ensure_numeric(points, Float)
     103    except NameError, e:
     104        raise NameError, e       
    95105    except:
    96106        msg = 'Points could not be converted to Numeric array'
     
    99109    try:
    100110        polygon = ensure_numeric(polygon, Float)
     111    except NameError, e:
     112        raise NameError, e       
    101113    except:
    102114        msg = 'Polygon could not be converted to Numeric array'
     
    166178    """
    167179
    168     from Numeric import array, Float, reshape, Int, zeros
    169 
    170 
    171180    #Input checks
    172181
     
    174183    try:
    175184        points = ensure_numeric(points, Float)
     185    except NameError, e:
     186        raise NameError, e       
    176187    except:
    177188        msg = 'Points could not be converted to Numeric array'
     
    180191    try:
    181192        polygon = ensure_numeric(polygon, Float)
     193    except NameError, e:
     194        raise NameError, e       
    182195    except:
    183196        msg = 'Polygon could not be converted to Numeric array'
     
    260273    """
    261274
    262     from Numeric import array, Float, reshape, zeros, Int
    263 
    264275
    265276    if verbose: print 'Checking input to separate_points_by_polygon'
     
    274285    try:
    275286        points = ensure_numeric(points, Float)
     287    except NameError, e:
     288        raise NameError, e       
    276289    except:
    277290        msg = 'Points could not be converted to Numeric array'
     
    281294    try:
    282295        polygon = ensure_numeric(polygon, Float)
     296    except NameError, e:
     297        raise NameError, e       
    283298    except:
    284299        msg = 'Polygon could not be converted to Numeric array'
     
    385400
    386401    def __call__(self, x, y):
    387         from Numeric import ones, Float, concatenate, array, reshape, choose
    388 
    389402        x = array(x).astype(Float)
    390403        y = array(y).astype(Float)
Note: See TracChangeset for help on using the changeset viewer.