Skip to content

Commit b39d42c

Browse files
lunar frames tests + bugfixes
1 parent 2c8beda commit b39d42c

File tree

4 files changed

+117
-7
lines changed

4 files changed

+117
-7
lines changed

src/Definitions/ephemeris.jl

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -197,23 +197,23 @@ end
197197
@inline function angles_to_rot6(θ, seq::Symbol)
198198
return (
199199
angle_to_dcm(θ[1], θ[2], θ[3], seq),
200-
angle_to_δdcm(θ[1], θ[2], θ[3], seq)
200+
_3angles_to_δdcm, seq)
201201
)
202202
end
203203

204204
@inline function angles_to_rot9(θ, seq::Symbol)
205205
return (
206206
angle_to_dcm(θ[1], θ[2], θ[3], seq),
207-
angle_to_δdcm(θ[1], θ[2], θ[3], seq),
208-
angle_to_δ²dcm[1], θ[2], θ[3], seq)
207+
_3angles_to_δdcm, seq),
208+
_3angles_to_δ²dcm(θ, seq)
209209
)
210210
end
211211

212212
@inline function angles_to_rot12(θ, seq::Symbol)
213213
return (
214214
angle_to_dcm(θ[1], θ[2], θ[3], seq),
215-
angle_to_δdcm(θ[1], θ[2], θ[3], seq),
216-
angle_to_δ²dcm[1], θ[2], θ[3], seq),
217-
angle_to_δ³dcm[1], θ[2], θ[3], seq)
215+
_3angles_to_δdcm, seq),
216+
_3angles_to_δ²dcm(θ, seq),
217+
_3angles_to_δ³dcm(θ, seq)
218218
)
219219
end

src/FrameTransformations.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ using FunctionWrappersWrappers: FunctionWrappersWrapper
99
using JSMDUtils.Math: D¹, D², D³, arcsec2rad,
1010
unitvec, δunitvec, δ²unitvec, δ³unitvec,
1111
cross3, cross6, cross9, cross12,
12-
angle_to_δdcm, angle_to_δdcm, angle_to_δ²dcm, angle_to_δ³dcm
12+
angle_to_δdcm, _3angles_to_δdcm, _3angles_to_δ²dcm, _3angles_to_δ³dcm
1313

1414
using JSMDInterfaces.Graph: AbstractJSMDGraphNode,
1515
add_edge!, add_vertex!, get_path, has_vertex

test/Definitions/Definitions.jl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,4 +38,7 @@ download(KERNELS; verbose=true, force=false)
3838
@safetestset "Planetary" begin
3939
include("planetary.jl")
4040
end
41+
@safetestset "Lunar" begin
42+
include("lunar.jl")
43+
end
4144
end;

test/Definitions/lunar.jl

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
using FrameTransformations
2+
using StaticArrays
3+
using LinearAlgebra
4+
using SPICE
5+
using RemoteFiles
6+
using Test
7+
8+
using Tempo
9+
using JSMDInterfaces.Ephemeris
10+
11+
using Ephemerides
12+
13+
@RemoteFileSet KERNELS "Spice Kernels Set" begin
14+
LEAP = @RemoteFile "https://naif.jpl.nasa.gov/pub/naif/generic_kernels/lsk/latest_leapseconds.tls" dir = joinpath(
15+
@__DIR__, "..", "assets"
16+
)
17+
DE432 = @RemoteFile "https://naif.jpl.nasa.gov/pub/naif/generic_kernels/spk/planets/de432s.bsp" dir = joinpath(
18+
@__DIR__, "..", "assets"
19+
)
20+
PA421 = @RemoteFile "https://naif.jpl.nasa.gov/pub/naif/generic_kernels/pck/moon_pa_de421_1900-2050.bpc" dir = joinpath(
21+
@__DIR__, "..", "assets"
22+
)
23+
PA440 = @RemoteFile "https://naif.jpl.nasa.gov/pub/naif/generic_kernels/pck/moon_pa_de440_200625.bpc" dir = joinpath(
24+
@__DIR__, "..", "assets"
25+
)
26+
FK_DE421 = @RemoteFile "https://naif.jpl.nasa.gov/pub/naif/generic_kernels/fk/satellites/moon_080317.tf" dir = joinpath(
27+
@__DIR__, "..", "assets"
28+
)
29+
FK_DE440 = @RemoteFile "https://naif.jpl.nasa.gov/pub/naif/generic_kernels/fk/satellites/moon_de440_220930.tf" dir = joinpath(
30+
@__DIR__, "..", "assets"
31+
)
32+
end;
33+
34+
download(KERNELS; verbose=true, force=false)
35+
36+
v2as = (x, y) -> acosd(max(-1, min(1, dot(x / norm(x), y / norm(y))))) * 3600
37+
38+
@testset "DE421" verbose = false begin
39+
40+
for kernel in (:LEAP, :PA421, :FK_DE421)
41+
furnsh(path(KERNELS[kernel]))
42+
end
43+
44+
45+
frames = FrameSystem{2,Float64}()
46+
add_axes_icrf!(frames)
47+
48+
eph = EphemerisProvider(path(KERNELS[:PA421]))
49+
@test_throws ArgumentError add_axes_pa421!(frames, eph, :PA421, -1)
50+
@test_throws ArgumentError add_axes_me421!(frames, :ME421, -1)
51+
@test_throws ArgumentError add_axes_me421!(frames, :ME421, 31006)
52+
53+
add_axes_pa421!(frames, eph, :PA421)
54+
add_axes_me421!(frames, :ME421, :PA421)
55+
56+
for _ in 1:100
57+
et = rand(0.0:1e8)
58+
59+
v = rand(BigFloat, 3)
60+
v /= norm(v)
61+
62+
# Test PA421!
63+
Rb = rotation6(frames, :PA421, :ICRF, et)
64+
Rs = sxform("MOON_PA", "J2000", et)
65+
66+
@test v2as(Rb[1] * v, Rs[1:3, 1:3] * v) 1e-6
67+
@test v2as(Rb[2] * v, Rs[4:6, 1:3] * v) 1e-6
68+
69+
# Test ME421!
70+
Rb = rotation6(frames, :ICRF, :ME421, et)
71+
Rs = sxform("J2000", "MOON_ME", et)
72+
73+
@test v2as(Rb[1] * v, Rs[1:3, 1:3] * v) 1e-6
74+
@test v2as(Rb[2] * v, Rs[4:6, 1:3] * v) 1e-6
75+
end
76+
77+
end
78+
79+
@testset "DE440" verbose = false begin
80+
81+
for kernel in (:LEAP, :PA440, :FK_DE440)
82+
furnsh(path(KERNELS[kernel]))
83+
end
84+
85+
frames = FrameSystem{2,Float64}()
86+
add_axes_icrf!(frames)
87+
88+
eph = EphemerisProvider(path(KERNELS[:PA440]))
89+
@test_throws ArgumentError add_axes_pa440!(frames, eph, :PA440, -1)
90+
91+
add_axes_pa440!(frames, eph, :PA440)
92+
93+
for _ in 1:100
94+
et = rand(0.0:1e8)
95+
96+
v = rand(BigFloat, 3)
97+
v /= norm(v)
98+
99+
# Test PA421!
100+
Rb = rotation6(frames, :PA440, :ICRF, et)
101+
Rs = sxform("MOON_PA", "J2000", et)
102+
103+
@test v2as(Rb[1] * v, Rs[1:3, 1:3] * v) 1e-6
104+
@test v2as(Rb[2] * v, Rs[4:6, 1:3] * v) 1e-6
105+
end
106+
107+
end

0 commit comments

Comments
 (0)