JuliaAstro / AstroBase.jl

Interfaces, types, and functions for space science packages
Mozilla Public License 2.0
13 stars 6 forks source link

Convert between HJD <-> BJD? #49

Open icweaver opened 3 years ago

icweaver commented 3 years ago

Hi,

Awesome package, thanks for all of your work! I am slowly migrating some routines in Python over to Julia and was wondering if there was already a way to convert between HJD <-> BJD, similarly to the astropy snippet I found here? https://gist.github.com/StuartLittlefair/4ab7bb8cf21862e250be8cb25f72bb7a

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

which for example would return something like this:

> helio_to_bary("1:12:43.2 +31:12:43", 2457681.00027, "CTIO")
<Time object: scale='tdb' format='jd' value=2457681.0010844585>

Sorry if this is the wrong place to ask this!

helgee commented 3 years ago

Hi!

This is the right place for your question 👍

AstroTime.jl alone will probably never support this because we need an ephemeris for the conversion. AstroBase.jl however could...

Shall I transfer the issue over there?

icweaver commented 3 years ago

Ah, ok. That would be great, thanks!