Changeset 5907
- Timestamp:
- Nov 6, 2008, 4:15:04 PM (16 years ago)
- Location:
- anuga_core/source_numpy_conversion/anuga/alpha_shape
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
anuga_core/source_numpy_conversion/anuga/alpha_shape/alpha_shape.py
r4955 r5907 20 20 21 21 import exceptions 22 from Numeric import array, Float, divide_safe, sqrt, product 22 import numpy 23 23 import random 24 24 … … 87 87 88 88 #Convert input to Numeric arrays 89 self.points = array(points).astype(Float)89 self.points = numpy.array(points).astype(numpy.float) 90 90 91 91 … … 240 240 ind3 = [self.deltri[j][2] for j in range(len(self.deltri))] 241 241 242 x1 = array([ x[j] for j in ind1 ])243 y1 = array([ y[j] for j in ind1 ])244 x2 = array([ x[j] for j in ind2 ])245 y2 = array([ y[j] for j in ind2 ])246 x3 = array([ x[j] for j in ind3 ])247 y3 = array([ y[j] for j in ind3 ])242 x1 = numpy.array([ x[j] for j in ind1 ]) 243 y1 = numpy.array([ y[j] for j in ind1 ]) 244 x2 = numpy.array([ x[j] for j in ind2 ]) 245 y2 = numpy.array([ y[j] for j in ind2 ]) 246 x3 = numpy.array([ x[j] for j in ind3 ]) 247 y3 = numpy.array([ y[j] for j in ind3 ]) 248 248 249 249 x21 = x2-x1 … … 286 286 zeroind = [k for k in range(len(denom)) if \ 287 287 (denom[k]< EPSILON and denom[k] > -EPSILON)] 288 try: 289 dx = divide_safe(y31*dist21 - y21*dist31,denom) 290 dy = divide_safe(x21*dist31 - x31*dist21,denom) 291 except ZeroDivisionError: 288 ##NumPy try: 289 ##NumPy dx = divide_safe(y31*dist21 - y21*dist31,denom) 290 ##NumPy dy = divide_safe(x21*dist31 - x31*dist21,denom) 291 ##NumPy except ZeroDivisionError: 292 ##NumPy raise AlphaError 293 # In NumPy there is no divide_safe(), so above code becomes: 294 dx = numpy.divide(y31*dist21 - y21*dist31,denom) 295 dy = numpy.divide(x21*dist31 - x31*dist21,denom) 296 if not numpy.alltrue(numpy.isfinite(dx)) or \ 297 not numpy.alltrue(numpy.isfinite(dy)): 292 298 raise AlphaError 293 299 294 self.triradius = 0.5* sqrt(dx*dx + dy*dy)300 self.triradius = 0.5*numpy.sqrt(dx*dx + dy*dy) 295 301 #print "triangle radii", self.triradius 296 302 … … 313 319 tri = self.deltri[t] 314 320 trinbr = self.deltrinbr[t] 315 dx = array([self.points[tri[(i+1)%3],0] -321 dx = numpy.array([self.points[tri[(i+1)%3],0] - 316 322 self.points[tri[(i+2)%3],0] for i in [0,1,2]]) 317 dy = array([self.points[tri[(i+1)%3],1] -323 dy = numpy.array([self.points[tri[(i+1)%3],1] - 318 324 self.points[tri[(i+2)%3],1] for i in [0,1,2]]) 319 elen = sqrt(dx*dx+dy*dy)325 elen = numpy.sqrt(dx*dx+dy*dy) 320 326 # really only need sign - not angle value: 321 anglesign = array([(-dx[(i+1)%3]*dx[(i+2)%3]-327 anglesign = numpy.array([(-dx[(i+1)%3]*dx[(i+2)%3]- 322 328 dy[(i+1)%3]*dy[(i+2)%3]) for i in [0,1,2]]) 323 329 … … 594 600 tri = self.deltri[tind[0]] 595 601 596 dx = array([self.points[tri[(i+1)%3],0] - \602 dx = numpy.array([self.points[tri[(i+1)%3],0] - \ 597 603 self.points[tri[(i+2)%3],0] for i in [0,1,2]]) 598 dy = array([self.points[tri[(i+1)%3],1] - \604 dy = numpy.array([self.points[tri[(i+1)%3],1] - \ 599 605 self.points[tri[(i+2)%3],1] for i in [0,1,2]]) 600 anglesign = array([(-dx[(i+1)%3]*dx[(i+2)%3]-\606 anglesign = numpy.array([(-dx[(i+1)%3]*dx[(i+2)%3]-\ 601 607 dy[(i+1)%3]*dy[(i+2)%3]) for i in [0,1,2]]) 602 608 # record any triangle that has an acute angle spanned by -
anuga_core/source_numpy_conversion/anuga/alpha_shape/test_alpha_shape.py
r4663 r5907 4 4 import sys 5 5 import unittest 6 from Numeric import allclose 6 import numpy 7 7 8 8 try: … … 32 32 result = alpha.get_delaunay() 33 33 answer = [(0, 1, 5), (5, 1, 4), (4, 2, 3), (2, 4, 1)] 34 assert allclose(answer, result)34 assert numpy.allclose(answer, result) 35 35 36 36 def test_3_points_on_line(self): … … 63 63 #print "result",result 64 64 answer = [(5, 0), (0, 1), (4, 5), (2, 3), (3, 4), (1, 2)] 65 assert allclose(answer, result)65 assert numpy.allclose(answer, result) 66 66 67 67 … … 80 80 #print "result",result 81 81 answer = [(0, 3), (3, 6), (0, 1), (1, 2), (2, 3), (3, 4), (4, 5), (5, 6)] 82 assert allclose(answer, result)82 assert numpy.allclose(answer, result) 83 83 84 84 … … 97 97 #print "result",result 98 98 answer = [(5, 0), (0, 1), (4, 5), (2, 3), (3, 4), (1, 2)] 99 assert allclose(answer, result)99 assert numpy.allclose(answer, result) 100 100 101 101 … … 114 114 #print "result",result 115 115 answer = [(0, 3), (3, 6), (0, 1), (1, 2), (2, 3), (3, 4), (4, 5), (5, 6)] 116 assert allclose(answer, result)116 assert numpy.allclose(answer, result) 117 117 118 118 … … 132 132 #print "result",result 133 133 answer = [(0, 1), (1, 2), (2, 3), (3, 4), (4, 5), (5, 6), (6, 0)] 134 assert allclose(answer, result)134 assert numpy.allclose(answer, result) 135 135 136 136 … … 148 148 result = alpha.get_boundary() 149 149 answer = [(1, 0), (0, 5), (3, 2), (4, 3), (2, 6), (6, 1), (5, 4)] 150 assert allclose(answer, result)150 assert numpy.allclose(answer, result) 151 151 152 152 … … 222 222 #print "result",result 223 223 answer = [(1, 0), (4, 3), (0, 4), (3, 1)] 224 assert allclose(answer, result)224 assert numpy.allclose(answer, result) 225 225 226 226 def test_sharp_indents(self): … … 239 239 #print "result",result 240 240 answer = [(3, 4), (2, 3), (0, 1), (1, 2), (4, 0)] 241 assert allclose(answer, result)241 assert numpy.allclose(answer, result) 242 242 243 243 … … 392 392 (61, 62), (62, 63), (59, 60), (58, 59), (60, 61), \ 393 393 (46, 45)] 394 assert allclose(answer, result)394 assert numpy.allclose(answer, result) 395 395 #------------------------------------------------------------- 396 396 if __name__ == "__main__":
Note: See TracChangeset
for help on using the changeset viewer.