Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Implement auto-downloading of IERS-A data - #4436

Merged
taldcroft merged 10 commits into
astropy:masterfrom
taldcroft:iers-cache
May 16, 2016
Merged

taldcroft merged 10 commits into
astropy:masterfrom
taldcroft:iers-cache

Conversation

@taldcroft

Copy link
Copy Markdown
Member

This is a candidate implementation to resolve #3275.

I'm putting this up prior to writing tests or even having it pass existing tests because it may be controversial. πŸ˜„ I've been thinking about this over the last week and have started at least four different versions. The trick is maintaining possibly strict back-compatible behavior (for the minority with this requirement) while introducing a default, SIMPLE behavior that just works for the majority. I find the existing IERS a bit confusing because of all the options that are supported.

The key is defaulting to auto-downloading and using IERS-A when required, by use of a new class IERS_Auto. The exact caching mechanism is TBD, but as mentioned we know in advance exactly when the source file is updated, so it is a really easy problem in this case. In this implementation I just put in a config var that specifies how old the cached file can be. Don't worry about this bit. However, I will say that I thought about fine-tuned optimizations like @mhvk suggested in #3275 and in the end rejected them as just too complicated. I think it's better to have a simple scheme that can be explained and understood by users and developers in a sentence or two.

What is more important is automatically using IERS-A via the IERS_Auto class in Time and Coordinates. This means that when a user first requires IERS values the file will always get downloaded. Supplying an IERS-A file with astropy is a bit pointless because it will always get superceded very shortly.

The auto-download behavior can be fully reverted to the current 1.1 behavior by setting a config var astropy.utils.data.iers.conf.auto_download to False (default = True). Users that require the legacy strict IERS-B can do this.

Another important idea: the IERS_Auto class is exempted from range checking because it is assured of having the most recent available data. This means the (possibly-clipped) interpolation is always within the confidence bounds of current Earth rotation knowledge. For actual use cases in astronomy (particularly observation planning) everything just works as well as it can given our best knowledge of Earth rotation. All the adhoc workarounds currently suggested would go away.

Of course the downside is that (in the default behavoir) reproducibility to numerical precision would go away. But someone would be free to write a script with auto-download disabled and thus get reproducible behavior. And in all cases reproducibility to within confidence limits of Earth rotation parameters would not be affected.

@taldcroft

Copy link
Copy Markdown
Member Author

cc: @embray @eteq

@taldcroft

Copy link
Copy Markdown
Member Author

And of course this needs to smoothly handle the case where the network turns out to be unavailable. First, use a timeout for the initial download of IERS-A. If this times out, then fall through to the standard IERS-B with a warning. (Note that in this case any extrapolation will generate an exception). Likewise if the currently cached IERS-A is too old and then the subsequent download of IERS-A fails, also fall through to IERS-B with a warning (which would also say how old the current file is).

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I don't understand why a separate class instead of a new argument to the existing class's open method.

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.

I did think about that. My first issue is that the IERS class is already pretty confusing to me, so adding an option that completely changes the behavior (and in fact the class of the output) of open() is just too much.

The other problem that convinced me a new class is the best way is that all of the existing options to IERS.open() are moot in this case. Thus you would need to raise an exception if any args or kwargs besides the auto_update option were provided. That just seems like a bad API.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Yeah, I thought that might be your thinking, and that makes sense.

If it were possible I would change the existing hierarchy such that there's some hidden _IERSBase class that is the same as the current IERS class, and what you're calling IERS_Auto would become just IERS. I wonder if it isn't too late to make that change since direct use of IERS isn't particularly advertised in the docs.

@embray

embray commented Jan 6, 2016

Copy link
Copy Markdown
Member

I still feel like if someone wanted to tackle #3961 that would make this mostly moot, but this is simpler for now...

@taldcroft

Copy link
Copy Markdown
Member Author

I still feel like if someone wanted to tackle #3961 that would make this mostly moot, but this is simpler for now...

