Changeset 4238


Ignore:
Timestamp:
Feb 7, 2007, 5:14:03 PM (17 years ago)
Author:
duncan
Message:

more for updated urs2sww

Files:
5 edited

Legend:

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

    r4225 r4238  
    608608                            self.get_all_attributes(),
    609609                            as_lat_long=as_lat_long)
    610                                    
     610             
     611        elif file_name[-4:] == ".urs" :
     612            msg = "ERROR: Can not write a .urs file as a relative file."
     613            assert absolute, msg
     614            _write_urs_file(file_name,
     615                            self.get_data_points(as_lat_long=True))
     616                                                         
    611617        else:
    612618            msg = 'Unknown file type %s ' %file_name
     
    12231229
    12241230    fd.close()
     1231 
     1232def _write_urs_file(file_name,
     1233                    points,
     1234                    delimiter=' '):
     1235    """
     1236    export a file, file_name, with the urs format
     1237    the data points are in lats and longs
     1238   
     1239    """   
     1240    fd = open(file_name,'w')   
     1241    fd.write(str(len(points))+"\n")   
     1242    # <lat> <long> <id#>
     1243    for i, vert in enumerate( points):
     1244        fd.write(str(round(vert[0],7)) + delimiter + \
     1245                 str(round(vert[1],7)) + delimiter +str(i+1)+ "\n")
     1246    fd.close()
    12251247   
    12261248def _point_atts2array(point_atts):
  • anuga_core/source/anuga/geospatial_data/test_geospatial_data.py

    r4225 r4238  
    20352035
    20362036
     2037    def test_write_urs_file(self):
     2038        lat_gong = degminsec2decimal_degrees(-34,00,0)
     2039        lon_gong = degminsec2decimal_degrees(150,30,0.)
     2040       
     2041        lat_2 = degminsec2decimal_degrees(-34,00,1)
     2042        lon_2 = degminsec2decimal_degrees(150,00,0.)
     2043        p1 = (lat_gong, lon_gong)
     2044        p2 = (lat_2, lon_2)
     2045        points = ImmutableSet([p1, p2, p1])
     2046        gsd = Geospatial_data(data_points=list(points),
     2047                              points_are_lats_longs=True)
     2048       
     2049        fn = tempfile.mktemp(".urs")
     2050        gsd.export_points_file(fn)
     2051        #print "fn", fn
     2052        handle = open(fn)
     2053        lines = handle.readlines()
     2054        assert lines[0],'2'
     2055        assert lines[1],'-34.0002778 150.0 1'
     2056        assert lines[2],'-34.0 150.5 2'
     2057        handle.close()
     2058        os.remove(fn)
     2059       
    20372060    def test_lat_long_set(self):
    20382061        lat_gong = degminsec2decimal_degrees(-34,30,0.)
     
    20962119                  [5.0, 1.0], [5.0, 2.0],[5.0, 3.0], [5.0, 4.0], [5.0, 5.0]]
    20972120        attributes = {'depth':[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13,
    2098                       14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25],'speed':[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13,
     2121                      14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25],
     2122                      'speed':[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13,
    20992123                      14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25]}
    21002124        G = Geospatial_data(points, attributes)
     
    21042128        factor = 0.21
    21052129
    2106         G1, G2  = G.split(factor) #will return G1 with 10% of points and G2 with 90%
    2107        
    2108 #        print 'len(G): %s  len(G1): %s len(G2): %s' %(len(G), len(G1), len(G2))
     2130        #will return G1 with 10% of points and G2 with 90%
     2131        G1, G2  = G.split(factor)
     2132       
     2133#        print 'len(G): %s len(G1): %s len(G2): %s' %(len(G), len(G1), len(G2))
    21092134#        print 'G: ', len(G),'G1: ', len(G1), 'G2: ', len(G2)
    21102135
  • anuga_core/source/anuga/shallow_water/data_manager.py

    r4223 r4238  
    44094409    #### URS UNGRIDDED 2 SWW ###
    44104410
    4411 def URS_points_needed_to_file(boundary_polygon, ll_lat, ll_long,
     4411def URS_points_needed_to_file(file_name, boundary_polygon, ll_lat, ll_long,
    44124412                              grid_spacing,
    44134413                      lat_amount, long_amount, zone=None):
    4414    
     4414    """
     4415    file_name - name of the urs file produced for David.
     4416    boundary_polygon - a list of points that describes a polygon.
     4417                      The last point is assumed ot join the first point.
     4418                      This is in UTM (lat long would be better though)
     4419
     4420    ll_lat - lower left latitude, in decimal degrees
     4421    ll-long - lower left longitude, in decimal degrees
     4422    grid_spacing - in deciamal degrees
     4423
     4424
     4425    Don't add the file extension.  It will be added.
     4426    """
    44154427    geo = URS_points_needed(boundary_polygon, ll_lat, ll_long, grid_spacing,
    44164428                      lat_amount, long_amount, zone=zone)
     4429    if not file[-4:] == ".urs":
     4430        file += ".urs"
     4431    geo.export_points_file(file_name)
    44174432   
    44184433def URS_points_needed(boundary_polygon, ll_lat, ll_long, grid_spacing,
     
    44714486    max_lat = max(seg_lat_long[0][0], seg_lat_long[1][0]) + buffer
    44724487    max_long = max(seg_lat_long[0][1], seg_lat_long[1][1]) + buffer
    4473     min_lat = max(seg_lat_long[0][0], seg_lat_long[1][0]) - buffer
    4474     min_long = max(seg_lat_long[0][1], seg_lat_long[1][1]) - buffer
     4488    min_lat = min(seg_lat_long[0][0], seg_lat_long[1][0]) - buffer
     4489    min_long = min(seg_lat_long[0][1], seg_lat_long[1][1]) - buffer
    44754490
    44764491    #print "ll_lat", ll_lat
  • anuga_core/source/anuga/shallow_water/test_data_manager.py

    r4225 r4238  
    50405040
    50415041    #### TESTS URS UNGRIDDED 2 SWW ###
    5042     def X_test_URS_points_needed(self):
     5042    def test_URS_points_needed(self):
    50435043       
    50445044        ll_lat = -21.5
     
    50575057        #Maybe see if I can fit the data to the polygon - have to represent
    50585058        # the poly as points though.
    5059         geo.export_points_file("results")
     5059        #geo.export_points_file("results.txt", as_lat_long=True)
    50605060        results = ImmutableSet(geo.get_data_points(as_lat_long=True))
    5061         print 'results',results
     5061        #print 'results',results
    50625062
    50635063        # These are a set of points that have to be in results
    50645064        points = []
    50655065        for i in range(18):
    5066             lat = -21.0 - 8/60 - grid_spacing * i
     5066            lat = -21.0 - 8./60 - grid_spacing * i
    50675067            points.append((lat,degminsec2decimal_degrees(114,35,0)))
    5068             #points.append((lat,degminsec2decimal_degrees(114,36,0)))
    5069             #points.append((lat,degminsec2decimal_degrees(114,52,0)))
    5070             #points.append((lat,degminsec2decimal_degrees(114,53,0)))
    5071            
     5068            points.append((lat,degminsec2decimal_degrees(114,36,0)))
     5069            points.append((lat,degminsec2decimal_degrees(114,52,0)))
     5070            points.append((lat,degminsec2decimal_degrees(114,53,0)))
     5071        geo_answer = Geospatial_data(data_points=points,
     5072                                     points_are_lats_longs=True)
     5073        #geo_answer.export_points_file("answer.txt", as_lat_long=True) 
    50725074        answer = ImmutableSet(points)
    5073         print "answer", answer
     5075       
    50745076        outs = answer.difference(results)
    5075         print "outs", outs
    5076         assert answer.issubset(results)
     5077        #print "outs", outs
     5078        # This doesn't work.  Though visualising the results shows that
     5079        # it is correct.
     5080        #assert answer.issubset(results)
     5081        # this is why;
     5082        #point (-21.133333333333333, 114.58333333333333)
     5083        #result (-21.133333332232368, 114.58333333300342)
     5084       
     5085        for point in points:
     5086            found = False
     5087            for result in results:
     5088                if allclose(point, result):
     5089                    found = True
     5090                    break
     5091            if not found:
     5092                assert False
     5093       
    50775094       
    50785095    def X_test_URS_points_neededII(self):
  • anuga_work/development/friction_dam_2006/run_dam.py

    r4055 r4238  
    153153if __name__ == "__main__":
    154154    for friction in [ 0.05]:
    155         main(friction, is_trial_run = False, outputdir_name='friction_set_A')
     155        main(friction, is_trial_run = True, outputdir_name='friction_set_A')
    156156   
    157157    #    to do
Note: See TracChangeset for help on using the changeset viewer.