Changeset 4295
- Timestamp:
- Mar 6, 2007, 10:56:39 AM (18 years ago)
- Location:
- anuga_core/source/anuga/shallow_water
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
anuga_core/source/anuga/shallow_water/data_manager.py
r4292 r4295 4587 4587 4588 4588 def urs_ungridded2sww(basename_in='o', basename_out=None, verbose=False, 4589 #mint=None, maxt=None,4589 mint=None, maxt=None, 4590 4590 mean_stage=0, 4591 4591 origin = None, … … 4594 4594 """ 4595 4595 parameters not used! 4596 origin4597 4596 #mint=None, maxt=None, 4598 4597 """ … … 4635 4634 4636 4635 #mesh.export_mesh_file(basename_in + '.tsh') 4637 times = [] 4636 # These are the times of the mux file 4637 mux_times = [] 4638 4638 for i in range(a_mux.time_step_count): 4639 times.append(a_mux.time_step * i) 4639 mux_times.append(a_mux.time_step * i) 4640 mux_times_start_i, mux_times_fin_i = mux2sww_time(mux_times, mint, maxt) 4641 times = mux_times[mux_times_start_i:mux_times_fin_i] 4642 4643 if mux_times_start_i == mux_times_fin_i: 4644 # Close the mux files 4645 for quantity, file in map(None, quantities, files_in): 4646 mux[quantity].close() 4647 msg="Due to mint and maxt there's no time info in the boundary SWW." 4648 assert 1==0 , msg #Happy to know a better way of doing this.. 4640 4649 4650 # If this raise is removed there is currently no downstream errors 4651 4641 4652 points_utm=ensure_numeric(points_utm) 4642 4653 #print "mesh_dic['generatedpointlist']", mesh_dic['generatedpointlist'] … … 4654 4665 4655 4666 outfile = NetCDFFile(swwname, 'w') 4656 # For a different way of doing this, check out tsh2sww 4667 # For a different way of doing this, check out tsh2sww 4668 # work out sww_times and the index range this covers 4657 4669 write_sww_header(outfile, times, len(volumes), len(points_utm)) 4670 outfile.mean_stage = mean_stage 4671 outfile.zscale = zscale 4658 4672 write_sww_triangulation(outfile, points_utm, volumes, 4659 4673 elevation, zone, origin=origin, verbose=verbose) … … 4662 4676 j = 0 4663 4677 # Read in a time slice from each mux file and write it to the sww file 4664 for HA, UA, VA in map(None, mux['HA'], mux['UA'], mux['VA']): 4665 write_sww_time_slice(outfile, HA, UA, VA, elevation, j, 4666 mean_stage=mean_stage, zscale=zscale, 4667 verbose=verbose) 4678 for HA, UA, VA in map(None, mux['HA'], mux['UA'], mux['VA']): 4679 if j >= mux_times_start_i and j < mux_times_fin_i: 4680 write_sww_time_slice(outfile, HA, UA, VA, elevation, 4681 j - mux_times_start_i, 4682 mean_stage=mean_stage, zscale=zscale, 4683 verbose=verbose) 4668 4684 j += 1 4669 4685 outfile.close() 4670 4686 # 4671 4687 # Do some conversions while writing the sww file 4688 def mux2sww_time(mux_times, mint, maxt): 4689 """ 4690 """ 4691 4692 if mint == None: 4693 mux_times_start_i = 0 4694 else: 4695 mux_times_start_i = searchsorted(mux_times, mint) 4696 4697 if maxt == None: 4698 mux_times_fin_i = len(mux_times) 4699 else: 4700 maxt += 0.5 # so if you specify a time where there is 4701 # data that time will be included 4702 mux_times_fin_i = searchsorted(mux_times, maxt) 4703 4704 return mux_times_start_i, mux_times_fin_i 4672 4705 4673 4706 def write_sww_header(outfile, times, number_of_volumes, number_of_points ): … … 4679 4712 number_of_times = len(times) 4680 4713 4681 #Create new file4682 4714 outfile.institution = 'Geoscience Australia' 4683 4715 outfile.description = 'Converted from XXX' … … 4689 4721 4690 4722 #Start time in seconds since the epoch (midnight 1/1/1970) 4691 outfile.starttime = starttime = times[0] 4723 if len(times) == 0: 4724 outfile.starttime = starttime = 0 4725 else: 4726 outfile.starttime = starttime = times[0] 4692 4727 4693 4728 … … 4775 4810 4776 4811 4777 # FIXME: Don't store the whole speeds and stage in memory.4778 # block it?4779 4812 def write_sww_time_slices(outfile, has, uas, vas, elevation, 4780 4813 mean_stage=0, zscale=1, … … 4796 4829 j += 1 4797 4830 4798 4799 4831 def write_sww_time_slice(outfile, ha, ua, va, elevation, slice_index, 4800 4832 mean_stage=0, zscale=1, … … 4804 4836 xmomentum = outfile.variables['xmomentum'] 4805 4837 ymomentum = outfile.variables['ymomentum'] 4806 4807 4838 4808 4839 w = zscale*ha + mean_stage 4809 4840 stage[slice_index] = w … … 4811 4842 xmomentum[slice_index] = ua*h 4812 4843 ymomentum[slice_index] = va*h 4844 4813 4845 4814 4846 class Urs_points: -
anuga_core/source/anuga/shallow_water/test_data_manager.py
r4284 r4295 5436 5436 os.remove(sww_file) 5437 5437 5438 def test_urs_ungridded2sww_mint_maxt (self): 5439 5440 #Zone: 50 5441 #Easting: 240992.578 Northing: 7620442.472 5442 #Latitude: -21 30 ' 0.00000 '' Longitude: 114 30 ' 0.00000 '' 5443 lat_long = [[-21.5,114.5],[-21,114.5],[-21,115]] 5444 time_step_count = 6 5445 time_step = 100 5446 tide = 9000000 5447 base_name, files = self.write_mux(lat_long, 5448 time_step_count, time_step) 5449 urs_ungridded2sww(base_name, mean_stage=tide, origin =(50,23432,4343), 5450 mint=101, maxt=500) 5451 5452 # now I want to check the sww file ... 5453 sww_file = base_name + '.sww' 5454 5455 #Let's interigate the sww file 5456 # Note, the sww info is not gridded. It is point data. 5457 fid = NetCDFFile(sww_file) 5458 5459 # Make x and y absolute 5460 x = fid.variables['x'][:] 5461 y = fid.variables['y'][:] 5462 geo_reference = Geo_reference(NetCDFObject=fid) 5463 points = geo_reference.get_absolute(map(None, x, y)) 5464 points = ensure_numeric(points) 5465 x = points[:,0] 5466 y = points[:,1] 5467 5468 #Check that first coordinate is correctly represented 5469 #Work out the UTM coordinates for first point 5470 zone, e, n = redfearn(lat_long[0][0], lat_long[0][1]) 5471 assert allclose([x[0],y[0]], [e,n]) 5472 5473 #Check the time vector 5474 times = fid.variables['time'][:] 5475 5476 times_actual = [200,300,400,500] 5477 5478 assert allclose(ensure_numeric(times), 5479 ensure_numeric(times_actual)) 5480 5481 #Check first value 5482 stage = fid.variables['stage'][:] 5483 xmomentum = fid.variables['xmomentum'][:] 5484 ymomentum = fid.variables['ymomentum'][:] 5485 elevation = fid.variables['elevation'][:] 5486 assert allclose(stage[0,0], e +tide) #Meters 5487 5488 #Check the momentums - ua 5489 #momentum = velocity*(stage-elevation) 5490 #momentum = velocity*(stage+elevation) 5491 # -(-elevation) since elevation is inverted in mux files 5492 # = n*(e+tide+n) based on how I'm writing these files 5493 answer = n*(e+tide+n) 5494 actual = xmomentum[0,0] 5495 assert allclose(answer, actual) #Meters 5496 5497 # check the stage values, first time step. 5498 # These arrays are equal since the Easting values were used as 5499 # the stage 5500 assert allclose(stage[0], x +tide) #Meters 5501 # check the elevation values. 5502 # -ve since urs measures depth, sww meshers height, 5503 # these arrays are equal since the northing values were used as 5504 # the elevation 5505 assert allclose(-elevation, y) #Meters 5506 5507 fid.close() 5508 self.delete_mux(files) 5509 os.remove(sww_file) 5510 5511 def test_urs_ungridded2sww_mint_maxtII (self): 5512 5513 #Zone: 50 5514 #Easting: 240992.578 Northing: 7620442.472 5515 #Latitude: -21 30 ' 0.00000 '' Longitude: 114 30 ' 0.00000 '' 5516 lat_long = [[-21.5,114.5],[-21,114.5],[-21,115]] 5517 time_step_count = 6 5518 time_step = 100 5519 tide = 9000000 5520 base_name, files = self.write_mux(lat_long, 5521 time_step_count, time_step) 5522 urs_ungridded2sww(base_name, mean_stage=tide, origin =(50,23432,4343), 5523 mint=0, maxt=100000) 5524 5525 # now I want to check the sww file ... 5526 sww_file = base_name + '.sww' 5527 5528 #Let's interigate the sww file 5529 # Note, the sww info is not gridded. It is point data. 5530 fid = NetCDFFile(sww_file) 5531 5532 # Make x and y absolute 5533 geo_reference = Geo_reference(NetCDFObject=fid) 5534 points = geo_reference.get_absolute(map(None, fid.variables['x'][:], 5535 fid.variables['y'][:])) 5536 points = ensure_numeric(points) 5537 x = points[:,0] 5538 5539 #Check the time vector 5540 times = fid.variables['time'][:] 5541 5542 times_actual = [0,100,200,300,400,500] 5543 assert allclose(ensure_numeric(times), 5544 ensure_numeric(times_actual)) 5545 5546 #Check first value 5547 stage = fid.variables['stage'][:] 5548 assert allclose(stage[0], x +tide) 5549 5550 fid.close() 5551 self.delete_mux(files) 5552 os.remove(sww_file) 5553 5554 def test_urs_ungridded2sww_mint_maxtIII (self): 5555 5556 #Zone: 50 5557 #Easting: 240992.578 Northing: 7620442.472 5558 #Latitude: -21 30 ' 0.00000 '' Longitude: 114 30 ' 0.00000 '' 5559 lat_long = [[-21.5,114.5],[-21,114.5],[-21,115]] 5560 time_step_count = 6 5561 time_step = 100 5562 tide = 9000000 5563 base_name, files = self.write_mux(lat_long, 5564 time_step_count, time_step) 5565 try: 5566 urs_ungridded2sww(base_name, mean_stage=tide, 5567 origin =(50,23432,4343), 5568 mint=301, maxt=399) 5569 except: 5570 pass 5571 else: 5572 self.failUnless(0 ==1, 'Bad input did not throw exception error!') 5573 5574 self.delete_mux(files) 5575 5438 5576 def test_URS_points_needed_and_urs_ungridded2sww(self): 5439 5577 # This doesn't actually check anything
Note: See TracChangeset
for help on using the changeset viewer.