Repository navigation
Improve get_body by using location of observer in light travel time correction - #10292
Conversation
mhvk
left a comment
There was a problem hiding this comment.
Looks good. Only one very minor quibble...
Also, a question of how to treat it. Your test_regression... makes it sound like you feel it is a bug fix. I agree. So, that would mean aiming for 4.0.2. Could you add a changelog entry for that release?
|
|
||
|
|
||
| def _get_apparent_body_position(body, time, ephemeris): | ||
| def _get_apparent_body_position(body, time, ephemeris, observer_loc): |
There was a problem hiding this comment.
I'd just call it obsgeoloc=None as you do in the non-private function (and add a default; even though this is private, it may be used and we might as well not break such uses)
| icrs_sun_from_geocentre = _get_apparent_body_position('sun', t, 'builtin', geocentre) | ||
|
|
||
| difference = (icrs_sun_from_alma - icrs_sun_from_geocentre).norm() | ||
| assert_quantity_allclose(difference, 0.13046941*u.m) |
There was a problem hiding this comment.
Ah, I just noticed the CI 32-bit failure is real - if you put, say atol=1*u.mm here, it should be OK.
mhvk
left a comment
There was a problem hiding this comment.
Thanks, @StuartLittlefair, it looks all good now -- in fact, get_body looks better than before! Merging...
|
Just letting you know. The Sun isn't a very good test for this. It's much better to use the Moon. I'm currently seeing +/-200 mas error in RA/Dec and +/-500 meters in distance over the course of a day using an older version of astropy. |
|
@mkbrewer - you're right, it would probably be good to have a test for the Moon. Might you be able to make a PR? Independently, thanks again for pointing out these problems! |
|
Since I haven't looked into your test procedures, I'm not sure what you would want. What I did was simply compare the Moon's position in RA/DEC, distance and Alt/Az in one minute intervals for 24 hours with my own solar system ephemeris program based on SOFA. I tested the output of my program for this period on the Moon against both Skyfield and JPL Horizons and got agreement to 0.5 mas in Declination, 1.5 mas in Right Ascension and 0.7 meters in distance against Horizons and similar results against Skyfield so long as I disabled polar motion. Skyfield seems to have a problem with that, but it's only about 12 mas in Declination and 4 meters in distance. As does SOFA, btw, but it only affects Alt/Az. That error is a rather huge at +/-1 arcsecond! (It affects astropy as well. If you are interested, please see the issue I opened on the Skyfield repository). Horizons also has an issue with apparent Right Ascension, being 53 mas off from SOFA. I pointed this out to them last June and, of course, they pointed their fingers at SOFA. At least they are now acknowledging the issue in their print out though. Of course, these errors are all very small compared to the errors I got testing the older version of astropy. I could certainly provide you with my test data and the script I used to generate the astropy data to compare against it if that would be helpful. |
|
@mkbrewer that would be fantastic, thank you! Perhaps open a new issue describing the Moon problems and provide the data there? |
|
I was just informing you of the issues you might have comparing astropy Moon data to Skyfield or Horizons. There may be a problem with polar motion in SOFA that affects astropy, but I'm still looking into that. I will certainly raise an issue on that if I determine that there is, in fact, a problem, but I'm not there yet. The file I attached contains a script for printing topocentric astrometric, apparent postions wrt the true equator and equinox, distance and alt/az that can be directly compared to equivalent Skyfield and Horizons output if you so choose. I also included the output from my program that you can compare to output from the script for astropy both before and after the modification in this merge to see how much of an improvement resulted from the change you made. I used the same EOPs (dut1,xp,yp) that astropy used on the test date in the script for the input to my program, so my data should be completely compatible with astropy in that respect. |
|
@StuartLittlefair please let me know if this works for you. |
|
Thanks @mkbrewer. This helped me a lot dig into what is happening. The short story is that with this PR, the astropy positions for the Moon are pretty damn good! For the long story, see below. I used @mkbrewer's scripts together with my additions in this PR to get the following: from astropy.time import Time
from astropy.coordinates import solar_system_ephemeris, EarthLocation, get_body, get_body_barycentric, SkyCoord
from astropy.coordinates.solar_system import _apparent_position_in_true_coordinates
# For comparison with JPL Horizons as this is what they use
solar_system_ephemeris.set('de430')
class_lat = -22.959748*u.deg
class_lon = -67.787260*u.deg
class_elev = 5186*u.m
class_loc = EarthLocation.from_geodetic(class_lon, class_lat, class_elev)
t = Time('2017-04-06 00:00', scale='utc')
moon_barycentric = _get_apparent_body_position('moon', t, 'de430',
class_loc.get_gcrs_posvel(t)[0])
obs = get_body_barycentric('earth', t, 'de430') + class_loc.get_gcrs_posvel(t)[0]
# ASTROMETRIC ICRF
SkyCoord(coord.GCRS(moon_barycentric - obs, obstime=t)).to_string(style='hmsdms')
'09h05m23.649s +15d36m28.9186s'c.f JPL Horizons "09 05 23.65 +15 36 28.9" and SkyField "09 05 23.64 +15 36 28.5" What about JPL's True Equator, True Equinox of date ("apparent") coordinates? Let's look at what the result of calling astropy's In [165]: _apparent_position_in_true_coordinates(get_body('moon', t, location=class_loc)).to_string(style='hmsdms')
Out[165]: '09h06m21.1377s +15d32m12.2391s'c.f JPL "09 06 21.13 +15 32 12.2" and SkyField "09 05 24.31 +15 36 25.3". You can see there is now excellent agreement with astropy and JPL Horizons for the moon! In fact, we're quite a bit more accurate than Skyfield for this one example. This also gives us confidence that implementing the transform between GCRS and TETE requested in #10230 will make it easier for people to use JPL Horizon query results within astropy and keep precision. |
|
Re: #10292 (comment) @StuartLittlefair , so are we expecting a follow-up PR to this? Or is this like a astropy-tutorial material? |
|
Very good news! And particularly nice that it works so well with what really is a small bug fix! Would be nice to have the Moon example as a test case and/or as an example for |
|
I think what I will do is work on #10230 when I get the time. Including lunar test cases and a tutorial about the different frames, how they relate and when to use each might fit well in a PR for that issue. |
|
Here are the comparisons I'm seeing from the coordinates that you posted with my own program based on SOFA, JPL Horizons and Skyfield. For my program, the astrometric positions are good to the uas level. The discrepancy in apparent positions is a bit perplexing. I am using the EOPs used by astropy 3.2.2 here. Could they be slightly different? The JPL results are slightly different due to the fact that they have their own set of EOPs, plus the 53 mas offset in apparent RA. Hint: When comparing with Horizons, it's best to choose decimal degrees for the output with "extra precision" checked. The Skyfield results do not include polar motion, so the discrepancy there is not surprising. @StuartLittlefair could you please run the script In the |
|
@pllim I was responding to @mhvk's request for a PR for testing on the Moon.
Since I don't know how to submit a PR for tests, that file |
|
@mkbrewer , to be credited properly for your contribution, it is still best for you to submit the PR yourself. Perhaps you might find https://docs.astropy.org/en/latest/development/workflow/development_workflow.html useful. Thanks! |
|
One possibility for the discrepancy in apparent position between astropy and my program is the issue with gravitational light deflection #10291 which I see is still open. |
|
I doubt it. For the example I looked at it made a negligible difference. Is there a reason you don’t want to upgrade astropy btw? Not saying you should but there may other bug fixes you are missing. I’ll post your example run on astropy dev as soon as I can. Lots to do and it’s early evening my time. |
|
Hi @mkbrewer I've attached the full output from your code to this post. Here's a snippet. First the file of positions from your SOFA program that you attached above: And what we get on astropy master: Note that amongst the differences between my version and yours are discrepancies in LST and UTC-UT1. Here's the output from the JPL web form for comparison: The astropy coordinates I get are 0.5 mas (astrometric) and 52 mas (apparent) different from JPL. |
|
Thank You. That is very helpful. Here my results: The average difference in DUT1 is 250 ns, so that is negligible. The difference in LST is due to the polar motion correction to longitude from equation (6.20) in USNO Circular 179. I am deriving my LST from equation (6.19) there. The hour angles are supposed to be the same and SOFA doesn't appear to add that correction to the local earth rotation angle, so I added it to LST. This is still under investigation on my part, so I'm not sure it is correct yet. In any case, it has no effect on anything else as I'm not using LST in any of my calculations. The discrepancy in apparent position is quite evident. @StuartLittlefair, you say that you looked at an example after correcting the light deflection problem then? By "negligible", do you mean much less than the 2.5 mas I'm seeing? If so, this could be due to the less than rigorous way that SOFA handles diurnal aberration when transforming from CIRS to observed. I am still investigating this and will post further comments about that under issue #10230. There is a bit of noise in your distance calculation which could very well be due to the 1.0e-8 seconds (3 meters at the speed of light) that you are iterating down to. There is a fairly large discrepancy in Alt/Az, I believe that this is due to some inconsistency regarding polar motion, but I'm still investigating that. This data will be very helpful in that regard. As you can see, this test against the Moon is very good for finding small problems. I will look into converting it into a pass/fail test that I could submit as a PR if I have the time. I'm more interested in actually solving the problems I see, rather than getting credit for a PR containing this test though, so it won't be a high priority for me. In the meantime, if one of you experts want to go ahead and implement this as a test, please feel free to use my script and data to do so. |
|
On second thought, the discrepancy in apparent position is unlikely to be due to diurnal aberration as it's not diurnal. Instead there is gradient that appears to be related to the Moon's position wrt the Earth. This makes light deflection a better candidate for this discrepancy. |
|
Thanks for the sleuthing! And thanks for cross-posting at #10291 - indeed, let's move further discussion there since people will not easily find it here. |
|
@StuartLittlefair — Could you share the Skyfield code that you used to generate the coordinates that do not quite match the other libraries? I just wrote a script to see the results myself and try fixing Skyfield: But, alas, the output — at least here on my laptop — agrees perfectly with the HORIZONS output and Astropy output that you quote above: To be more exact: Skyfield here agrees most closely with AstroPy, while we both dissent very slightly from the HORIZONS result with respect to the arcseconds of the apparent RA, where HORIZONS has 21.13 but both Skyfield and AstroPy prefer 21.14. If you’ll share your code, I'll be happy to improve Skyfield's docs to better help programmers avoid whatever snag your code ran into that hurt its accuracy. Thanks! |
|
@brandon-rhodes do you have an alert for mentions of Skyfield ;) Thanks very much for following up... You code matches mine exactly apart from the following differences:
I suspect the last one explains most of the difference, since the astrometric coordinates are very close. The use of |
Alas, I do not! That’s not a bad idea, though. In this case it was an issue opened by @mkbrewer that mentioned a similar effort to reach agreement between his library and Astropy that led me to cross-reference with his issues over here. I’m glad you found the docs clear! All I will do, then, is try to make sure that my example code is rigorous in using of-date RA and dec every time it calls |
Make low-accuracy results like those mentioned in astropy/astropy#10292 less likely by consistently asking for epoch-of-date coordinates every time `apparent()` coordinates are generated. And add exactly such an example to the docstring of the `radec()` call itself, since that is where users are likely to look.
|
As you’ll see in the commit just mentioned, upon review I think some blame might be placed on Skyfield’s Instead of showing how to use So instead I’ve pivoted the |
Improve get_body by using location of observer in light travel time correction
Improve get_body by using location of observer in light travel time correction
Improve get_body by using location of observer in light travel time correction




Description
There are a series of issues raised to help improve the utility of the coordinates package for solar system objects. These include #10271, #10239, #10230, #10291 and #9362. This is a minor PR to solve the least of those issues - a correct treatment of light travel time for non-geocentric observers.
This is a very minor correction (around 0.1m for the ICRS location of the Sun in the test example!), but also a very small change to the code.
Fixes #10271