Skip to content

Commit

Permalink
add units almost everywhere
Browse files Browse the repository at this point in the history
  • Loading branch information
ioshchepkov committed Mar 25, 2021
1 parent ae8e727 commit ce2d274
Show file tree
Hide file tree
Showing 21 changed files with 1,456 additions and 1,548 deletions.
653 changes: 331 additions & 322 deletions Pipfile.lock

Large diffs are not rendered by default.

339 changes: 146 additions & 193 deletions pygeoid/coordinates/ellipsoid.py

Large diffs are not rendered by default.

66 changes: 23 additions & 43 deletions pygeoid/coordinates/position.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"""

import astropy.units as u
from pygeoid.coordinates import transform


Expand All @@ -18,13 +19,15 @@ class Position3D:
Cartesian coordinates, in metres.
"""

def __init__(self, x, y, z):
@u.quantity_input
def __init__(self, x: u.m, y: u.m, z: u.m):
self._x = x
self._y = y
self._z = z

@classmethod
def from_geodetic(cls, lat, lon, height, ell, degrees=True):
@u.quantity_input
def from_geodetic(cls, lat: u.deg, lon: u.deg, height: u.m, ell):
"""Position, initialized from geodetic coordinates.
Parameters
Expand All @@ -37,16 +40,14 @@ def from_geodetic(cls, lat, lon, height, ell, degrees=True):
Geodetic height, in metres.
ell : instance of the `pygeoid.coordinates.ellipsoid.Ellipsoid`
Reference ellipsoid to which geodetic coordinates are referenced to.
degrees : bool, optional
If True, the input `lat` and `lon` are given in degrees,
otherwise radians.
"""
x, y, z = transform.geodetic_to_cartesian(lat, lon, height, ell=ell,
degrees=degrees)
x, y, z = transform.geodetic_to_cartesian(lat, lon, height, ell=ell)
return cls(x, y, z)

@classmethod
def from_spherical(cls, lat, lon, radius, degrees=True):
@u.quantity_input
def from_spherical(cls, lat: u.deg, lon: u.deg, radius: u.m):
"""Position, initialized from spherical coordinates.
Parameters
Expand All @@ -55,16 +56,13 @@ def from_spherical(cls, lat, lon, radius, degrees=True):
Spherical latitude and longitude.
radius : float or array_like of floats
Radius, in metres.
degrees : bool, optional
If True, the input `lat` and `lon` are given in degrees,
otherwise radians.
"""
x, y, z = transform.spherical_to_cartesian(lat, lon, radius,
degrees=degrees)
x, y, z = transform.spherical_to_cartesian(lat, lon, radius)
return cls(x, y, z)

@classmethod
def from_ellipsoidal(cls, rlat, lon, u, ell, degrees=True):
@u.quantity_input
def from_ellipsoidal(cls, rlat: u.deg, lon: u.deg, u: u.m, ell):
"""Position, initialized from ellipsoidal coordinates.
Parameters
Expand All @@ -77,18 +75,14 @@ def from_ellipsoidal(cls, rlat, lon, u, ell, degrees=True):
Polar axis of the ellipsoid passing through the point.
ell : instance of the `pygeoid.coordinates.ellipsoid.Ellipsoid`
Reference ellipsoid to which geodetic coordinates are referenced to.
degrees : bool, optional
If True, the input `rlat` and `lon` are given in degrees,
otherwise radians.
"""
x, y, z = transform.ellipsoidal_to_cartesian(rlat, lon, u, ell=ell,
degrees=degrees)
x, y, z = transform.ellipsoidal_to_cartesian(rlat, lon, u, ell=ell)
return cls(x, y, z)

@property
def cartesian(self):
"""Return 3D cartesian coordinates"""
return (self._x, self._y, self._z)
return self._x, self._y, self._z

@property
def x(self):
Expand All @@ -105,16 +99,13 @@ def z(self):
"""Return z coordinate"""
return self._z

def geodetic(self, ell, degrees=True):
def geodetic(self, ell):
"""Return geodetic coordinates.
Parameters
----------
ell : instance of the `pygeoid.coordinates.ellipsoid.Ellipsoid`
Reference ellipsoid to which geodetic coordinates are referenced to.
degrees : bool, optional
If True, the output geodetic latitude and longitude will be in degrees,
otherwise radians.
Returns
-------
Expand All @@ -124,18 +115,12 @@ def geodetic(self, ell, degrees=True):
Geodetic height, in metres.
"""
lat, lon, height = transform.cartesian_to_geodetic(
self._x, self._y, self._z, ell=ell, degrees=degrees)
self._x, self._y, self._z, ell=ell)
return lat, lon, height

def spherical(self, degrees=True):
def spherical(self):
"""Return spherical (geocentric) coordinates.
Parameters
----------
degrees : bool, optional
If True, the output spherical latitude and longitude will be in degrees,
otherwise radians.
Returns
-------
lat, lon : float or array_like of floats
Expand All @@ -144,19 +129,16 @@ def spherical(self, degrees=True):
Radius, in metres.
"""
lat, lon, radius = transform.cartesian_to_spherical(
self._x, self._y, self._z, degrees=degrees)
self._x, self._y, self._z)
return lat, lon, radius

def ellipsoidal(self, ell, degrees=True):
def ellipsoidal(self, ell):
"""Return ellipsoidal-harmonic coordinates.
Parameters
----------
ell : instance of the `pygeoid.coordinates.ellipsoid.Ellipsoid`
Reference ellipsoid to which ellipsoidal coordinates are referenced to.
degrees : bool, optional
If True, the output reduced latitude and longitude will
be in degrees, otherwise radians.
Returns
-------
Expand All @@ -168,10 +150,11 @@ def ellipsoidal(self, ell, degrees=True):
Polar axis of the ellipsoid passing through the given point.
"""
rlat, lon, u = transform.cartesian_to_ellipsoidal(
self._x, self._y, self._z, ell=ell, degrees=degrees)
self._x, self._y, self._z, ell=ell)
return rlat, lon, u

def enu(self, origin, ell=None, degrees=True):
@u.quantity_input
def enu(self, origin: u.deg, ell=None):
"""Return local east-north-up cartesian coordinates.
Parameters
Expand All @@ -183,16 +166,13 @@ def enu(self, origin, ell=None, degrees=True):
Reference ellipsoid to which geodetic coordinates
are referenced to. Default is None, meaning spherical
coordinates instead of geodetic.
degrees : bool, optional
If True, the input `lat0` and `lon0` are given in degrees,
otherwise radians.
Returns
-------
x, y, z : float or array_like of floats
Local east-north-up cartesian coordinates, in metres.
"""
east, north, up = transform.ecef_to_enu(
self._x, self._y, self._z, origin, ell=ell, degrees=degrees)
self._x, self._y, self._z, origin, ell=ell)

return east, north, up
Loading

0 comments on commit ce2d274

Please sign in to comment.