Changeset 5189


Ignore:
Timestamp:
Apr 2, 2008, 11:36:59 AM (17 years ago)
Author:
duncan
Message:

adding hacky function, points2polygon

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

Legend:

Unmodified
Added
Removed
  • anuga_core/source/anuga/shallow_water/data_manager.py

    r5115 r5189  
    19451945              %(min(times), max(times), len(times))
    19461946        print '  Quantities [SI units]:'
     1947        # Comment out for reduced memory consumption
    19471948        for name in ['stage', 'xmomentum', 'ymomentum']:
    19481949            q = fid.variables[name][:].flat
     
    19601961    try:
    19611962        q = fid.variables[quantity][:]
     1963       
     1964       
    19621965    except:
    19631966        quantity_dict = {}
     
    19661969        #Convert quantity expression to quantities found in sww file   
    19671970        q = apply_expression_to_dictionary(quantity, quantity_dict)
    1968 
     1971    #print "q.shape",q.shape
    19691972    if len(q.shape) == 2:
    19701973        #q has a time component and needs to be reduced along
     
    21632166        fid.close()
    21642167        return basename_out
     2168
    21652169
    21662170#Backwards compatibility
     
    58495853    return iterate_over
    58505854
     5855def points2polygon(points_file,
     5856                    minimum_triangle_angle=3.0):
     5857    """
     5858    WARNING: This function is not fully working. 
     5859   
     5860    Function to return a polygon returned from alpha shape, given a points file.
     5861   
     5862    WARNING: Alpha shape returns multiple polygons, but this function only returns one polygon.
     5863   
     5864    """
     5865    from anuga.pmesh.mesh import Mesh, importMeshFromFile
     5866    from anuga.shallow_water import Domain   
     5867    from anuga.pmesh.mesh_interface import create_mesh_from_regions
     5868   
     5869    mesh = importMeshFromFile(points_file)
     5870    mesh.auto_segment()
     5871    mesh.exportASCIIsegmentoutlinefile("outline.tsh")
     5872    mesh2 = importMeshFromFile("outline.tsh")
     5873    mesh2.generate_mesh(maximum_triangle_area=1000000000, minimum_triangle_angle=minimum_triangle_angle, verbose=False)
     5874    mesh2.export_mesh_file('outline_meshed.tsh')
     5875    domain = Domain("outline_meshed.tsh", use_cache = False)
     5876    polygon =  domain.get_boundary_polygon()
     5877    return polygon
    58515878
    58525879#-------------------------------------------------------------
     
    58585885    import os
    58595886    os.umask(umask)
    5860 
  • anuga_core/source/anuga/shallow_water/test_data_manager.py

    r5175 r5189  
    2525from anuga.coordinate_transforms.geo_reference import Geo_reference, \
    2626     DEFAULT_ZONE
     27from anuga.geospatial_data.geospatial_data import Geospatial_data
    2728
    2829class Test_Data_Manager(unittest.TestCase):
     
    27522753        from Numeric import array, zeros, allclose, Float, concatenate, NewAxis
    27532754        from Scientific.IO.NetCDF import NetCDFFile
    2754         from anuga.geospatial_data.geospatial_data import Geospatial_data
    2755 
    27562755        # Used for points that lie outside mesh
    27572756        NODATA_value = 1758323
     
    73917390        assert (file_line2 == 'goodbye screen catcher\n')
    73927391       
     7392 
     7393    def test_points2polygon(self): 
     7394        att_dict = {}
     7395        pointlist = array([[1.0, 0.0],[0.0, 1.0],[0.0, 0.0]])
     7396        att_dict['elevation'] = array([10.1, 0.0, 10.4])
     7397        att_dict['brightness'] = array([10.0, 1.0, 10.4])
     7398       
     7399        fileName = tempfile.mktemp(".csv")
     7400       
     7401        G = Geospatial_data(pointlist, att_dict)
     7402       
     7403        G.export_points_file(fileName)
     7404       
     7405        polygon = points2polygon(fileName)
     7406       
     7407        # This test may fail if the order changes
     7408        assert (polygon == [[0.0, 0.0],[1.0, 0.0],[0.0, 1.0]])
    73937409       
    73947410
Note: See TracChangeset for help on using the changeset viewer.