Skip to content

Add Local Earth Rotation Angle. Adjust sidereal time for the TIO.#11680

Merged
mhvk merged 14 commits intoastropy:mainfrom
mkbrewer:issue-10239-eral
Jun 20, 2021
Merged

Add Local Earth Rotation Angle. Adjust sidereal time for the TIO.#11680
mhvk merged 14 commits intoastropy:mainfrom
mkbrewer:issue-10239-eral

Conversation

@mkbrewer
Copy link
Copy Markdown
Contributor

@mkbrewer mkbrewer commented May 1, 2021

Description

This pull request is to address my request in issue #10239 for the Local Earth Rotation Angle (eral). It also corrects the local sidereal time for the TIO in models that include it. My preference would be to also change the meaning of greenwich to be the angle at the TIO (i.e. GMST, GAST, or ERA), but I don't think @mhvk would go along with that.

Fixes #10239

@pep8speaks
Copy link
Copy Markdown

pep8speaks commented May 1, 2021

Hello @mkbrewer 👋! It looks like you've made some changes in your pull request, so I've checked the code again for style.

There are no PEP8 style issues with this pull request - thanks! 🎉

Comment last updated at 2021-05-22 22:38:01 UTC

@github-actions github-actions bot added the time label May 1, 2021
@pllim pllim added this to the v5.0 milestone May 1, 2021
@mkbrewer
Copy link
Copy Markdown
Contributor Author

mkbrewer commented May 1, 2021

The sidereal time checks will likely fail due to the addition of the TIO, which amounts to around 500 ns. In fact, this is much less than the ~30 us uncertainty in DUT1 though. I've also not added any checks for the Local Earth Rotation Angle. I am unable to do this as I can't actually run Astropy on my computer, so I'll leave this to others.

@mkbrewer
Copy link
Copy Markdown
Contributor Author

mkbrewer commented May 1, 2021

I have no idea what this is all about:

/home/docs/checkouts/readthedocs.org/user_builds/astropy/envs/11680/lib/python3.8/site-packages/astropy/time/core.py:docstring of astropy.time.core.Time.to_local:9: WARNING: py:obj reference target not found: Earth
/home/docs/checkouts/readthedocs.org/user_builds/astropy/envs/11680/lib/python3.8/site-packages/astropy/time/core.py:docstring of astropy.time.core.Time.to_local:9: WARNING: py:obj reference target not found: rotation
.
.
.

@mkbrewer
Copy link
Copy Markdown
Contributor Author

mkbrewer commented May 1, 2021

Yay! I figured it out.

Copy link
Copy Markdown
Contributor

@mhvk mhvk left a comment

Choose a reason for hiding this comment

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

@mkbrewer - thanks so much for the PR! I had a quick look and see some parts that should fail - did you try it out yourself? Or am I wrong?

Regardless, we will need some tests that check the code works as expected (in astropy/time/tests/test_sidereal.py and perhaps also astropy/time/tests/test_precision.py). Also, we'd need to describe the new method in the documentation, probably easiest in the section about sidereal time, https://docs.astropy.org/en/latest/time/index.html#sidereal-time (which corresponds to docs/time/index.rst). I'm happy to help with both.

I note in-line that a lot of the code duplicates what we just added to erfa_astrom.apio - ideally, we just have it in one place. Though I think it is best to first just get everything working properly.

@mhvk mhvk force-pushed the issue-10239-eral branch from 717c61b to ec68e6f Compare May 8, 2021 02:00
@mhvk
Copy link
Copy Markdown
Contributor

mhvk commented May 8, 2021

@mkbrewer - I've gone ahead and made sure the code ran and added some tests and documentation.

Looking at the code again, I also realized sidereal_time could trivially do the required calculation as long as I added a new entry in SIDEREAL_TIME_MODELS - I think that is simpler, and has the advantage that if someone looks at the docstring of sidereal_time, they will also be pointed to the existence of earth_rotation_angle (I did keep that method, since I think it is well worth having a simple shortcut for which one has to put in no extra arguments except a possible longitude).

