The utils Module

This Python 3.11 module implements several helper functions for coding map projections.

  • Alexander Raichev (AR), 2012-01-26: Refactored code from release 0.3.

NOTE:

All lengths are measured in meters and all angles are measured in radians unless indicated otherwise.

rhealpixdggs.utils.auth_lat(phi: float, e: float, inverse: bool = False, radians: bool = False) float

Given a point of geographic latitude phi on an ellipse of eccentricity e, return the authalic latitude of the point. If inverse =True, then compute its inverse approximately.

EXAMPLES:

>>> beta = auth_lat(pi/3, 0.08181919104281579, radians=True)
>>> print(my_round(beta, 15))
1.045256493205824

>>> print(my_round(auth_lat(beta, 0.08181919104281579, radians=True, inverse=True), 15))
1.047197551196598

>>> print(my_round(pi/3, 15))
1.047197551196598

NOTES:

For small flattenings f (f < 1/150), when calculating authalic from common latitude, power series approximation (from https://doi.org/10.48550/arXiv.2212.05818) gives more accurate results than direct formula (for double-precission accuracy). For the inverse, again power series approximation is used, which is standard in cartography for small flattenings. The one used in this case is from https://doi.org/10.48550/arXiv.2212.05818

rhealpixdggs.utils.auth_rad(a: float, e: float, inverse: bool = False) float

Return the radius of the authalic sphere of the ellipsoid with major radius a and eccentricity e. If inverse = True, then return the major radius of the ellipsoid with authalic radius a and eccentricity e.

EXAMPLES:

>>> auth_rad(1, 0)
1
>>> for i in range(2, 11):
...     e = 1.0/i**2
...     print(my_round((e, auth_rad(1, 1.0/i**2)), 15))
(0.25, 0.989393259670095)
(0.111111111111111, 0.997935147429943)
(0.0625, 0.999348236455825)
(0.04, 0.99973321235361)
(0.027777777777778, 0.99987137105188)
(0.020408163265306, 0.999930576285614)
(0.015625, 0.999959307080847)
(0.012345679012346, 0.999974596271211)
(0.01, 0.999983332861089)
rhealpixdggs.utils.my_round(x: Any, digits: int = 0) Any

Round the floating point number or list/tuple of floating point numbers to digits number of digits. Calls Python’s round() function.

EXAMPLES:

>>> print(my_round(1./7, 6))
0.142857
>>> print(my_round((1./3, 1./7), 6))
(0.333333, 0.142857)
rhealpixdggs.utils.wrap_latitude(phi: float, radians: bool = False) float

Given a point p on the unit circle at angle phi from the positive x-axis, if p lies in the right half of the circle, then return its angle that lies in the interval [-pi/2, pi/2]. If p lies in the left half of the circle, then reflect it through the origin, and return the angle of the reflected point that lies in the interval [-pi/2, pi/2]. If radians = True, then phi and the output are given in radians. Otherwise, they are given in degrees.

EXAMPLES:

>>> wrap_latitude(45.0, radians=False)
45.0
>>> wrap_latitude(-45.0, radians=False)
-45.0
>>> wrap_latitude(90.0, radians=False)
90.0
>>> wrap_latitude(-90.0, radians=False)
-90.0
>>> wrap_latitude(135.0, radians=False)
-45.0
>>> wrap_latitude(-135.0, radians=False)
45.0
rhealpixdggs.utils.wrap_longitude(lam: float, radians: bool = False) float

Given a point p on the unit circle at angle lam from the positive x-axis, return its angle theta in the range -pi <= theta < pi. If radians = True, then lam and the output are given in radians. Otherwise, they are given in degrees.

EXAMPLES:

>>> wrap_longitude(2*pi + pi, radians=True)
-3.141592653589793