The caching is the easy part of this, and if someone does #3961 then that will be quickly inserted in here.

The hard part (conceptually) is plugging a new default behavior deep into Time and Coordinates without screwing things up, while allowing for back-compatibility.

@taldcroft

Copy link
Copy Markdown
Member Author

One more thing is that it wouldn't be too hard to have "on-demand" downloading which is triggered by actually trying to do a conversion that is in a time range where newer data would help. The exact algorithm for this would depend on details of the IERS bulletin files. This tighter coupling is not ideal, but on the whole probably worth doing to prevent unnecessary network access.

@taldcroft taldcroft changed the title WIP on a new way of using IERS data in astropy Implement auto-downloading of IERS-A data Apr 29, 2016
@taldcroft

taldcroft commented May 1, 2016

Copy link
Copy Markdown
Member Author

@mhvk @eteq - I have done a bunch of work on the auto-download of IERS data and I think this is getting very close. This PR is based on #4810 because it won't work without that.

I know this is not going to be entirely straightforward to review, but please plan to carve out some time in advance of the code freeze. Some of the logic behind the behavior is a bit intricate, but I've tried to be fairly verbose in the code comments.

Some known issues:

  • Lots of coordinates fails due to trying to connect to the internet. We need to think about this.
  • I was getting one doc build warning that I did not understand.
  • The doc section on Auto-refresh behavior is not finished.

Comment thread docs/utils/iers.rst Outdated
@@ -0,0 +1,165 @@
.. _utils:

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@taldcroft , if you are talking about .../utils/index.rst:5: WARNING: duplicate label utils, other instance in .../utils/iers.rst Sphinx warning, it means that this label has been used. Change it to something more unique like .. _utils-iers: would fix the warning. Of course, you also have to change any references to this particular label (but not the other conflicting one).

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.

@pllim - thanks! I got sidetracked about the error it was reporting and usually expect Sphinx messages to be misleading or useless. In this case though I should have been able to see it.

@taldcroft

Copy link
Copy Markdown
Member Author

