Repository navigation
fixed bugs in get_sun - #4952
Conversation
| earth_v = earth_pv_bary[..., 1, :] | ||
|
|
||
| # convert barycentric velocity to units of c | ||
| earth_v = (earth_v*u.au/u.d).to(u.m/u.s)/c |
There was a problem hiding this comment.
I normally try to use quantities throughout, but since we're connecting with erfa here, Ithink the following might be clearer:
# convert barycentric velocity to units of c, but keep as array for passing in to erfa
earth_v /= c.to(u.au/u.d).value
|
Very puzzling about the tests passing by hand vs on travis. Might there be some astrometric state that gets set up in running previous tests that actually adds a wrong path? cc @eteq |
|
Forget the tests passing by hand; this was confusion on my part about which version of astropy I had installed. You should be able to see an updated version of the comment above but if not - the test failures are caused by the GCRS-ICRS conversion behaving oddly for coordinates very near the Sun. Perhaps this is due to asymmetric handling of light deflection? |
|
On this PR in a larger scope: Since the previous routine was clearly wrong, and since answers will therefore change anyway, how about just making |
|
Set milestone to 1.2 at first, but then realised this affects 1.0 too. Obviously, for 1.0.10 we cannot use @eteq: what do you think? |
|
How about making this PR use the same code as the default implementation in your PR? This PR could then be back ported as a bug fix. In your PR you could then make get_sun into an alias for the routines in solar_system.py. The bug in older versions would get fixed but the results wouldn't suddenly change across versions. Did I get that right? |
|
Yes, makes sense. |
|
@StuartLittlefair - the light deflection should operate exactly the same for the different routes, as it's the same underlying ERFA function. But that doesn't mean it actually is... Or maybe some part of the transform graph is now sending it through some frame that results in it being inverted (which is not the same)? Will try to investigate that ASAP. @mhvk - I very much disagree that |
|
Wait, I'm confused about the "your implementation". Is that a reference to something in #4920 ? |
|
Looking into it, i think we are just pushing the limits of the atciqz and aticq algorithms in erfa. Round trip calculations for directions pointing straight at the sun don't work using these algorithms, but atic13 and atci13 do. These routines are 10 times slower though! Maybe I can come up with a quick test to see if the accurate routines need to be used. |
|
@eteq no, that's not it. Using the more accurate routines doesn't seem to help much. |
|
OK - I don't know why I keep going round in circles on this but I think using |
|
OK. After fairly extensive testing I now understand that this is caused by the light deflection routine in erfa The following snippet shows this: In [1]: from astropy.coordinates.builtin_frames.utils import get_jd12
In [2]: from astropy.time import Time
In [3]: from astropy import _erfa as erfa
In [4]: import numpy as np
In [5]: pv = np.array([[0,0,0], [0,0,0]])
In [6]: t = Time("2014-06-25T00:00")
In [7]: jd1, jd2 = get_jd12(t, 'tdb')
In [8]: astrom = erfa.apcs13(jd1, jd2, pv)
In [9]: icrs_ra, icrs_dec = 1.6313043965326768, 0.40839069815051204
In [10]: gcrs_ra, gcrs_dec = erfa.atciqz(icrs_ra, icrs_dec, astrom)
In [11]: icrs_ra_return, icrs_dec_return = erfa.aticq(gcrs_ra, gcrs_dec, astrom)
In [12]: coo = coord.SkyCoord(icrs_ra, icrs_dec, unit='rad')
In [13]: coo_return = coord.SkyCoord(icrs_ra_return, icrs_dec_return, unit='rad')
In [14]: coo.separation(coo_return).to(u.arcsec)
Out[14]: <Angle 62.246915327364164 arcsec>There is a mechanism in In the latest commits I have relaxed this parameter in Note that I did not re-write |
|
@StuartLittlefair - great that you found the origin of the problem. Just so I understand: given that we look exactly at the centre of the Sun, light deflection should be zero. Is the problem is that the code currently gets fed a coordinate which is not exactly zero, and therefore calculates a light deflection that is far too large? Also, more for practical purposes: I don't really like the idea of changing |
|
The problem is slightly more subtle than that. Basically, the routine The routine However, the output of To get round this issue, In 1.2 we will still have this issue. Although the coordinates returned by |
|
Since I share your caution about changing ERFA I've checked that C code using the SOFA library gives the same bug (it does). I've also contacted SOFA with details of this PR to see if they believe it is a bug that needs fixing and if they approve of the change I've made. |
|
@StuartLittlefair - Thanks for investigating this - the meat of this looks good to me. I am a bit uneasy about changing But be sure to make a PR against https://github.com/liberfa/erfa that replicates this behavior. That's the "official" copy of ERFA, so if you don't include it there it will be removed from Astropy the next time there's an ERFA update to Astropy. And we definitely don't want a "special Astropy" version of ERFA. |
|
Oh, but just to be clear: the fixes that do not include the ERFA modifications are the most important fixes to get in that area clearly bugs (rather than debatable "features", given that the light deflection thing is still right going in one direction). Am I understanding right that the erfa changes are only for that one test, @StuartLittlefair ? If so, it could be we should merge only the first part of this now (and relax the tolerance on the |
|
@eteq - that's right. The erfa changes are only necessary for that one test. We could change the object for the Also, an alternative to changing erfa itself would be to create our own versions of |
|
@StuartLittlefair - oh, good point re: making our own |
|
I just merged #4979, so fine to rebase on master now. |
…n calculations for directions closer than 90 arcsecs to solar centre
…ore relaxed light deflection by sun
|
Alright, tests are passing (the coverage decrease is in another subpackage so not a real issue). Merging now - thanks @StuartLittlefair! P.S. re: @mhvk's
My tentative plan is to move the python-wrapping stuff (probably as a separate |
|
@eteq - does this need a changelog entry? Or is it affects-dev? (in the latter case it should be given that label). |
fixed second set of bugs in get_sun
|
Good catch, @astrofrog - it does indeed need a changelog entry. Added to master in a48ea34, and 1.2.x in 34eb2fa |
@mhvk spotted a discrepancy between the coordinates reported by
get_sunand the JPL ephemerides in #4920.This discrepancy is predominantly caused by using the incorrect units for velocity in the call to
erfa.ab. In addition, the velocity had an incorrect sign and should have been the barycentric, not heliocentric velocity.The routine now returns positions accurate to ~0.15 arcsec and 100 km compared to the JPL ephemerides, over the time range CE 1950 to 2050.
One problem I haven't been able to understand is that these changes cause the tests to fail at this function.
I think the failure is something to do with the GCRS-ICRS transforms. For other bodies, the roundtrip GCRS-ICRS-GCRS ends back where it started. For the Sun it does not; however I'm not sure why. This test is now failing because the position returned by
get_sunis now close enough to the Sun to fall foul of this.