Changeset 3134
- Timestamp:
- Jun 13, 2006, 10:10:40 AM (19 years ago)
- Location:
- inundation/coordinate_transforms
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
inundation/coordinate_transforms/geo_reference.py
r3129 r3134 9 9 from Numeric import array, Float, ArrayType, reshape, allclose 10 10 from utilities.numerical_tools import ensure_numeric 11 from utilities.anuga_exceptions import ANUGAError, TitleError, ParsingError 12 13 14 #import exceptions 15 #class TitleError(exceptions.IOError): pass 16 #class ParsingError(exceptions.IOError): pass 11 from utilities.anuga_exceptions import ANUGAError, TitleError, ParsingError, \ 12 ShapeError 13 17 14 18 15 DEFAULT_ZONE = -1 … … 195 192 """ 196 193 197 if self.is_absolute():198 return points194 #if self.is_absolute(): 195 # return points 199 196 200 197 … … 204 201 205 202 points = ensure_numeric(points, Float) 206 207 203 if len(points.shape) == 1: 208 204 #One point has been passed 209 205 msg = 'Single point must have two elements' 210 assert len(points) == 2, msg 211 points = reshape(points, (1,2)) 206 if not len(points) == 2: 207 raise ShapeError, msg 208 #points = reshape(points, (1,2)) 212 209 213 210 214 211 msg = 'Input must be an N x 2 array or list of (x,y) values. ' 215 212 msg += 'I got an %d x %d array' %points.shape 216 assert points.shape[1] == 2, msg 217 218 219 # Old code 220 #is_list = False 221 #if type(points) == types.ListType: 222 # is_list = True 223 # if len(points)>0 and type(points[0]) \ 224 # not in [types.ListType,types.TupleType]: 225 # #a single point is being passed. make it a list of lists 226 # points = [points] 227 #elif type(points) == ArrayType: 228 # if len(points.shape) == 1: 229 # points = [points] 230 231 ## convert into array 232 #points = array(points).astype(Float) 233 234 235 # Add primary geo ref from points 236 237 238 239 points[:,0] += self.xllcorner 240 points[:,1] += self.yllcorner 213 if not points.shape[1] == 2: 214 raise ShapeError, msg 215 216 217 # Add geo ref to points 218 if not self.is_absolute(): 219 points[:,0] += self.xllcorner 220 points[:,1] += self.yllcorner 241 221 242 222 -
inundation/coordinate_transforms/test_geo_reference.py
r3129 r3134 107 107 self.failUnless(point[0]-x==new_point[0], ' failed') 108 108 self.failUnless(point[1]-y==new_point[1], ' failed') 109 109 110 110 111 def test_change_points_geo_ref2(self): … … 207 208 self.failUnless(point[1]+point_y-y==new_point[1], ' failed') 208 209 210 209 211 def test_get_absolute(self): 210 212 x = 7.0 … … 222 224 self.failUnless(point[0]+x==new_point[0], ' failed') 223 225 self.failUnless(point[1]+y==new_point[1], ' failed') 224 226 227 228 g = Geo_reference() 229 lofl = [[3.0,34.0], [64.0,6.0]] 230 new_lofl = g.get_absolute(lofl) 231 #print "lofl",lofl 232 #print "new_lofl",new_lofl 233 234 self.failUnless(type(new_lofl) == types.ListType, ' failed') 235 self.failUnless(type(new_lofl) == type(lofl), ' failed') 236 for point,new_point in map(None,lofl,new_lofl): 237 self.failUnless(point[0]==new_point[0], ' failed') 238 self.failUnless(point[1]==new_point[1], ' failed') 239 225 240 def test_is_absolute(self): 226 241 … … 364 379 'bad text file did not raise error!') 365 380 os.remove(point_file) 366 381 382 def test_error_message_ShapeError(self): 383 384 new_g = Geo_reference() 385 try: 386 new_g.get_absolute((8.9, 7.8, 9.0)) 387 except ShapeError: 388 pass 389 else: 390 self.failUnless(0 ==1, 391 'bad shape did not raise error!') 392 os.remove(point_file) 393 394 new_g = Geo_reference() 395 try: 396 new_g.get_absolute(((8.9, 7.8, 9.0))) 397 except ShapeError: 398 pass 399 else: 400 self.failUnless(0 ==1, 401 'bad shape did not raise error!') 402 os.remove(point_file) 403 367 404 #------------------------------------------------------------- 368 405 if __name__ == "__main__":
Note: See TracChangeset
for help on using the changeset viewer.