Changeset 6304 for branches/numpy/anuga/coordinate_transforms
- Timestamp:
- Feb 10, 2009, 11:11:04 AM (16 years ago)
- Location:
- branches/numpy
- Files:
-
- 4 edited
- 1 copied
Legend:
- Unmodified
- Added
- Removed
-
branches/numpy/anuga/coordinate_transforms/geo_reference.py
r6149 r6304 11 11 from anuga.utilities.anuga_exceptions import ANUGAError, TitleError, ParsingError, \ 12 12 ShapeError 13 14 import Numeric as num 13 from anuga.config import netcdf_float, netcdf_int, netcdf_float32 14 15 import numpy as num 15 16 16 17 … … 64 65 self.xllcorner = xllcorner 65 66 self.yllcorner = yllcorner 67 #self.is_absolute = num.allclose([self.xllcorner, self.yllcorner], 0) 66 68 67 69 if NetCDFObject is not None: … … 99 101 100 102 # Fix some assertion failures 101 if type(self.zone) == num.ArrayTypeand self.zone.shape == ():103 if isinstance(self.zone, num.ndarray) and self.zone.shape == (): 102 104 self.zone = self.zone[0] 103 if type(self.xllcorner) == num.ArrayTypeand self.xllcorner.shape == ():105 if isinstance(self.xllcorner, num.ndarray) and self.xllcorner.shape == (): 104 106 self.xllcorner = self.xllcorner[0] 105 if type(self.yllcorner) == num.ArrayTypeand self.yllcorner.shape == ():107 if isinstance(self.yllcorner, num.ndarray) and self.yllcorner.shape == (): 106 108 self.yllcorner = self.yllcorner[0] 107 109 108 assert ( type(self.xllcorner) == types.FloatType or\109 type(self.xllcorner) == types.IntType)110 assert ( type(self.yllcorner) == types.FloatType or\111 type(self.yllcorner) == types.IntType)112 assert ( type(self.zone) == types.IntType)110 assert (self.xllcorner.dtype.kind in num.typecodes['Float'] or 111 self.xllcorner.dtype.kind in num.typecodes['Integer']) 112 assert (self.yllcorner.dtype.kind in num.typecodes['Float'] or 113 self.yllcorner.dtype.kind in num.typecodes['Integer']) 114 assert (self.zone.dtype.kind in num.typecodes['Integer']) 113 115 114 116 try: … … 173 175 174 176 # Fix some assertion failures 175 if (type(self.zone) == num.ArrayType and self.zone.shape == ()):177 if isinstance(self.zone, num.ndarray) and self.zone.shape == (): 176 178 self.zone = self.zone[0] 177 if type(self.xllcorner) == num.ArrayTypeand self.xllcorner.shape == ():179 if isinstance(self.xllcorner, num.ndarray) and self.xllcorner.shape == (): 178 180 self.xllcorner = self.xllcorner[0] 179 if type(self.yllcorner) == num.ArrayTypeand self.yllcorner.shape == ():181 if isinstance(self.yllcorner, num.ndarray) and self.yllcorner.shape == (): 180 182 self.yllcorner = self.yllcorner[0] 181 182 assert (type(self.xllcorner) == types.FloatType) 183 assert (type(self.yllcorner) == types.FloatType) 184 assert (type(self.zone) == types.IntType) 185 183 184 # useless asserts - see try/except code above 185 # assert (type(self.xllcorner) == types.FloatType) 186 # assert (type(self.yllcorner) == types.FloatType) 187 # assert (type(self.zone) == types.IntType) 188 186 189 187 190 def change_points_geo_ref(self, points, 188 191 points_geo_ref=None): 189 192 """ 190 Change the geo reference of a list or Numeric array of points to193 Change the geo reference of a list or numeric array of points to 191 194 be this reference.(The reference used for this object) 192 195 If the points do not have a geo ref, assume 'absolute' values … … 197 200 is_list = True 198 201 199 points = ensure_numeric(points, num. Float)202 points = ensure_numeric(points, num.float) 200 203 201 204 if len(points.shape) == 1: … … 243 246 244 247 245 248 ## 249 # @brief 250 # @param points 251 # @return 252 # @note 246 253 def get_absolute(self, points): 247 """ 248 Given a set of points geo referenced to this instance, 254 """Given a set of points geo referenced to this instance, 249 255 return the points as absolute values. 250 256 """ 251 257 252 #if self.is_absolute ():258 #if self.is_absolute: 253 259 # return points 260 254 261 is_list = False 255 262 if type(points) == types.ListType: 256 263 is_list = True 257 264 258 points = ensure_numeric(points, num. Float)265 points = ensure_numeric(points, num.float) 259 266 if len(points.shape) == 1: 260 267 #One point has been passed … … 264 271 #points = reshape(points, (1,2)) 265 272 266 267 273 msg = 'Input must be an N x 2 array or list of (x,y) values. ' 268 274 msg += 'I got an %d x %d array' %points.shape 269 275 if not points.shape[1] == 2: 270 276 raise ShapeError, msg 271 272 277 273 278 # Add geo ref to points 279 #if not self.is_absolute: 274 280 if not self.is_absolute(): 275 281 points[:,0] += self.xllcorner 276 282 points[:,1] += self.yllcorner 277 283 #self.is_absolute = True 278 284 279 285 if is_list: … … 296 302 is_list = True 297 303 298 points = ensure_numeric(points, num. Float)304 points = ensure_numeric(points, num.float) 299 305 if len(points.shape) == 1: 300 306 #One point has been passed -
branches/numpy/anuga/coordinate_transforms/test_geo_reference.py
r6149 r6304 9 9 from anuga.config import netcdf_mode_r, netcdf_mode_w, netcdf_mode_a 10 10 11 import Numericas num11 import numpy as num 12 12 13 13 … … 171 171 #print "4 new_lofl",new_lofl 172 172 173 self.failUnless( type(new_lofl) == num.ArrayType, ' failed')173 self.failUnless(isinstance(new_lofl, num.ndarray), ' failed') 174 174 self.failUnless(type(new_lofl) == type(lofl), ' failed') 175 175 lofl[:,0] -= x … … 189 189 #print "5 new_lofl",new_lofl 190 190 191 self.failUnless( type(new_lofl) == num.ArrayType, ' failed')191 self.failUnless(isinstance(new_lofl, num.ndarray), ' failed') 192 192 self.failUnless(type(new_lofl) == type(lofl), ' failed') 193 193 … … 206 206 #print "new_lofl",new_lofl 207 207 208 self.failUnless( type(new_lofl) == num.ArrayType, ' failed')208 self.failUnless(isinstance(new_lofl, num.ndarray), ' failed') 209 209 self.failUnless(type(new_lofl) == type(lofl), ' failed') 210 210 for point,new_point in map(None,[lofl],new_lofl): … … 229 229 self.failUnless(point[0]+point_x-x==new_point[0], ' failed') 230 230 self.failUnless(point[1]+point_y-y==new_point[1], ' failed') 231 232 233 def test_get_absolute(self):231 232 def test_get_absolute_list(self): 233 # test with supplied offsets 234 234 x = 7.0 235 235 y = 3.0 236 236 237 g = Geo_reference(56,x,y) 238 lofl = [[3.0,34.0], [64.0,6.0]] 239 new_lofl = g.get_absolute(lofl) 240 #print "lofl",lofl 241 #print "new_lofl",new_lofl 242 243 self.failUnless(type(new_lofl) == types.ListType, ' failed') 244 self.failUnless(type(new_lofl) == type(lofl), ' failed') 245 for point,new_point in map(None,lofl,new_lofl): 246 self.failUnless(point[0]+x==new_point[0], ' failed') 247 self.failUnless(point[1]+y==new_point[1], ' failed') 248 237 g = Geo_reference(56, x, y) 238 points = [[3.0,34.0], [64.0,6.0]] 239 new_points = g.get_absolute(points) 240 241 self.failUnless(type(new_points) == types.ListType, 'failed') 242 self.failUnless(type(new_points) == type(points), 'failed') 243 for point, new_point in map(None, points, new_points): 244 self.failUnless(point[0]+x == new_point[0], 'failed') 245 self.failUnless(point[1]+y == new_point[1], 'failed') 246 247 # test with no supplied offsets 248 g = Geo_reference() 249 points = [[3.0,34.0], [64.0,6.0]] 250 new_points = g.get_absolute(points) 251 252 self.failUnless(type(new_points) == types.ListType, 'failed') 253 self.failUnless(type(new_points) == type(points), 'failed') 254 for point, new_point in map(None, points, new_points): 255 self.failUnless(point[0] == new_point[0], 'failed') 256 self.failUnless(point[1] == new_point[1], 'failed') 249 257 258 # test that calling get_absolute twice does the right thing 259 # first call 260 dx = 10.0 261 dy = 10.0 262 g = Geo_reference(56, dx, dy) 263 points = [[3.0,34.0], [64.0,6.0]] 264 expected_new_points = [[3.0+dx,34.0+dy], [64.0+dx,6.0+dy]] 265 new_points = g.get_absolute(points) 266 267 self.failUnless(type(new_points) == types.ListType, 'failed') 268 self.failUnless(type(new_points) == type(points), 'failed') 269 for point, new_point in map(None, expected_new_points, new_points): 270 self.failUnless(point[0] == new_point[0], 'failed') 271 self.failUnless(point[1] == new_point[1], 'failed') 272 273 # and repeat from 'new_points = g.get_absolute(points)' above 274 # to see if second call with same input gives same results. 275 new_points = g.get_absolute(points) 276 277 self.failUnless(type(new_points) == types.ListType, 'failed') 278 self.failUnless(type(new_points) == type(points), 'failed') 279 for point, new_point in map(None, expected_new_points, new_points): 280 self.failUnless(point[0] == new_point[0], 'failed') 281 self.failUnless(point[1] == new_point[1], 'failed') 282 283 def test_get_absolute_array(self): 284 '''Same test as test_get_absolute_list(), but with numeric arrays.''' 285 286 # test with supplied offsets 287 x = 7.0 288 y = 3.0 289 290 g = Geo_reference(56, x, y) 291 points = num.array([[3.0,34.0], [64.0,6.0]]) 292 new_points = g.get_absolute(points) 293 294 self.failUnless(isinstance(new_points, num.ndarray), 'failed') 295 self.failUnless(type(new_points) == type(points), 'failed') 296 self.failUnless(num.alltrue(points == new_points), 'failed') 297 298 # test with no supplied offsets 250 299 g = Geo_reference() 251 lofl = [[3.0,34.0], [64.0,6.0]] 252 new_lofl = g.get_absolute(lofl) 253 #print "lofl",lofl 254 #print "new_lofl",new_lofl 255 256 self.failUnless(type(new_lofl) == types.ListType, ' failed') 257 self.failUnless(type(new_lofl) == type(lofl), ' failed') 258 for point,new_point in map(None,lofl,new_lofl): 259 self.failUnless(point[0]==new_point[0], ' failed') 260 self.failUnless(point[1]==new_point[1], ' failed') 261 300 points = num.array([[3.0,34.0], [64.0,6.0]]) 301 new_points = g.get_absolute(points) 302 303 self.failUnless(isinstance(new_points, num.ndarray), 'failed') 304 self.failUnless(type(new_points) == type(points), 'failed') 305 self.failUnless(num.alltrue(points == new_points), 'failed') 306 307 # test that calling get_absolute twice does the right thing 308 # first call 309 dx = 10.0 310 dy = 10.0 311 g = Geo_reference(56, dx, dy) 312 points = num.array([[3.0,34.0], [64.0,6.0]]) 313 expected_new_points = num.array([[3.0+dx,34.0+dy], [64.0+dx,6.0+dy]]) 314 new_points = g.get_absolute(points) 315 316 self.failUnless(isinstance(new_points, num.ndarray), 'failed') 317 self.failUnless(type(new_points) == type(points), 'failed') 318 msg = ('First call of .get_absolute() returned %s\nexpected %s' 319 % (str(new_points), str(expected_new_points))) 320 self.failUnless(num.alltrue(expected_new_points == new_points), msg) 321 322 # and repeat from 'new_points = g.get_absolute(points)' above 323 # to see if second call with same input gives same results. 324 new_points = g.get_absolute(points) 325 326 self.failUnless(isinstance(new_points, num.ndarray), 'failed') 327 self.failUnless(type(new_points) == type(points), 'failed') 328 msg = ('Second call of .get_absolute() returned %s\nexpected %s' 329 % (str(new_points), str(expected_new_points))) 330 self.failUnless(num.alltrue(expected_new_points == new_points), msg) 331 332 # and repeat again to see if *third* call with same input 333 # gives same results. 334 new_points = g.get_absolute(points) 335 336 self.failUnless(isinstance(new_points, num.ndarray), 'failed') 337 self.failUnless(type(new_points) == type(points), 'failed') 338 msg = ('Second call of .get_absolute() returned %s\nexpected %s' 339 % (str(new_points), str(expected_new_points))) 340 self.failUnless(num.alltrue(expected_new_points == new_points), msg) 341 262 342 def test_is_absolute(self): 263 343 … … 427 507 if __name__ == "__main__": 428 508 429 suite = unittest.makeSuite(geo_referenceTestCase,'test') 509 #suite = unittest.makeSuite(geo_referenceTestCase,'test') 510 suite = unittest.makeSuite(geo_referenceTestCase,'test_get_absolute') 430 511 runner = unittest.TextTestRunner() #verbosity=2) 431 512 runner.run(suite) -
branches/numpy/anuga/coordinate_transforms/test_lat_long_UTM_conversion.py
r6149 r6304 12 12 from anuga.utilities.anuga_exceptions import ANUGAError 13 13 14 import Numericas num14 import numpy as num 15 15 16 16 -
branches/numpy/anuga/coordinate_transforms/test_redfearn.py
r6149 r6304 11 11 from anuga.utilities.anuga_exceptions import ANUGAError 12 12 13 import Numericas num13 import numpy as num 14 14 15 15
Note: See TracChangeset
for help on using the changeset viewer.