Skip to content

Implement framework for observed hour angle-declination transforms. - #11676

Merged
mhvk merged 10 commits into
astropy:mainfrom
mkbrewer:issue-10239-hadec
May 21, 2021
Merged

mhvk merged 10 commits into
astropy:mainfrom
mkbrewer:issue-10239-hadec

Conversation

@mkbrewer

@mkbrewer mkbrewer commented Apr 30, 2021 •

Copy link
Copy Markdown
Contributor

Description

This pull request is to address my request in issue #10239 for an observed Hour Angle/Declination frame to complement the AltAz frame. It's been a year now since I made this request and nothing has come of it, so I felt that it was necessary to take matters into my own hands. I have included a few basic tests here. Since the code is basically the same as that for AltAz, I don't think it is necessary to test for accuracy other than these. I did need to change the name of one existing test: test_icrs_consistency() to test_icrs_altaz_consistency(). I'm sure that there is likely to be some "glue" that I have neglected here and could use some help with that. I have made no attempt at amending the documentation as I wouldn't know where to begin with that. Also, I neglected to add [skip ci] to my commit message. Sorry about that.

@pep8speaks

pep8speaks commented Apr 30, 2021 •

Copy link
Copy Markdown

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-20 23:41:13 UTC

@github-actions github-actions Bot left a comment

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.

Welcome to Astropy 👋 and congratulations on your first pull request! 🎉

A project member will respond to you as soon as possible; in the meantime, please have a look over the Checklist for Contributed Code and make sure you've addressed as many of the questions there as possible.

If you feel that this pull request has not been responded to in a timely manner, please leave a comment mentioning our software support engineer @embray, or send a message directly to the development mailing list. If the issue is urgent or sensitive in nature (e.g., a security vulnerability) please send an e-mail directly to the private e-mail [email protected].

@mhvk mhvk left a comment

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.

This PR looks very good. I think the repeated tests probably cover most cases, but I wouldn't mind one or two simple tests that explicitly show that for some inputs, the HA and Dec are as expected (could be observing something near Spring equinox and showing that sources with RA12 are at HA0 at mightnight, and that their Dec is close.

Also, I think some documentation would be good - though I'm not 100% sure where it would be best.

Comment thread astropy/coordinates/tests/test_intermediate_transformations.py Outdated
Comment thread astropy/coordinates/builtin_frames/cirs_observed_transforms.py Outdated
Comment thread astropy/coordinates/tests/test_intermediate_transformations.py Outdated
@StuartLittlefair

Copy link
Copy Markdown
Contributor

I just want to say that I will get round to reviewing this ASAP, but I am under a lot of work pressure until May 15th, so probably not before then.

@mkbrewer

mkbrewer commented May 7, 2021

Copy link
Copy Markdown
Contributor Author

Regarding tests for accuracy, my point is that these would be redundant. For instance, if test_aa_high_precision() passes, then it can be guaranteed that the corresponding test for HADec would also pass, should I create it. This is because both AltAz and HADec are derived from the same vector in atioq().

Comment thread astropy/coordinates/builtin_frames/cirs_observed_transforms.py Outdated
@mhvk
mhvk force-pushed the issue-10239-hadec branch from 710045d to 5a7936d Compare May 7, 2021 19:07
@mhvk

mhvk commented May 7, 2021

Copy link
Copy Markdown
Contributor

@mkbrewer - OK, I rebased to get rid of the merge conflicts and made the simplification I suggested. I also took the liberty to squash the multiple smaller commits. Locally, the tests pass, and on second thought I agree with you that there is not much point in separate precision tests.

What still would be good, I think, is to have at least a simple example somewhere in the documentation, like

In [1]: from astropy import units as u

In [2]: from astropy.coordinates import EarthLocation, SkyCoord, HADec

In [3]: from astropy.time import Time

In [4]: el = EarthLocation.of_site('keck')

In [5]: t = Time('2010-03-21T10:00:00')

In [6]: sc = SkyCoord(12*u.hourangle, 10*u.deg)

In [7]: hadec = HADec(obstime=t, location=el)

In [8]: sc.transform_to(hadec)
Out[8]: 
<SkyCoord (HADec: obstime=2010-03-21T10:00:00.000, location=(-5464487.81759887, -2492806.59108569, 2151240.19451846) m, pressure=0.0 hPa, temperature=0.0 deg_C, relative_humidity=0.0, obswl=1.0 micron): (ha, dec) in deg
    (353.19976268, 9.93902734)>

(where I verified the result with the veritable skycalc)

Comment thread astropy/coordinates/builtin_frames/hadec.py Outdated
@mkbrewer

mkbrewer commented May 7, 2021

Copy link
Copy Markdown
Contributor Author

Regarding documentation, can you handle that? I can't find any similar example for either AltAz or TETE anywhere in the docs directory, so I wouldn't know where to start.

@mhvk

mhvk commented May 7, 2021

Copy link
Copy Markdown
Contributor

