Ignore:
Timestamp:
Nov 6, 2008, 12:17:15 PM (16 years ago)
Author:
ole
Message:

Reverted numpy changes to the trunk that should have been made to the branch.
The command was svn merge -r 5895:5890 .

File:
1 edited

Legend:

Unmodified
Added
Removed
  • anuga_core/source/anuga/utilities/polygon.py

    r5891 r5897  
    1010#    #print 'Could not find scipy - using Numeric'
    1111
    12 ##from numpy import float, int, zeros, ones, array, concatenate, reshape, dot, allclose, newaxis, ascontiguousarray
    13 import numpy
     12from Numeric import Float, Int, zeros, ones, array, concatenate, reshape, dot, allclose
    1413
    1514
     
    7776    # FIXME (Ole): Write this in C
    7877
    79     line0 = ensure_numeric(line0, numpy.float)
    80     line1 = ensure_numeric(line1, numpy.float)   
     78    line0 = ensure_numeric(line0, Float)
     79    line1 = ensure_numeric(line1, Float)   
    8180
    8281    x0 = line0[0,0]; y0 = line0[0,1]
     
    9089    u1 = (x2-x0)*(y1-y0) - (y2-y0)*(x1-x0)
    9190       
    92     if numpy.allclose(denom, 0.0):
     91    if allclose(denom, 0.0):
    9392        # Lines are parallel - check if they coincide on a shared a segment
    9493
    95         if numpy.allclose( [u0, u1], 0.0 ):
     94        if allclose( [u0, u1], 0.0 ):
    9695            # We now know that the lines if continued coincide
    9796            # The remaining check will establish if the finite lines share a segment
     
    121120            if line0_starts_on_line1 and line0_ends_on_line1:
    122121                # Shared segment is line0 fully included in line1
    123                 segment = numpy.array([[x0, y0], [x1, y1]])               
     122                segment = array([[x0, y0], [x1, y1]])               
    124123
    125124            if line1_starts_on_line0 and line1_ends_on_line0:
    126125                # Shared segment is line1 fully included in line0
    127                 segment = numpy.array([[x2, y2], [x3, y3]])
     126                segment = array([[x2, y2], [x3, y3]])
    128127           
    129128
     
    131130            if line0_starts_on_line1 and line1_ends_on_line0:
    132131                # Shared segment from line0 start to line 1 end
    133                 segment = numpy.array([[x0, y0], [x3, y3]])
     132                segment = array([[x0, y0], [x3, y3]])
    134133
    135134            if line1_starts_on_line0 and line0_ends_on_line1:
    136135                # Shared segment from line1 start to line 0 end
    137                 segment = numpy.array([[x2, y2], [x1, y1]])                               
     136                segment = array([[x2, y2], [x1, y1]])                               
    138137
    139138
     
    141140            if line0_starts_on_line1 and line1_starts_on_line0:
    142141                # Shared segment from line0 start to line 1 end
    143                 segment = numpy.array([[x0, y0], [x2, y2]])
     142                segment = array([[x0, y0], [x2, y2]])
    144143
    145144            if line0_ends_on_line1 and line1_ends_on_line0:
    146145                # Shared segment from line0 start to line 1 end
    147                 segment = numpy.array([[x3, y3], [x1, y1]])               
     146                segment = array([[x3, y3], [x1, y1]])               
    148147
    149148               
     
    162161
    163162        # Sanity check - can be removed to speed up if needed
    164         assert numpy.allclose(x, x2 + u1*(x3-x2))
    165         assert numpy.allclose(y, y2 + u1*(y3-y2))       
     163        assert allclose(x, x2 + u1*(x3-x2))
     164        assert allclose(y, y2 + u1*(y3-y2))       
    166165
    167166        # Check if point found lies within given line segments
     
    169168            # We have intersection
    170169
    171             return 1, numpy.array([x, y])
     170            return 1, array([x, y])
    172171        else:
    173172            # No intersection
     
    204203
    205204
    206     line0 = ensure_numeric(line0, numpy.float)
    207     line1 = ensure_numeric(line1, numpy.float)   
     205    line0 = ensure_numeric(line0, Float)
     206    line1 = ensure_numeric(line1, Float)   
    208207
    209208    status, value = _intersection(line0[0,0], line0[0,1],
     
    257256        # converted to a numeric array.
    258257        msg = 'Points could not be converted to Numeric array'
    259         raise TypeError, msg
     258        raise msg
    260259
    261260    try:
     
    266265        # If this fails it is going to be because the points can't be
    267266        # converted to a numeric array.
    268         msg = 'Polygon %s could not be converted to Numeric array' % (str(polygon))
    269         raise TypeError, msg
     267        msg = 'Polygon %s could not be converted to Numeric array' %(str(polygon))
     268        raise msg
    270269
    271270    if len(points.shape) == 1:
    272271        # Only one point was passed in. Convert to array of points
    273         points = numpy.reshape(points, (1,2))
     272        points = reshape(points, (1,2))
    274273
    275274    indices, count = separate_points_by_polygon(points, polygon,
     
    313312    #if verbose: print 'Checking input to outside_polygon'
    314313    try:
    315         points = ensure_numeric(points, numpy.float)
     314        points = ensure_numeric(points, Float)
    316315    except NameError, e:
    317316        raise NameError, e
     
    321320
    322321    try:
    323         polygon = ensure_numeric(polygon, numpy.float)
     322        polygon = ensure_numeric(polygon, Float)
    324323    except NameError, e:
    325324        raise NameError, e
     
    331330    if len(points.shape) == 1:
    332331        # Only one point was passed in. Convert to array of points
    333         points = numpy.reshape(points, (1,2))
     332        points = reshape(points, (1,2))
    334333
    335334    indices, count = separate_points_by_polygon(points, polygon,
     
    340339    if count == len(indices):
    341340        # No points are outside
    342         return numpy.array([])
     341        return array([])
    343342    else:
    344343        return indices[count:][::-1]  #return reversed
     
    355354    #if verbose: print 'Checking input to outside_polygon'
    356355    try:
    357         points = ensure_numeric(points, numpy.float)
     356        points = ensure_numeric(points, Float)
    358357    except NameError, e:
    359358        raise NameError, e
     
    363362
    364363    try:
    365         polygon = ensure_numeric(polygon, numpy.float)
     364        polygon = ensure_numeric(polygon, Float)
    366365    except NameError, e:
    367366        raise NameError, e
     
    372371    if len(points.shape) == 1:
    373372        # Only one point was passed in. Convert to array of points
    374         points = numpy.reshape(points, (1,2))
     373        points = reshape(points, (1,2))
    375374
    376375
     
    440439    assert isinstance(verbose, bool), 'Keyword argument "verbose" must be boolean'
    441440
    442 ##    print 'Before: points=%s, flags=%s' % (type(points), str(points.flags))
     441
    443442    try:
    444 ##        points = numpy.ascontiguousarray(ensure_numeric(points, numpy.float))
    445         points = ensure_numeric(points, numpy.float)
     443        points = ensure_numeric(points, Float)
    446444    except NameError, e:
    447445        raise NameError, e
    448446    except:
    449447        msg = 'Points could not be converted to Numeric array'
    450         raise TypeError, msg
    451 ##    print 'After: points=%s, flags=%s' % (type(points), str(points.flags))
     448        raise msg
    452449
    453450    #if verbose: print 'Checking input to separate_points_by_polygon 2'
    454451    try:
    455 ##        polygon = numpy.ascontiguousarray(ensure_numeric(polygon, numpy.float))
    456         polygon = ensure_numeric(polygon, numpy.float)
     452        polygon = ensure_numeric(polygon, Float)
    457453    except NameError, e:
    458454        raise NameError, e
    459455    except:
    460456        msg = 'Polygon could not be converted to Numeric array'
    461         raise TypeError, msg
     457        raise msg
    462458
    463459    msg = 'Polygon array must be a 2d array of vertices'
     
    476472        # Only one point was passed in.
    477473        # Convert to array of points
    478         points = numpy.reshape(points, (1,2))
     474        points = reshape(points, (1,2))
    479475
    480476   
    481477    msg = 'Point array must have two columns (x,y), '
    482     msg += 'I got points.shape[1] == %d' % points.shape[1]
     478    msg += 'I got points.shape[1] == %d' %points.shape[0]
    483479    assert points.shape[1] == 2, msg
    484480
     
    495491
    496492
    497     indices = numpy.zeros( M, numpy.int )
     493    indices = zeros( M, Int )
    498494
    499495    count = _separate_points_by_polygon(points, polygon, indices,
     
    622618
    623619    try:
    624         polygon = ensure_numeric(polygon, numpy.float)
     620        polygon = ensure_numeric(polygon, Float)
    625621    except NameError, e:
    626622        raise NameError, e
     
    631627    x = polygon[:,0]
    632628    y = polygon[:,1]
    633     x = numpy.concatenate((x, [polygon[0,0]]), axis = 0)
    634     y = numpy.concatenate((y, [polygon[0,1]]), axis = 0)
     629    x = concatenate((x, [polygon[0,0]]), axis = 0)
     630    y = concatenate((y, [polygon[0,1]]), axis = 0)
    635631   
    636632    return x, y
     
    684680    """
    685681
    686     def __init__(self, regions, default=0.0, geo_reference=None, verbose=False):
     682    def __init__(self, regions, default=0.0, geo_reference=None):
    687683
    688684        try:
     
    727723            self.regions.append( (P, value) )
    728724
    729         self.verbose = verbose
    730 
    731725
    732726
    733727
    734728    def __call__(self, x, y):
    735         x = numpy.array(x).astype(numpy.float)
    736         y = numpy.array(y).astype(numpy.float)
    737 
    738         assert len(x.shape) == 1 and len(y.shape) == 1
    739        
    740         N = x.shape[0]
    741         assert y.shape[0] == N
    742 
    743         points = numpy.ascontiguousarray(numpy.concatenate( (x[:,numpy.newaxis], y[:,numpy.newaxis]), axis=1 ))
    744        
     729        x = array(x).astype(Float)
     730        y = array(y).astype(Float)
     731
     732        N = len(x)
     733        assert len(y) == N
     734
     735        points = concatenate( (reshape(x, (N, 1)),
     736                               reshape(y, (N, 1))), axis=1 )
     737
    745738        if callable(self.default):
    746             z = self.default(x, y)
     739            z = self.default(x,y)
    747740        else:
    748             z = numpy.ones(N, numpy.float) * self.default
     741            z = ones(N, Float) * self.default
    749742
    750743        for polygon, value in self.regions:
    751             indices = inside_polygon(points, polygon, verbose=self.verbose)
     744            indices = inside_polygon(points, polygon)
    752745
    753746            # FIXME: This needs to be vectorised
    754747            if callable(value):
    755748                for i in indices:
    756                     xx = numpy.array([x[i]])
    757                     yy = numpy.array([y[i]])
     749                    xx = array([x[i]])
     750                    yy = array([y[i]])
    758751                    z[i] = value(xx, yy)[0]
    759752            else:
Note: See TracChangeset for help on using the changeset viewer.