Changeset 2531
 Timestamp:
 Mar 13, 2006, 11:57:44 AM (18 years ago)
 Location:
 inundation/utilities
 Files:

 2 edited
Legend:
 Unmodified
 Added
 Removed

inundation/utilities/numerical_tools.py
r2526 r2531 4 4 """ 5 5 6 import Numeric 7 8 6 7 #Establish which Numeric package to use 8 #(this should move to somewhere central) 9 try: 10 from scipy import ArrayType, array, sum, innerproduct, ravel, sqrt 11 except: 12 print 'Could not find scipy  using Numeric' 13 from Numeric import ArrayType, array, sum, innerproduct, ravel, sqrt 14 9 15 10 16 def angle(v): … … 14 20 15 21 from math import acos, pi, sqrt 16 from Numeric import sum, array17 22 18 23 l = sqrt( sum (array(v)**2)) … … 72 77 """Mean value of a vector 73 78 """ 74 return(float( Numeric.sum(x))/len(x))79 return(float(sum(x))/len(x)) 75 80 76 81 … … 90 95 cy = y  mean(y) 91 96 92 p = Numeric.innerproduct(cx,cy)/N97 p = innerproduct(cx,cy)/N 93 98 return(p) 94 99 … … 130 135 """ 131 136 132 y = Numeric.ravel(x)133 p = Numeric.sqrt(Numeric.innerproduct(y,y))137 y = ravel(x) 138 p = sqrt(innerproduct(y,y)) 134 139 return p 135 140 … … 168 173 This function is necessary as array(A) can cause memory overflow. 169 174 """ 170 171 from Numeric import ArrayType, array172 175 173 176 if typecode is None: 
inundation/utilities/polygon.py
r2378 r2531 4 4 """ 5 5 6 7 try: 8 from scipy import Float, Int, zeros, ones, array, concatenate, reshape, dot 9 except: 10 print 'Could not find scipy  using Numeric' 11 from Numeric import Float, Int, zeros, ones, array, concatenate, reshape, dot 12 13 14 from math import sqrt 6 15 from utilities.numerical_tools import ensure_numeric 16 7 17 8 18 def point_on_line(x, y, x0, y0, x1, y1): … … 14 24 15 25 """ 16 17 from Numeric import array, dot, allclose18 from math import sqrt19 26 20 27 a = array([x  x0, y  y0]) … … 46 53 """ 47 54 48 from Numeric import array, Float, reshape49 50 55 if verbose: print 'Checking input to inside_polygon' 56 51 57 try: 52 58 points = ensure_numeric(points, Float) 59 except NameError, e: 60 raise NameError, e 53 61 except: 54 62 msg = 'Points could not be converted to Numeric array' … … 57 65 try: 58 66 polygon = ensure_numeric(polygon, Float) 67 except NameError, e: 68 raise NameError, e 59 69 except: 60 70 msg = 'Polygon %s could not be converted to Numeric array' %(str(polygon)) … … 88 98 """ 89 99 90 from Numeric import array, Float, reshape91 92 100 if verbose: print 'Checking input to outside_polygon' 93 101 try: 94 102 points = ensure_numeric(points, Float) 103 except NameError, e: 104 raise NameError, e 95 105 except: 96 106 msg = 'Points could not be converted to Numeric array' … … 99 109 try: 100 110 polygon = ensure_numeric(polygon, Float) 111 except NameError, e: 112 raise NameError, e 101 113 except: 102 114 msg = 'Polygon could not be converted to Numeric array' … … 166 178 """ 167 179 168 from Numeric import array, Float, reshape, Int, zeros169 170 171 180 #Input checks 172 181 … … 174 183 try: 175 184 points = ensure_numeric(points, Float) 185 except NameError, e: 186 raise NameError, e 176 187 except: 177 188 msg = 'Points could not be converted to Numeric array' … … 180 191 try: 181 192 polygon = ensure_numeric(polygon, Float) 193 except NameError, e: 194 raise NameError, e 182 195 except: 183 196 msg = 'Polygon could not be converted to Numeric array' … … 260 273 """ 261 274 262 from Numeric import array, Float, reshape, zeros, Int263 264 275 265 276 if verbose: print 'Checking input to separate_points_by_polygon' … … 274 285 try: 275 286 points = ensure_numeric(points, Float) 287 except NameError, e: 288 raise NameError, e 276 289 except: 277 290 msg = 'Points could not be converted to Numeric array' … … 281 294 try: 282 295 polygon = ensure_numeric(polygon, Float) 296 except NameError, e: 297 raise NameError, e 283 298 except: 284 299 msg = 'Polygon could not be converted to Numeric array' … … 385 400 386 401 def __call__(self, x, y): 387 from Numeric import ones, Float, concatenate, array, reshape, choose388 389 402 x = array(x).astype(Float) 390 403 y = array(y).astype(Float)
Note: See TracChangeset
for help on using the changeset viewer.