-
Notifications
You must be signed in to change notification settings - Fork 40
/
transform2.py
61 lines (54 loc) · 1.47 KB
/
transform2.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
"""
A Python program for the Mollweide projection.
Contact:
Ningchuan Xiao
The Ohio State University
Columbus, OH
"""
__author__ = "Ningchuan Xiao <[email protected]>"
from numpy import pi, cos, sin, radians, degrees, sqrt
def opt_theta(lat, verbose=False):
"""
Finds optimal theta value using Newton-Raphson iteration.
Input
lat: the latitude value
verbose: True to print intermediate output
Output
theta
"""
lat1 = radians(lat)
theta = lat1
while True:
dtheta = -(theta+sin(theta)-
pi*sin(lat1))/(1.0+cos(theta))
if verbose:
print("theta =", degrees(theta))
print("delta =", degrees(dtheta))
if int(1000000*dtheta) == 0:
break
theta = theta+dtheta
return theta/2.0
def transform2(lon, lat, lon0=0, R=1.0):
"""
Returns the transformation of lon and lat
on the Mollweide projection.
Input
lon: longitude
lat: latitude
lon0: central meridian
R: radius of the globe
Output
x: x coordinate (origin at 0,0)
y: y coordinate (origin at 0,0)
"""
lon1 = lon-lon0
if lon0 != 0:
if lon1>180:
lon1 = -((180+lon0)+(lon1-180))
elif lon1<-180:
lon1 = (180-lon0)-(lon1+180)
theta = opt_theta(lat)
x = sqrt(8.0)/pi*R*lon1*cos(theta)
x = radians(x)
y = sqrt(2.0)*R*sin(theta)
return x, y