Repository navigation
Add support for equatorial_radius and flattening in BaseGeodeticRepresentation. - #14763
Conversation
|
Thank you for your contribution to Astropy! 🌌 This checklist is meant to remind the package maintainers who will review this pull request of some common things to look for.
|
5eeecd0 to
923ce18
Compare
|
I am able to reproduce the test failure locally with I am still trying to understand why ... 🤔 |
mhvk
left a comment
There was a problem hiding this comment.
Thanks, this looks great, and hence most of my comments (and perhaps confusion) are about names... I haven't quite figured out the best way forward, but think I better just submit my present review since you may have better ideas.
p.s. Review is far easier with things split out - thanks very much for humouring me!
|
Having just added the "whatsnew-needed" label, I think what we also have to do is to add some documentation... I think a short additional section at the end of https://docs.astropy.org/en/latest/coordinates/representations.html#creating-your-own-representations should be good enough for now. |
|
@mhvk thanks for your review!
Let me know how do you feel about those suggestions. |
|
@cmarmo - when I did my review yesterday I also wondered if it was actually necessary to have two subclasses, and whether, instead, we should not just return closer to what you had, where Also, good to know that the consensus in the community is to just call it geodetic even for other planetary bodies. If so, let's go for it. Anyway, it sounds like we have a plan! p.s. It doesn't have to be now, but if you think it is better, I'd be fine with moving the explicit representations from |
923ce18 to
042d51f
Compare
Wonderful! :) |
mhvk
left a comment
There was a problem hiding this comment.
Now definitely moving towards minimal comments and nitpicks - I think overall this is looking very good!
But obviously need to figure out why the tests are failing. My guess is that it is the registration of the test classes, and I give a suggestion in-line on how to fix this...
To do is a what's-new entry and documentation!
7a62c19 to
6dce627
Compare
6dce627 to
5007cf7
Compare
mhvk
left a comment
There was a problem hiding this comment.
Great! Code is now all OK - the diff makes me feel this is exactly right, with just a clean chunk moved from earth.py to the new geodetic.py, and logical additions.
Most of the remaining comments are just textual, on the added documentation.
One thought (not for this PR!!): it might make sense to allow one to input a BaseGeodeticRepresentation subclass in EarthLocation.to_geodetic (maybe as the ellipsoid argument), so people can use their custom classes in there.
| * `~astropy.coordinates.CylindricalRepresentation`: | ||
| cylindrical polar coordinates, represented by a cylindrical radius | ||
| (``rho``), azimuthal angle (``phi``), and height (``z``). | ||
| * `~astropy.coordinates.BaseGeodeticRepresentation`: |
There was a problem hiding this comment.
This class is different in that it is not useful in itself but has to be subclassed. How about here describing WGS84GeodeticRepresentation (which is useful in itself), and then at the end noting the two other pre-defined ones, and giving a link to your new section about how to create one's own?
There was a problem hiding this comment.
This class is different in that it is not useful in itself but has to be subclassed.
I understand this point.
But then WGS84GeodeticRepresentation is a specific case, which is not true for the other items in the list.
What about removing the geodetic description from the list and adding a paragraph like:
"Astropy also offers a BaseGeodeticRepresentation useful to create specific representations on spheroidal bodies... blah...blah..."
eerovaher
left a comment
There was a problem hiding this comment.
I have some comments regarding the tests.
| def test_custombasegeodetic_error(): | ||
| # Test incomplete initialization. |
There was a problem hiding this comment.
I'd like the test names to be descriptive enough that such comments would not be necessary. pytest shows the names of failing tests and they can be also displayed by running pytest with increased verbosity, but reading the comment requires looking up the source code for the test.
| msg = "module 'erfa' has no attribute 'foo'" | ||
| with pytest.raises(AttributeError, match=msg): | ||
|
|
||
| class CustomGeodeticEllipsoidError(BaseGeodeticRepresentation): |
There was a problem hiding this comment.
If I read the code I can figure out why an error is implemented as a subclass of BaseGeodeticRepresentation, but I'd rather not spend the effort.
| class CustomGeodeticEllipsoidError(BaseGeodeticRepresentation): | |
| class InvalidCustomGeodeticEllipsoid(BaseGeodeticRepresentation): |
This also applies to the other class in this function.
| s1g = CustomGeodetic( | ||
| lon=[0.8, 1.3] * u.radian, | ||
| lat=[0.3, 0.98] * u.radian, | ||
| height=[100.0, 367.0] * u.m, | ||
| ) | ||
|
|
||
| s2g = CartesianRepresentation.from_representation(s1g) | ||
|
|
||
| s3g = CustomGeodetic.from_representation(s2g) |
There was a problem hiding this comment.
I don't like having variables that are used exactly once because I don't know that they'll be discarded almost immediately when I'm reading the code, so I try to memorize what they are only to find out very quickly that I can forget about them entirely.
| s1g = CustomGeodetic( | |
| lon=[0.8, 1.3] * u.radian, | |
| lat=[0.3, 0.98] * u.radian, | |
| height=[100.0, 367.0] * u.m, | |
| ) | |
| s2g = CartesianRepresentation.from_representation(s1g) | |
| s3g = CustomGeodetic.from_representation(s2g) | |
| initial = CustomGeodetic( | |
| lon=[0.8, 1.3] * u.radian, | |
| lat=[0.3, 0.98] * u.radian, | |
| height=[100.0, 367.0] * u.m, | |
| ) | |
| roundtripped = CustomGeodetic.from_representation( | |
| CartesianRepresentation.from_representation(initial) | |
| ) |
| assert "customgeodeticerror" not in REPRESENTATION_CLASSES | ||
|
|
||
|
|
||
| def test_custombasegeodetic_roundtrip(): |
There was a problem hiding this comment.
This test should be parametrized. If one of the asserts fails then the following asserts in the test function are not executed, but in the case of a parametrized test one of the parametrizations failing does not prevent other parametrizations of the same test from running, so a parametrized test suite is more granular and informative with no or very little extra effort.
|
|
||
| s3g = CustomGeodetic.from_representation(s2g) | ||
|
|
||
| assert quantity_allclose(s1g.lon, s3g.lon) |
There was a problem hiding this comment.
It is better to use assert_quantity_allclose() because it is more informative if the assertion fails.
|
@eerovaher , Thanks for your comments, I believe I have addressed all your concern? @mhvk something is wrong with the conversion of EDIT: removing a debugging print helped a lot... 😅 |
|
@cmarmo - the reason that |
|
p.s. Just updated my branch with an additional commit that moves |
|
I cannot check the "allow edits from maintainers" because of https://github.com/orgs/community/discussions/5634. |
a5e35a3 to
a10c965
Compare
…sentation. Add tests and documentation.
5eb5e6d to
a30f021
Compare
|
I have pushed a new version of the documentation implementing my suggestion in answering this comment. Let me know if it is acceptable. |
mhvk
left a comment
There was a problem hiding this comment.
Sorry for the trouble, I hadn't realized group accounts were different!
And also sorry that my PR missed some things!
But it now all looks great! I have one possible suggestion for the documentation, but am also happy to merge as is, so will leave that up to you and approve now.
|
|
||
|
|
||
| Astropy also offers a `~astropy.coordinates.BaseGeodeticRepresentation` useful to | ||
| create specific representations on spheroidal bodies (see |
There was a problem hiding this comment.
I think this paragraph is very clear! Should we mention the existing earth-based ones? E.g.,
Astropy also offers a `~astropy.coordinates.BaseGeodeticRepresentation` useful to
create specific `repreentations` on spheroidal bodies. This is used internally for the
standard Earth ellipsoids used in `~astropy.coordinates.EarthLocation`
(`~astropy.coordinates.WGS84GeodeticRepresentation`,
`~astropy.coordinates.WGS72GeodeticRepresentation`, and
`~astropy.coordinates.GRS80GeodeticRepresentation`), but
can also be customized; see :ref:`astropy-coordinates-create-geodetic`.
All these are coordinates on ...
There was a problem hiding this comment.
I like it! I'm adding it right now.
c08a964 to
e6c0a86
Compare
|
The tests seem to be stuck, so I'm going to close & reopen. Hopefully, that will resolve it. Otherwise, everything is OK, so I'm going to try our new "auto-merge" feature |
Pull request was closed
|
Thanks! 🥳 |
Description
This pull request adds support for
equatorial_radiusandflatteninginBaseGeodeticRepresentation.A new classStandardGeodeticRepresentationis added inheriting fromBaseGeodeticRepresentation, retrievingspheroid attributes from a standard code.All geodetic representations classes are factorized into
geodetic.py.Tests are added.
Follows the suggestion in #14714 (review).
Towards #11170.
Thanks for considering it.
This work is funded by the Europlanet 2024 Research Infrastructure (RI) Grant.