Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DM-39168: Add utility to compute apparent motion #65

Merged
merged 1 commit into from
Sep 10, 2024

Conversation

cmsaunders
Copy link
Collaborator

No description provided.

@cmsaunders cmsaunders force-pushed the tickets/DM-39168 branch 3 times, most recently from bcce819 to af0fde4 Compare August 5, 2024 15:09
Copy link
Contributor

@parejkoj parejkoj left a comment

Choose a reason for hiding this comment

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

Just to check: why can't you use astropy to do the PM+parallax correction directly? I see you're doing just that in the tests; would it make sense to just make this function a wrapper around astropy.SkyCoord conversions?

I'll trust you on the parallax math itself: I don't have the reference to hand.

python/lsst/drp/tasks/gbdesAstrometricFit.py Outdated Show resolved Hide resolved
python/lsst/drp/tasks/gbdesAstrometricFit.py Show resolved Hide resolved
python/lsst/drp/tasks/gbdesAstrometricFit.py Outdated Show resolved Hide resolved
python/lsst/drp/tasks/gbdesAstrometricFit.py Show resolved Hide resolved
python/lsst/drp/tasks/gbdesAstrometricFit.py Outdated Show resolved Hide resolved
tests/test_gbdesAstrometricFit.py Outdated Show resolved Hide resolved
tests/test_gbdesAstrometricFit.py Outdated Show resolved Hide resolved
astropy_dDec = newCoords.dec.degree - refNewCoords.dec.degree

np.testing.assert_allclose(astropy_dRA, ra_correction.value, rtol=1e-1)
np.testing.assert_allclose(astropy_dDec, dec_correction.value, rtol=1e-1)
Copy link
Contributor

Choose a reason for hiding this comment

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

1e-1 degrees accuracy doesn't seem very good?

Separately, the mathematical definition for rtol/atol in np.allclose always trips me up. I'd suggest using our own assertFloatsAlmostEqual, as the rtol/atol distinction is clearer (it's one or the other, not a combination of the two).

Copy link
Collaborator Author

@cmsaunders cmsaunders Aug 16, 2024

Choose a reason for hiding this comment

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

Yeah, this is why I asked you to review the ticket! They're also both different from the value from gbdes, which is done via a change of coordinate systems. If I recall correctly, if you start digging into the astropy calculation, it takes you into a maze of ERFA code, and I never figured out exactly how the parallax part was being calculated. Maybe @timj has a better idea for how to approach this?

For the allclose vs assertFloatsAlmostEqual, I just forgot that assertFloatsAlmostEqual allows arrays, unlike assertAlmostEqual, so I have switched to that.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The upshot is that the actual differences are all about -0.012 mas, which may come down to the choice of ecliptic angle between the function and astropy, and I have decided this is acceptable in this context.

Copy link
Member

Choose a reason for hiding this comment

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

I am still worrying that your Times are all in UTC and would like confirmation that they really should be in UTC and not TAI.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I'm still replying to comments and haven't pushed any changes yet. The times come from the VisitTable and should be TAI. This is endemic in gbdesAstrometricFit.

Copy link
Member

Choose a reason for hiding this comment

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

Ok. So every astropy.time.Time you create will need scale="tai" added to it.

Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks, changing to assertFloatsAlmostEqual should make the exact comparison more obvious. And Tim's right about requiring scale in the astropy time objects.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Right, I already made the scale change.

tests/test_gbdesAstrometricFit.py Outdated Show resolved Hide resolved
tests/test_gbdesAstrometricFit.py Outdated Show resolved Hide resolved
@cmsaunders
Copy link
Collaborator Author

It's not possible to use the astropy.SkyCoord conversions here for just parallax because they include other apparent motions like annual aberration. (See this github issue discussing the topic: astropy/astropy#9140.) Annual aberration is one of the effects that is accounted for by the overall per-visit part of the astrometric model, so we do not want it included here, where we are looking for only the correction to the position of a source relative to the other sources in the field.
There is a sort of hack in astropy.SkyCoord, where you can get motion due to parallax by itself by comparing a nearby and distant star. I don't think it's sufficient for this to be the actual way we do the correction, but I use it in the test because I don't have another good way to confirm the parallax calculation.

dec=self.Decs * u.degree,
pm_ra_cosdec=pmRA_cosDec * u.mas / u.yr,
pm_dec=self.pmDecs * u.mas / u.yr,
obstime=Time(refEpoch, format="mjd"),
Copy link
Member

Choose a reason for hiding this comment

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

General point -- be careful with timescales. If you know you are using tai everywhere you might want to specify that. If you know it's UTC somewhere, then say so. All your Time objects are defaulting to UTC and that might not be what you mean given that all our times in FITS metadata and elsewhere are TAI.

@cmsaunders cmsaunders force-pushed the tickets/DM-39168 branch 2 times, most recently from e7c1634 to bf23a25 Compare August 21, 2024 02:57
Copy link
Contributor

@parejkoj parejkoj left a comment

Choose a reason for hiding this comment

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

A few more comments, particularly about the tests.

# Set parallaxes to zero to test proper motion part by itself.
parallaxes = np.zeros(len(self.ras)) * u.mas

data = Table(
Copy link
Contributor

Choose a reason for hiding this comment

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

I would recommend importing this with the full namespace as well, as Table is another generic term like Time, otherwise it's not obvious that it came from astropy.

astropyDRA = newCoords.ra.degree - coords.ra.degree
astropyDDec = newCoords.dec.degree - coords.dec.degree

self.assertFloatsAlmostEqual(astropyDRA, raCorrection.value, rtol=1e-6)
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe make this comparison directly in milliarcsecond, as I can't translate 1e-6 into mas in my head to know whether this is a "good" result or not. Something like this should make it more obvious how much the difference is, though what exactly you need for atol I don't know, but I think that's what you really want here.

Suggested change
self.assertFloatsAlmostEqual(astropyDRA, raCorrection.value, rtol=1e-6)
self.assertFloatsAlmostEqual(astropyDRA.to_value(u.mas), raCorrection.to_value(u.mas), atol=1)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This is the relative difference though, so 1e-6 is unitless. I added a comment that the proper motions are on the scale of 0-3 mas/yr and the differences are on the scale of 1e-8 mas.

astropyDRA = newCoords.ra.degree - refNewCoords.ra.degree
astropyDDec = newCoords.dec.degree - refNewCoords.dec.degree

self.assertFloatsAlmostEqual(astropyDRA, raCorrection.value, rtol=1e-1)
Copy link
Contributor

Choose a reason for hiding this comment

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

As I noted above, you should do the comparison in mas and probably with atol, so we can see how accurate it is in "real" units. It's not obvious to me what a 10% accuracy means here, but it doesn't feel like it's very good?

Copy link
Collaborator Author

@cmsaunders cmsaunders Sep 9, 2024

Choose a reason for hiding this comment

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

Well, the actual accuracy is about 1.1% at worst, but I rounded up rather than have the value be too tuned. I guess I could do 2e-2. For the atol, I'm not sure that it's preferable here, since you don't know what the values of astropyDRA and raCorrection are here (they are ~1-2 mas). I'm going to just add a comment on the scale of the errors here, which correspond to 0.04 mas at most.

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah, thank you for that clarification. That's not as bad as I'd thought.

@cmsaunders cmsaunders merged commit 919eaa2 into main Sep 10, 2024
3 checks passed
@cmsaunders cmsaunders deleted the tickets/DM-39168 branch September 10, 2024 18:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants