Skip to content

Commit

Permalink
Tdbtcb (#24)
Browse files Browse the repository at this point in the history
* tdbtcb

* tdbtcb

* tdbtcb fixed

* test fixed
  • Loading branch information
prakharcode authored and helgee committed Jun 6, 2018
1 parent 0c3938b commit 3712df7
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/constants.jl
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ const MOD_JD_77 = 43144.0
const ELG = 6.969290134e-10
const DAYS_PER_MILLENNIUM = 365250.0

const ELB = 1.550519768e-8
const TDB0 = -6.55e-5
const ELB = 1.550519768e-8

const JD_MIN = -68569.5
const JD_MAX = 1e9
Expand Down
33 changes: 32 additions & 1 deletion src/conversions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -460,6 +460,38 @@ julia> AstroTime.Epochs.ut1tt(ut1.jd1, ut1.jd2, AstroTime.Epochs.deltat(ut1))
date, date1
end

"""
tdbtcb(jd1, jd2)
Transform a two-part Julian date from `TDB` to `TCB`.
# Example
julia> tdb = Epoch{TDB}(2.4578265e6, 0.30440190993249416)
2017-03-14T07:18:20.325 TDB
julia> AstroTime.Epochs.tdbtcb(tdb.jd1, tdb.jd2)
(2.4578265e6, 0.30440190993249416)
```
"""
@inline function tdbtcb(jd1, jd2)
t77td = MJD + MOD_JD_77
t77tf = OFFSET_TT_TAI/SECONDS_PER_DAY
jd0 = TDB0/SECONDS_PER_DAY
elbb = ELB/(1.0-ELB)
if jd1 > jd2
d = t77td - jd1
f = jd2 - jd0
date = jd1
date1 = f - ( d - ( f - t77tf ) ) * elbb
else
d = t77td - jd2
f = jd1 - jd0
date = f + ( d - ( f - t77tf ) ) * elbb
date1 = jd2
end
date, date1
end

"""
tcbtdb(jd1, jd2)
Expand Down Expand Up @@ -529,7 +561,6 @@ end

end


# TAI <-> UTC
@transform UTC TAI ep begin
jd1, jd2 = julian1(ep), julian2(ep)
Expand Down
14 changes: 14 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -194,8 +194,22 @@ AstroTime.update()
@test Epochs.ut1tt(julian1(ut1), julian2(ut1), dt(ut1)) == ERFA.tttdb(julian1(ut1), julian2(ut1), dt(ut1))
@test Epochs.ut1tt(julian2(ut1), julian1(ut1), dt(ut1)) == ERFA.tttdb(julian2(ut1), julian1(ut1), dt(ut1))

# Doing approximate checking due to small machine epsilon. (fails on windows 32-bit)
let (jd1, jd2) = Epochs.tdbtcb(julian1(tdb), julian2(tdb))
erfa_jd1, erfa_jd2 = ERFA.tdbtcb(julian1(tdb), julian2(tdb))
@test jd1 erfa_jd1
@test jd2 == erfa_jd2
end

let (jd2, jd1) = Epochs.tdbtcb(julian2(tdb), julian1(tdb))
erfa_jd2, erfa_jd1 = ERFA.tdbtcb(julian2(tdb), julian1(tdb))
@test jd2 erfa_jd2
@test jd1 == erfa_jd1
end

@test Epochs.tcbtdb(julian1(tcb), julian2(tcb)) == ERFA.tcbtdb(julian1(tcb), julian2(tcb))
@test Epochs.tcbtdb(julian2(tcb), julian1(tcb)) == ERFA.tcbtdb(julian2(tcb), julian1(tcb))

for jd in 2414105.0:10.0:2488985.0
@test Epochs.diff_tdb_tt(jd, 0.5) Epochs.diff_tdb_tt(jd,0.5,0.0,0.0,0.0,0.0) atol=40e-6
end
Expand Down

0 comments on commit 3712df7

Please sign in to comment.