source: anuga_core/source/anuga/coordinate_transforms/test_redfearn.py @ 5421

Last change on this file since 5421 was 4202, checked in by duncan, 17 years ago

sigh. the 'bug' that I fixed in 4199 wasn't a bug. It was correct. Reverting by doing svn merge -r4199:4198 https://datamining.anu.edu.au/svn/ga/ in inundation dir

File size: 9.7 KB
Line 
1
2#Test of redfearns formula. Tests can be verified at
3#
4#http://www.cellspark.com/UTM.html
5#http://www.ga.gov.au/nmd/geodesy/datums/redfearn_geo_to_grid.jsp
6
7
8import unittest
9from Numeric import allclose
10
11from redfearn import *
12from anuga.utilities.anuga_exceptions import ANUGAError
13
14#-------------------------------------------------------------
15
16class TestCase(unittest.TestCase):
17
18    def test_decimal_degrees_conversion(Self):
19        lat = degminsec2decimal_degrees(-37,39,10.15610)
20        lon = degminsec2decimal_degrees(143,55,35.38390) 
21        assert allclose(lat, -37.65282114)
22        assert allclose(lon, 143.9264955)
23
24        dd,mm,ss = decimal_degrees2degminsec(-37.65282114)
25        assert dd==-37
26        assert mm==39
27        assert allclose(ss, 10.15610)
28
29        dd,mm,ss = decimal_degrees2degminsec(143.9264955)
30        assert dd==143
31        assert mm==55
32        assert allclose(ss, 35.38390) 
33
34
35    def test_UTM_1(self):
36        #latitude:  -37 39' 10.15610"
37        #Longitude: 143 55' 35.38390"
38        #Site Name:    GDA-MGA: (UTM with GRS80 ellipsoid)
39        #Zone:   54   
40        #Easting:  758173.797  Northing: 5828674.340
41        #Latitude:   -37  39 ' 10.15610 ''  Longitude: 143  55 ' 35.38390 ''
42        #Grid Convergence:  1  47 ' 19.36 ''  Point Scale: 1.00042107
43
44        lat = degminsec2decimal_degrees(-37,39,10.15610)
45        lon = degminsec2decimal_degrees(143,55,35.38390) 
46        assert allclose(lat, -37.65282114)
47        assert allclose(lon, 143.9264955)
48
49
50        zone, easting, northing = redfearn(lat,lon)
51
52        assert zone == 54
53        assert allclose(easting, 758173.797)
54        assert allclose(northing, 5828674.340)
55
56
57    def test_UTM_2(self):
58        #TEST 2
59
60        #Latitude:  -37 57 03.7203
61        #Longitude: 144 25 29.5244
62        #Zone:   55   
63        #Easting:  273741.297  Northing: 5796489.777
64        #Latitude:   -37  57 ' 3.72030 ''  Longitude: 144  25 ' 29.52440 ''
65        #Grid Convergence:  -1  35 ' 3.65 ''  Point Scale: 1.00023056
66
67        lat = degminsec2decimal_degrees(-37,57,03.7203)
68        lon = degminsec2decimal_degrees(144,25,29.5244) 
69        #print lat, lon
70
71        zone, easting, northing = redfearn(lat,lon)
72
73        assert zone == 55
74        assert allclose(easting, 273741.297)
75        assert allclose(northing, 5796489.777)
76
77       
78    def test_UTM_3(self):
79        #Test 3
80        lat = degminsec2decimal_degrees(-60,0,0)
81        lon = degminsec2decimal_degrees(130,0,0) 
82
83        zone, easting, northing = redfearn(lat,lon)
84        #print zone, easting, northing
85
86        assert zone == 52
87        assert allclose(easting, 555776.267)
88        assert allclose(northing, 3348167.264)
89
90
91    def test_UTM_4(self):
92        #Test 4 (Kobenhavn, Northern hemisphere)
93        lat = 55.70248
94        dd,mm,ss = decimal_degrees2degminsec(lat)
95
96        lon = 12.58364
97        dd,mm,ss = decimal_degrees2degminsec(lon)
98
99        zone, easting, northing = redfearn(lat,lon)
100
101
102        assert zone == 33
103        assert allclose(easting, 348157.631)
104        assert allclose(northing, 6175612.993) 
105
106
107    def test_UTM_5(self):
108        #Test 5 (Wollongong)
109
110        lat = degminsec2decimal_degrees(-34,30,0.)
111        lon = degminsec2decimal_degrees(150,55,0.) 
112       
113        zone, easting, northing = redfearn(lat,lon)
114
115        #print zone, easting, northing
116
117        assert zone == 56
118        assert allclose(easting, 308728.009)
119        assert allclose(northing, 6180432.601)
120
121
122    #def test_UTM_6(self):
123    #    """Test 6 (Don's Wollongong file's ref point)
124    #    """
125    #
126    #    lat = -34.490286785873
127    #    lon = 150.79712139578
128    #
129    #    dd,mm,ss = decimal_degrees2degminsec(lat)
130    #    print dd,mm,ss
131    #    dd,mm,ss = decimal_degrees2degminsec(lon)       
132    #    print dd,mm,ss
133    #     
134    #    zone, easting, northing = redfearn(lat,lon)
135    #
136    #    print zone, easting, northing
137    #
138    #    assert zone == 56
139    #    #assert allclose(easting, 297717.36468927) #out by 10m
140    #    #assert allclose(northing, 6181725.1724276)
141
142    def test_convert_lats_longs(self):
143
144        #Site Name:    GDA-MGA: (UTM with GRS80 ellipsoid)
145        #Zone:   56   
146        #Easting:  222908.705  Northing: 6233785.284
147        #Latitude:   -34  0 ' 0.00000 ''  Longitude: 150  0 ' 0.00000 ''
148        #Grid Convergence:  -1  40 ' 43.13 ''  Point Scale: 1.00054660
149
150        lat_gong = degminsec2decimal_degrees(-34,30,0.)
151        lon_gong = degminsec2decimal_degrees(150,55,0.)
152       
153        lat_2 = degminsec2decimal_degrees(-34,00,0.)
154        lon_2 = degminsec2decimal_degrees(150,00,0.)
155       
156        lats = [lat_gong, lat_2]
157        longs = [lon_gong, lon_2]
158        points, zone = convert_from_latlon_to_utm(latitudes=lats, longitudes=longs)
159
160        assert allclose(points[0][0], 308728.009)
161        assert allclose(points[0][1], 6180432.601)
162        assert allclose(points[1][0],  222908.705)
163        assert allclose(points[1][1], 6233785.284)
164        self.failUnless(zone == 56,
165                        'Bad zone error!')
166       
167    def test_convert_lats_longs2(self):
168
169        #Site Name:    GDA-MGA: (UTM with GRS80 ellipsoid)
170        #Zone:   56   
171        #Easting:  222908.705  Northing: 6233785.284
172        #Latitude:   -34  0 ' 0.00000 ''  Longitude: 150  0 ' 0.00000 ''
173        #Grid Convergence:  -1  40 ' 43.13 ''  Point Scale: 1.00054660
174
175        lat_gong = degminsec2decimal_degrees(-34,30,0.)
176        lon_gong = degminsec2decimal_degrees(150,55,0.)
177       
178        lat_2 = degminsec2decimal_degrees(34,00,0.)
179        lon_2 = degminsec2decimal_degrees(100,00,0.)
180       
181        lats = [lat_gong, lat_2]
182        longs = [lon_gong, lon_2]
183       
184        try:
185            points, zone = convert_from_latlon_to_utm(latitudes=lats, longitudes=longs)
186        except ANUGAError:
187            pass
188        else:
189            self.failUnless(False,
190                            'Error not thrown error!')
191           
192    def test_convert_lats_longs3(self):
193
194        #Site Name:    GDA-MGA: (UTM with GRS80 ellipsoid)
195        #Zone:   56   
196        #Easting:  222908.705  Northing: 6233785.284
197        #Latitude:   -34  0 ' 0.00000 ''  Longitude: 150  0 ' 0.00000 ''
198        #Grid Convergence:  -1  40 ' 43.13 ''  Point Scale: 1.00054660
199
200        lat_gong = "-34.5"
201        lon_gong = "150.916666667"
202        lat_2 = degminsec2decimal_degrees(34,00,0.)
203        lon_2 = degminsec2decimal_degrees(100,00,0.)
204       
205        lats = [lat_gong, lat_2]
206        longs = [lon_gong, lon_2]
207        try:
208            points, zone  = convert_from_latlon_to_utm(latitudes=lats, longitudes=longs)
209        except ANUGAError:
210            pass
211        else:
212            self.failUnless(False,
213                            'Error not thrown error!')
214
215    def test_convert_latlon_to_UTM1(self):
216
217        #Site Name:    GDA-MGA: (UTM with GRS80 ellipsoid)
218        #Zone:   56   
219        #Easting:  222908.705  Northing: 6233785.284
220        #Latitude:   -34  0 ' 0.00000 ''  Longitude: 150  0 ' 0.00000 ''
221        #Grid Convergence:  -1  40 ' 43.13 ''  Point Scale: 1.00054660
222
223        lat_gong = degminsec2decimal_degrees(-34,30,0.)
224        lon_gong = degminsec2decimal_degrees(150,55,0.)
225       
226        lat_2 = degminsec2decimal_degrees(-34,00,0.)
227        lon_2 = degminsec2decimal_degrees(150,00,0.)
228       
229        points = [[lat_gong, lon_gong], [lat_2, lon_2]]
230        points, zone = convert_from_latlon_to_utm(points=points)
231        #print "points",points
232        assert allclose(points[0][0], 308728.009)
233        assert allclose(points[0][1], 6180432.601)
234        assert allclose(points[1][0],  222908.705)
235        assert allclose(points[1][1], 6233785.284)
236        self.failUnless(zone == 56,
237                        'Bad zone error!')
238
239    def test_convert_latlon_to_UTM2(self):       
240
241        #Site Name:    GDA-MGA: (UTM with GRS80 ellipsoid)
242        #Zone:   56   
243        #Easting:  222908.705  Northing: 6233785.284
244        #Latitude:   -34  0 ' 0.00000 ''  Longitude: 150  0 ' 0.00000 ''
245        #Grid Convergence:  -1  40 ' 43.13 ''  Point Scale: 1.00054660
246
247        lat_gong = degminsec2decimal_degrees(-34,30,0.)
248        lon_gong = degminsec2decimal_degrees(150,55,0.)
249       
250        lat_2 = degminsec2decimal_degrees(34,00,0.)
251        lon_2 = degminsec2decimal_degrees(100,00,0.)
252
253        points = [[lat_gong, lon_gong], [lat_2, lon_2]]
254
255        try:
256            points, zone = convert_from_latlon_to_utm(points=points)           
257        except ANUGAError:
258            pass
259        else:
260            self.fail('Error not thrown error!')
261
262    def test_convert_latlon_to_UTM3(self):           
263
264        #Site Name:    GDA-MGA: (UTM with GRS80 ellipsoid)
265        #Zone:   56   
266        #Easting:  222908.705  Northing: 6233785.284
267        #Latitude:   -34  0 ' 0.00000 ''  Longitude: 150  0 ' 0.00000 ''
268        #Grid Convergence:  -1  40 ' 43.13 ''  Point Scale: 1.00054660
269
270        lat_gong = "-34.5"
271        lon_gong = "150.916666667"
272        lat_2 = degminsec2decimal_degrees(34,00,0.)
273        lon_2 = degminsec2decimal_degrees(100,00,0.)
274
275        points = [[lat_gong, lon_gong], [lat_2, lon_2]]
276
277        try:
278            points, zone = convert_from_latlon_to_utm(points=points)           
279        except ANUGAError:
280            pass
281        else:
282            self.fail('Error not thrown error!')
283
284           
285#-------------------------------------------------------------
286if __name__ == "__main__":
287
288    #mysuite = unittest.makeSuite(TestCase,'test_convert_latlon_to_UTM1')
289    mysuite = unittest.makeSuite(TestCase,'test')
290    runner = unittest.TextTestRunner()
291    runner.run(mysuite)
Note: See TracBrowser for help on using the repository browser.