[21759] | 1 | import numpy as np
|
---|
[17587] | 2 |
|
---|
| 3 | def 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
|
---|
[17712] | 25 | print ' ll2xy: creating coordinates in north polar stereographic (Std Latitude: 70N Meridian: 45)'
|
---|
[17587] | 26 | else:
|
---|
| 27 | delta = central_meridian
|
---|
| 28 | slat = standard_parallel
|
---|
[17712] | 29 | print ' ll2xy: creating coordinates in south polar stereographic (Std Latitude: 71S Meridian: 0)'
|
---|
[17587] | 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
|
---|
[21759] | 38 | ex = np.sqrt(ex2)
|
---|
[17587] | 39 |
|
---|
[21759] | 40 | latitude = np.abs(lat) * np.pi/180.
|
---|
| 41 | longitude = (lon + delta) * np.pi/180.
|
---|
[17587] | 42 |
|
---|
| 43 | # compute X and Y in grid coordinates.
|
---|
[21759] | 44 | T = np.tan(np.pi/4-latitude/2) / ((1-ex*np.sin(latitude))/(1+ex*np.sin(latitude)))**(ex/2)
|
---|
[17587] | 45 |
|
---|
| 46 | if (90 - slat) < 1.e-5:
|
---|
[21759] | 47 | rho = 2.*re*T/np.sqrt((1.+ex)**(1.+ex)*(1.-ex)**(1.-ex))
|
---|
[17587] | 48 | else:
|
---|
[21759] | 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))
|
---|
[17587] | 52 | rho = re*mc*T/tc
|
---|
| 53 |
|
---|
[21759] | 54 | y = -rho * sgn * np.cos(sgn*longitude)
|
---|
| 55 | x = rho * sgn * np.sin(sgn*longitude)
|
---|
[17587] | 56 |
|
---|
[21759] | 57 | cnt1=np.nonzero(latitude>= np.pi/2.)[0]
|
---|
[17587] | 58 |
|
---|
| 59 | if cnt1:
|
---|
| 60 | x[cnt1,0] = 0.0
|
---|
| 61 | y[cnt1,0] = 0.0
|
---|
| 62 | return x,y
|
---|