- Timestamp:
- Nov 1, 2010, 12:04:57 PM (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/anuga_core/source/anuga/abstract_2d_finite_volumes/test_gauge.py
r7778 r8063 84 84 os.remove(self.sww.filename) 85 85 86 def _create_sww(self ):86 def _create_sww(self,stage=10.0, timestep=2.0): 87 87 self.sww = SWW_file(self.domain) 88 88 self.sww.store_connectivity() 89 89 self.sww.store_timestep() 90 self.domain.set_quantity('stage', 10.0) # This is automatically limited90 self.domain.set_quantity('stage', stage) # This is automatically limited 91 91 # so it will not be less than the elevation 92 self.domain. time = 2.92 self.domain.set_time(self.domain.get_time()-self.domain.starttime+timestep) 93 93 self.sww.store_timestep() 94 94 … … 459 459 os.remove(points_file) 460 460 os.remove(point1_filename) 461 462 461 462 def test_sww2csv_multiple_files(self): 463 """ 464 This is testing the sww2csv_gauges function, by creating a multiple 465 sww file and then exporting the gauges and checking the results. 466 """ 467 timestep=2.0 468 domain = self.domain 469 domain.set_starttime(0.) 470 # Create two sww files with timestep at end. These are to be 471 # stored consecutively in the gauge csv files 472 basename='datatest' 473 domain.set_name(basename) 474 self._create_sww(stage=10.,timestep=timestep) 475 476 domain.set_name(basename+str(time.time())) 477 domain.set_time(domain.get_time()+timestep) 478 self._create_sww(stage=20.,timestep=timestep) 479 480 points_file = tempfile.mktemp(".csv") 481 file_id = open(points_file,"w") 482 483 # test the function at these points 484 points = [[5.0,1.],[0.5,2.]] 485 486 # create a csv file containing our gauge points 487 points_file = tempfile.mktemp(".csv") 488 file_id = open(points_file,"w") 489 file_id.write("name,easting,northing \n\ 490 point1, 5.0, 1.0\n\ 491 point2, 0.5, 2.0\n") 492 file_id.close() 493 494 sww2csv_gauges(basename+".sww", 495 points_file, 496 quantities=['stage', 'elevation'], 497 use_cache=False, 498 verbose=False) 499 500 point1_answers_array = [[0.0,1.0,-5.0], [2.0,10.0,-5.0],[4.0,10.0,-5.0], 501 [6.0,20.0,-5.0]] 502 point1_filename = 'gauge_point1.csv' 503 point1_handle = file(point1_filename) 504 point1_reader = reader(point1_handle) 505 point1_reader.next() 506 507 line=[] 508 for i,row in enumerate(point1_reader): 509 # note the 'hole' (element 1) below - skip the new 'hours' field 510 line.append([float(row[0]),float(row[2]),float(row[3])]) 511 #print 'line',line[i],'point1',point1_answers_array[i] 512 assert num.allclose(line[i], point1_answers_array[i]) 513 514 point2_answers_array = [[0.0,1.0,-0.5], [2.0,10.0,-0.5],[4.0,10.0,-0.5], 515 [6.0,20.0,-0.5]] 516 point2_filename = 'gauge_point2.csv' 517 point2_handle = file(point2_filename) 518 point2_reader = reader(point2_handle) 519 point2_reader.next() 520 521 line=[] 522 for i,row in enumerate(point2_reader): 523 # note the 'hole' (element 1) below - skip the new 'hours' field 524 line.append([float(row[0]),float(row[2]),float(row[3])]) 525 #print 'line',line[i],'point2',point2_answers_array[i] 526 assert num.allclose(line[i], point2_answers_array[i]) 527 528 # clean up 529 point1_handle.close() 530 point2_handle.close() 531 os.remove(points_file) 532 os.remove(point1_filename) 533 os.remove(point2_filename) 534 535 #remove second swwfile not removed by tearDown 536 os.remove(basename+".sww") 463 537 464 538 #-------------------------------------------------------------
Note: See TracChangeset
for help on using the changeset viewer.