Changeset 2492
- Timestamp:
- Mar 8, 2006, 2:23:18 PM (19 years ago)
- Location:
- inundation/pyvolution
- Files:
-
- 1 deleted
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
inundation/pyvolution/test_data_manager.py
r2491 r2492 764 764 os.remove(root + '.prj') 765 765 766 def test_dem2pts_remove_Nullvalues(self): 767 """Test conversion from dem in ascii format to native NetCDF xya format 768 """ 769 770 import time, os 771 from Numeric import array, zeros, allclose, Float, concatenate 772 from Scientific.IO.NetCDF import NetCDFFile 773 774 #Write test asc file 775 root = 'demtest' 776 777 filename = root+'.asc' 778 fid = open(filename, 'w') 779 fid.write("""ncols 5 780 nrows 6 781 xllcorner 2000.5 782 yllcorner 3000.5 783 cellsize 25 784 NODATA_value -9999 785 """) 786 #Create linear function 787 # ref_ will write all the values 788 # new_ref_ will write the values except for NODATA_values 789 ref_points = [] 790 ref_elevation = [] 791 new_ref_pts = [] 792 new_ref_elev = [] 793 NODATA_value = -9999 794 for i in range(6): 795 y = (6-i)*25.0 796 for j in range(5): 797 x = j*25.0 798 z = x+2*y 799 #if j == 4: z = NODATA_value 800 if i == 1 and j == 2: z = NODATA_value 801 if i == 2 and j == 4: z = NODATA_value 802 if i == 3 and j == 3: z = NODATA_value 803 if i == 5 and j == 1: z = NODATA_value 804 805 if z <> NODATA_value: 806 new_ref_elev.append(z) 807 new_ref_pts.append( [x,y] ) 808 809 ref_points.append( [x,y] ) 810 ref_elevation.append(z) 811 812 fid.write('%f ' %z) 813 fid.write('\n') 814 815 fid.close() 816 817 nn = ref_elevation.count(NODATA_value) 818 819 #Write prj file with metadata 820 metafilename = root+'.prj' 821 fid = open(metafilename, 'w') 822 823 824 fid.write("""Projection UTM 825 Zone 56 826 Datum WGS84 827 Zunits NO 828 Units METERS 829 Spheroid WGS84 830 Xshift 0.0000000000 831 Yshift 10000000.0000000000 832 Parameters 833 """) 834 fid.close() 835 836 #Convert to NetCDF pts 837 convert_dem_from_ascii2netcdf(root) 838 dem2pts(root) 839 840 #Check contents 841 #Get NetCDF 842 fid = NetCDFFile(root+'.pts', 'r') 843 844 # Get the variables 845 #print fid.variables.keys() 846 points = fid.variables['points'] 847 elevation = fid.variables['elevation'] 848 849 #Check values 850 851 assert len(points) == len(new_ref_pts), 'length of returned points not correct' 852 assert allclose(points, new_ref_pts), 'points do not align' 853 854 assert len(elevation) == len(new_ref_elev), 'length of returned elevation not correct' 855 assert allclose(elevation, new_ref_elev), 'elevations do not align' 856 857 #Cleanup 858 fid.close() 859 860 861 os.remove(root + '.pts') 862 os.remove(root + '.dem') 863 os.remove(root + '.asc') 864 os.remove(root + '.prj') 865 866 867 766 868 767 869
Note: See TracChangeset
for help on using the changeset viewer.