But of course, this means you now better review my contributions!

@mhvk
Copy link
Copy Markdown
Contributor

mhvk commented May 8, 2021

On your comment on top:

My preference would be to also change the meaning of greenwich to be the angle at the TIO (i.e. GMST, GAST, or ERA)

I agree we should provide a way to just get the angle out without the _to_local method. I think re-using 'greenwich' for that is a bit strange, but might 'tio' make sense? Or perhaps False?

p.s. This reminds me that nominally a string should be an observatory, and we now have EarthLocation.of_site, so really that should be done too...

@mkbrewer
Copy link
Copy Markdown
Contributor Author

mkbrewer commented May 8, 2021

@mhvk I'm afraid that I must disagree with this re-implementation. Just because something can be done, that doesn't mean that it should be done. Sidereal time and Earth rotation angle are different beasties. Allowing the return of Earth rotation angle through the call of a public method called sidereal_time just isn't right.

Furthermore, while sidereal time is a general term which can be taken to mean either Greenwich sidereal time or local sidereal time, Earth rotation angle specifically refers to the angle between the CIO and the TIO. As currently written, the method now called earth_rotation_angle always returns the local Earth rotation angle and never the Earth rotation angle itself. As you say, this could be mitigated by accepting the argument 'tio' (in place of 'greenwich') to return the actual Earth rotation angle rather than the local Earth rotation angle.

My argument for interpreting the string 'greenwich' to mean Greenwich sidereal time in the sidereal_time method is that it is very likely that users are expecting Greenwich sidereal time when they use this argument already. In fact, 0 longitude isn't even the longitude of the Royal Observatory Greenwich, which is given as -0.001475 in sites.json for the EarthLocation 'greenwich'.

It might be a good idea to accept an EarthLocation object in the longitude arguments for both sidereal_time and earth_rotation_angle in addition to a longitude, None or the strings 'greenwich' in the case of sidereal_time or 'tio' in the case of earth_rotation_angle. That way, if someone actually wants the local sidereal time or local Earth rotation angle at Greenwich, they can just use the argument EarthLocation.of_site('greenwich'). This would also be consistent with usage in the solar system method get_body, which uses this approach.

@mhvk
Copy link
Copy Markdown
Contributor

mhvk commented May 8, 2021

OK, that's fair. I'll revert allowing 'era' in sidereal_time proper but will factor out the code in common.

@mkbrewer
Copy link
Copy Markdown
Contributor Author

mkbrewer commented May 8, 2021

Oh, one more thing. There is apparently an exception that can occur in getattr(time, scale) that is handled in get_jd12(). If that is the case, this should also be handled in _erfa_sidereal_time().

@mhvk
Copy link
Copy Markdown
Contributor

mhvk commented May 8, 2021

Just to be sure that I understand your suggestion: is it that 'greenwich' will mean just return the output of era00, gmst.., etc., i.e., not to apply the TIO locator at all, or just not to apply the polar motion correction?

The former I think is fine, since it means that there is no change from before; the latter probably is OK too.

I also like your idea of just allowing one to pass in an EarthLocation - in the method there really isn't that much sense to allow arbitrary strings for observatories, since normally the Time should just be initialized with the correct location.

@mhvk
Copy link
Copy Markdown
Contributor

mhvk commented May 8, 2021

