Changeset 1577 for inundation/ga/storm_surge/pyvolution/data_manager.py
- Timestamp:
- Jul 5, 2005, 12:16:43 PM (19 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
inundation/ga/storm_surge/pyvolution/data_manager.py
r1502 r1577 921 921 return cls(domain, mode) 922 922 923 def dem2pts(basename_in, basename_out=None, verbose=False): 923 def dem2pts(basename_in, basename_out=None, verbose=False, 924 easting_min=None, easting_max=None, 925 northing_min=None, northing_max=None): 924 926 """Read Digitial Elevation model from the following NetCDF format (.dem) 925 927 … … 983 985 outfile.description = 'NetCDF pts format for compact and portable storage ' +\ 984 986 'of spatial point data' 987 #assign default values 988 if easting_min is None: easting_min = xllcorner 989 if easting_max is None: easting_max = xllcorner + ncols*cellsize 990 if northing_min is None: northing_min = yllcorner 991 if northing_max is None: northing_max = yllcorner + nrows*cellsize 992 993 #compute offsets to update georeferencing 994 easting_offset = xllcorner - easting_min 995 northing_offset = yllcorner - northing_min 985 996 986 997 #Georeferencing 987 998 outfile.zone = zone 988 outfile.xllcorner = xllcorner#Easting of lower left corner989 outfile.yllcorner = yllcorner#Northing of lower left corner999 outfile.xllcorner = easting_min #Easting of lower left corner 1000 outfile.yllcorner = northing_min #Northing of lower left corner 990 1001 outfile.false_easting = false_easting 991 1002 outfile.false_northing = false_northing … … 1002 1013 1003 1014 # dimension definitions 1004 outfile.createDimension('number_of_points', nrows*ncols) 1015 nrows_in_bounding_box = int(round((easting_max-easting_min)/cellsize)) 1016 ncols_in_bounding_box = int(round((northing_max-northing_min)/cellsize)) 1017 outfile.createDimension('number_of_points', nrows_in_bounding_box*ncols_in_bounding_box) 1005 1018 outfile.createDimension('number_of_dimensions', 2) #This is 2d data 1006 1019 … … 1016 1029 #Store data 1017 1030 #FIXME: Could perhaps be faster using array operations 1031 index = 0 1018 1032 for i in range(nrows): 1019 1033 if verbose: print 'Processing row %d of %d' %(i, nrows) 1020 1034 1021 y = (nrows-i)*cellsize 1035 y = (nrows-i)*cellsize + yllcorner 1022 1036 for j in range(ncols): 1023 index = i*ncols + j 1024 1025 x = j*cellsize 1026 points[index, :] = [x,y] 1027 elevation[index] = dem_elevation[i, j] 1037 #index = i*ncols + j 1038 1039 x = j*cellsize + xllcorner 1040 if easting_min <= x <= easting_max and \ 1041 northing_min <= y <= northing_max: 1042 points[index, :] = [x-easting_min,y-northing_min] 1043 elevation[index] = dem_elevation[i, j] 1044 index += 1 1045 1046 #print easting_min, easting_max 1047 #print index, nrows_in_bounding_box*ncols_in_bounding_box 1048 #print nrows, ncols 1049 assert index == nrows_in_bounding_box*ncols_in_bounding_box, 'index not equal to number of points' 1028 1050 1029 1051 infile.close()
Note: See TracChangeset
for help on using the changeset viewer.