Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deprecate the coordinate conversion methods #126

Merged
merged 1 commit into from
Jun 20, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions boule/_ellipsoid.py
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,14 @@ def geodetic_to_spherical(self, longitude, latitude, height):
"""
Convert from geodetic to geocentric spherical coordinates.

.. warning::

**This method is deprecated and will be removed in Boule v0.5.0.**
Please use the equivalent function in
`pymap3d <https:/geospace-code/pymap3d/>`__ instead
(``pymap3d.geodetic2spherical``) which is available since version
2.9.0.

The geodetic datum is defined by this ellipsoid. The coordinates are
converted following [Vermeille2002]_.

Expand All @@ -363,6 +371,12 @@ def geodetic_to_spherical(self, longitude, latitude, height):
Converted spherical radius coordinates in meters.

"""
warn(
"Ellipsoid.geodetic_to_spherical is deprecated and will be removed "
"in Boule v0.5.0. Use pymap3d.geodetic2spherical instead.",
FutureWarning,
)

latitude_rad = np.radians(latitude)
coslat, sinlat = np.cos(latitude_rad), np.sin(latitude_rad)
prime_vertical_radius = self.prime_vertical_radius(sinlat)
Expand All @@ -380,6 +394,14 @@ def spherical_to_geodetic(self, longitude, spherical_latitude, radius):
"""
Convert from geocentric spherical to geodetic coordinates.

.. warning::

**This method is deprecated and will be removed in Boule v0.5.0.**
Please use the equivalent function in
`pymap3d <https:/geospace-code/pymap3d/>`__ instead
(``pymap3d.spherical2geodetic``) which is available since version
2.9.0.

The geodetic datum is defined by this ellipsoid. The coordinates are
converted following [Vermeille2002]_.

Expand All @@ -406,6 +428,12 @@ def spherical_to_geodetic(self, longitude, spherical_latitude, radius):
Converted ellipsoidal height coordinates in meters.

"""
warn(
"Ellipsoid.spherical_to_geodetic is deprecated and will be removed "
"in Boule v0.5.0. Use pymap3d.spherical2geodetic instead.",
FutureWarning,
)

spherical_latitude = np.radians(spherical_latitude)
k, big_z, big_d = self._spherical_to_geodetic_terms(spherical_latitude, radius)
latitude = np.degrees(
Expand Down
22 changes: 17 additions & 5 deletions boule/tests/test_ellipsoid.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
"""
Test the base Ellipsoid class.
"""
import warnings

import numpy as np
import numpy.testing as npt
import pymap3d
Expand All @@ -21,6 +19,20 @@
ELLIPSOID_NAMES = [e.name for e in ELLIPSOIDS]


def test_coordinate_conversion_deprecations():
"""
Check if warn is raised when using coordinate conversion functions
"""
with pytest.warns(FutureWarning) as warning:
WGS84.geodetic_to_spherical(0, 0, 0)
assert len(warning) >= 1
assert "geodetic2spherical" in warning[0].message.args[0]
with pytest.warns(FutureWarning) as warning:
WGS84.spherical_to_geodetic(0, 0, 6_000_000)
assert len(warning) >= 1
assert "spherical2geodetic" in warning[0].message.args[0]


def test_check_flattening():
"""
Check if error/warns is raised after invalid flattening
Expand Down Expand Up @@ -57,7 +69,7 @@ def test_check_flattening():
geocentric_grav_const=0,
angular_velocity=0,
)
with warnings.catch_warnings(record=True) as warn:
with pytest.warns(UserWarning) as warn:
Ellipsoid(
name="almost-zero-flattening",
semimajor_axis=1,
Expand Down Expand Up @@ -94,7 +106,7 @@ def test_check_geocentric_grav_const():
"""
Check if warn is raised after negative geocentric_grav_const
"""
with warnings.catch_warnings(record=True) as warn:
with pytest.warns(UserWarning) as warn:
Ellipsoid(
name="negative_gm",
semimajor_axis=1,
Expand Down Expand Up @@ -335,7 +347,7 @@ def test_normal_gravity_computed_on_internal_point(ellipsoid):
Check if warn is raised if height is negative
"""
latitude = np.linspace(-90, 90, 100)
with warnings.catch_warnings(record=True) as warn:
with pytest.warns(UserWarning) as warn:
ellipsoid.normal_gravity(latitude, height=-10)
assert len(warn) >= 1

Expand Down