Skip to content

Let IERS table used in time/coordinates determined by science state - #9244

Merged
mhvk merged 9 commits into
astropy:masterfrom
mhvk:iers-science-state
Oct 26, 2019
Merged

mhvk merged 9 commits into
astropy:masterfrom
mhvk:iers-science-state

Conversation

@mhvk

@mhvk mhvk commented Sep 16, 2019 •

Copy link
Copy Markdown
Contributor

Addresses the first item in #9227, that it would be good to allow users to determine what IERS table is used for all time and coordinate transformations in astropy (specifically, this is to help PINT use an up-to-date IERS-B file rather than IERS_Auto).

Here, this is done with a new iers.earth_rotation_table science state class, which is check in time and coordinates.

cc @aarchiba

EDIT: changed name to earth_rotation_table

@mhvk mhvk added this to the v4.0 milestone Sep 16, 2019
@mhvk
mhvk requested review from eteq and taldcroft September 16, 2019 21:18
@mhvk mhvk mentioned this pull request Sep 16, 2019
1 of 7 tasks
@mhvk
mhvk force-pushed the iers-science-state branch 2 times, most recently from 610d35a to 70c0cd2 Compare September 17, 2019 13:55
@aarchiba

Copy link
Copy Markdown
Contributor

Very nice! But what about the global variables iers.IERS.iers_table and friends? Those will by default evade the control of earth_rotation_table. They don't seem to be much used in astropy itself (apart from IERS_Auto's no-network fallback), but are we setting up users for an unpleasant surprise when they use them?

As it stands, they always have the value of "the last IERS table of this class that was opened". They are documented in the docstrings in iers.py. They make it awkward to obtain an IERS_Auto instance that isn't shared with anyone (you have to manually reset IERS_Auto.iers_table to None before and after your IERS_Auto.open()) - and if you don't, since IERS_Auto is mutable it can mutate under you if someone else requests a new value while you're working.

@mhvk

mhvk commented Sep 18, 2019

Copy link
Copy Markdown
Contributor Author

@aarchiba - very good points. Might it make most sense to deprecate cls.iers_table? When I wrote the initial IERS_A and IERS_B classes, the ScienceState class did not yet exist, and IERS_Auto has been pasted on a bit.

It would seem reasonably unlikely that anybody except PINT wants full control over the IERS tables, so I mostly want to be sure that we get it right for PINT!

@aarchiba

Copy link
Copy Markdown
Contributor

@aarchiba - very good points. Might it make most sense to deprecate cls.iers_table? When I wrote the initial IERS_A and IERS_B classes, the ScienceState class did not yet exist, and IERS_Auto has been pasted on a bit.

I do think those should disappear. Shame we can't (easily) make them properties that emit a DeprecationWarning when accessed... I can do the metaclass thing if you want, it does work. But maybe we just need to think through what users (if any) actually expect from these class attributes and only support that.

It would seem reasonably unlikely that anybody except PINT wants full control over the IERS tables, so I mostly want to be sure that we get it right for PINT!

I was thinking about this - if we could count on IERS_Auto to keep IERS B up to date, and if we could just look at the columns in it that carry untouched IERS B data, we could drop the keep-things-up-to-date code we now have. Of course, as long as we're supporting python 2 we also need to work with astropy 2.0, so this is a down-the-road consideration. But I'm not sure astropy actually needs separate auto-updating IERS A and B classes.

@bsipocz

bsipocz commented Sep 18, 2019 •

Copy link
Copy Markdown
Member

Of course, as long as we're supporting python 2 we also need to work with astropy 2.0, so this is a down-the-road consideration.

Not sure whether "we" is PINT or astropy here. If the latter, than we're approaching to the final drop of python2 super quickly, so no need to include that in any considerations.
And even if it's PINT, none of these fixes are milestoned to be backported to the astropy 2.0 branch, so that case will need to have a separate workaround downstream, I'm afraid.

@mhvk

mhvk commented Sep 18, 2019

Copy link
Copy Markdown
Contributor Author

