Changeset 5916
- Timestamp:
- Nov 6, 2008, 5:12:39 PM (15 years ago)
- Location:
- anuga_core/source_numpy_conversion/anuga/coordinate_transforms
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
anuga_core/source_numpy_conversion/anuga/coordinate_transforms/geo_reference.py
r5736 r5916 8 8 9 9 import types, sys 10 from Numeric import array, Float, ArrayType, reshape, allclose 10 import numpy 11 11 from anuga.utilities.numerical_tools import ensure_numeric 12 12 from anuga.utilities.anuga_exceptions import ANUGAError, TitleError, ParsingError, \ … … 98 98 99 99 # Fix some assertion failures 100 if type(self.zone) == ArrayTypeand self.zone.shape == ():100 if isinstance(self.zone, numpy.ndarray) and self.zone.shape == (): 101 101 self.zone = self.zone[0] 102 if type(self.xllcorner) == ArrayTypeand self.xllcorner.shape == ():102 if isinstance(self.xllcorner, numpy.ndarray) and self.xllcorner.shape == (): 103 103 self.xllcorner = self.xllcorner[0] 104 if type(self.yllcorner) == ArrayTypeand self.yllcorner.shape == ():104 if isinstance(self.yllcorner, numpy.ndarray) and self.yllcorner.shape == (): 105 105 self.yllcorner = self.yllcorner[0] 106 106 107 assert ( type(self.xllcorner) == types.FloatTypeor\108 type(self.xllcorner) == types.IntType)109 assert ( type(self.yllcorner) == types.FloatTypeor\110 type(self.yllcorner) == types.IntType)111 assert ( type(self.zone) == types.IntType)107 assert (isinstance(self.xllcorner, types.FloatType) or\ 108 isinstance(self.xllcorner, types.IntType)) 109 assert (isinstance(self.yllcorner, types.FloatType) or\ 110 isinstance(self.yllcorner, types.IntType)) 111 assert (isinstance(self.zone, types.IntType)) 112 112 113 113 try: … … 172 172 173 173 # Fix some assertion failures 174 if( type(self.zone) == ArrayTypeand self.zone.shape == ()):174 if(isinstance(self.zone, numpy.ndarray) and self.zone.shape == ()): 175 175 self.zone = self.zone[0] 176 if type(self.xllcorner) == ArrayTypeand self.xllcorner.shape == ():176 if isinstance(self.xllcorner, numpy.ndarray) and self.xllcorner.shape == (): 177 177 self.xllcorner = self.xllcorner[0] 178 if type(self.yllcorner) == ArrayTypeand self.yllcorner.shape == ():178 if isinstance(self.yllcorner, numpy.ndarray) and self.yllcorner.shape == (): 179 179 self.yllcorner = self.yllcorner[0] 180 180 181 assert ( type(self.xllcorner) == types.FloatType)182 assert ( type(self.yllcorner) == types.FloatType)183 assert ( type(self.zone) == types.IntType)181 assert (isinstance(self.xllcorner, types.FloatType)) 182 assert (isinstance(self.yllcorner, types.FloatType)) 183 assert (isinstance(self.zone, types.IntType)) 184 184 185 185 … … 196 196 is_list = True 197 197 198 points = ensure_numeric(points, Float)198 points = ensure_numeric(points, numpy.float) 199 199 200 200 if len(points.shape) == 1: … … 202 202 msg = 'Single point must have two elements' 203 203 assert len(points) == 2, msg 204 points = reshape(points, (1,2))204 points = numpy.reshape(points, (1,2)) 205 205 206 206 msg = 'Points array must be two dimensional.\n' … … 239 239 """ 240 240 241 return allclose([self.xllcorner, self.yllcorner], 0)241 return numpy.allclose([self.xllcorner, self.yllcorner], 0) 242 242 243 243 … … 255 255 is_list = True 256 256 257 points = ensure_numeric(points, Float)257 points = ensure_numeric(points, numpy.float) 258 258 if len(points.shape) == 1: 259 259 #One point has been passed … … 295 295 is_list = True 296 296 297 points = ensure_numeric(points, Float)297 points = ensure_numeric(points, numpy.float) 298 298 if len(points.shape) == 1: 299 299 #One point has been passed -
anuga_core/source_numpy_conversion/anuga/coordinate_transforms/redfearn.py
r5662 r5916 8 8 """ 9 9 from anuga.coordinate_transforms.geo_reference import Geo_reference, DEFAULT_ZONE 10 from Numeric import array11 10 12 11 def degminsec2decimal_degrees(dd,mm,ss): -
anuga_core/source_numpy_conversion/anuga/coordinate_transforms/test_geo_reference.py
r4663 r5916 7 7 8 8 from geo_reference import * 9 from Numeric import allclose,array 10 9 import numpy 11 10 12 11 class geo_referenceTestCase(unittest.TestCase): … … 164 163 y = 443.0 165 164 g = Geo_reference(56,x,y) 166 lofl = array([[3.0,323.0], [6.0,645.0]])165 lofl = numpy.array([[3.0,323.0], [6.0,645.0]]) 167 166 new_lofl = g.change_points_geo_ref(lofl) 168 167 #print "4 lofl",lofl 169 168 #print "4 new_lofl",new_lofl 170 169 171 self.failUnless( type(new_lofl) == ArrayType, ' failed')170 self.failUnless(isinstance(new_lofl, numpy.ndarray), ' failed') 172 171 self.failUnless(type(new_lofl) == type(lofl), ' failed') 173 172 lofl[:,0] -= x 174 173 lofl[:,1] -= y 175 assert allclose(lofl,new_lofl)174 assert numpy.allclose(lofl,new_lofl) 176 175 177 176 def test_change_points_geo_ref5(self): … … 179 178 y = 3.0 180 179 g = Geo_reference(56,x,y) 181 lofl = array([[3.0,323.0]])180 lofl = numpy.array([[3.0,323.0]]) 182 181 183 182 … … 187 186 #print "5 new_lofl",new_lofl 188 187 189 self.failUnless( type(new_lofl) == ArrayType, ' failed')188 self.failUnless(isinstance(new_lofl, numpy.ndarray), ' failed') 190 189 self.failUnless(type(new_lofl) == type(lofl), ' failed') 191 190 … … 199 198 y = 3.0 200 199 g = Geo_reference(56,x,y) 201 lofl = array([355.0,3.0])200 lofl = numpy.array([355.0,3.0]) 202 201 new_lofl = g.change_points_geo_ref(lofl.copy()) 203 202 #print "lofl",lofl 204 203 #print "new_lofl",new_lofl 205 204 206 self.failUnless( type(new_lofl) == ArrayType, ' failed')205 self.failUnless(isinstance(new_lofl, numpy.ndarray), ' failed') 207 206 self.failUnless(type(new_lofl) == type(lofl), ' failed') 208 207 for point,new_point in map(None,[lofl],new_lofl): -
anuga_core/source_numpy_conversion/anuga/coordinate_transforms/test_lat_long_UTM_conversion.py
r4197 r5916 1 2 1 #Test of redfearns formula. Tests can be verified at 3 2 # … … 7 6 8 7 import unittest 9 from Numeric import allclose 8 import numpy 10 9 11 10 from lat_long_UTM_conversion import * … … 28 27 lat = degminsec2decimal_degrees(-37,39,10.15610) 29 28 lon = degminsec2decimal_degrees(143,55,35.38390) 30 assert allclose(lat, -37.65282114)31 assert allclose(lon, 143.9264955)29 assert numpy.allclose(lat, -37.65282114) 30 assert numpy.allclose(lon, 143.9264955) 32 31 33 32 … … 35 34 36 35 assert zone == 54 37 assert allclose(easting, 758173.797)38 assert allclose(northing, 5828674.340)36 assert numpy.allclose(easting, 758173.797) 37 assert numpy.allclose(northing, 5828674.340) 39 38 40 39 lat_calced, long_calced = UTMtoLL(northing, easting, zone) 41 assert allclose(lat, lat_calced)42 assert allclose(lon, long_calced)40 assert numpy.allclose(lat, lat_calced) 41 assert numpy.allclose(lon, long_calced) 43 42 44 43 … … 61 60 62 61 assert zone == 55 63 assert allclose(easting, 273741.297)64 assert allclose(northing, 5796489.777)62 assert numpy.allclose(easting, 273741.297) 63 assert numpy.allclose(northing, 5796489.777) 65 64 66 65 lat_calced, long_calced = UTMtoLL(northing, easting, zone) 67 assert allclose(lat, lat_calced)68 assert allclose(lon, long_calced)66 assert numpy.allclose(lat, lat_calced) 67 assert numpy.allclose(lon, long_calced) 69 68 70 69 … … 78 77 79 78 assert zone == 52 80 assert allclose(easting, 555776.267)81 assert allclose(northing, 3348167.264)79 assert numpy.allclose(easting, 555776.267) 80 assert numpy.allclose(northing, 3348167.264) 82 81 83 82 Lat, Long = UTMtoLL(northing, easting, zone) … … 94 93 95 94 assert zone == 33 96 assert allclose(easting, 348157.631)97 assert allclose(northing, 6175612.993)95 assert numpy.allclose(easting, 348157.631) 96 assert numpy.allclose(northing, 6175612.993) 98 97 99 98 lat_calced, long_calced = UTMtoLL(northing, easting, zone, 100 99 isSouthernHemisphere=False) 101 assert allclose(lat, lat_calced)102 assert allclose(lon, long_calced)100 assert numpy.allclose(lat, lat_calced) 101 assert numpy.allclose(lon, long_calced) 103 102 104 103 def test_UTM_5(self): … … 113 112 114 113 assert zone == 56 115 assert allclose(easting, 308728.009)116 assert allclose(northing, 6180432.601)114 assert numpy.allclose(easting, 308728.009) 115 assert numpy.allclose(northing, 6180432.601) 117 116 118 117 lat_calced, long_calced = UTMtoLL(northing, easting, zone) 119 assert allclose(lat, lat_calced)120 assert allclose(lon, long_calced)118 assert numpy.allclose(lat, lat_calced) 119 assert numpy.allclose(lon, long_calced) 121 120 #------------------------------------------------------------- 122 121 if __name__ == "__main__": -
anuga_core/source_numpy_conversion/anuga/coordinate_transforms/test_redfearn.py
r5663 r5916 1 2 1 #Test of redfearns formula. Tests can be verified at 3 2 # … … 7 6 8 7 import unittest 9 from Numeric import allclose 8 import numpy 10 9 11 10 from redfearn import * … … 19 18 lat = degminsec2decimal_degrees(-37,39,10.15610) 20 19 lon = degminsec2decimal_degrees(143,55,35.38390) 21 assert allclose(lat, -37.65282114)22 assert allclose(lon, 143.9264955)20 assert numpy.allclose(lat, -37.65282114) 21 assert numpy.allclose(lon, 143.9264955) 23 22 24 23 dd,mm,ss = decimal_degrees2degminsec(-37.65282114) 25 24 assert dd==-37 26 25 assert mm==39 27 assert allclose(ss, 10.15610)26 assert numpy.allclose(ss, 10.15610) 28 27 29 28 dd,mm,ss = decimal_degrees2degminsec(143.9264955) 30 29 assert dd==143 31 30 assert mm==55 32 assert allclose(ss, 35.38390)31 assert numpy.allclose(ss, 35.38390) 33 32 34 33 … … 44 43 lat = degminsec2decimal_degrees(-37,39,10.15610) 45 44 lon = degminsec2decimal_degrees(143,55,35.38390) 46 assert allclose(lat, -37.65282114)47 assert allclose(lon, 143.9264955)45 assert numpy.allclose(lat, -37.65282114) 46 assert numpy.allclose(lon, 143.9264955) 48 47 49 48 … … 51 50 52 51 assert zone == 54 53 assert allclose(easting, 758173.797)54 assert allclose(northing, 5828674.340)52 assert numpy.allclose(easting, 758173.797) 53 assert numpy.allclose(northing, 5828674.340) 55 54 56 55 … … 72 71 73 72 assert zone == 55 74 assert allclose(easting, 273741.297)75 assert allclose(northing, 5796489.777)73 assert numpy.allclose(easting, 273741.297) 74 assert numpy.allclose(northing, 5796489.777) 76 75 77 76 … … 85 84 86 85 assert zone == 52 87 assert allclose(easting, 555776.267)88 assert allclose(northing, 3348167.264)86 assert numpy.allclose(easting, 555776.267) 87 assert numpy.allclose(northing, 3348167.264) 89 88 90 89 … … 101 100 102 101 assert zone == 33 103 assert allclose(easting, 348157.631)104 assert allclose(northing, 6175612.993)102 assert numpy.allclose(easting, 348157.631) 103 assert numpy.allclose(northing, 6175612.993) 105 104 106 105 … … 116 115 117 116 assert zone == 56 118 assert allclose(easting, 308728.009)119 assert allclose(northing, 6180432.601)117 assert numpy.allclose(easting, 308728.009) 118 assert numpy.allclose(northing, 6180432.601) 120 119 121 120 def test_UTM_6_nonstandard_projection(self): … … 126 125 127 126 assert zone == 50 128 assert allclose(easting, 213251.040253)129 assert allclose(northing, 6762559.15978)127 assert numpy.allclose(easting, 213251.040253) 128 assert numpy.allclose(northing, 6762559.15978) 130 129 131 130 #Testing using the native zone … … 133 132 134 133 assert zone == 50 135 assert allclose(easting, 213251.040253)136 assert allclose(northing, 6762559.15978)134 assert numpy.allclose(easting, 213251.040253) 135 assert numpy.allclose(northing, 6762559.15978) 137 136 138 137 #Then project to zone 49 … … 140 139 141 140 assert zone == 49 142 assert allclose(easting, 796474.020057)143 assert allclose(northing, 6762310.25162)141 assert numpy.allclose(easting, 796474.020057) 142 assert numpy.allclose(northing, 6762310.25162) 144 143 145 144 … … 151 150 152 151 assert zone == 49 153 assert allclose(easting, 788653.192779)154 assert allclose(northing, 6773605.46384)152 assert numpy.allclose(easting, 788653.192779) 153 assert numpy.allclose(northing, 6773605.46384) 155 154 156 155 #Then project to zone 50 … … 158 157 159 158 assert zone == 50 160 assert allclose(easting, 204863.606467)161 assert allclose(northing, 6773440.04726)159 assert numpy.allclose(easting, 204863.606467) 160 assert numpy.allclose(northing, 6773440.04726) 162 161 163 162 #Testing point on zone boundary … … 166 165 167 166 assert zone == 50 168 assert allclose(easting, 208199.768268)169 assert allclose(northing, 6769820.01453)167 assert numpy.allclose(easting, 208199.768268) 168 assert numpy.allclose(northing, 6769820.01453) 170 169 171 170 #Then project to zone 49 … … 173 172 174 173 assert zone == 49 175 assert allclose(easting, 791800.231817)176 assert allclose(northing, 6769820.01453)174 assert numpy.allclose(easting, 791800.231817) 175 assert numpy.allclose(northing, 6769820.01453) 177 176 178 177 #Testing furthest point in Geraldton scenario) … … 181 180 182 181 assert zone == 49 183 assert allclose(easting, 737178.16131)184 assert allclose(northing, 6876426.38578)182 assert numpy.allclose(easting, 737178.16131) 183 assert numpy.allclose(northing, 6876426.38578) 185 184 186 185 #Then project to zone 50 … … 188 187 189 188 assert zone == 50 190 assert allclose(easting, 148260.567427)191 assert allclose(northing, 6873587.50926)189 assert numpy.allclose(easting, 148260.567427) 190 assert numpy.allclose(northing, 6873587.50926) 192 191 193 192 #Testing outside GDA zone (New Zeland) … … 196 195 197 196 assert zone == 60 198 assert allclose(easting, 580174.259843)199 assert allclose(northing, 5127641.114461)197 assert numpy.allclose(easting, 580174.259843) 198 assert numpy.allclose(northing, 5127641.114461) 200 199 201 200 #Then project to zone 59 … … 203 202 204 203 assert zone == 59 205 assert allclose(easting, 1061266.922118)206 assert allclose(northing, 5104249.395469)204 assert numpy.allclose(easting, 1061266.922118) 205 assert numpy.allclose(northing, 5104249.395469) 207 206 208 207 #Then skip three zones 57 (native 60) … … 210 209 211 210 assert zone == 57 212 assert allclose(easting, 2023865.527497)213 assert allclose(northing, 4949253.934967)211 assert numpy.allclose(easting, 2023865.527497) 212 assert numpy.allclose(northing, 4949253.934967) 214 213 215 214 # Note Projecting into the Northern Hemisphere Does not coincide … … 227 226 # Google Earth interpretation 228 227 assert zone == 57 229 assert allclose(easting, 259473.69)230 assert allclose(northing, 4876249.13)228 assert numpy.allclose(easting, 259473.69) 229 assert numpy.allclose(northing, 4876249.13) 231 230 232 231 # ArcMap's interpretation … … 239 238 240 239 assert zone == 56 241 assert allclose(easting, 740526.321055)242 assert allclose(northing, 4876249.13)240 assert numpy.allclose(easting, 740526.321055) 241 assert numpy.allclose(northing, 4876249.13) 243 242 244 243 … … 283 282 points, zone = convert_from_latlon_to_utm(latitudes=lats, longitudes=longs) 284 283 285 assert allclose(points[0][0], 308728.009)286 assert allclose(points[0][1], 6180432.601)287 assert allclose(points[1][0], 222908.705)288 assert allclose(points[1][1], 6233785.284)284 assert numpy.allclose(points[0][0], 308728.009) 285 assert numpy.allclose(points[0][1], 6180432.601) 286 assert numpy.allclose(points[1][0], 222908.705) 287 assert numpy.allclose(points[1][1], 6233785.284) 289 288 self.failUnless(zone == 56, 290 289 'Bad zone error!') … … 355 354 points, zone = convert_from_latlon_to_utm(points=points) 356 355 #print "points",points 357 assert allclose(points[0][0], 308728.009)358 assert allclose(points[0][1], 6180432.601)359 assert allclose(points[1][0], 222908.705)360 assert allclose(points[1][1], 6233785.284)356 assert numpy.allclose(points[0][0], 308728.009) 357 assert numpy.allclose(points[0][1], 6180432.601) 358 assert numpy.allclose(points[1][0], 222908.705) 359 assert numpy.allclose(points[1][1], 6233785.284) 361 360 self.failUnless(zone == 56, 362 361 'Bad zone error!')
Note: See TracChangeset
for help on using the changeset viewer.