Skip to content

Units issue with FK4 transforms with and without e terms - #4293

Merged
mhvk merged 2 commits into
astropy:masterfrom
mhvk:abberation-e-terms
Aug 24, 2016
Merged

mhvk merged 2 commits into
astropy:masterfrom
mhvk:abberation-e-terms

Conversation

@mhvk

@mhvk mhvk commented Jul 24, 2016

Copy link
Copy Markdown
Contributor

Mostly to @eteq: in the process of looking at trying to make coordinates fully shaped, I encountered the fk4_to_fk4_no_e transformation (and its inverse) and realised there surely is a units problem in https://github.com/astropy/astropy/blob/master/astropy/coordinates/builtin_frames/fk4.py#L173

r = r - eterms_a.reshape(3, 1) + np.dot(eterms_a, r) * r

Here, as written, r has units of length since it comes from fk4coord.cartesian.xyz, but eterms_a has units of degrees, since it just multiplies the constant of abberation k (which is given as a number that is in degrees, though it is the ratio of the speed of the earth to the speed of light, so is really a unit-less number), with eccentricity e (why converted to radians?) and some cosines and sines. I think what really should have happened here is to have r divided by d_orig so that it contains dimensionless direction cosines, but is this true?

My suggestion would be to write fk4_e_terms using units, and also use units throughout, so we're sure that what is being done is correct.

(Separately, the normalisation distances do not take into account the possibility of multiple coordinates, but that I can solve trivially if I understand how the above equation is supposed to work.)

@astrofrog

Copy link
Copy Markdown
Member

Huh, I thought that we had this right since the coordinates benchmarks were giving good results. This reminds me, we should run those benchmarks again! (and consider automating the process)

@astrofrog

Copy link
Copy Markdown
Member

I'm surprised - we have accuracy tests against AST here with a tolerance of 10µas - but if the units really are so wrong above, I'm surprised we agree this well! It would be great if someone could dig into this further.

@mhvk

mhvk commented Nov 18, 2015

Copy link
Copy Markdown
Contributor Author

@astrofrog - note that there are two errors, one in that r is not properly normalized, and one that k has degrees rather than radians as a unit. The former will only affect coordinates with an actual distance -- if most tests are with coordinates on the unit sphere, then those will be fine. The unit of k seems more surprising...

@mhvk

mhvk commented Dec 4, 2015

Copy link
Copy Markdown
Contributor Author

@eteq - while you're on coordinates again, could you have a look at this issue? I'm fairly convinced there is a bug -- in particular in the units of the constant of aberration -- but as @astrofrog notes, it is odd that it would pass all the benchmarks and comparisons (unless of course others are making the same mistake...)

@eteq

eteq commented Dec 4, 2015

Copy link
Copy Markdown
Member

Everything @mhvk has said seems right to me... But I confess I don't really understand the E-terms very well - I think @astrofrog or maybe @adrn actually wrote it? It was definitely prior to Quantity, so that's why the units aren't used there. (I know "git blame" says it was me, but that's from various layers of re-organization...)

@eteq eteq added this to the v1.1.1 milestone Dec 4, 2015
@eteq

eteq commented Dec 4, 2015

Copy link
Copy Markdown
Member

And re: the degree/radians question: is it possible that it's just that the terms are small enough that even magnified by a factor of 360/2pi, they're close enough?

@eteq eteq modified the milestones: v1.0.8, v1.1.1 Dec 4, 2015
@mhvk

mhvk commented Dec 30, 2015

Copy link
Copy Markdown
Contributor Author

Looking over old issues/PRs: I checked the suggestion of @eteq that perhaps the changes introduced by treating k as radians while it was meant to be in degrees were too small to be noticed. Unfortunately, this is not true: test_fk4_no_e_fk4.py and test_galactic_fk4.py fail if I convert k to radians (independent of whether I normalise r properly; curiously, test_fk4_no_e_fk5.py works without problem). Could it be that AST does it wrong as well?

@mhvk

mhvk commented Dec 30, 2015

Copy link
Copy Markdown
Contributor Author

@embray embray modified the milestones: v1.0.8, v1.0.9 Jan 7, 2016
@eteq

eteq commented Mar 10, 2016

Copy link
Copy Markdown
Member

@astrofrog, do you have any insight on this from your recent asv/coordinate-benchmark fiddlings?

@eteq eteq modified the milestones: v1.0.10, v1.0.9 Mar 10, 2016
@astrofrog

Copy link
Copy Markdown
Member

@eteq - not yet, I haven't had much of a chance to dig into this yet.

@mhvk

mhvk commented Jul 24, 2016

Copy link
Copy Markdown
Contributor Author

@eteq, @astrofrog - looking with fresh eyes after a long time at this FK4 e-terms issue, I see that previous results were mostly correct because two errors compensated each other: while the unit of the constant of aberration was inconsistently taken to be in radians, the eccentricity of the earth's orbit was inconsistently taken to be in degrees. Since only the product of the two enters, the final answer was correct. Anyway, I now made the simplest possible correction (still without explicitly using units), and also ensured that the normalisation of distances was done correctly. Please have a look.

p.s. Since the normalisation was a bug that could have affected coordinates with non-unit distances, I'll add a note to the changelog.

@mhvk

mhvk commented Jul 24, 2016

Copy link
Copy Markdown
Contributor Author