@aarchiba - I think that updating IERS_B as part of IERS_Auto is definitely an option (or have an IERS_B_Auto. But better discussed as part of #9227.

As for deprecating cls.iers_table - nothing in astropy now relies on it, and it should not be too hard to implement (some combination of deprecated_attribute and classproperty should do the trick). But before doing that as part of this PR, I'd like some input from @taldcroft and @eteq.

@aarchiba

Copy link
Copy Markdown
Contributor

Of course, as long as we're supporting python 2 we also need to work with astropy 2.0, so this is a down-the-road consideration.

not sure whether "we" is PINT or astropy here. If the latter, than we're approaching to the final drop of python2 super quickly, so no need to include that in any considerations.

Sorry, yes, that was unclear. As I understand it, astropy's support of python2 is basically over; nothing since astropy 2.0 works on python2, and I don't expect this to make it in to that maintenance branch. So as long as PINT supports python2, it needs to work with that aging version of astropy.

PINT's support of python2 is under discussion, but a number of key pieces of pulsar software do not work on python3, including one by one of the PINT maintainers. (And of course they are awkward to compile and install, so users may delay upgrading them.) So there will be a desire for PINT to keep working with python2 for some time yet.

@mhvk

mhvk commented Oct 10, 2019

Copy link
Copy Markdown
Contributor Author

@eteq, @taldcroft - would you be able to review this new ScienceState for IERS? I think it is in good shape (code coverage failure is a red herring), but an outstanding question of whether to deprecate the caching done on the IERS classes proper. My own sense is that we can deprecate, but it is also totally fine to punt that to another issue/PR, and at least get this PR in.

@taldcroft taldcroft left a comment

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.

Looks generally good. I didn't know about ScienceState! I reviewed the parts relevant to time and left some minor comments.

Comment thread astropy/utils/iers/iers.py Outdated
return table


class earth_rotation_table(ScienceState):

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.

Might it be worth overriding the __repr__ so it does not try to print the whole IERS table? That isn't really helping out, and basically <ScienceState earth_rotation_table: IERS_A> is what users would want to see.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Good idea. Since for that it is by far the easiest to adjust ScienceState as well, let me also ping @astrofrog (@astrofrog, I changed it such that the context repr never is more than 1 line)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Comment thread astropy/utils/iers/iers.py Outdated
--------
To temporarily use the IERS-B file packaged with astropy:

>>> from astropy.utils import iers

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.

Don't these code blocks need to be indented with a leading ... packaged with astropy:: (two colons)? Or maybe I'm missing advances in sphinx/rst docs?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yes, I think those were not run the way I had it. Corrected...

assert allclose_sec(t._delta_ut1_utc, -0.58682110003124965)


@pytest.mark.skipif('not HAS_IERS_A')

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.

This diff is unfortunately not helpful, but I did a by-eye compare of the files for master and this branch. I'm just trying to make sure the existing test has not been changed substantively. You did change the way the delta and status values are computed. I think it's equivalent, but maybe life would be easier if you just left in the original two tests test_ut1_iers_A and test_ut1_iers_Auto and then add tests on top? This is finicky code so any time I see an existing test modified it rings bells.

I note that in the new do_ut1_prediction_test there is no check on the jd value being different for the non-context manager case.

    def test_ut1_iers_A(self):
        tnow = Time.now()
        iers_a = iers.IERS_A.open()
        tnow.delta_ut1_utc, status = iers_a.ut1_utc(tnow, return_status=True)
        assert status == iers.FROM_IERS_A_PREDICTION
        tnow_ut1_jd = tnow.ut1.jd
        assert tnow_ut1_jd != tnow.jd

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

OK, I reorganized the file so the diff is more obvious, and re-instated the .jd test (I had removed it since it is possible, at least in principle, that delta_ut1_utc equals 0. Though probably sufficiently unlikely that one might ignore that - much more likely something is wrong when the jd doesn't change...

@eteq eteq left a comment

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 like this pretty much as-is with just one change to suggest (and am approving on the theory that it is straightforward to implement): instead of earth_rotation_table it should be earth_orientation_table because it's not just rotation, these also have the polar motion and so on.

@mhvk

mhvk commented Oct 25, 2019

Copy link
Copy Markdown
Contributor Author

My logic was that IERS stands for "Earth Rotation (and Reference System)" and "orientation" misses the leap second aspect (while rotation does include wobbling...). But if you feel strongly, I will change; need to rebase anyway...

@eteq

eteq commented Oct 25, 2019

Copy link
Copy Markdown
Member

@mhvk - IERS the organization has rotation in its name, but (admittedly, rather inconsistently), the files from their authoritative source (https://datacenter.iers.org/eop.php) are called "Earth orientation parameters", so I think "orientation". I guess really do be really pedantic it could be earth_orientation_and_rotation_table, but I think "orientation" at least could be viewed as including rotation (while vice versa does not).

@eteq

eteq commented Oct 25, 2019

Copy link
Copy Markdown
Member

(So I guess that means I do feel strongly...)

@mhvk

mhvk commented Oct 25, 2019

Copy link
Copy Markdown
Contributor Author

Last try: why would rotation not include the wobbling of the axis? (Though if that doesn't convince you, I'll change it; I do not mind that much even if I could do without the work right now...)

@eteq

eteq commented Oct 25, 2019 •

Copy link
Copy Markdown
Member

@mhvk - to me "rotation" is only the Earth spinning on its axis, and any motion of the axis is "orientation" not "rotation". But I admit this is deep down the pedantic road...

(As a citation, I give https://en.wikipedia.org/wiki/Earth_orientation_parameters, but when I look at that it's still a bit ambiguous because it does say oreintation parameters are "irregularities in the rotation of the Earth"...)

@mhvk

mhvk commented Oct 25, 2019

Copy link
Copy Markdown
Contributor Author

I'll go for earth_orientation_table...

@astrofrog

Copy link
Copy Markdown
Member

Yeah orientation sounds reasonable to me (I can see arguments both ways but that'd be my choice if I had to pick a side)

@mhvk
mhvk force-pushed the iers-science-state branch from d35a45d to a0d2f27 Compare October 25, 2019 22:56
@mhvk

mhvk commented Oct 25, 2019

Copy link
Copy Markdown
Contributor Author

OK, changed to earth_orientation_table and rebased.

@bsipocz

bsipocz commented Oct 25, 2019

Copy link
Copy Markdown
Member

So is this a merge if CI passes then?

@mhvk
mhvk merged commit cfb1c2f into astropy:master Oct 26, 2019
@mhvk
mhvk deleted the iers-science-state branch November 19, 2019 22:05
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.

6 participants