On the exception catching in get_jd12 - this is specifically for a time out of range of the IERS table. For sidereal time, so far my tendency has been that the user should take some explicit action if they are happy with times that are off by up to 1s. My tendency would be to do the same for ERA (at least let's do that for this PR; in my revised version, all erfa functions are called the same way).

@mkbrewer
Copy link
Copy Markdown
Contributor Author

mkbrewer commented May 8, 2021

Just to be sure that I understand your suggestion: is it that 'greenwich' will mean just return the output of era00, gmst.., etc., i.e., not to apply the TIO locator at all

Correct. These are mathematical quantities that are useful for use in other equations by users.

@mkbrewer
Copy link
Copy Markdown
Contributor Author

mkbrewer commented May 8, 2021

I guess what you're saying is that you'd prefer that the exception not be handled. If so, that's fine.

@mhvk
Copy link
Copy Markdown
Contributor

mhvk commented May 8, 2021

OK, that means that for 'greenwich', the answer will not change from what it was before. That seems good!

@mkbrewer
Copy link
Copy Markdown
Contributor Author

mkbrewer commented May 8, 2021

Seems good to me also. Doing otherwise would break code that expects Greenwich sidereal time.

@mhvk mhvk force-pushed the issue-10239-eral branch from 635188b to 05b9203 Compare May 8, 2021 18:23
@mhvk
Copy link
Copy Markdown
Contributor

mhvk commented May 8, 2021

OK, I now also allow EarthLocation input, and 'greenwich' and 'tio' mean ignore the locator. I only mention 'tio' for earth_rotation_angle - here, of course we have real freedom, so let me know if you think this is not a useful marker.

@mhvk
Copy link
Copy Markdown
Contributor

mhvk commented May 8, 2021

Failure seems unrelated - see #11717

@mkbrewer
Copy link
Copy Markdown
Contributor Author

mkbrewer commented May 8, 2021

OK, I now also allow EarthLocation input, and 'greenwich' and 'tio' mean ignore the locator. I only mention 'tio' for earth_rotation_angle - here, of course we have real freedom, so let me know if you think this is not a useful marker.

Oh, I forgot to address this. I think it is fine, desirable in fact, to allow both 'greenwich' and 'tio' for Greenwich sidereal time. That way, those who like consistency can use 'tio' for both Greenwich sidereal time and Earth rotation angle, while the change won't break anything for users who are using 'greenwich' currently.

@mkbrewer
Copy link
Copy Markdown
Contributor Author

mkbrewer commented May 22, 2021

@mhvk @taldcroft In this comment: #11680 (comment) I was asked to catch all strings other than tio and greenwich. I did that, but it seems that a string is also valid in Longitude, which caused this to fail:

1162   >>> t.sidereal_time('apparent', '-90d')  # doctest: +FLOAT_CMP +REMOTE_DATA
UNEXPECTED EXCEPTION: ValueError('Invalid longitude string')
Traceback (most recent call last):
  File "/opt/hostedtoolcache/Python/3.7.10/x64/lib/python3.7/doctest.py", line 1337, in __run
    compileflags, 1), test.globs)
  File "<doctest index.rst[148]>", line 1, in <module>
  File "/home/runner/work/astropy/astropy/.tox/py37-test-devdeps/lib/python3.7/site-packages/astropy/time/core.py", line 1904, in sidereal_time
    raise ValueError("Invalid longitude string")
ValueError: Invalid longitude string

How should this be resolved?

@mhvk mhvk force-pushed the issue-10239-eral branch from e00a150 to 17e72e2 Compare May 22, 2021 16:20
@mhvk
Copy link
Copy Markdown
Contributor

mhvk commented May 22, 2021

@mkbrewer - as you see, I just reverted that change. @taldcroft's request was logical but clearly neither he nor I realized at that moment that strings were actually generally allowed as input!

@mkbrewer
Copy link
Copy Markdown
Contributor Author

Thanks.

@mkbrewer
Copy link
Copy Markdown
Contributor Author

@taldcroft Might you be able to give me an estimate of when you will have the time to take a look at this? If so, I'll look back then rather than checking hourly to see if there has been an update.

@mkbrewer
Copy link
Copy Markdown
Contributor Author

mkbrewer commented Jun 2, 2021

@mhvk @taldcroft Has this PR somehow fallen by the wayside? I addressed all of the comments and I'd like to be done with this.

@mhvk
Copy link
Copy Markdown
Contributor

