Skip to content

Refactor EarthLocation as instance of BodyLocation. Add flattening and equatorial radius as parameters. - #14714

Closed
cmarmo wants to merge 1 commit into
astropy:mainfrom
oudeis-io:bodylocation
Closed

cmarmo wants to merge 1 commit into
astropy:mainfrom
oudeis-io:bodylocation

Conversation

@cmarmo

@cmarmo cmarmo commented Apr 28, 2023 •

Copy link
Copy Markdown
Member

Description

Towards #11170.

This pull request refactors EarthLocation as instance of BodyLocation.

The class BaseGeodeticRepresentation can now be described using custom equatorial_radius and flattening parameters.
Geodetic computations are then performed calling erfa.gc2gde and erfa.gd2gce when no standard ellipsoid is available.
Helpers for those two functions have been added.

This work is funded by the Europlanet 2024 Research Infrastructure (RI) Grant.

@github-actions

Copy link
Copy Markdown
Contributor

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.

  • Do the proposed changes actually accomplish desired goals?
  • Do the proposed changes follow the Astropy coding guidelines?
  • Are tests added/updated as required? If so, do they follow the Astropy testing guidelines?
  • Are docs added/updated as required? If so, do they follow the Astropy documentation guidelines?
  • Is rebase and/or squash necessary? If so, please provide the author with appropriate instructions. Also see "When to rebase and squash commits".
  • Did the CI pass? If no, are the failures related? If you need to run daily and weekly cron jobs as part of the PR, please apply the "Extra CI" label. Codestyle issues can be fixed by the bot.
  • Is a change log needed? If yes, did the change log check pass? If no, add the "no-changelog-entry-needed" label. If this is a manual backport, use the "skip-changelog-checks" label unless special changelog handling is necessary.
  • Is this a big PR that makes a "What's new?" entry worthwhile and if so, is (1) a "what's new" entry included in this PR and (2) the "whatsnew-needed" label applied?
  • Is a milestone set? Milestone must be set but we cannot check for it on Actions; do not let the green checkmark fool you.
  • At the time of adding the milestone, if the milestone set requires a backport to release branch(es), apply the appropriate "backport-X.Y.x" label(s) before merge.

@cmarmo
cmarmo marked this pull request as draft April 28, 2023 21:58
@pllim pllim added this to the v6.0 milestone Apr 28, 2023

@mhvk mhvk left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@cmarmo - thanks, that's quick! I have some initial comments, but also a request, to perhaps break this up in smaller PRs. This mostly since some parts I am confident are fine & needed, but I'm wondering a bit about the implementation of BodyLocation -- because of something I only recalled when I saw your PR, viz., that we've been thinking for quite a while that EarthLocation really shouldn't be a subclass of Quantity (see #4261). Indeed, the implementation of the various representations in #11086 by @astrojuanlu was meant to be a first step towards removing that.

Now I want to be sure that we don't let uncertainty about that stand in the way of actually getting a new BodyLocation implemented, but I think much will become clearer if we do it in steps. And that has the additional advantage that it makes review easier!

So, how about the following order:

  1. Separate out astropy.units support for gc2gde and gd2gce, adding a few basic tests (I'd rename test_structured_erfa_ufunc to test_quantity_erfa_ufunc and add a class TestGeodetic).
  2. Add support for equatorial_radius and flattening in BaseGeodeticRepresentation and insert a by-ID subclass from which the earth-based ones inherit (see in-line comment). Could be either in current earth.py or a new geodetic.py -- I think the latter would move under representations once that is refactored to be a module with multiple files (see #13688). Can add tests to test_geodetic_representations.
  3. Actually implement BodyLocation.

p.s. If it makes your life a lot easier, fine to combine 1+2 - might save you writing specific erfa tests...
p.s. @astrojuanlu - if you have time to look at this too, it would be appreciated!

Comment thread astropy/coordinates/body.py Outdated
"""Convert to a tuple with X, Y, and Z as quantities."""
return (self.x, self.y, self.z)

def get_itrs(self, obstime=None):

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be on EarthLocation - the T is for Terristrial!

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

uhh... 😱 ... shame on me! 🤦

Comment thread astropy/coordinates/body.py Outdated

def __init_subclass__(cls, **kwargs):
super().__init_subclass__(**kwargs)
if "_ellipsoid" in cls.__dict__:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My sense is for the real base class to have _equatorial_radius and _flattening and then have a subclass of that (say, NamedGeodeticRepresentation??), which has ellipsoid and inside sets _equatorial_radius and _flattening using erfa.eform (maybe bform later!) - inside its own __init_subclass__() before calling super() to this part. That will make the implementation below considerably simpler (always using gc2gd2 and gd2gce and thus removing the need for gc2gd and gd2gc.

Comment thread astropy/units/quantity_helper/erfa.py Outdated
def helper_gc2gde(f, unit1, nounit, unit2):
from astropy.units.si import m, radian

if nounit is not None:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that's too strict: it should just be dimensionless_unscaled (as a ratio of two radii). Note that this allows putting in float/ndarray - they will be treated as dimensionless. So this can just go inside the try/except below.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed in #14729, I wonder if the error message there will benefit from being more explicit though...

Comment thread astropy/units/quantity_helper/erfa.py Outdated
def helper_gd2gce(f, unit1, nounit, unit2, unit3, unit4):
from astropy.units.si import m, radian

if nounit is not None:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As for gc2gde above.

Comment thread astropy/coordinates/body.py Outdated
Converts geodetic coordinates to 3D rectangular (geocentric)
cartesian coordinates.
"""
if hasattr(self, "_flattening"):

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we follow my suggestion above, then to_cartesian will only need this branch, since flattening and equatorial_radius will always be defined.

Comment thread astropy/coordinates/body.py Outdated
Converts 3D rectangular cartesian coordinates (assumed geocentric) to
geodetic coordinates.
"""
if hasattr(cls, "_flattening"):

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here, no need for the _ellipsoid branch.

@cmarmo

cmarmo commented May 1, 2023

Copy link
Copy Markdown
Member Author

@mhvk thanks for your review!
I like the step by step strategy, so I have opened #14729 to address item .1.
Let me know if I have correctly interpreted your suggestions.
Thanks!

@astrojuanlu

Copy link
Copy Markdown
Member

Thanks for the ping @mhvk, I'm glad that there is steady progress towards better support for other bodies in Astropy!

Unfortunately I'm not using the library on a daily basis anymore and it's unlikely that I'll have time to review this PR.

@cmarmo

cmarmo commented May 10, 2023

Copy link
Copy Markdown
Member Author

I am going to close this pr as we are moving with a step by step strategy ... and I was already messing up with the branches.... 😅

@cmarmo cmarmo closed this May 10, 2023
@cmarmo
cmarmo deleted the bodylocation branch May 10, 2023 23:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants