Changeset 6147


Ignore:
Timestamp:
Jan 13, 2009, 12:04:14 PM (10 years ago)
Author:
rwilson
Message:

Change Numeric imports to general form - ready to change to NumPy?.

Location:
anuga_core/source/anuga/alpha_shape
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • anuga_core/source/anuga/alpha_shape/alpha_shape.py

    r4955 r6147  
    2020
    2121import exceptions
    22 from Numeric import array, Float, divide_safe, sqrt, product
    2322import random
    2423
    2524from load_mesh.loadASCII import export_boundary_file
    2625from anuga.geospatial_data.geospatial_data import Geospatial_data
     26
     27import Numeric as num
     28
    2729
    2830class AlphaError(exceptions.Exception):pass
     
    8789       
    8890        #Convert input to Numeric arrays
    89         self.points = array(points).astype(Float)
     91        self.points = num.array(points).astype(num.Float)
    9092
    9193   
     
    240242        ind3 = [self.deltri[j][2] for j in range(len(self.deltri))]
    241243
    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 ])
     244        x1 = num.array([ x[j] for j in ind1 ])
     245        y1 = num.array([ y[j] for j in ind1 ])
     246        x2 = num.array([ x[j] for j in ind2 ])
     247        y2 = num.array([ y[j] for j in ind2 ])
     248        x3 = num.array([ x[j] for j in ind3 ])
     249        y3 = num.array([ y[j] for j in ind3 ])
    248250
    249251        x21 = x2-x1
     
    287289                       (denom[k]< EPSILON and  denom[k] > -EPSILON)]
    288290        try:
    289             dx = divide_safe(y31*dist21 - y21*dist31,denom)
    290             dy = divide_safe(x21*dist31 - x31*dist21,denom)
     291            dx = num.divide_safe(y31*dist21 - y21*dist31,denom)
     292            dy = num.divide_safe(x21*dist31 - x31*dist21,denom)
    291293        except ZeroDivisionError:
    292294            raise  AlphaError
    293295           
    294         self.triradius = 0.5*sqrt(dx*dx + dy*dy)
     296        self.triradius = 0.5*num.sqrt(dx*dx + dy*dy)
    295297        #print "triangle radii", self.triradius
    296298
     
    313315            tri = self.deltri[t]
    314316            trinbr = self.deltrinbr[t]
    315             dx = array([self.points[tri[(i+1)%3],0] -
    316                         self.points[tri[(i+2)%3],0] for i in [0,1,2]])
    317             dy = array([self.points[tri[(i+1)%3],1] -
    318                         self.points[tri[(i+2)%3],1] for i in [0,1,2]])
    319             elen = sqrt(dx*dx+dy*dy)
     317            dx = num.array([self.points[tri[(i+1)%3],0] -
     318                            self.points[tri[(i+2)%3],0] for i in [0,1,2]])
     319            dy = num.array([self.points[tri[(i+1)%3],1] -
     320                            self.points[tri[(i+2)%3],1] for i in [0,1,2]])
     321            elen = num.sqrt(dx*dx+dy*dy)
    320322            # really only need sign - not angle value:
    321             anglesign = array([(-dx[(i+1)%3]*dx[(i+2)%3]-
    322                                 dy[(i+1)%3]*dy[(i+2)%3]) for i in [0,1,2]])
     323            anglesign = num.array([(-dx[(i+1)%3]*dx[(i+2)%3]-
     324                                    dy[(i+1)%3]*dy[(i+2)%3]) for i in [0,1,2]])
    323325           
    324326            #print "dx ",dx,"\n"
     
    594596            tri = self.deltri[tind[0]]
    595597           
    596             dx = array([self.points[tri[(i+1)%3],0] - \
    597                         self.points[tri[(i+2)%3],0] for i in [0,1,2]])
    598             dy = array([self.points[tri[(i+1)%3],1] - \
    599                         self.points[tri[(i+2)%3],1] for i in [0,1,2]])
    600             anglesign = array([(-dx[(i+1)%3]*dx[(i+2)%3]-\
    601                                 dy[(i+1)%3]*dy[(i+2)%3]) for i in [0,1,2]])
     598            dx = num.array([self.points[tri[(i+1)%3],0] - \
     599                           self.points[tri[(i+2)%3],0] for i in [0,1,2]])
     600            dy = num.array([self.points[tri[(i+1)%3],1] - \
     601                           self.points[tri[(i+2)%3],1] for i in [0,1,2]])
     602            anglesign = num.array([(-dx[(i+1)%3]*dx[(i+2)%3]-\
     603                                   dy[(i+1)%3]*dy[(i+2)%3]) for i in [0,1,2]])
    602604            # record any triangle that has an acute angle spanned by
    603605            #two edges along the boundary..
  • anuga_core/source/anuga/alpha_shape/test_alpha_shape.py

    r4663 r6147  
    44import sys
    55import unittest
    6 from Numeric import allclose
     6
     7import Numeric as num
    78
    89try:
     
    3233        result = alpha.get_delaunay()
    3334        answer = [(0, 1, 5), (5, 1, 4), (4, 2, 3), (2, 4, 1)]
    34         assert allclose(answer, result)
     35        assert num.allclose(answer, result)
    3536
    3637    def test_3_points_on_line(self):
     
    6364        #print "result",result
    6465        answer = [(5, 0), (0, 1), (4, 5), (2, 3), (3, 4), (1, 2)]
    65         assert allclose(answer, result)
     66        assert num.allclose(answer, result)
    6667
    6768
     
    8081        #print "result",result
    8182        answer = [(0, 3), (3, 6), (0, 1), (1, 2), (2, 3), (3, 4), (4, 5), (5, 6)]
    82         assert allclose(answer, result)
     83        assert num.allclose(answer, result)
    8384
    8485
     
    9798        #print "result",result
    9899        answer = [(5, 0), (0, 1), (4, 5), (2, 3), (3, 4), (1, 2)]
    99         assert allclose(answer, result)
     100        assert num.allclose(answer, result)
    100101
    101102
     
    114115        #print "result",result
    115116        answer = [(0, 3), (3, 6), (0, 1), (1, 2), (2, 3), (3, 4), (4, 5), (5, 6)]
    116         assert allclose(answer, result)
     117        assert num.allclose(answer, result)
    117118   
    118119
     
    132133        #print "result",result
    133134        answer = [(0, 1), (1, 2), (2, 3), (3, 4), (4, 5), (5, 6), (6, 0)]
    134         assert allclose(answer, result)
     135        assert num.allclose(answer, result)
    135136
    136137
     
    148149        result = alpha.get_boundary()
    149150        answer = [(1, 0), (0, 5), (3, 2), (4, 3), (2, 6), (6, 1), (5, 4)]
    150         assert allclose(answer, result)
     151        assert num.allclose(answer, result)
    151152
    152153
     
    222223        #print "result",result
    223224        answer = [(1, 0), (4, 3), (0, 4), (3, 1)]
    224         assert allclose(answer, result)
     225        assert num.allclose(answer, result)
    225226 
    226227    def test_sharp_indents(self):
     
    239240        #print "result",result
    240241        answer = [(3, 4), (2, 3), (0, 1), (1, 2), (4, 0)]
    241         assert allclose(answer, result)
     242        assert num.allclose(answer, result)
    242243
    243244       
     
    392393                  (61, 62), (62, 63), (59, 60), (58, 59), (60, 61), \
    393394                  (46, 45)]
    394         assert allclose(answer, result)   
     395        assert num.allclose(answer, result)   
    395396#-------------------------------------------------------------
    396397if __name__ == "__main__":
Note: See TracChangeset for help on using the changeset viewer.