Changeset 2062


Ignore:
Timestamp:
Nov 24, 2005, 1:05:20 PM (18 years ago)
Author:
ole
Message:

Found, unit tested, and fixed bug in outside polygon.
Then refactored sww2dem, to a more efficient way of assigning missing values

Location:
inundation
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • inundation/pyvolution/data_manager.py

    r2061 r2062  
    14801480    from Numeric import array2string
    14811481   
    1482     from utilities.polygon import inside_polygon
     1482    from utilities.polygon import inside_polygon, outside_polygon, separate_points_by_polygon
    14831483    from util import apply_expression_to_dictionary
    14841484   
     
    16761676
    16771677
    1678     #Assign NODATA_value to all points outside bounding polygon (from interpolation mesh)
    1679     P = interp.mesh.get_boundary_polygon()
    1680     inside_indices = inside_polygon(grid_points, P)
    1681 
    1682     #FIXME: Remove when new interpolation takes care of this
    1683     for i in range(nrows):
    1684         if verbose and i%((nrows+10)/10)==0:
    1685             print 'Doing row %d of %d' %(i, nrows)
    1686 
    1687         base_index = (nrows-i-1)*ncols     
    1688         for j in range(ncols):
    1689             index = base_index+j
    1690 
    1691             if not sometrue(inside_indices == index):
    1692                 grid_values[index] = NODATA_value
    1693 
    1694     #############           
    1695 
    1696    
    1697 
    16981678    if verbose:
    16991679        print 'Interpolated values are in [%f, %f]' %(min(grid_values),
    17001680                                                      max(grid_values))
     1681
     1682    #Assign NODATA_value to all points outside bounding polygon (from interpolation mesh)
     1683    P = interp.mesh.get_boundary_polygon()
     1684    outside_indices = outside_polygon(grid_points, P, closed=True)
     1685
     1686    for i in outside_indices:
     1687        grid_values[i] = NODATA_value       
     1688
     1689
     1690
    17011691
    17021692    if format.lower() == 'ers':
  • inundation/pyvolution/test_data_manager.py

    r2061 r2062  
    35903590    suite = unittest.makeSuite(Test_Data_Manager,'test')
    35913591    #suite = unittest.makeSuite(Test_Data_Manager,'test_sww2dem_asc_missing_points')
    3592     #suite = unittest.makeSuite(Test_Data_Manager,'test_sww2dem_boundingbox')   
     3592    #suite = unittest.makeSuite(Test_Data_Manager,'test_sww2dem_asc_elevation')   
    35933593    #suite = unittest.makeSuite(Test_Data_Manager,'test_dem2pts_bounding_box')
    35943594    #suite = unittest.makeSuite(Test_Data_Manager,'test_decimate_dem')
  • inundation/utilities/polygon.py

    r1911 r2062  
    116116        return count != 1
    117117    else:
    118         return indices[count:][::-1]  #return reversed
     118        if count == len(indices):
     119            # No points are outside
     120            return []
     121        else:   
     122            return indices[count:][::-1]  #return reversed
    119123
    120124
  • inundation/utilities/test_polygon.py

    r1910 r2062  
    247247        #evaluate to True as the point 0.5, 1.0 is outside the unit square
    248248
     249    def test_all_outside_polygon(self):
     250        """Test case where all points are outside poly
     251        """
     252       
     253        U = [[0,0], [1,0], [1,1], [0,1]] #Unit square   
     254
     255        points = [[2,2], [1,3], [-1,1], [0,2]] #All outside
     256
     257
     258        indices, count = separate_points_by_polygon(points, U)
     259        #print indices, count
     260        assert count == 0 #None inside
     261        assert allclose(indices, [3,2,1,0])
     262
     263        indices = outside_polygon(points, U, closed = True)
     264        assert allclose(indices, [0,1,2,3])
     265
     266        indices = inside_polygon(points, U, closed = True)
     267        assert allclose(indices, [])               
     268
     269
     270    def test_all_inside_polygon(self):
     271        """Test case where all points are inside poly
     272        """
     273       
     274        U = [[0,0], [1,0], [1,1], [0,1]] #Unit square   
     275
     276        points = [[0.5,0.5], [0.2,0.3], [0,0.5]] #All inside (or on edge)
     277
     278
     279        indices, count = separate_points_by_polygon(points, U)
     280        assert count == 3 #All inside
     281        assert allclose(indices, [0,1,2])
     282
     283        indices = outside_polygon(points, U, closed = True)
     284        assert allclose(indices, [])
     285
     286        indices = inside_polygon(points, U, closed = True)
     287        assert allclose(indices, [0,1,2])
     288       
     289
    249290    def test_separate_points_by_polygon(self):
    250291        U = [[0,0], [1,0], [1,1], [0,1]] #Unit square   
Note: See TracChangeset for help on using the changeset viewer.