Skip to content

Commit

Permalink
Added check_linktime
Browse files Browse the repository at this point in the history
  • Loading branch information
MicheleCeresoli committed Jul 30, 2024
1 parent 5c06efb commit 4c9fb03
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 8 deletions.
11 changes: 9 additions & 2 deletions ext/TaylorSeriesExt.jl
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
module TaylorSeriesExt

import Ephemerides: find_logical_record
using Ephemerides: DAF,
import Ephemerides: find_logical_record, check_linktime

using Ephemerides: DAF, SPKLink,
SPKSegmentHeader2, SPKSegmentHeader8, SPKSegmentHeader20,
SPKSegmentHeader1, SPKSegmentHeader5, SPKSegmentHeader9,
SPKSegmentHeader14, SPKSegmentHeader18

using TaylorSeries: constant_term, Taylor1


function find_logical_record(head::SPKSegmentHeader2, time::Taylor1{<:Real})
return find_logical_record(head, constant_term(time))
end
Expand Down Expand Up @@ -39,4 +42,8 @@ function find_logical_record(daf::DAF, head::SPKSegmentHeader18, time::Taylor1{<
return find_logical_record(daf, head, constant_term(time))
end

function check_linktime(link::SPKLink, time::Taylor1{<:Real})
return check_linktime(link, constant_term(time))
end

end
10 changes: 10 additions & 0 deletions src/links.jl
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,16 @@ segment associated to this link, in seconds since J2000.0
"""
@inline final_time(link::SPKLink) = final_time(descriptor(link))

"""
check_linktime(link::SPKLink, time::Number)
Return whether `time`, expressed in seconds since J2000.0 is within the SPK link bounds.
"""
@inline function check_linktime(link::SPKLink, time::Number)
return initial_time(link) <= time <= final_time(link)
end


"""
reverse_link(link::SPKLink)
Expand Down
4 changes: 2 additions & 2 deletions src/transform.jl
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ for (order, pfun1, afun1, pfun2, afun2) in zip(
links = spk_links(eph)
if haskey(links, to) && haskey(links[to], from)
for link in links[to][from]
if initial_time(link) <= time <= final_time(link)
if check_linktime(link, time)
return factor(link)*$(pfun2)(get_daf(eph, file_id(link)), link, time)
end
end
Expand Down Expand Up @@ -63,7 +63,7 @@ for (order, pfun1, afun1, pfun2, afun2) in zip(
links = pck_links(eph)
if haskey(links, to) && haskey(links[to], from)
for link in links[to][from]
if initial_time(link) <= time <= final_time(link)
if check_linktime(link, time)
return $(afun2)(get_daf(eph, file_id(link)), link, time)
end
end
Expand Down
26 changes: 22 additions & 4 deletions test/spk/spk2.jl
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,28 @@ DJ2000 = 2451545

end

# ----
# TaylorSeries Extension Test

t = Taylor1(5)

tj = rand(ep)

pt = ephem_rotation3(ephj, cid, tid, t + tj)
vt = ephem_rotation6(ephj, cid, tid, t + tj)[4:6]
at = differentiate.(vt)
jt = differentiate.(at)

se = ephem_rotation12(ephj, cid, tid, tj)

@test evaluate(pt) se[1:3] atol=1e-12 rtol=1e-12
@test evaluate(vt) se[4:6] atol=1e-12 rtol=1e-12
@test evaluate(at) se[7:9] atol=1e-12 rtol=1e-12
@test evaluate(jt) se[10:12] atol=1e-12 rtol=1e-12

# ----
# Thread-safe testing

tj = shuffle(collect(LinRange(t1j, t2j, 200)))

pos = zeros(3, length(tj))
Expand All @@ -194,7 +215,4 @@ DJ2000 = 2451545
end

@test pos pos_m atol=1e-14 rtol=1e-14
end



end

0 comments on commit 4c9fb03

Please sign in to comment.