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

Last change on this file since 3616 was 3616, checked in by ole, 18 years ago

Got Karratha running again.

File size: 9.6 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        zone, points = convert_lats_longs(lats, 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            zone, points = convert_lats_longs(lats, 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            zone, points = convert_lats_longs(lats, longs)
209        except ANUGAError:
210            pass
211        else:
212            self.failUnless(False,
213                            'Error not thrown error!')
214
215    # Similar test for alternative interface       
216    def test_convert_latlon_to_UTM1(self):
217
218        #Site Name:    GDA-MGA: (UTM with GRS80 ellipsoid)
219        #Zone:   56   
220        #Easting:  222908.705  Northing: 6233785.284
221        #Latitude:   -34  0 ' 0.00000 ''  Longitude: 150  0 ' 0.00000 ''
222        #Grid Convergence:  -1  40 ' 43.13 ''  Point Scale: 1.00054660
223
224        lat_gong = degminsec2decimal_degrees(-34,30,0.)
225        lon_gong = degminsec2decimal_degrees(150,55,0.)
226       
227        lat_2 = degminsec2decimal_degrees(-34,00,0.)
228        lon_2 = degminsec2decimal_degrees(150,00,0.)
229       
230        points = [[lat_gong, lon_gong], [lat_2, lon_2]]
231        points, zone = convert_points_from_latlon_to_utm(points)
232
233        assert allclose(points[0][0], 308728.009)
234        assert allclose(points[0][1], 6180432.601)
235        assert allclose(points[1][0],  222908.705)
236        assert allclose(points[1][1], 6233785.284)
237        self.failUnless(zone == 56,
238                        'Bad zone error!')
239
240    def test_convert_latlon_to_UTM2(self):       
241
242        #Site Name:    GDA-MGA: (UTM with GRS80 ellipsoid)
243        #Zone:   56   
244        #Easting:  222908.705  Northing: 6233785.284
245        #Latitude:   -34  0 ' 0.00000 ''  Longitude: 150  0 ' 0.00000 ''
246        #Grid Convergence:  -1  40 ' 43.13 ''  Point Scale: 1.00054660
247
248        lat_gong = degminsec2decimal_degrees(-34,30,0.)
249        lon_gong = degminsec2decimal_degrees(150,55,0.)
250       
251        lat_2 = degminsec2decimal_degrees(34,00,0.)
252        lon_2 = degminsec2decimal_degrees(100,00,0.)
253
254        points = [[lat_gong, lon_gong], [lat_2, lon_2]]
255
256        try:
257            points, zone = convert_points_from_latlon_to_utm(points)           
258        except ANUGAError:
259            pass
260        else:
261            self.fail('Error not thrown error!')
262
263    def test_convert_latlon_to_UTM3(self):           
264
265        #Site Name:    GDA-MGA: (UTM with GRS80 ellipsoid)
266        #Zone:   56   
267        #Easting:  222908.705  Northing: 6233785.284
268        #Latitude:   -34  0 ' 0.00000 ''  Longitude: 150  0 ' 0.00000 ''
269        #Grid Convergence:  -1  40 ' 43.13 ''  Point Scale: 1.00054660
270
271        lat_gong = "-34.5"
272        lon_gong = "150.916666667"
273        lat_2 = degminsec2decimal_degrees(34,00,0.)
274        lon_2 = degminsec2decimal_degrees(100,00,0.)
275
276        points = [[lat_gong, lon_gong], [lat_2, lon_2]]
277
278        try:
279            points, zone = convert_points_from_latlon_to_utm(points)           
280        except ANUGAError:
281            pass
282        else:
283            self.fail('Error not thrown error!')
284
285           
286#-------------------------------------------------------------
287if __name__ == "__main__":
288
289    mysuite = unittest.makeSuite(TestCase,'test')
290    runner = unittest.TextTestRunner()
291    runner.run(mysuite)
Note: See TracBrowser for help on using the repository browser.