source: issm/branches/trunk-larour-NatGeoScience2016/src/m/coordsystems/ll2xy.py@ 21759

Last change on this file since 21759 was 21759, checked in by Eric.Larour, 8 years ago

CHG: merged branch back to trunk-jpl 21754.

File size: 1.9 KB
Line 
1import numpy as np
2
3def ll2xy(lat,lon,sgn=-1,central_meridian=0,standard_parallel=71):
4 '''
5 LL2XY - converts lat lon to polar stereographic
6
7 Converts from geodetic latitude and longitude to Polar
8 Stereographic (X,Y) coordinates for the polar regions.
9 Author: Michael P. Schodlok, December 2003 (map2ll)
10
11 Usage:
12 x,y = ll2xy(lat,lon,sgn)
13 x,y = ll2xy(lat,lon,sgn,central_meridian,standard_parallel)
14
15 - sgn = Sign of latitude +1 : north latitude (default is mer=45 lat=70)
16 -1 : south latitude (default is mer=0 lat=71)
17 '''
18
19 assert sgn==1 or sgn==-1, 'error: sgn should be either +1 or -1'
20
21 #Get central_meridian and standard_parallel depending on hemisphere
22 if sgn == 1:
23 delta = 45
24 slat = 70
25 print ' ll2xy: creating coordinates in north polar stereographic (Std Latitude: 70N Meridian: 45)'
26 else:
27 delta = central_meridian
28 slat = standard_parallel
29 print ' ll2xy: creating coordinates in south polar stereographic (Std Latitude: 71S Meridian: 0)'
30
31 # Conversion constant from degrees to radians
32 cde = 57.29577951
33 # Radius of the earth in meters
34 re = 6378.273*10**3
35 # Eccentricity of the Hughes ellipsoid squared
36 ex2 = .006693883
37 # Eccentricity of the Hughes ellipsoid
38 ex = np.sqrt(ex2)
39
40 latitude = np.abs(lat) * np.pi/180.
41 longitude = (lon + delta) * np.pi/180.
42
43 # compute X and Y in grid coordinates.
44 T = np.tan(np.pi/4-latitude/2) / ((1-ex*np.sin(latitude))/(1+ex*np.sin(latitude)))**(ex/2)
45
46 if (90 - slat) < 1.e-5:
47 rho = 2.*re*T/np.sqrt((1.+ex)**(1.+ex)*(1.-ex)**(1.-ex))
48 else:
49 sl = slat*np.pi/180.
50 tc = np.tan(np.pi/4.-sl/2.)/((1.-ex*np.sin(sl))/(1.+ex*np.sin(sl)))**(ex/2.)
51 mc = np.cos(sl)/np.sqrt(1.0-ex2*(np.sin(sl)**2))
52 rho = re*mc*T/tc
53
54 y = -rho * sgn * np.cos(sgn*longitude)
55 x = rho * sgn * np.sin(sgn*longitude)
56
57 cnt1=np.nonzero(latitude>= np.pi/2.)[0]
58
59 if cnt1:
60 x[cnt1,0] = 0.0
61 y[cnt1,0] = 0.0
62 return x,y
Note: See TracBrowser for help on using the repository browser.