Changeset 3416


Ignore:
Timestamp:
Jul 25, 2006, 1:44:50 PM (19 years ago)
Author:
duncan
Message:

finish interpolating sww to csv file function

Location:
inundation/fit_interpolate
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • inundation/fit_interpolate/interpolate.py

    r3411 r3416  
    330330                else:
    331331                    velocity = 0
    332                    
    333             print "depth",depth
    334             print "velocity",velocity
    335332            depths.append(depth)
    336333            velocitys.append(velocity)
  • inundation/fit_interpolate/test_interpolate.py

    r3412 r3416  
    1111from math import sqrt
    1212import tempfile
     13import csv
    1314
    1415from Scientific.IO.NetCDF import NetCDFFile
     
    13531354            self.failUnless( z[i,0] == answer[11,0], 'Fail!')
    13541355
    1355     def ztest_interpolate_sww2csv(self):
     1356    def test_interpolate_sww2csv(self):
    13561357
    13571358        def elevation_function(x, y):
     
    13771378        domain.set_quantity('elevation', elevation_function)
    13781379        domain.set_quantity('friction', 0.03)
    1379         domain.set_quantity('xmomentum', 10.0)
    1380         domain.set_quantity('ymomentum', 100.0)
     1380        domain.set_quantity('xmomentum', 3.0)
     1381        domain.set_quantity('ymomentum', 4.0)
    13811382
    13821383        ######################
     
    14001401        sww.store_connectivity()
    14011402        sww.store_timestep(['stage', 'xmomentum', 'ymomentum'])
    1402         domain.set_quantity('stage', -1.0)
     1403        domain.set_quantity('stage', 10.0) # This is automatically limmited
     1404        # so it will not be less than the elevation
    14031405        domain.time = 2.
    14041406        sww.store_timestep(['stage', 'xmomentum', 'ymomentum'])
     
    14061408        # test the function
    14071409        points = [[5.0,1.],[0.5,2.]]
    1408         interpolate_sww2csv(sww.filename, points, "aa.csv", "bb.csv")
    1409 
    1410         print "sww.filename",sww.filename
    1411         #os.remove(sww.filename)
     1410        depth_file = tempfile.mktemp(".csv")
     1411        velocity_file = tempfile.mktemp(".csv")
     1412        interpolate_sww2csv(sww.filename, points, depth_file, velocity_file,
     1413                            verbose=False)
     1414
     1415        depth_answers_array = [[6.0, 1.5], [15., 10.5]]
     1416        velocity_answers_array = [[5./6.0, 5./1.5], [5./15., 5./10.5]]
     1417        depth_reader = csv.reader(file(depth_file))
     1418        depth_reader.next()
     1419        velocity_reader = csv.reader(file(velocity_file))
     1420        velocity_reader.next()
     1421        for depths, velocitys, depth_answers, velocity_answers in map(None,
     1422                                              depth_reader,
     1423                                              velocity_reader,
     1424                                              depth_answers_array,
     1425                                              velocity_answers_array):
     1426            for i in range(len(depths)):
     1427                #print "depths",depths[i]
     1428                #print "depth_answers",depth_answers[i]
     1429                #print "velocitys",velocitys[i]
     1430                #print "velocity_answers_array", velocity_answers[i]
     1431                msg = 'Interpolation failed'
     1432                assert allclose(float(depths[i]), depth_answers[i]), msg
     1433                assert allclose(float(velocitys[i]), velocity_answers[i]), msg
     1434       
     1435        #print "sww.filename",sww.filename
     1436        os.remove(sww.filename)
    14121437#-------------------------------------------------------------
    14131438if __name__ == "__main__":
Note: See TracChangeset for help on using the changeset viewer.