From 785d521c7e47ff3caa0dfd7f08a148c90293c72d Mon Sep 17 00:00:00 2001 From: markwieczorek Date: Tue, 8 Oct 2024 18:45:03 +0200 Subject: [PATCH] Add `semimedium_axis` property to sphere and ellipsoid (#192) Add the `semimedium_axis` and `semimajor_axis_longitude` to the Sphere and Ellipsoid classes for compatibility with the `TriaxialEllipsoid`. Don't use mathematical symbols for the `semimedium_axis`. Remove the "Added for compatibility with pymap3d" comment in some of the properties. --- boule/_ellipsoid.py | 17 +++++++++++++++ boule/_sphere.py | 39 +++++++++++++++++++++-------------- boule/tests/test_ellipsoid.py | 10 +++++++++ boule/tests/test_sphere.py | 11 ++++++++++ 4 files changed, 62 insertions(+), 15 deletions(-) diff --git a/boule/_ellipsoid.py b/boule/_ellipsoid.py index 6568d029..bd8f9847 100644 --- a/boule/_ellipsoid.py +++ b/boule/_ellipsoid.py @@ -182,6 +182,23 @@ def semiminor_axis(self): """ return self.semimajor_axis * (1 - self.flattening) + @property + def semimedium_axis(self): + """ + The semimedium axis of the ellipsoid is equal to its semimajor axis. + Units: :math:`m`. + """ + return self.semimajor_axis + + @property + def semimajor_axis_longitude(self): + r""" + The semimajor axis longitude of the ellipsoid is equal to zero. + Definition: :math:`\lambda_a = 0`. + Units: :math:`m`. + """ + return 0 + @property def thirdflattening(self): r""" diff --git a/boule/_sphere.py b/boule/_sphere.py index 84f08bd8..3cd4d288 100644 --- a/boule/_sphere.py +++ b/boule/_sphere.py @@ -145,9 +145,15 @@ def _check_geocentric_grav_const(self, geocentric_grav_const, value): @property def semiminor_axis(self): """ - The semiminor axis of the sphere is equal to its radius. Added for - compatibility with pymap3d. - Definition: :math:`b = R`. + The semiminor axis of the sphere is equal to its radius. + Units: :math:`m`. + """ + return self.radius + + @property + def semimedium_axis(self): + """ + The semimedium axis of the sphere is equal to its radius. Units: :math:`m`. """ return self.radius @@ -155,18 +161,24 @@ def semiminor_axis(self): @property def semimajor_axis(self): """ - The semimajor axis of the sphere is equal to its radius. Added for - compatibility with pymap3d. - Definition: :math:`a = R`. + The semimajor axis of the sphere is equal to its radius. Units: :math:`m`. """ return self.radius + @property + def semimajor_axis_longitude(self): + r""" + The semimajor axis longitude of the sphere is equal to zero. + Definition: :math:`\lambda_a = 0`. + Units: :math:`m`. + """ + return 0 + @property def flattening(self): r""" - The flattening of the sphere is equal to zero. Added for compatibility - with pymap3d. + The flattening of the sphere is equal to zero. Definition: :math:`f = \dfrac{a - b}{a}`. Units: adimensional. """ @@ -175,8 +187,7 @@ def flattening(self): @property def thirdflattening(self): r""" - The third flattening of the sphere is equal to zero. Added for - compatibility with pymap3d + The third flattening of the sphere is equal to zero. Definition: :math:`f^{\prime\prime}= \dfrac{a -b}{a + b}`. Units: adimensional. """ @@ -190,8 +201,7 @@ def eccentricity(self): @property def first_eccentricity(self): r""" - The (first) eccentricity of the sphere is equal to zero. Added for - compatibility with pymap3d. + The (first) eccentricity of the sphere is equal to zero. Definition: :math:`e = \dfrac{\sqrt{a^2 - b^2}}{a} = \sqrt{2f - f^2}`. Units: adimensional. """ @@ -209,8 +219,7 @@ def area(self): @property def mean_radius(self): """ - The mean radius of the ellipsoid is equal to its radius. Added for - compatibility with pymap3d. + The mean radius of the ellipsoid is equal to its radius. Definition: :math:`R_0 = R`. Units: :math:`m`. """ @@ -220,7 +229,7 @@ def mean_radius(self): def semiaxes_mean_radius(self): """ The arithmetic mean radius of the ellipsoid semi-axes is equal to its - radius. Added for compatibility with pymap3d. + radius. Definition: :math:`R_1 = R`. Units: :math:`m`. """ diff --git a/boule/tests/test_ellipsoid.py b/boule/tests/test_ellipsoid.py index ec9be376..c977d3ad 100644 --- a/boule/tests/test_ellipsoid.py +++ b/boule/tests/test_ellipsoid.py @@ -104,6 +104,16 @@ def test_check_geocentric_grav_const(): assert len(warn) >= 1 +@pytest.mark.parametrize("ellipsoid", ELLIPSOIDS, ids=ELLIPSOID_NAMES) +def test_semiaxes(ellipsoid): + """ + Check that the semimedium axis is equal to the semimajor axis and that + the longitude of the semimajor axis is zero. + """ + assert ellipsoid.semimedium_axis == ellipsoid.semimajor_axis + assert ellipsoid.semimajor_axis_longitude == 0 + + @pytest.mark.parametrize("ellipsoid", ELLIPSOIDS, ids=ELLIPSOID_NAMES) def test_geodetic_to_spherical_on_equator(ellipsoid): "Test geodetic to geocentric coordinates conversion on equator." diff --git a/boule/tests/test_sphere.py b/boule/tests/test_sphere.py index 9b18b00a..acfe91aa 100644 --- a/boule/tests/test_sphere.py +++ b/boule/tests/test_sphere.py @@ -78,6 +78,17 @@ def test_check_geocentric_grav_const(): assert len(warn) >= 1 +def test_semiaxes(sphere): + """ + Check that the semiaxes are all equal to the sphere radius and that + the longitude of the semimajor axis is zero. + """ + assert sphere.semimajor_axis == sphere.radius + assert sphere.semimedium_axis == sphere.radius + assert sphere.semiminor_axis == sphere.radius + assert sphere.semimajor_axis_longitude == 0 + + @pytest.mark.parametrize("si_units", [False, True], ids=["mGal", "SI"]) def test_normal_gravity_pole_equator(sphere, si_units): """