Created
October 17, 2019 10:07
-
-
Save StuartLittlefair/4ab7bb8cf21862e250be8cb25f72bb7a to your computer and use it in GitHub Desktop.
Quick snippet to use astropy to convert from heliocentric times to barycentric and vice-versa
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from astropy.coordinates import SkyCoord, EarthLocation | |
from astropy import units as u | |
from astropy.time import Time | |
def helio_to_bary(coords, hjd, obs_name): | |
helio = Time(hjd, scale='utc', format='jd') | |
obs = EarthLocation.of_site(obs_name) | |
star = SkyCoord(coords, unit=(u.hour, u.deg)) | |
ltt = helio.light_travel_time(star, 'heliocentric', location=obs) | |
guess = helio - ltt | |
# if we assume guess is correct - how far is heliocentric time away from true value? | |
delta = (guess + guess.light_travel_time(star, 'heliocentric', obs)).jd - helio.jd | |
# apply this correction | |
guess -= delta * u.d | |
ltt = guess.light_travel_time(star, 'barycentric', obs) | |
return guess.tdb + ltt | |
def bary_to_helio(coords, bjd, obs_name): | |
bary = Time(bjd, scale='tdb', format='jd') | |
obs = EarthLocation.of_site(obs_name) | |
star = SkyCoord(coords, unit=(u.hour, u.deg)) | |
ltt = bary.light_travel_time(star, 'barycentric', location=obs) | |
guess = bary - ltt | |
delta = (guess + guess.light_travel_time(star, 'barycentric', obs)).jd - bary.jd | |
guess -= delta * u.d | |
ltt = guess.light_travel_time(star, 'heliocentric', obs) | |
return guess.utc + ltt |
iwellaway
commented
Feb 7, 2020
via email
•
Thanks Stuart,
I like the idea of checking the guess and correcting it slightly. We don’t have to run this process too many times in the code, only in setup in fact, so I might put this in for completeness.
Thanks for your help, it’s much appreciated.
Ian
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment