# Distance to Moon: inconsistent results?

**URL:** <https://community.openastronomy.org/t/distance-to-moon-inconsistent-results/217>\
**Category:** Astropy\
**Created:** [November 8, 2021, 11:24am UTC](https://community.openastronomy.org/t/distance-to-moon-inconsistent-results/217 "2021-11-08T11:24:08Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![tammojan](https://dub1.discourse-cdn.com/flex005/user_avatar/community.openastronomy.org/tammojan/32/145_2.png) [@tammojan](https://community.openastronomy.org/u/tammojan)\
**Post date:** [November 8, 2021, 11:24am UTC](https://community.openastronomy.org/t/distance-to-moon-inconsistent-results/217/1 "2021-11-08T11:24:08Z")

</div>

I’m computing the distance to the Moon in two ways, that I think should yield the same result. However, there’s a 150m difference. Am I overlooking something?

```python
from astropy.time import Time
from astropy.coordinates import GCRS, get_moon, EarthLocation, solar_system_ephemeris
import astropy.units as u

solar_system_ephemeris.set("de430");

t0 = Time("2021-10-08T12:00")

loc = EarthLocation(lat=52*u.deg, lon=6*u.deg)

res1 = get_moon(t0, location=loc).distance
# 361084.21km

res2 = (get_moon(t0).cartesian - loc.get_gcrs(t0).cartesian).norm()
# 361084.05km

res1 - res2

res1 - res2
# 0.15716625km

```

---

<div class="post-metadata">

**Author:** ![ayshih](https://dub1.discourse-cdn.com/flex005/user_avatar/community.openastronomy.org/ayshih/32/84_2.png) [@ayshih](https://community.openastronomy.org/u/ayshih)\
**Post date:** [November 8, 2021, 2:02pm UTC](https://community.openastronomy.org/t/distance-to-moon-inconsistent-results/217/2 "2021-11-08T14:02:51Z")

</div>

Although it is not noted in the docstring for `get_moon()`, that function returns the apparent position of the Moon as seen by the observer, which depends on the Moon-observer light travel time. (It is noted in [the docstring of `get_body()`](https://docs.astropy.org/en/stable/api/astropy.coordinates.get_body.html), which `get_moon()` calls.) Thus, `get_moon(t0, location=loc)` and `get_moon(t0)` actually refer to different locations, and the milliseconds of difference in light travel time likely accounts for the difference you are seeing because the Moon moves at ~29 km/s.

---

<div class="post-metadata">

**Author:** ![tammojan](https://dub1.discourse-cdn.com/flex005/user_avatar/community.openastronomy.org/tammojan/32/145_2.png) [@tammojan](https://community.openastronomy.org/u/tammojan)\
**Post date:** [November 9, 2021, 3:08pm UTC](https://community.openastronomy.org/t/distance-to-moon-inconsistent-results/217/3 "2021-11-09T15:08:41Z")

</div>

Thank you, that makes sense!

---

<div class="post-metadata">

**Author:** ![nealmcb](https://dub1.discourse-cdn.com/flex005/user_avatar/community.openastronomy.org/nealmcb/32/152_2.png) [@nealmcb](https://community.openastronomy.org/u/nealmcb)\
**Post date:** [January 4, 2022, 4:21am UTC](https://community.openastronomy.org/t/distance-to-moon-inconsistent-results/217/4 "2022-01-04T04:21:49Z")

</div>

Interesting - thanks folks!

It seems that this should be noted in the documentation.  
I made a PR to do so:

> <https://github.com/astropy/astropy/pull/12683>
>
> Add doc comment to get\_moon(), like the one for get\_body(), based on conversatio…n at
> https://community.openastronomy.org/t/distance-to-moon-inconsistent-results/217
> 
> \<!-- This comments are hidden when you submit the pull request,
> so you do not need to remove them! --\>
> 
> \<!-- Please be sure to check out our contributing guidelines,
> https://github.com/astropy/astropy/blob/master/CONTRIBUTING.md .
> Please be sure to check out our code of conduct,
> https://github.com/astropy/astropy/blob/master/CODE\_OF\_CONDUCT.md . --\>
> 
> \<!-- If you are new or need to be re-acquainted with Astropy
> contributing workflow, please see
> http://docs.astropy.org/en/latest/development/workflow/development\_workflow.html .
> There is even a practical example at
> https://docs.astropy.org/en/latest/development/workflow/git\_edit\_workflow\_examples.html#astropy-fix-example . --\>
> 
> \<!-- Astropy coding style guidelines can be found here:
> https://docs.astropy.org/en/latest/development/codeguide.html#coding-style-conventions
> Our testing infrastructure enforces to follow a subset of the PEP8 to be
> followed. You can check locally whether your changes have followed these by
> running the following command:
> 
> flake8 astropy --count --select=E101,W191,W291,W292,W293,W391,E111,E112,E113,E30,E502,E722,E901,E902,E999,F822,F823
> 
> \--\>
> 
> \<!-- Please just have a quick search on GitHub to see if a similar
> pull request has already been posted.
> We have old closed pull requests that might provide useful code or ideas
> that directly tie in with your pull request. --\>
> 
> \<!-- We have several automatic features that run when a pull request is open.
> They can appear daunting but do not worry because maintainers will help
> you navigate them, if necessary. --\>
> 
> \### Description
> \<!-- Provide a general description of what your pull request does.
> Complete the following sentence and add relevant details as you see fit. --\>
> 
> This pull request essentially copies a comment in get\_body() into
> get\_moon(), since it is relevant there also.
> It addresses a confusion highlighted by the conversation at
> https://community.openastronomy.org/t/distance-to-moon-inconsistent-results/217
> 
> Note: it may be the case that some other routines in solar\_system.py could use
> the same comment, but I didn't check very carefully.
> 
> \<!-- If the pull request closes any open issues you can add this.
> If you replace \<Issue Number\> with a number, GitHub will automatically link it.
> If this pull request is unrelated to any issues, please remove
> the following line. --\>
