Repository navigation
Speed up EarthLocation.get_gcrs - #11073
Conversation
|
This speed up is amazing! In that call to I am very pleased that you have come around to adding this additional method to the I don't think your calculation of the velocity in the target frame is unclear, in fact, I think it is quite innovative With this change, we should revisit the intermediate rotation transforms for CIRS and TETE as this new method makes the helper function that you added there superfluous. |
|
There does seem to be a slight issue here though: |
|
One odd thing is that in |
|
In |
|
@mkbrewer - I made a private method somewhat on purpose, as I think it helps separating getting the speed-up from how to expose a more flexible In an ideal world, I feel we should not need any of these methods as the transformation machinery itself would be fast enough; from that perspective, keeping everything in Anyway, let's do the speed-up first! |
|
The failure is very puzzling: I can understand a difference in |
|
Then in the TETE<->GCRS transforms, we could simply have: |
|
Hmm, I cannot reproduce that locally. I suspect the output is fairly old, and the position already did not match, but is OK for float comparison, while the velocity now changed a little (probably for the better...) and is triggering the failure. |
|
As you noticed, the JPL based example is much closer, even though of course |
|
How about trying it using the JPL ephemeris then? If you do, please time it for both the master and this PR. |
|
OK, I updated the docs with the new values (which are within tolerance). As for timings with JPL: So, speed-up is very similar (since time was dominated by |
|
Hmm, I thought the JPL lookups would be quite a bit faster than the built in calculations. Perhaps, it's just the overhead associated with file I/O which would be mitigated for an array of times. Since this results in a slight change in position, I'd appreciate it if you could run this script and post the output: I haven't converted apparent position to use the TETE frame there, but you are welcome to do that. |
|
Whoops, wrong script. |
|
Thanks. I'll compare this output to my program. |
|
Woo-Hoo! Everything is now dead on to one digit in the last decimal place in RA/Dec and Alt (3.6 uas) and the maximum offset in Az is 3 decimal places (10.8 uas). |
|
For the most part the distance is good to 1 mm. There are just a few samples that are off by 1.5 - 2 mm. |
|
I'd need to add another decimal place to my output to see any real difference here. |
|
@mkbrewer - for a proper comparison, I wondered if one should transform to |
|
Yeah, I said that you were welcome to do that. I just wasn't real sure of myself on the proper syntax is all. I profiled the conversion from GCRS to AltAz: Looks like most of the time was spent in |
|
No problem! Here's the output (just in case: code is missing the import of TETE). |
|
Here are three sets of plots. Astropy_10994-11073_Comparison.pdf The first in each set is from the last data that I got from you. This was from PR #10994 before the CIRS attributes were changed from GCRS position and velocity to There is still a very small residual in RA/Dec. This is entirely in the astrometric position as the apparent position tracks it exactly. To me, the second set of plots is the most interesting. This is the residual in the distance to the Moon. The ~+/-2 cm oscillation and the jumps seen previously are gone. Since all of the samples include the same number of ephemeris lookups, the variation in distance with time of observation from the ephemeris should be smooth. This implies that the oscillation and jumps were somehow associated with The way that I calculate light time delay is quite different. I do the ephemeris lookups sequentially in time using the light time delay for each time as the starting guess for the next time. In this way, the light time delay stays very well converged throughout the set of observation times so that there is no drift within an acceptance window. |
| itrs_to_gcrs = ref_to_gcrs @ matrix_transpose(ref_to_itrs) | ||
| # Earth's rotation vector in the ref frame is rot_vec_ref = (0,0,OMEGA_EARTH), | ||
| # so in GCRS it is rot_vec_gcrs[..., 2] @ OMEGA_EARTH. | ||
| rot_vec_gcrs = CartesianRepresentation(ref_to_gcrs[..., 2] * OMEGA_EARTH, |
There was a problem hiding this comment.
this is particularly neat, and like all great things, obvious in retrospect!
|
This is beautiful. The speed up is one thing, but the fact that we have narrowed down the remaining discrepancies with @mkbrewer's code to the FiniteDifferenceTransform's poor precision in velocity is particularly pleasing. Given that, I have 1 minor request before merging, which is to tighten the tolerances in They're currently set to 0.5mas, but the plots @mkbrewer added clearly show we are doing better than that. I'd suggest reducing them to 0.002 mas, which should prevent anyone making changes that degrade our precision down the road. Perhaps we can also add a target distance of 376252883.247 meters as well? This value is taken from MKB's code and I this PR shows agreement to 11 mm, so perhaps a tolerance of 15mm is appropriate. |
|
Here's the latest from my program with one extra digit of precision. |
|
Yes, good point; I tightened the tests, using the new numbers as well. Also slightly rewrote the test to compare the numbers directly (but then added |
|
(codecov failure is unrelated) |
|
Somehow, it squeaked by. I see a residual of 2.16 uas in azimuth for that point. |
|
Thanks @mhvk. Happy to merge this now unless you think we should wait for others to check it over. |
|
Oh, and that 15 mm tolerance for distance is a bit wide. The actual actual maximum residual is 1.3 mm. |
|
Checking numbers: So maybe 2 uas is OK and for distance we can use 2 mm (which is about 1uas * distance). I'll still change the latter. |
495714f to
5dc87d3
Compare
|
In it went - thanks, @mkbrewer and @StuartLittlefair! |
|
That's odd. Here's what I have from the file you posted. |
|
Perhaps we are down to the point where round off introduces a bit of random noise. |
|
One difference is that in the test case, the observer's location gets passed in already in |
|
@mhvk @StuartLittlefair This is a followup regarding the improved accuracy of this PR. While working with Brandon Rhodes on polar motion, we discovered that the remaining issue that was causing the residual in ICRS RA/Dec to be +/-0.2 mas and the residual in moon distance to be +/-40 cm was that he is using the IERS 2010 ellipsoid rather than the WGS-84 ellipsoid that my site coordinates are referred to. After using a bit of a hack to redefine his ellipsoid as WGS-84, these remaining residuals went away. I then noticed that the noise in the moon distance was +/-1 mm again just as it was for this PR. This led me to realize that the noise was originating on my side. I was using the method to build two part dates recommended in MKB-Astropy_11073_Comparison.pdf Most of the remaining residual is due to the need for yet another decimal place in the Astropy output! Here also is the new comparison of my program with the latest version (still a work in progress) of Skyfield after hacking it to use the WGS-84 ellipsoid: MKB-Skyfield_WGS84_Comparison.pdf Most of the remaining residual there is due the fact that neither my program nor Astropy currently supports deflection of light due to the gravitational field of the Earth itself (see issue #10843). |
|
Fantastic!!! (And am happy to run the tests again with different precision...) |
|
OK. If you are willing, this is one decimal above machine precision. |
|
Here's the output: |
|
@mhvk Thanks for posting that. It led me to yet another subtle bug in my program that led to ~40 ns of round off jitter in my times. After correcting that, here are the new plots: MKB-Astropy_11073_Comparison.pdf The average residuals are now 61 nas (yes, nano-arcseconds) in ICRS RA, 29 nas in ICRS Dec, 66 nas in Apparent RA, 31 nas in Apparent Dec, 5 nas in Azimuth, 0.2 nas in Elevation and 28 microns in distance. Here are new target values for 2017-04-06 00:00:00 UTC from my program: Although, you might as well use your own. |
|
Wow!! Of course, we're now both so similar in part because (I think) we use the same SOFA/ERFA routines. I'm starting on comparisons with CALC11 - ignoring ocean loading for now (which I didn't know was a thing until a week ago...). I adjusted the test - realizing that at first it failed because I had not included the location in the time object (and this matters slightly for transformation to other time scales...). See #11103. |
|
Hi all, I've been eagerly following these developments, as I'm in the process of switching to Astropy for our radio interferometer delays within the katpoint package. I'm also continuously comparing against CALC11 and trying to squeeze out the maximum reasonable precision. @mhvk, you would probably be interested in https://gitlab.com/ska-telescope/almacalc/. It's not quite ready for wider release (for one, the license and copyright are probably wrong) but you are welcome to give it a spin 😄 And I would very much like to compare notes. |

Now that we have a faster method for calculating
obsgeolocandobsgeovelfrom anEarthLocation, there was no reason not to use it insideEarthLocationas well. The speed up is dramatic (see below). This partially addresses #11072.Note that with this change, the new
include_velocityargument introduced toget_itrs()is no longer used. I thought it made most sense to just revert it, as I think we still have larger decisions to make on how to deal with storing a location.It also changes the calculation slightly (see in-line comment); if it is felt this makes the code too unclear, I can revert that commit.
cc @mkbrewer
EDIT: also