@mkbrewer - hmm, you're right, it is actually far from obvious where a simple example about how to use HADec (or AltAz for that matter) would go in the documentation. I do see that the list of frames available in, e.g., https://docs.astropy.org/en/latest/coordinates/skycoord.html is quite out of date. So, let me (1) cc @eteq, @adrn for possible suggestions; and (2) suggest that perhaps we should leave this to a separate issue that is maybe more specifically about the various frames and their uses (which I'll raise if the others agree).

I think otherwise this PR is in very good shape, though ideally @StuartLittlefair has a look as well (@StuartLittlefair - the addition is actually as simple as @mkbrewer had promised it would be).

Comment thread docs/changes/coordinates/11676.feature.rst Outdated
@mhvk

mhvk commented May 17, 2021

Copy link
Copy Markdown
Contributor

@StuartLittlefair - would you have some time to review this HADec implementation?

@StuartLittlefair StuartLittlefair left a comment •

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.

Thanks so much @mkbrewer and @mhvk.

As you promised @mkbrewer the fix here is very straightforward and nicely implemented. I'm really sorry we didn't get round to implementing it, and that review took me so long.

I've got no issues with the code here at all, but I think what we are missing is a single test that a conversion into the new HaDec frame gives the "right" answer.

I don't think an explicit test of the HaDec results is necessary - the transform code is well tested by the AltAz tests and I think that any silly changes to the codebase would break the round-tripping that is tested. We'll just have to be careful to implement such a test if anyone ever splits the AltAz and HaDec transforms - perhaps if we ever move away from erfa, for example.

I've approved this PR, so it could be merged, but there's a very minor tweak to the what's new entry that I'd like if @mkbrewer approves

Comment thread docs/changes/coordinates/11676.feature.rst
assert_allclose(hd1.dec, hd2.dec)
assert_allclose(hd1.ha, hd2.ha)
assert_allclose(hd1.dec, hd3.dec)
assert_allclose(hd1.ha, hd3.ha)

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.

@mkbrewer - to address @StuartLittlefair's larger comment, I'd suggest to here also check the numerical values of one of these three, just to ensure we do not later do something silly that makes, e.g., HADec be just an alias for AltAz (as is, I think all the tests would pass if one were to do that!).

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'll go ahead and create a precision test.

@mkbrewer

Copy link
Copy Markdown
Contributor Author

OK. I've added a test. I'm likely to be tangled up in units though. Does ha need to be converted to u.hourangle somehow? Will allclose() work with the tolerance set to u.uas? Unfortunately, I have no way of testing this myself.

@mhvk

mhvk commented May 20, 2021

Copy link
Copy Markdown
Contributor

@mkbrewer - yes, with units those things should "Just work"! The changes look good, and I'll get this in once the tests pass. Thanks again!

@mhvk mhvk added the zzz 💤 merge-when-ci-passes Do not use: We have auto-merge option now. label May 20, 2021
@mhvk

mhvk commented May 20, 2021

Copy link
Copy Markdown
Contributor

Sadly the new test fails...

@mhvk mhvk removed the zzz 💤 merge-when-ci-passes Do not use: We have auto-merge option now. label May 20, 2021
@mhvk

mhvk commented May 20, 2021

Copy link
Copy Markdown
Contributor

OK, it is just a different wrapping of ha. I guess that brings up the question of whether HA should be between -12 and 12 hours, or between 0 and 24...

@mhvk
mhvk force-pushed the issue-10239-hadec branch from 1ba4af4 to 4551c62 Compare May 20, 2021 22:53
@mhvk

mhvk commented May 20, 2021

Copy link
Copy Markdown
Contributor

OK, I pushed a fix, and also added a test that does not rely on remote data - using the "overhead" test so that the answers are known to be right by inspection. Will merge if tests now pass.

@mhvk mhvk added the zzz 💤 merge-when-ci-passes Do not use: We have auto-merge option now. label May 20, 2021
@mkbrewer

Copy link
Copy Markdown
Contributor Author

@mhvk Hour angle always ranges from -12 to +12.

@mhvk

mhvk commented May 20, 2021

Copy link
Copy Markdown
Contributor

Yes, I felt that made more sense, but that is not what your HADec class does.... I'll push an update.

Plus a small name change to make a test more logical.
@mkbrewer

Copy link
Copy Markdown
Contributor Author

That's odd. Both atioq() and ae2hd() return the result of atan2(). This should always lie between -pi and pi.

@mhvk

mhvk commented May 21, 2021

Copy link
Copy Markdown
Contributor

@mkbrewer - the problem is that the [Unit]SphericalRepresentation class uses a Longitude for which the default wrap angle is 360 degrees. I now fixed it following what is done in SkyOffsetFrame - but I'll raise another issue that we should make this more flexible - see #11767.

Anyway, I think the current fix is the best we can do without a more general solution... And since tests pass, I'll merge it. Thanks again!

@mhvk
mhvk merged commit 7f242bc into astropy:main May 21, 2021
@mkbrewer
mkbrewer deleted the issue-10239-hadec branch May 21, 2021 00:25
@dhomeier dhomeier mentioned this pull request Aug 17, 2021
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.

5 participants