@StuartLittlefair - just realised that since you fixed some aberration issues earlier, you might also be a logical one to have a look at this PR.

"""
# Constant of aberration at J2000
k = 0.0056932
k = 0.0056932 # in degrees (v_earth/c ~ 1e-4 rad ~ 0.0057 deg)

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.

For a source, we could cite Explanatory Supplement to the Astronomical Almanac (Seidelmann, 2005) which gives this exact value on p171.

@StuartLittlefair

Copy link
Copy Markdown
Contributor

@mhvk this looks right to me.

As a double check I tested the implementation here against the transformations on pp170 of Explanatory Supplement to the Astronomical Almanac (Seidelmann, 2005) which is an independent test of sorts since his formulae work directly on the ra and dec properties whilst the astropy routine transforms the CartesianRepresentation . The two methods agree so I think this is 👍

I include my test below as a separate comment in case you want to add as a regression test...

@StuartLittlefair

StuartLittlefair commented Jul 25, 2016 •

Copy link
Copy Markdown
Contributor

Here's my test:

from astropy import coordinates as coord, units as u
from astropy.tests.helper import assert_quantity_allclose as assert_allclose

fk4 = coord.FK4(10.00039633*u.deg, 40.99492542*u.deg) # M31
equinox = fk4.equinox

Dc = -0.065838*u.arcsec
Dd = 0.35299*u.arcsec
# obliquity of Earth's orbit, B1950, radians
o = 0.40920613517217536

fk4noe_dec = fk4.dec - (Dd*np.cos(fk4.ra) - Dc*np.sin(fk4.ra))*np.sin(fk4.dec) -Dc*np.tan(o)*np.cos(fk4.dec)
fk4noe_ra = fk4.ra - (Dc*np.cos(fk4.ra) + Dd*np.sin(fk4.ra))/(np.cos(fk4.dec)) 

fk4noe = fk4.transform_to(coord.FK4NoETerms)
assert_allclose(fk4noe.ra, fk4noe_ra, rtol=5e-7)
assert_allclose(fk4noe.dec, fk4noe_dec)

@astrofrog

Copy link
Copy Markdown
Member

We should make sure we update the coordinates-benchmark after this.

@mhvk

mhvk commented Jul 27, 2016

Copy link
Copy Markdown
Contributor Author

@StuartLittlefair - thanks! I added the test. @eteq, @astrofrog, or @adrn - could you please check that the normalisation in the distances is now done correctly? The original equation was clearly wrong, but I'm not sure that my "correction" is OK, since it effectively assumes large distance.

@mhvk
mhvk force-pushed the abberation-e-terms branch from 3f32634 to 17b243d Compare August 11, 2016 13:50
@mhvk

mhvk commented Aug 11, 2016

Copy link
Copy Markdown
Contributor Author

I rebased to get rid of the unrelated failures from a new scipy version. I also looked up the explanatory supplement to convince myself that any conversion from FK4 involving e-terms is assumed to be on the unit sphere, which means that the current code should be correct. @eteq, @astrofrog, or @adrn - would you please do a final check?

@bsipocz

bsipocz commented Aug 16, 2016 •

Copy link
Copy Markdown
Member

Could someone change the milestone? 1.0.10 is already released. (Or maybe the friendly astropybot does check it, too?)

(There are also two other unclosed issues in the milestone, ideally those should be moved on as well.)

@mhvk
mhvk force-pushed the abberation-e-terms branch from 17b243d to 0a4e838 Compare August 16, 2016 13:53
@mhvk mhvk modified the milestones: v1.0.11, v1.0.10 Aug 16, 2016
@mhvk

mhvk commented Aug 16, 2016

Copy link
Copy Markdown
Contributor Author

@bsipocz - thanks for noticing. It is actually a bit odd that 1.0.10 got released without this being noted! Anyway, I moved the entry in the changelog and rebased for good measure.

@eteq, @astrofrog, or @adrn - I think this really should be OK, but could one of you do a final check?


def test_regression_4293():
"""Really just an extra test on FK4 no e, after finding that the units
were not always taken correctly. This test is against explicityly doing

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.

explicityly --> explicitly

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.

Done

@adrn

adrn commented Aug 16, 2016

Copy link
Copy Markdown
Member

Also: did you mean to update the astropy_helpers commit?

@mhvk Code looks fine to me -- a few minor notes above. Thanks!

@mhvk
mhvk force-pushed the abberation-e-terms branch from 0a4e838 to 0db08d5 Compare August 19, 2016 15:54
@mhvk

mhvk commented Aug 19, 2016

Copy link
Copy Markdown
Contributor Author

@adrn - thanks for the review, and for noticing the "abritrarily set" precision of the test. This gives a bit more confidence in the routine itself too.

@mhvk

mhvk commented Aug 24, 2016

Copy link
Copy Markdown
Contributor Author

Thanks all for the reviews! Will now merge.

@mhvk
mhvk merged commit e0ce38d into astropy:master Aug 24, 2016
@mhvk
mhvk deleted the abberation-e-terms branch August 24, 2016 15:45
eteq pushed a commit that referenced this pull request Dec 21, 2016
Units issue with FK4 transforms with and without e terms
eteq pushed a commit that referenced this pull request Dec 21, 2016
Units issue with FK4 transforms with and without e terms
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.

7 participants