OK, now something strange has come up. It looks like the IERS-B values that are supplied in the finals2000A.all file (http://maia.usno.navy.mil/ser7/finals2000A.all) do not match corresponding values from the actual IERS-B file (http://hpiers.obspm.fr/iers/eop/eopc04/eopc04_IAU2000.62-now). For instance in the table below columns 2 and 3 are from IERS-B, while column 4 (UT1_UTC_B_finals) is from the UT1_UTC_B column of the IERS-A file. The last column delta is the difference. As you can see the delta value can be up to 5 times larger than then stated error on UT1-UTC, i.e. 18 microsec vs. 3.4 microsec.

In [41]: iers_b_ok
Out[41]: 
<IERS_B length=7>
  MJD    UT1_UTC  e_UT1_UTC UT1_UTC_B_finals       delta       
   d        s         s            s                 s         
float64  float64   float64      float64           float64      
------- --------- --------- ---------------- ------------------
53747.0 0.3335044  1.03e-05         0.333506 -1.60000000005e-06
53748.0 0.3337777   3.4e-06         0.333768            9.7e-06
53749.0 0.3339995   6.3e-06         0.334007 -7.49999999999e-06
53750.0 0.3340951   7.4e-06         0.334111          -1.59e-05
53751.0 0.3340757   5.5e-06         0.334096          -2.03e-05
53752.0 0.3339359   3.4e-06         0.333954          -1.81e-05
53753.0 0.3336386   1.4e-06         0.333636  2.60000000002e-06

This came up in regression testing.

724   >>> import astropy.units as u
725   >>> t = Time('2006-01-15 21:24:37.5', format='iso', scale='utc',
726   ...          location=(-155.933222*u.deg, 19.48125*u.deg), precision=6)
727   >>> t.utc.iso
728   '2006-01-15 21:24:37.500000'
729   >>> t.ut1.iso
Expected:
    '2006-01-15 21:24:37.834078'
Got:
    '2006-01-15 21:24:37.834098'

@mhvk

mhvk commented May 10, 2016

Copy link
Copy Markdown
Contributor

Yikes, that is not good at all! Though now that you mention it, I vaguely recall that I saw that the two columns were not identical before (it is already strange that they have different number of significant digits, though the errors you find are clearly larger than this). There may be errors in initial versions of IERS B that are corrected but not propagated to IERS A. Sigh.

@taldcroft

Copy link
Copy Markdown
Member Author

So who is right? It's easy enough to use the actual available IERS-B values (that are bundled with astropy) in IERS_Auto.

@mhvk

mhvk commented May 10, 2016

Copy link
Copy Markdown
Contributor

IERS B is supposed to have final values.

@taldcroft

taldcroft commented May 10, 2016

Copy link
Copy Markdown
Member Author

@mhvk - see 09c02a6 for a patch. Ugh. (Skipped tests because a doctest now appears to be wanting remote data even though this addition should not have affected that. So something else to track down...).

# radec_actual = ra=3.3094193224314625 deg, dec=15.183757021354532 deg
# distance = 2.6285 arcsec
assert distance < 5 * u.arcsec
assert distance < 10 * u.arcsec

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.

Did this get worse? That seems very strange!

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Yeah, I'm also confused by this. I just tried a merge of this branch locally and found that 5 still works just fine...?

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.

This was probably due to the iers-b issue. I agree it should be possible to revert this change.

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.

Actually this is still a problem. @eteq - maybe you ran tests without --remote-data (which falls back to the IERS-B values)?

I think the source of difference is that with IERS_Auto you get the last available values for UT1-UTC instead of zero (for out-of-range IERS-B). That gives a time diff of 0.6 sec, which can mean up to 0.6 * 15 arcsec.

Looking at the testing for AltAz, I wonder if the discrepancies are related to time diffs?

Anyway, I propose that changing to the original 5 arcsec tolerance to 10 arcsec should be OK now that we understand it.

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.

OK, that sounds good. When you change the line, could you add a comment to remind us?

@mhvk

mhvk commented May 11, 2016

Copy link
Copy Markdown
Contributor

@taldcroft - I've started looking at this. Overall, it looks good, though I want to think a bit more whether it isn't possible to make more minimal changes to IERS itself, keeping additions mostly within the IERS_Auto class.

One annoyance: now that IERS_A turns out not to have correct IERS_B values, shouldn't we auto-update IERS_B too?!

@eteq

eteq commented May 12, 2016

Copy link
Copy Markdown
Member

OK, I have some inkling of what's going on here: if you look at http://datacenter.iers.org/web/guest/eop you can see the original sources of the IERS_B files. There you'll see the curious fact that the official IERS B bulletin and the one that eopc04_IAU2000.62-now comes from also don't agree (although well within the errors). This is probably a smoothing effect because the whole thing comes from fitting models that depend on the data, so the small variations are probably due to wiggling polynomials and the like. I suspect the same holds for UT1-UTC.

The finals2000A file says it's updated weekly. But the bulletin B is updated on different periods and the "real" underlying bulletin A is updated at yet a different time. So my hunch is that sometimes they're not consistent because one has not been updated when the other has, and there's some wiggle room.

That's a long way of saying: the B bulletin is probably always more right. It's also unclear where/when finals2000A gets their B values anyway, so what's done here is probably the best choice.

@eteq

eteq commented May 12, 2016

Copy link
Copy Markdown
Member

Oh, and one related note (not particularly critical here but could be fixed at the same time): @mhvk, is there a specific reason for getting IERS B from http://hpiers.obspm.fr/iers/eop/eopc04/eopc04_IAU2000.62-now instead of http://datacenter.iers.org/eop/-/somos/5Rgv/latest/214 ? The latter seem more "official" but hard to know...

@pllim

pllim commented May 13, 2016

Copy link
Copy Markdown
Member

You might see something similar to #4896 with --remote-data.

@mhvk

mhvk commented May 13, 2016

Copy link
Copy Markdown
Contributor

@taldcroft - I think not extrapolating is better (or setting to 0 -- it really doesn't matter and we do warn!). And yes, let's make time_now private.

@eteq

eteq commented May 13, 2016

Copy link
Copy Markdown
Member

I think setting to 0 is bad because it makes a sudden discontinuity in just-off-the-edge. But I'm fine either way with extrapolating or not (i.e., +0 to leaving it like current master).

@taldcroft

Copy link
Copy Markdown
Member Author

Extrapolating over long time scales would be bad (just imagine PM_x at JD=10000), and using the last value is closest for small extrapolations:
image

@eteq

eteq commented May 13, 2016

Copy link
Copy Markdown
Member

Good point re: long time scales. I'm convinced (just make sure to add a quick note about that in API changes, is this is a small but possibly important change for anyone who actually cares about it)

@taldcroft

Copy link
Copy Markdown
Member Author

@eteq @mhvk - I think I have addressed all the comments in the last 6 commits. I have to step away for dinner but will rebase and squash a bit after that.

@eteq

eteq commented May 16, 2016

Copy link
Copy Markdown
Member

@taldcroft - still needs a changelog entry (including my suggestion of an "API change" mention for the changed extrapolation), but maybe you meant to do that post-rebase. With that, looks pretty solid!

@taldcroft

taldcroft commented May 16, 2016

Copy link
Copy Markdown
Member Author

@eteq - yes, I had forgotten about the changelog, but compensated now by putting in 4 separate entries!

Rebased version pushed. The commit in 274a10a might be controversial. I discovered that the hor2eq AltAz comparisons were failing again with --remote-data, and badly for the no-atmosphere case. So I actually just ran hor2eq on our CfA network (fortunately have IDL and it just ran out of the box) for a more reasonable date, namely 2000-01-01, where definitive Earth rotation values are available. These did not match at the ~5 arcsec level. At this time I noticed that if I set the time scale of obstime to UT1 then the original tests (< 5 arcsec and < 0.4 arcsec) were passing for both --remote-data and not.

So I can't say exactly what is going on here (just too long working on this), except that I think that previously the tests were "accidentally" passing by virtue of effectively zeroing out delta_ut1_utc for the 2041 test date.

@eteq

eteq commented May 16, 2016

Copy link
Copy Markdown
Member

Huh, strange about the hor2eq business. But I wouldn't worry too much - I noticed this in the "todo" section of hor2eq:

Difference between UTC and UT1 in determining LAST -- is this important?****

So my hunch is that hor2eq is implicitly assuming UTC=UT1, and that's why it worked in the 2041 case, just as you said. So I think what you've done here is just fine.

If the tests pass, I say we merge!

@eteq eteq mentioned this pull request May 16, 2016
14 tasks
taldcroft added 10 commits May 16, 2016 07:19
Make IERS-A consistent with B and fix issue with table behaviors [skip ci]
WIP on IERS caching [skip ci]
Abstract out checking of interpolation indices to a method [skip ci]
Intermediate commit, rebase later [skip ci]
Add in logic for updating based on predictive times
Mostly functional version with tests
Add test IERS-A files
Catch error downloading new IERS file
Skip a doctest and make sure IERS table URL matches
Remove IERS_HINT which no longer applies
Add sanity check when extending IERS table
Update documentation
Get more tests passing

Improve docs

Fix some tests and whitespace cleanup
@taldcroft
taldcroft merged commit 170c4b6 into astropy:master May 16, 2016
@taldcroft
taldcroft deleted the iers-cache branch May 16, 2016 12:49
@eteq

eteq commented May 16, 2016

Copy link
Copy Markdown
Member

πŸŽ†

eteq pushed a commit that referenced this pull request May 16, 2016
Implement auto-downloading of IERS data
@eteq

eteq commented May 16, 2016

Copy link
Copy Markdown
Member

backported to 1.2.x in 7048693

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.

Automatic download of IERS A table for times not covered by IERS B

5 participants