Changeset 8989
- Timestamp:
- Sep 24, 2013, 11:20:02 AM (12 years ago)
- Location:
- trunk/anuga_core/source/anuga
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/anuga_core/source/anuga/abstract_2d_finite_volumes/quantity.py
r8978 r8989 1130 1130 1131 1131 1132 msg = 'Filename must be a text string' 1133 assert isinstance(filename, basestring), msg 1134 1135 msg = 'Extension should be .grd or asc' 1136 assert os.path.splitext(filename)[1] in ['.grd', '.asc'], msg 1137 1138 1139 msg = "set_values_from_grd_file is only defined for location='vertices' or 'centroids'" 1140 assert location in ['vertices', 'centroids'], msg 1141 1142 1143 1144 1145 1146 root = filename[:-4] 1147 1148 1149 #Read DEM data 1150 datafile = open(filename) 1151 1152 if verbose: log.critical('Reading data from %s' % (filename)) 1153 1154 lines = datafile.readlines() 1155 datafile.close() 1156 1157 if verbose: log.critical('Got %d lines' % len(lines)) 1158 1159 1160 ncols = int(lines[0].split()[1].strip()) 1161 nrows = int(lines[1].split()[1].strip()) 1162 1163 1164 # Do cellsize (line 4) before line 2 and 3 1165 cellsize = float(lines[4].split()[1].strip()) 1166 1167 # Checks suggested by Joaquim Luis 1168 # Our internal representation of xllcorner 1169 # and yllcorner is non-standard. 1170 xref = lines[2].split() 1171 if xref[0].strip() == 'xllcorner': 1172 xllcorner = float(xref[1].strip()) # + 0.5*cellsize # Correct offset 1173 elif xref[0].strip() == 'xllcenter': 1174 xllcorner = float(xref[1].strip()) 1175 else: 1176 msg = 'Unknown keyword: %s' % xref[0].strip() 1177 raise Exception, msg 1178 1179 yref = lines[3].split() 1180 if yref[0].strip() == 'yllcorner': 1181 yllcorner = float(yref[1].strip()) # + 0.5*cellsize # Correct offset 1182 elif yref[0].strip() == 'yllcenter': 1183 yllcorner = float(yref[1].strip()) 1184 else: 1185 msg = 'Unknown keyword: %s' % yref[0].strip() 1186 raise Exception, msg 1187 1188 NODATA_value = int(float(lines[5].split()[1].strip())) 1189 1190 assert len(lines) == nrows + 6 1191 1192 1193 #Store data 1194 import numpy 1195 1196 datafile = open(filename) 1197 Z = numpy.loadtxt(datafile, skiprows=6) 1198 datafile.close() 1199 1200 #print Z.shape 1201 #print Z 1202 1203 # For raster data we need to a flip and transpose 1204 Z = numpy.flipud(Z) 1205 1206 # Transpose z to have y coordinates along the first axis and x coordinates 1207 # along the second axis 1208 Z = Z.transpose() 1209 1210 x = num.linspace(xllcorner, xllcorner+cellsize*(ncols-1), ncols) 1211 y = num.linspace(yllcorner, yllcorner+cellsize*(nrows-1), nrows) 1212 1132 # msg = 'Filename must be a text string' 1133 # assert isinstance(filename, basestring), msg 1134 # 1135 # msg = 'Extension should be .grd or asc' 1136 # assert os.path.splitext(filename)[1] in ['.grd', '.asc'], msg 1137 # 1138 # 1139 # msg = "set_values_from_grd_file is only defined for location='vertices' or 'centroids'" 1140 # assert location in ['vertices', 'centroids'], msg 1141 # 1142 # 1143 # 1144 # 1145 # 1146 # root = filename[:-4] 1147 # 1148 # 1149 # #Read DEM data 1150 # datafile = open(filename) 1151 # 1152 # if verbose: log.critical('Reading data from %s' % (filename)) 1153 # 1154 # lines = datafile.readlines() 1155 # datafile.close() 1156 # 1157 # if verbose: log.critical('Got %d lines' % len(lines)) 1158 # 1159 # 1160 # ncols = int(lines[0].split()[1].strip()) 1161 # nrows = int(lines[1].split()[1].strip()) 1162 # 1163 # 1164 # # Do cellsize (line 4) before line 2 and 3 1165 # cellsize = float(lines[4].split()[1].strip()) 1166 # 1167 # # Checks suggested by Joaquim Luis 1168 # # Our internal representation of xllcorner 1169 # # and yllcorner is non-standard. 1170 # xref = lines[2].split() 1171 # if xref[0].strip() == 'xllcorner': 1172 # xllcorner = float(xref[1].strip()) # + 0.5*cellsize # Correct offset 1173 # elif xref[0].strip() == 'xllcenter': 1174 # xllcorner = float(xref[1].strip()) 1175 # else: 1176 # msg = 'Unknown keyword: %s' % xref[0].strip() 1177 # raise Exception, msg 1178 # 1179 # yref = lines[3].split() 1180 # if yref[0].strip() == 'yllcorner': 1181 # yllcorner = float(yref[1].strip()) # + 0.5*cellsize # Correct offset 1182 # elif yref[0].strip() == 'yllcenter': 1183 # yllcorner = float(yref[1].strip()) 1184 # else: 1185 # msg = 'Unknown keyword: %s' % yref[0].strip() 1186 # raise Exception, msg 1187 # 1188 # NODATA_value = int(float(lines[5].split()[1].strip())) 1189 # 1190 # assert len(lines) == nrows + 6 1191 # 1192 # 1193 # #Store data 1194 # import numpy 1195 # 1196 # datafile = open(filename) 1197 # Z = numpy.loadtxt(datafile, skiprows=6) 1198 # datafile.close() 1199 # 1200 # #print Z.shape 1201 # #print Z 1202 # 1203 # # For raster data we need to a flip and transpose 1204 # Z = numpy.flipud(Z) 1205 # 1206 # # Transpose z to have y coordinates along the first axis and x coordinates 1207 # # along the second axis 1208 # Z = Z.transpose() 1209 # 1210 # x = num.linspace(xllcorner, xllcorner+cellsize*(ncols-1), ncols) 1211 # y = num.linspace(yllcorner, yllcorner+cellsize*(nrows-1), nrows) 1212 1213 1214 1215 from anuga.file_conversion.grd2array import grd2array 1216 1217 x,y,Z = grd2array(filename) 1218 1213 1219 1214 1220 if location == 'centroids': … … 1220 1226 points = ensure_absolute(points, geo_reference=self.domain.geo_reference) 1221 1227 1222 # print numpy.max(points[:,0]) 1223 # print numpy.min(points[:,0]) 1224 # print numpy.max(points[:,1]) 1225 # print numpy.min(points[:,1]) 1226 # 1227 # print numpy.max(x) 1228 # print numpy.min(x) 1229 # print numpy.max(y) 1230 # print numpy.min(y) 1231 1232 1233 #print x.shape, x 1234 #print y.shape, y 1228 1235 1229 1236 1230 from anuga.fit_interpolate.interpolate2d import interpolate2d … … 1274 1268 # Cleanup centroid values 1275 1269 self.interpolate() 1270 1271 1272 1276 1273 1277 1274 def set_values_from_lat_long_grid_file(self, -
trunk/anuga_core/source/anuga/utilities/model_tools.py
r8983 r8989 102 102 Rfile = dir +'/'+filename 103 103 print Rfile 104 105 if Rfile[-4:] == '.svn': 106 continue 107 104 108 #print filename 105 109
Note: See TracChangeset
for help on using the changeset viewer.