source: issm/trunk/src/py3/coordsystems/xy2ll.py@ 20500

Last change on this file since 20500 was 20500, checked in by Mathieu Morlighem, 9 years ago

merged trunk-jpl and trunk for revision 20497

File size: 2.4 KB
Line 
1import numpy as npy
2from math import pi
3
4def xy2ll(x, y, sgn, *args):
5 '''
6 XY2LL - converts xy to lat long
7
8 Converts Polar Stereographic (X, Y) coordinates for the polar regions to
9 latitude and longitude Stereographic (X, Y) coordinates for the polar
10 regions.
11 Author: Michael P. Schodlok, December 2003 (map2xy.m)
12
13 Usage:
14 [lat, lon] = xy2ll(x, y, sgn);
15 [lat, lon] = xy2ll(x, y, sgn, central_meridian, standard_parallel);
16
17 - sgn = Sign of latitude +1 : north latitude (default is mer=45 lat=70)
18 -1 : south latitude (default is mer=0 lat=71)
19 '''
20
21 #Get central_meridian and standard_parallel depending on hemisphere
22 if len(args) == 2:
23 delta = args[0]
24 slat = args[1]
25 elif len(args) == 0:
26 if sgn == 1:
27 delta = 45.
28 slat = 70.
29 print(' xy2ll: creating coordinates in north polar stereographic (Std Latitude: 70degN Meridian: 45deg)')
30 elif sgn == -1:
31 delta = 0.
32 slat = 71.
33 print(' xy2ll: creating coordinates in south polar stereographic (Std Latitude: 71degS Meridian: 0deg)')
34 else:
35 raise ValueError('sgn should be either +1 or -1')
36 else:
37 raise Exception('bad usage: type "help(xy2ll)" for details')
38
39 # if x,y passed as lists, convert to numpy arrays
40 if type(x) != "numpy.ndarray":
41 x=npy.array(x)
42 if type(y) != "numpy.ndarray":
43 y=npy.array(y)
44
45 ## Conversion constant from degrees to radians
46 cde = 57.29577951
47 ## Radius of the earth in meters
48 re = 6378.273*10**3
49 ## Eccentricity of the Hughes ellipsoid squared
50 ex2 = .006693883
51 ## Eccentricity of the Hughes ellipsoid
52 ex = npy.sqrt(ex2)
53
54 sl = slat*pi/180.
55 rho = npy.sqrt(x**2 + y**2)
56 cm = npy.cos(sl) / npy.sqrt(1.0 - ex2 * (npy.sin(sl)**2))
57 T = npy.tan((pi/4.0) - (sl/2.0)) / ((1.0 - ex*npy.sin(sl)) / (1.0 + ex*npy.sin(sl)))**(ex / 2.0)
58
59 if abs(slat-90.) < 1.e-5:
60 T = rho*npy.sqrt((1. + ex)**(1. + ex) * (1. - ex)**(1. - ex)) / 2. / re
61 else:
62 T = rho * T / (re * cm)
63
64 chi = (pi / 2.0) - 2.0 * npy.arctan(T)
65 lat = chi + ((ex2 / 2.0) + (5.0 * ex2**2.0 / 24.0) + (ex2**3.0 / 12.0)) * \
66 npy.sin(2 * chi) + ((7.0 * ex2**2.0 / 48.0) + (29.0 * ex2**3 / 240.0)) * \
67 npy.sin(4.0 * chi) + (7.0 * ex2**3.0 / 120.0) * npy.sin(6.0 * chi)
68
69 lat = sgn * lat
70 lon = npy.arctan2(sgn * x,-sgn * y)
71 lon = sgn * lon
72
73 res1 = npy.nonzero(rho <= 0.1)[0]
74 if len(res1) > 0:
75 lat[res1] = 90. * sgn
76 lon[res1] = 0.0
77
78 lon = lon * 180. / pi
79 lat = lat * 180. / pi
80 lon = lon - delta
81
82 return lat, lon
Note: See TracBrowser for help on using the repository browser.