Skip to content

Commit

Permalink
Add semimedium_axis property to sphere and ellipsoid (#192)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
MarkWieczorek authored Oct 8, 2024
1 parent c69fec3 commit 785d521
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 15 deletions.
17 changes: 17 additions & 0 deletions boule/_ellipsoid.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"""
Expand Down
39 changes: 24 additions & 15 deletions boule/_sphere.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,28 +145,40 @@ 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

@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.
"""
Expand All @@ -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.
"""
Expand All @@ -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.
"""
Expand All @@ -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`.
"""
Expand All @@ -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`.
"""
Expand Down
10 changes: 10 additions & 0 deletions boule/tests/test_ellipsoid.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."
Expand Down
11 changes: 11 additions & 0 deletions boule/tests/test_sphere.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
"""
Expand Down

0 comments on commit 785d521

Please sign in to comment.