Skip to content

Instantly share code, notes, and snippets.

@StuartLittlefair
Created October 17, 2019 10:07
Show Gist options
  • Save StuartLittlefair/4ab7bb8cf21862e250be8cb25f72bb7a to your computer and use it in GitHub Desktop.
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
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
Copy link

iwellaway commented Feb 7, 2020 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment