Changeset 4348
- Timestamp:
- Apr 3, 2007, 2:36:58 PM (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
r4326 r4348 4040 4040 """ 4041 4041 self.quantity_name = quantity_name 4042 quantity_units = {'HA':'CENTIMETERS',4042 quantity_units = {'HA':'CENTIMETERS', 4043 4043 'UA':'CENTIMETERS/SECOND', 4044 'VA':'CENTIMETERS/SECOND'} 4044 'VA':'CENTIMETERS/SECOND'} 4045 4046 multiplier_dic = {'HA':100.0, # To convert from m to cm 4047 'UA':100.0, # m/s to cm/sec 4048 'VA':-100.0} # MUX files have positve x in the 4049 # Southern direction. This corrects for it, when writing nc files. 4050 4051 self.quantity_multiplier = multiplier_dic[self.quantity_name] 4045 4052 4046 4053 #self.file_name = file_name … … 4073 4080 def store_timestep(self, quantity_slice): 4074 4081 """ 4082 Write a time slice of quantity info 4075 4083 quantity_slice is the data to be stored at this time step 4076 4084 """ … … 4086 4094 #Store time 4087 4095 time[i] = i*self.time_step #self.domain.time 4088 quantity[i,:] = quantity_slice*100 # To convert from m to cm 4089 # And m/s to cm/sec 4096 quantity[i,:] = quantity_slice* self.quantity_multiplier 4090 4097 4091 4098 def close(self): … … 4712 4719 swwname = basename_out + '.sww' 4713 4720 4721 if verbose: print 'Output to ', swwname 4714 4722 outfile = NetCDFFile(swwname, 'w') 4715 4723 # For a different way of doing this, check out tsh2sww … … 4874 4882 h = w - elevation 4875 4883 xmomentum[j] = ua*h 4876 ymomentum[j] = va*h4884 ymomentum[j] = -1*va*h # -1 since in mux files south is positive. 4877 4885 j += 1 4878 4886 … … 4889 4897 h = w - elevation 4890 4898 xmomentum[slice_index] = ua*h 4891 ymomentum[slice_index] = va*h4899 ymomentum[slice_index] = -1*va*h # -1 since in mux files south is positive. 4892 4900 4893 4901 def urs2txt(basename_in, location_index=None): -
anuga_core/source/anuga/shallow_water/test_data_manager.py
r4326 r4348 4759 4759 # Write quantity info 4760 4760 for time in range(time_step_count): 4761 for i in range(points_num): 4762 f.write(pack('f',q_time[time,i])) 4761 for point_i in range(points_num): 4762 f.write(pack('f',q_time[time,point_i])) 4763 #print " mux_names[i]", mux_names[i] 4764 #print "f.write(pack('f',q_time[time,i]))", q_time[time,point_i] 4763 4765 f.close() 4764 4766 return base_name, files … … 4837 4839 # Write quantity info 4838 4840 for time in range(time_step_count): 4839 for i in range(points_num): 4840 f.write(pack('f',q_time[time,i])) 4841 for point_i in range(points_num): 4842 f.write(pack('f',q_time[time,point_i])) 4843 #print " mux_names[i]", mux_names[i] 4844 #print "f.write(pack('f',q_time[time,i]))", q_time[time,point_i] 4841 4845 f.close() 4842 4846 return base_name, files … … 4913 4917 #Check that first coordinate is correctly represented 4914 4918 #Work out the UTM coordinates for first point 4915 zone, e, n = redfearn(-34.5, 150.66667) 4919 zone, e, n = redfearn(-34.5, 150.66667) 4916 4920 4917 4921 assert allclose(geo_reference.get_absolute([[x[0],y[0]]]), [e,n]) … … 4932 4936 #Check the momentums - ua 4933 4937 #momentum = velocity*(stage-elevation) 4934 #momentum = velocity*(stage+elevation) 4938 # elevation = - depth 4939 #momentum = velocity_ua *(stage+depth) 4940 # = n*(e+tide+n) based on how I'm writing these files 4941 # 4942 answer_x = n*(e+tide+n) 4943 actual_x = xmomentum[0,0] 4944 #print "answer_x",answer_x 4945 #print "actual_x",actual_x 4946 assert allclose(answer_x, actual_x) #Meters 4947 4948 #Check the momentums - va 4949 #momentum = velocity*(stage-elevation) 4935 4950 # -(-elevation) since elevation is inverted in mux files 4936 # = n*(e+tide+n) based on how I'm writing these files 4937 answer = n*(e+tide+n) 4938 actual = xmomentum[0,0] 4939 assert allclose(answer, actual) #Meters 4940 4951 #momentum = velocity_va *(stage+elevation) 4952 # = e*(e+tide+n) based on how I'm writing these files 4953 answer_y = e*(e+tide+n) * -1 # talking into account mux file format 4954 actual_y = ymomentum[0,0] 4955 #print "answer_y",answer_y 4956 #print "actual_y",actual_y 4957 assert allclose(answer_y, actual_y) #Meters 4958 4959 assert allclose(answer_x, actual_x) #Meters 4960 4941 4961 # check the stage values, first time step. 4942 4962 # These arrays are equal since the Easting values were used as … … 4964 4984 ha=2 4965 4985 ua=5 4966 va=10 4986 va=-10 #-ve added to take into account mux file format where south 4987 # is positive. 4967 4988 base_name, files = self.write_mux(lat_long_points, 4968 4989 time_step_count, time_step, … … 5008 5029 answer = 230 5009 5030 actual = ymomentum[0,0] 5031 #print "answer",answer 5032 #print "actual",actual 5010 5033 assert allclose(answer, actual) #Meters^2/ sec 5011 5034 … … 5381 5404 assert allclose(stage[0,0], e +tide) #Meters 5382 5405 5406 5383 5407 #Check the momentums - ua 5384 5408 #momentum = velocity*(stage-elevation) 5385 # momentum = velocity*(stage+elevation)5386 # -(-elevation) since elevation is inverted in mux files5409 # elevation = - depth 5410 #momentum = velocity_ua *(stage+depth) 5387 5411 # = n*(e+tide+n) based on how I'm writing these files 5388 answer = n*(e+tide+n) 5389 actual = xmomentum[0,0] 5390 assert allclose(answer, actual) #Meters 5412 # 5413 answer_x = n*(e+tide+n) 5414 actual_x = xmomentum[0,0] 5415 #print "answer_x",answer_x 5416 #print "actual_x",actual_x 5417 assert allclose(answer_x, actual_x) #Meters 5418 5419 #Check the momentums - va 5420 #momentum = velocity*(stage-elevation) 5421 # elevation = - depth 5422 #momentum = velocity_va *(stage+depth) 5423 # = e*(e+tide+n) based on how I'm writing these files 5424 # 5425 answer_y = -1*e*(e+tide+n) 5426 actual_y = ymomentum[0,0] 5427 #print "answer_y",answer_y 5428 #print "actual_y",actual_y 5429 assert allclose(answer_y, actual_y) #Meters 5391 5430 5392 5431 # check the stage values, first time step. … … 5458 5497 #Check the momentums - ua 5459 5498 #momentum = velocity*(stage-elevation) 5460 # momentum = velocity*(stage+elevation)5461 # -(-elevation) since elevation is inverted in mux files5499 # elevation = - depth 5500 #momentum = velocity_ua *(stage+depth) 5462 5501 # = n*(e+tide+n) based on how I'm writing these files 5463 answer = n*(e+tide+n) 5464 actual = xmomentum[0,0] 5465 assert allclose(answer, actual) #Meters 5502 # 5503 answer_x = n*(e+tide+n) 5504 actual_x = xmomentum[0,0] 5505 #print "answer_x",answer_x 5506 #print "actual_x",actual_x 5507 assert allclose(answer_x, actual_x) #Meters 5508 5509 #Check the momentums - va 5510 #momentum = velocity*(stage-elevation) 5511 # elevation = - depth 5512 #momentum = velocity_va *(stage+depth) 5513 # = e*(e+tide+n) based on how I'm writing these files 5514 # 5515 answer_y = -1*e*(e+tide+n) 5516 actual_y = ymomentum[0,0] 5517 #print "answer_y",answer_y 5518 #print "actual_y",actual_y 5519 assert allclose(answer_y, actual_y) #Meters 5466 5520 5467 5521 # check the stage values, first time step. … … 5532 5586 #Check the momentums - ua 5533 5587 #momentum = velocity*(stage-elevation) 5534 # momentum = velocity*(stage+elevation)5535 # -(-elevation) since elevation is inverted in mux files5588 # elevation = - depth 5589 #momentum = velocity_ua *(stage+depth) 5536 5590 # = n*(e+tide+n) based on how I'm writing these files 5537 answer = n*(e+tide+n) 5538 actual = xmomentum[0,0] 5539 assert allclose(answer, actual) #Meters 5591 # 5592 answer_x = n*(e+tide+n) 5593 actual_x = xmomentum[0,0] 5594 #print "answer_x",answer_x 5595 #print "actual_x",actual_x 5596 assert allclose(answer_x, actual_x) #Meters 5597 5598 #Check the momentums - va 5599 #momentum = velocity*(stage-elevation) 5600 # elevation = - depth 5601 #momentum = velocity_va *(stage+depth) 5602 # = e*(e+tide+n) based on how I'm writing these files 5603 # 5604 answer_y = -1*e*(e+tide+n) 5605 actual_y = ymomentum[0,0] 5606 #print "answer_y",answer_y 5607 #print "actual_y",actual_y 5608 assert allclose(answer_y, actual_y) #Meters 5540 5609 5541 5610 # check the stage values, first time step. … … 5605 5674 #Check the momentums - ua 5606 5675 #momentum = velocity*(stage-elevation) 5607 # momentum = velocity*(stage+elevation)5608 # -(-elevation) since elevation is inverted in mux files5676 # elevation = - depth 5677 #momentum = velocity_ua *(stage+depth) 5609 5678 # = n*(e+tide+n) based on how I'm writing these files 5610 answer = n*(e+tide+n) 5611 actual = xmomentum[0,0] 5612 assert allclose(answer, actual) #Meters 5679 # 5680 answer_x = n*(e+tide+n) 5681 actual_x = xmomentum[0,0] 5682 #print "answer_x",answer_x 5683 #print "actual_x",actual_x 5684 assert allclose(answer_x, actual_x) #Meters 5685 5686 #Check the momentums - va 5687 #momentum = velocity*(stage-elevation) 5688 # elevation = - depth 5689 #momentum = velocity_va *(stage+depth) 5690 # = e*(e+tide+n) based on how I'm writing these files 5691 # 5692 answer_y = -1*e*(e+tide+n) 5693 actual_y = ymomentum[0,0] 5694 #print "answer_y",answer_y 5695 #print "actual_y",actual_y 5696 assert allclose(answer_y, actual_y) #Meters 5613 5697 5614 5698 # check the stage values, first time step. … … 5826 5910 #------------------------------------------------------------- 5827 5911 if __name__ == "__main__": 5828 #suite = unittest.makeSuite(Test_Data_Manager,'test_urs2 txt')5912 #suite = unittest.makeSuite(Test_Data_Manager,'test_urs2sww') 5829 5913 #suite = unittest.makeSuite(Test_Data_Manager,'cache_test_URS_points_needed_and_urs_ungridded2sww') 5830 5914 #suite = unittest.makeSuite(Test_Data_Manager,'test_urs2sww_momentum')
Note: See TracChangeset
for help on using the changeset viewer.