Skip to content

Taylor series #48

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 13 commits into
base: dev
Choose a base branch
from
3 changes: 1 addition & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,8 @@ jobs:
fail-fast: false
matrix:
version:
- '1.7'
- '1.8'
- '1.9'
- '1.10'
- '1'
os:
- ubuntu-latest
Expand Down
15 changes: 11 additions & 4 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "Ephemerides"
uuid = "6a9c3322-c8fe-4c26-8ad6-14a6f8acd2a0"
authors = ["JSMD Team"]
version = "1.2.1"
version = "1.2.2"

[deps]
JSMDInterfaces = "6b30ee2f-618e-4a15-bf4e-7df7b496e609"
Expand All @@ -11,16 +11,23 @@ PreallocationTools = "d236fae5-4411-538c-8e31-a6e3d9e00b46"
PrecompileTools = "aea7be01-6a6a-4083-8856-8a6e6704d82a"
StaticArraysCore = "1e83bf80-4336-4d27-bf5d-d5a4f845583c"

[weakdeps]
TaylorSeries = "6aa5eb33-94cf-58f4-a9d0-e4b2c4fc25ea"

[extensions]
TaylorSeriesExt = ["TaylorSeries"]

[compat]
JSMDInterfaces = "1.4"
LazyArtifacts = "1"
PreallocationTools = "0.4"
PreallocationTools = ">=0.4"
PrecompileTools = "1"
StaticArraysCore = "1.4"
julia = "1.7"
TaylorSeries = ">=0.15"
julia = "1.9"

[extras]
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"

[targets]
test = ["Test"]
test = ["Test", "TaylorSeries"]
1 change: 1 addition & 0 deletions docs/src/api/lapi.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ Ephemerides.file_id
Ephemerides.list_id
Ephemerides.element_id
Ephemerides.factor
Ephemerides.check_linktime
Ephemerides.reverse_link
Ephemerides.create_linktables
Ephemerides.add_spklinks!
Expand Down
49 changes: 49 additions & 0 deletions ext/TaylorSeriesExt.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
module TaylorSeriesExt

import Ephemerides: find_logical_record, check_linktime

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

using TaylorSeries: constant_term, Taylor1
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
using TaylorSeries: constant_term, Taylor1
using TaylorSeries: constant_term, Taylor1, AbstractSeries



function find_logical_record(head::SPKSegmentHeader2, time::Taylor1{<:Real})
return find_logical_record(head, constant_term(time))
end

function find_logical_record(head::SPKSegmentHeader8, time::Taylor1{<:Real})
return find_logical_record(head, constant_term(time))
end

function find_logical_record(head::SPKSegmentHeader20, time::Taylor1{<:Real})
return find_logical_record(head, constant_term(time))
end

function find_logical_record(daf::DAF, head::SPKSegmentHeader1, time::Taylor1{<:Real})
return find_logical_record(daf, head, constant_term(time))
end

function find_logical_record(daf::DAF, head::SPKSegmentHeader5, time::Taylor1{<:Real})
return find_logical_record(daf, head, constant_term(time))
end

function find_logical_record(daf::DAF, head::SPKSegmentHeader9, time::Taylor1{<:Real})
return find_logical_record(daf, head, constant_term(time))
end

function find_logical_record(daf::DAF, head::SPKSegmentHeader14, time::Taylor1{<:Real})
return find_logical_record(daf, head, constant_term(time))
end

function find_logical_record(daf::DAF, head::SPKSegmentHeader18, time::Taylor1{<:Real})
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
1 change: 1 addition & 0 deletions test/Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ LazyArtifacts = "4af54fe1-eca0-43a8-85a7-787d91b784e3"
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
SPICE = "5bab7191-041a-5c2e-a744-024b9c3a5062"
TaylorSeries = "6aa5eb33-94cf-58f4-a9d0-e4b2c4fc25ea"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
3 changes: 2 additions & 1 deletion test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ using LazyArtifacts
using LinearAlgebra
using Random
using SPICE
using TaylorSeries

import JSMDInterfaces.Ephemeris as jEphem

Expand All @@ -17,7 +18,7 @@ end;


