Skip to content

Commit

Permalink
Remove _ellipsoid from BodycentricRepresentation.
Browse files Browse the repository at this point in the history
  • Loading branch information
cmarmo committed Jun 17, 2023
1 parent 508ee27 commit d17d2dc
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 23 deletions.
9 changes: 2 additions & 7 deletions astropy/coordinates/representation/geodetic.py
Expand Up @@ -150,17 +150,12 @@ class BaseBodycentricRepresentation(BaseRepresentation):
_wrap_angle = 180 * u.deg

def __init_subclass__(cls, **kwargs):
if "_ellipsoid" in cls.__dict__:
equatorial_radius, flattening = erfa.eform(getattr(erfa, cls._ellipsoid))
cls._equatorial_radius = equatorial_radius * u.m
cls._flattening = flattening * u.dimensionless_unscaled
ELLIPSOIDS[cls._ellipsoid] = cls
elif (
if (
"_equatorial_radius" not in cls.__dict__
or "_flattening" not in cls.__dict__
):
raise AttributeError(
f"{cls.__name__} requires '_ellipsoid' or '_equatorial_radius' and '_flattening'."
f"{cls.__name__} requires '_equatorial_radius' and '_flattening'."
)
if not hasattr(
cls._wrap_angle, "unit"
Expand Down
19 changes: 3 additions & 16 deletions astropy/coordinates/tests/test_geodetic_representations.py
Expand Up @@ -42,10 +42,6 @@ class CustomSphericBodycentric(BaseBodycentricRepresentation):
_equatorial_radius = 4000000.0 * u.m


class WGS84BodycentricRepresentation(BaseBodycentricRepresentation):
_ellipsoid = "WGS84"


class IAUMARS2000GeodeticRepresentationEast180(BaseGeodeticRepresentation):
_equatorial_radius = 3396190.0 * u.m
_flattening = 0.5886007555512007 * u.percent
Expand Down Expand Up @@ -101,7 +97,6 @@ def test_geodetic_bodycentric_equivalence_spherical_bodies():
[
CustomGeodetic,
WGS84GeodeticRepresentation,
WGS84BodycentricRepresentation,
IAUMARS2000GeodeticRepresentationEast360,
IAUMARS2000GeodeticRepresentationWest360,
IAUMARS2000BodycentricRepresentation,
Expand All @@ -128,7 +123,6 @@ def test_cartesian_geodetic_roundtrip(geodeticrepresentation):
[
CustomGeodetic,
WGS84GeodeticRepresentation,
WGS84BodycentricRepresentation,
IAUMARS2000GeodeticRepresentationEast360,
IAUMARS2000GeodeticRepresentationWest360,
IAUMARS2000BodycentricRepresentation,
Expand Down Expand Up @@ -245,20 +239,13 @@ def test_non_length_error(representation):
representation(10 * u.deg, 20 * u.deg, 30)


@pytest.mark.parametrize(
"baserepresentation",
[
BaseGeodeticRepresentation,
BaseBodycentricRepresentation,
],
)
def test_subclass_bad_ellipsoid(baserepresentation):
def test_subclass_bad_ellipsoid():
# Test incomplete initialization.

msg = "module 'erfa' has no attribute 'foo'"
with pytest.raises(AttributeError, match=msg):

class InvalidCustomEllipsoid(baserepresentation):
class InvalidCustomEllipsoid(BaseGeodeticRepresentation):
_ellipsoid = "foo"

assert "foo" not in ELLIPSOIDS
Expand All @@ -273,7 +260,7 @@ class InvalidCustomEllipsoid(baserepresentation):
],
)
def test_geodetic__subclass_missing_equatorial_radius(baserepresentation):
msg = "requires '_ellipsoid' or '_equatorial_radius' and '_flattening'."
msg = "'_equatorial_radius' and '_flattening'."
with pytest.raises(AttributeError, match=msg):

class MissingCustomAttribute(baserepresentation):
Expand Down

0 comments on commit d17d2dc

Please sign in to comment.