The ellipsoids Module¶
This Python 3.11 code implements ellipsoids of revolution.
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.
By ‘ellipsoid’ throughout, I mean an ellipsoid of revolution and not a general (triaxial) ellipsoid. Points lying on an ellipsoid are given in geodetic (longitude, latitude) coordinates.
- class rhealpixdggs.ellipsoids.Ellipsoid(R=None, a=6378137.0, b=None, e=None, f=0.0033528106647474805, lon_0=0, lat_0=0, radians=False)¶
Bases:
object
Represents an ellipsoid of revolution (possibly a sphere) with a geodetic longitude-latitude coordinate frame.
INSTANCE ATTRIBUTES:
sphere - True if the ellipsoid is a sphere, and False otherwise.
R - The radius of the ellipsoid in meters, implying that it is a sphere.
a - Major radius of the ellipsoid in meters.
b - Minor radius of the ellipsoid in meters.
e - Eccentricity of the ellipsoid.
f - Flattening of the ellipsoid.
R_A - Authalic radius of the ellipsoid in meters.
lon_0 - Central meridian.
lat_0 - Latitude of origin.
radians - If True, use angles measured in radians for all calculations. Use degrees otherwise.
phi_0 - The latitude separating the equatorial region and the north polar region in the context of the (r)HEALPix projection.
Except for phi_0, these attribute names match the names of the PROJ ellipsoid parameters <https://proj.org/en/9.4/usage/ellipsoids.html#ellipsoid-spherification-parameters>
- get_points(filename)¶
Return a list of longitude-latitude points contained in the file with filename filename. Assume the file is a text file containing at most one longitude-latitude point per line with the coordinates separated by whitespace and angles given in degrees.
- graticule(n=400, spacing=None)¶
Return a list of longitude-latitude points sampled from a longitude-latitude graticule on this ellipsoid with the given spacing between meridians and between parallels. The number of points on longitude and latitude per pi radians is n. The spacing should be specified in the angle units used for this ellipsoid. If spacing=None, then a default spacing of pi/16 radians will be set.
EXAMPLES:
>>> E = UNIT_SPHERE >>> print(len(E.graticule(n=400))) 25600
- lattice(n=90)¶
Return a 2n x n square lattice of longitude-latitude points.
EXAMPLES:
>>> E = UNIT_SPHERE >>> for p in E.lattice(n=3): ... print(p) (-150.0, -60.0) (-150.0, 0.0) (-150.0, 60.0) (-90.0, -60.0) (-90.0, 0.0) (-90.0, 60.0) (-30.0, -60.0) (-30.0, 0.0) (-30.0, 60.0) (30.0, -60.0) (30.0, 0.0) (30.0, 60.0) (90.0, -60.0) (90.0, 0.0) (90.0, 60.0) (150.0, -60.0) (150.0, 0.0) (150.0, 60.0)
- meridian(lam, n=200)¶
Return a list of n equispaced longitude-latitude points lying along the meridian of longitude lam. Avoid the poles.
- parallel(phi, n=200)¶
Return a list of 2*n equispaced longitude-latitude points lying along the parallel of latitude phi.
- pi()¶
Return pi if self.radians = True and 180 otherwise.
- random_point(lam_min=None, lam_max=None, phi_min=None, phi_max=None)¶
Return a point (given in geodetic coordinates) sampled uniformly at random from the section of this ellipsoid with longitude in the range lam_min <= lam < lam_max and latitude in the range phi_min <= phi < phi_max. But avoid the poles.
EXAMPLES:
>>> E = UNIT_SPHERE >>> print(E.random_point()) (-1.0999574573422948, 0.21029104897701129)
- xyz(lam, phi)¶
Given a point on this ellipsoid with longitude-latitude coordinates (lam, phi), return the point’s 3D rectangular coordinates.
EXAMPLES:
>>> E = UNIT_SPHERE >>> print(tuple(x.tolist() for x in my_round(E.xyz(0, 45), 15))) (0.707106781186548, 0.0, 0.707106781186548)