mhvk commented Jun 2, 2021

@taldcroft - would you have time to look at this Earth Rotation Angle PR again? I think your (good) comments were all addressed, but would rather not dismiss your "request for changes" without you having another look.

@mkbrewer
Copy link
Copy Markdown
Contributor Author

@mhvk It's now been a month since @taldcroft 's initial review and still no followup. How long must we wait?

@mhvk
Copy link
Copy Markdown
Contributor

mhvk commented Jun 19, 2021

@mkbrewer - let's get it in by the end of the week - I do think it is all OK. (Of course it doesn't really matter in the larger scheme, as it will only get in 5.0, which will be the Fall, but I do similarly like to have things properly off my plate!).

Copy link
Copy Markdown
Member

@taldcroft taldcroft left a comment

Choose a reason for hiding this comment

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

LGTM.

@mhvk
Copy link
Copy Markdown
Contributor

mhvk commented Jun 20, 2021

OK, let's get it in! Thanks, @mkbrewer, that was a nice collaboration!

@mhvk mhvk merged commit f7282a1 into astropy:main Jun 20, 2021
string 'greenwich' or 'tio', the result will be relative to longitude
0 for models before 2000, and relative to the Terrestrial Intermediate
Origin (TIO) for later ones (i.e., the output of the relevant ERFA
function that calculates greenwich sidereal time).
Copy link
Copy Markdown
Member

@maxnoe maxnoe Jun 20, 2021

Choose a reason for hiding this comment

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

I think this should mention that if a plain number is passed, it is assumed to be degrees, which I think is a bit surprising, as plain numbers are usually interpreted as radians, right?

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.

It is really for backward compatibility for sidereal_time - if I had written this now I would have insisted on a unit (and plain Longitude input does). So, my sense is not to advertise it.

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.

Wouldn't we allow to change this as this targets 5.0? It seems like a good change to me to require a unit

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.

Not quite sure whether it is worth it, but I guess we could indeed have a DeprecationWarning starting in 5.0.

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.

I'm a bit confused by this. The documentation used to say:

            The longitude on the Earth at which to compute the sidereal time.
            Can be given as a `~astropy.units.Quantity` with angular units
            (or an `~astropy.coordinates.Angle` or
            `~astropy.coordinates.Longitude`)

In fact, as we found out, one can also use a string (e.g. '10.2345d'). I'm not sure why this was dropped, but the code hasn't changed in that respect. Isn't the Longitude constructor intelligent enough to convert all of these to degrees if given another angular unit?

Copy link
Copy Markdown
Contributor Author

@mkbrewer mkbrewer Jun 20, 2021

Choose a reason for hiding this comment

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

Oh, I think I understand. Although this is not mentioned, one can also use a float as the argument, in which case it is assumed to be degrees. I agree with @maxnoe on this. We should have mentioned that in the documentation. Too bad he didn't bring this up a bit earlier. In some respect, I don't think it matters much though. People don't usually specify the longitude of an observatory in radians anyway. And, if they did, they would soon find out that the result would be incorrect.

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.

Yes, I guess it should have been "or anything that can initialize a Longitude" - the fact that float is also allowed is extra (because we give a default unit of u.deg in the initializer). The question is whether it is worth doing a quick follow-up PR that deprecates that behaviour (and perhaps clarifies the docstring).

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.

I'll leave that entirely up to you. Obviously, sidereal_time() has been around for awhile, so any confusion will only affect new users and people who have been using it for years may not appreciate depreciation warnings, but if you feel strongly that a unit should be specified, then go ahead and require one.

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.

@mkbrewer I didn't habe a look at this earlier because I only noticed this PR because the corresponding issue Was closed by merging it ;)

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.

And I am very happy to have it closed after being open for over a year!

@mkbrewer mkbrewer deleted the issue-10239-eral branch June 20, 2021 21:02
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.

Requesting local earth rotation angle and one additional built-in frame

6 participants