Changeset 1132
- Timestamp:
- Mar 23, 2005, 10:00:15 AM (20 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
inundation/ga/storm_surge/pyvolution/test_data_manager.py
r1130 r1132 707 707 os.remove('small.sww') 708 708 709 710 709 711 def test_ferret2sww3(self): 710 712 """ … … 725 727 # Fourth value (index==3) is -6.50198 cm 726 728 727 728 729 from coordinate_transforms.redfearn import redfearn 729 730 730 fid1 = NetCDFFile('small_ha.nc','a') 731 fid3 = NetCDFFile('small_va.nc','a') 732 733 #Populate with decent values 734 fid1.variables['HA'][:][0,0,3]=130.7 735 fid3.variables['VA'][:][0,0,3]=10.0 736 737 731 fid1 = NetCDFFile('test_ha.nc','w') 732 fid2 = NetCDFFile('test_ua.nc','w') 733 fid3 = NetCDFFile('test_va.nc','w') 734 fid4 = NetCDFFile('test_e.nc','w') 735 736 h1_list = [150.66667,150.83334,151.] 737 h2_list = [-34.5,-34.33333] 738 739 long_name = 'LON' 740 lat_name = 'LAT' 741 742 nx = 3 743 ny = 2 744 745 for fid in [fid1,fid2,fid3]: 746 fid.createDimension(long_name,nx) 747 fid.createVariable(long_name,'d',(long_name,)) 748 fid.variables[long_name].point_spacing='uneven' 749 fid.variables[long_name].units='degrees_east' 750 fid.variables[long_name].assignValue(h1_list) 751 752 fid.createDimension(lat_name,ny) 753 fid.createVariable(lat_name,'d',(lat_name,)) 754 fid.variables[lat_name].point_spacing='uneven' 755 fid.variables[lat_name].units='degrees_north' 756 fid.variables[lat_name].assignValue(h2_list) 757 758 fid.createDimension('TIME',2) 759 fid.createVariable('TIME','d',('TIME',)) 760 fid.variables['TIME'].point_spacing='uneven' 761 fid.variables['TIME'].units='seconds' 762 fid.variables['TIME'].assignValue([0.,1.]) 763 if fid == fid3: break 764 765 766 for fid in [fid4]: 767 fid.createDimension(long_name,nx) 768 fid.createVariable(long_name,'d',(long_name,)) 769 fid.variables[long_name].point_spacing='uneven' 770 fid.variables[long_name].units='degrees_east' 771 fid.variables[long_name].assignValue(h1_list) 772 773 fid.createDimension(lat_name,ny) 774 fid.createVariable(lat_name,'d',(lat_name,)) 775 fid.variables[lat_name].point_spacing='uneven' 776 fid.variables[lat_name].units='degrees_north' 777 fid.variables[lat_name].assignValue(h2_list) 778 779 name = {} 780 name[fid1]='HA' 781 name[fid2]='UA' 782 name[fid3]='VA' 783 name[fid4]='ELEVATION' 784 785 units = {} 786 units[fid1]='cm' 787 units[fid2]='cm/s' 788 units[fid3]='cm/s' 789 units[fid4]='m' 790 791 values = {} 792 values[fid1]=[[[5., 10.,15.], [13.,18.,23.]],[[50.,100.,150.],[130.,180.,230.]]] 793 values[fid2]=[[[1., 2.,3.], [4.,5.,6.]],[[7.,8.,9.],[10.,11.,12.]]] 794 values[fid3]=[[[13., 12.,11.], [10.,9.,8.]],[[7.,6.,5.],[4.,3.,2.]]] 795 values[fid4]=[[-3000,-3100,-3200],[-4000,-5000,-6000]] 796 797 for fid in [fid1,fid2,fid3]: 798 fid.createVariable(name[fid],'d',('TIME',lat_name,long_name)) 799 fid.variables[name[fid]].point_spacing='uneven' 800 fid.variables[name[fid]].units=units[fid] 801 fid.variables[name[fid]].assignValue(values[fid]) 802 fid.variables[name[fid]].missing_value = -99999999. 803 if fid == fid3: break 804 805 for fid in [fid4]: 806 fid.createVariable(name[fid],'d',(lat_name,long_name)) 807 fid.variables[name[fid]].point_spacing='uneven' 808 fid.variables[name[fid]].units=units[fid] 809 fid.variables[name[fid]].assignValue(values[fid]) 810 fid.variables[name[fid]].missing_value = -99999999. 811 812 738 813 fid1.sync(); fid1.close() 814 fid2.sync(); fid2.close() 739 815 fid3.sync(); fid3.close() 740 741 fid1 = NetCDFFile('small_ha.nc','r') 742 fid2 = NetCDFFile('small_e.nc','r') 743 fid3 = NetCDFFile('small_va.nc','r') 816 fid4.sync(); fid4.close() 817 818 fid1 = NetCDFFile('test_ha.nc','r') 819 fid2 = NetCDFFile('test_e.nc','r') 820 fid3 = NetCDFFile('test_va.nc','r') 821 744 822 745 823 first_amp = fid1.variables['HA'][:][0,0,0] 746 fourth_amp = fid1.variables['HA'][:][0,0,3]824 third_amp = fid1.variables['HA'][:][0,0,2] 747 825 first_elevation = fid2.variables['ELEVATION'][0,0] 748 fourth_elevation= fid2.variables['ELEVATION'][:][0,3] 749 first_speed = fid3.variables['VA'][0,0] 750 fourth_speed = fid3.variables['VA'][:][0,0,3] 751 #print 'fourth speed', fourth_speed 826 third_elevation= fid2.variables['ELEVATION'][:][0,2] 827 first_speed = fid3.variables['VA'][0,0,0] 828 third_speed = fid3.variables['VA'][:][0,0,2] 752 829 753 830 fid1.close() … … 756 833 757 834 #Call conversion (with zero origin) 758 ferret2sww(' small', verbose=False,835 ferret2sww('test', verbose=False, 759 836 origin = (56, 0, 0)) 760 837 761 838 762 #Read output file ' small.sww'763 fid = NetCDFFile(' small.sww')839 #Read output file 'test.sww' 840 fid = NetCDFFile('test.sww') 764 841 765 842 766 843 #Check first value 844 elevation = fid.variables['elevation'][:] 767 845 stage = fid.variables['stage'][:] 768 846 xmomentum = fid.variables['xmomentum'][:] … … 771 849 #print ymomentum 772 850 first_height = first_amp/100 - first_elevation 773 fourth_height = fourth_amp/100 - fourth_elevation 774 851 third_height = third_amp/100 - third_elevation 775 852 first_momentum=first_speed*first_height/100 776 fourth_momentum=fourth_speed*fourth_height/100853 third_momentum=third_speed*third_height/100 777 854 778 855 assert allclose(ymomentum[0][0],first_momentum) #Meters 779 780 #print 'YM1', ymomentum[0][1] 781 #print 'YM4', ymomentum[0][3] 782 #print '4M', fourth_momentum 783 assert allclose(ymomentum[0][1],fourth_momentum) #Meters 856 assert allclose(ymomentum[0][2],third_momentum) #Meters 784 857 785 858 fid.close() … … 787 860 #Cleanup 788 861 import os 789 os.remove('small.sww') 862 os.remove('test.sww') 863 os.remove('test_va.nc') 864 os.remove('test_ua.nc') 865 os.remove('test_ha.nc') 790 866 791 867
Note: See TracChangeset
for help on using the changeset viewer.