@testset "Ephemerides" verbose=true begin
include("spk/spk.jl")
include(joinpath("spk", "spk.jl"))
include("properties.jl")
include("interfaces.jl")
include("twobody.jl")
Expand Down
21 changes: 20 additions & 1 deletion test/spk/spk1.jl
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ DJ2000 = 2451545
@test_throws jEphem.EphemerisError ephem_vector9(ephj, cid, tid, t1j)
@test_throws jEphem.EphemerisError ephem_vector12(ephj, cid, tid, t1j)


ep = t1j:1:t2j
for j in 1:3000

Expand Down Expand Up @@ -73,9 +74,27 @@ DJ2000 = 2451545
# D²(t->ephem_vector6(ephj, cid, tid, t), tj)
# D³(t->ephem_vector6(ephj, cid, tid, t), tj)

# ----
# TaylorSeries Extension Test

t = Taylor1(5)

tj = rand(head.epochs)

pt = ephem_vector3(ephj, cid, tid, t + tj)
vt = differentiate.(pt)

se = ephem_vector6(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

end


# ---
# Thread-safe testing

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

pos = zeros(3, length(tj))
Expand All @@ -92,4 +111,4 @@ DJ2000 = 2451545

kclear()

end
end
22 changes: 22 additions & 0 deletions test/spk/spk12.jl
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,31 @@ DJ2000 = 2451545
# Acceleration
@test D¹(t->ephem_vector9(ephj, cid, tid, t), tj) ≈ yj4[4:12] atol=1e-9 rtol=1e-13

# ----
# TaylorSeries Extension Test

t = Taylor1(5)

tj = rand(ep)

pt = ephem_vector3(ephj, cid, tid, t + tj)
vt = differentiate.(pt)
at = differentiate.(vt)
jt = differentiate.(at)

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

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

end


# ---
# Thread-safe testing

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

pos = zeros(3, length(tj))
Expand Down
21 changes: 21 additions & 0 deletions test/spk/spk13.jl
Original file line number Diff line number Diff line change
Expand Up @@ -101,10 +101,31 @@ DJ2000 = 2451545

# Acceleration
@test D¹(t->ephem_vector9(ephj, cid, tid, t), tj) ≈ yj4[4:12] atol=jatol rtol=jrtol

# ----
# TaylorSeries Extension Test

t = Taylor1(5)

tj = rand(ep)

pt = ephem_vector3(ephj, cid, tid, t + tj)
vt = differentiate.(pt)
at = differentiate.(vt)
jt = differentiate.(at)

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

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

end

# ---
# Thread-safe testing

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

pos = zeros(3, length(tj))
Expand Down
21 changes: 21 additions & 0 deletions test/spk/spk14.jl
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,28 @@ DJ2000 = 2451545

end

# ----
# TaylorSeries Extension Test

t = Taylor1(5)

tj = rand(head.epochs)

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

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

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

# ---
# Thread-safe testing

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

pos = zeros(3, length(tj))
Expand Down
6 changes: 6 additions & 0 deletions test/spk/spk15.jl
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,12 @@ DJ2000 = 2451545

end

# ----
# TaylorSeries Extension Test

# Doesn't make sense as the autodiff above

# ---
# Thread-safe testing
tj = shuffle(collect(LinRange(t1j, t2j, 200)))

Expand Down
6 changes: 6 additions & 0 deletions test/spk/spk17.jl
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,12 @@ DJ2000 = 2451545

end

# ----
# TaylorSeries Extension Test

# Doesn't make sense as the autodiff comment above

# ---
# Thread-safe testing
tj = shuffle(collect(LinRange(t1j, t2j, 200)))

Expand Down
22 changes: 22 additions & 0 deletions test/spk/spk18.jl
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,28 @@ DJ2000 = 2451545

end


# ----
# TaylorSeries Extension Test

t = Taylor1(5)

tj = rand(ep)

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

se = ephem_vector12(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)))

Expand Down
21 changes: 21 additions & 0 deletions test/spk/spk19.jl
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,27 @@ DJ2000 = 2451545

end

# ----
# TaylorSeries Extension Test

t = Taylor1(5)

tj = rand(ep)

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

se = ephem_vector12(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)))

Expand Down
Loading
Loading