Skip to content

Commit 8cd29ca

Browse files
authored
chore: increase code coverage for AstrodynamicalCalculations (#264)
## Changes While code coverage is not yet near 100%, this commit adds coverage! --- Reviewer: @cadojo
1 parent f7dd3ad commit 8cd29ca

File tree

10 files changed

+228
-60
lines changed

10 files changed

+228
-60
lines changed

.devcontainer/devcontainer-lock.json

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
{
2+
"features": {
3+
"ghcr.io/devcontainer-community/devcontainer-features/starship.rs:1": {
4+
"version": "1.0.0",
5+
"resolved": "ghcr.io/devcontainer-community/devcontainer-features/starship.rs@sha256:436765d97a663dc00b69466dca52dd7dcc073ad43c1aa25237852c291ffb2489",
6+
"integrity": "sha256:436765d97a663dc00b69466dca52dd7dcc073ad43c1aa25237852c291ffb2489"
7+
},
8+
"ghcr.io/devcontainers-extra/features/pre-commit:2": {
9+
"version": "2.0.18",
10+
"resolved": "ghcr.io/devcontainers-extra/features/pre-commit@sha256:6e0bb2ce80caca1d94f44dab5d0653d88a1c00984e590adb7c6bce012d0ade6e",
11+
"integrity": "sha256:6e0bb2ce80caca1d94f44dab5d0653d88a1c00984e590adb7c6bce012d0ade6e"
12+
},
13+
"ghcr.io/devcontainers/features/git-lfs:1": {
14+
"version": "1.2.5",
15+
"resolved": "ghcr.io/devcontainers/features/git-lfs@sha256:71c2b371cf12ab7fcec47cf17369c6f59156100dad9abf9e4c593049d789de72",
16+
"integrity": "sha256:71c2b371cf12ab7fcec47cf17369c6f59156100dad9abf9e4c593049d789de72"
17+
},
18+
"ghcr.io/devcontainers/features/git:1": {
19+
"version": "1.3.4",
20+
"resolved": "ghcr.io/devcontainers/features/git@sha256:f24645e64ad39a596131a50ec96f7d5cf7a2a87544cce772dd4b7182a233e98a",
21+
"integrity": "sha256:f24645e64ad39a596131a50ec96f7d5cf7a2a87544cce772dd4b7182a233e98a"
22+
},
23+
"ghcr.io/devcontainers/features/github-cli:1": {
24+
"version": "1.0.14",
25+
"resolved": "ghcr.io/devcontainers/features/github-cli@sha256:ca677566507c4118e4368cd76a4800807e911e5e350cc3525fb67ebc9132dfa1",
26+
"integrity": "sha256:ca677566507c4118e4368cd76a4800807e911e5e350cc3525fb67ebc9132dfa1"
27+
},
28+
"ghcr.io/devcontainers/features/python:1": {
29+
"version": "1.7.1",
30+
"resolved": "ghcr.io/devcontainers/features/python@sha256:cf9b6d879790a594b459845b207c5e1762a0c8f954bb8033ff396e497f9c301b",
31+
"integrity": "sha256:cf9b6d879790a594b459845b207c5e1762a0c8f954bb8033ff396e497f9c301b"
32+
},
33+
"ghcr.io/julialang/devcontainer-features/julia:1": {
34+
"version": "1.2.0",
35+
"resolved": "ghcr.io/julialang/devcontainer-features/julia@sha256:748ff7272e392e0c2ac7c837dbdc6c8cfa1dd3f81819fd29a111c718e3c4199d",
36+
"integrity": "sha256:748ff7272e392e0c2ac7c837dbdc6c8cfa1dd3f81819fd29a111c718e3c4199d"
37+
},
38+
"ghcr.io/rocker-org/devcontainer-features/apt-packages:1": {
39+
"version": "1.0.2",
40+
"resolved": "ghcr.io/rocker-org/devcontainer-features/apt-packages@sha256:87a4d7750a596a5db034ba8508782f31aebdc2ffe955c66aaecb33d9de2ecdae",
41+
"integrity": "sha256:87a4d7750a596a5db034ba8508782f31aebdc2ffe955c66aaecb33d9de2ecdae"
42+
},
43+
"ghcr.io/rocker-org/devcontainer-features/quarto-cli:1": {
44+
"version": "1.1.4",
45+
"resolved": "ghcr.io/rocker-org/devcontainer-features/quarto-cli@sha256:74960cb27e2be0dbea52c666342fd4eb69475cec971440265b3944eee30e1f86",
46+
"integrity": "sha256:74960cb27e2be0dbea52c666342fd4eb69475cec971440265b3944eee30e1f86"
47+
}
48+
}
49+
}

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ trajectory = propagate(orbit, orbital_period(orbit))
4646

4747
furnsh(
4848
de440s(), # position and velocity data for nearby planets
49-
latest_leapseconds_lsk(), # timekeeping, parsing epochs
49+
latest_leapseconds_tls(), # timekeeping, parsing epochs
5050
gm_de440(), # mass parameters for major solar system bodies
5151
pck00011(), # physical properties of major solar system bodies
5252
)

lib/AstrodynamicalCalculations/LICENSE

Lines changed: 0 additions & 21 deletions
This file was deleted.

lib/AstrodynamicalCalculations/README.md

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
[![Tests](https://github.com/cadojo/AstrodynamicalCalculations.jl/workflows/Tests/badge.svg)](https://github.com/cadojo/AstrodynamicalCalculations.jl/actions?query=workflow%3ATests)
2-
[![Docs](https://github.com/cadojo/AstrodynamicalCalculations.jl/workflows/Documentation/badge.svg)](https://cadojo.github.io/AstrodynamicalCalculations.jl)
3-
41
# `AstrodynamicalCalculations.jl`
52

63
_Common calculations relating to orbital mechanics and astrodynamics._
@@ -23,7 +20,7 @@ also provided.
2320
Two newer Lambert solver implementations (Lancaster / Blanchard, and
2421
Oldenhuis) are also provided, but they are currently not working. Something seems to have
2522
not transferred well while porting the code from MATLAB to Julia. I hope to work on this
26-
more in 2024.
23+
more in 2026.
2724

2825
## Getting Stated
2926

lib/AstrodynamicalCalculations/src/R2BPCalculations.jl

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,8 @@ Returns semimajor axis parameter, a.
226226
"""
227227
semimajor_axis(r::Number, v::Number, μ) = inv((2 / r) - (v^2 / μ))
228228
semimajor_axis(r, v, μ) = semimajor_axis(norm(r), norm(v), μ)
229-
semimajor_axis(x, y, z, ẋ, ẏ, ż, μ) = semimajor_axis((x, y, z), (ẋ, ẏ, ż), μ)
229+
semimajor_axis(x, y, z, ẋ, ẏ, ż, μ) =
230+
semimajor_axis(SVector(x, y, z), SVector(ẋ, ẏ, ż), μ)
230231

231232
"""
232233
Returns the orbital inclination.
@@ -272,7 +273,7 @@ Returns specific orbital energy, ϵ.
272273
specific_energy(a, μ) = (-μ / (2 * a))
273274
specific_energy(r, v, μ) = (v^2 / 2) -/ r)
274275
specific_energy(x, y, z, ẋ, ẏ, ż, μ) =
275-
specific_energy(norm((x, y, z)), norm((ẋ, ẏ, ż)), μ)
276+
specific_energy(norm(SVector(x, y, z)), norm(SVector(ẋ, ẏ, ż)), μ)
276277

277278
"""
278279
Returns C3 value.
@@ -291,7 +292,7 @@ Returns the specific potential energy: the energy per unit mass.
291292
"""
292293
specific_potential_energy(r, μ) =/ r)
293294
specific_potential_energy(x, y, z, ẋ, ẏ, ż, μ) =
294-
specific_potential_energy(norm((x, y, z)), μ)
295+
specific_potential_energy(norm(SVector(x, y, z)), μ)
295296
specific_potential_energy(r, μ, R, J₂, ϕ) =
296297
/ r) * (1 - J₂ * (R / r)^2 * ((3 / 2) * (sin(ϕ))^2 - (1 / 2)))
297298

@@ -301,7 +302,7 @@ Returns orbital eccentricity vector e̅.
301302
function eccentricity_vector(x, y, z, ẋ, ẏ, ż, μ)
302303
h₁, h₂, h₃ = specific_angular_momentum_vector(x, y, z, ẋ, ẏ, ż)
303304
return (1 / μ) *
304-
(_cross(ẋ, ẏ, ż, h₁, h₂, h₃) - μ * SVector(x, y, z) / norm((x, y, z)))
305+
(_cross(ẋ, ẏ, ż, h₁, h₂, h₃) - μ * SVector(x, y, z) / norm(SVector(x, y, z)))
305306

306307
end
307308

@@ -333,8 +334,8 @@ orbital_radius(x, y, z, ẋ, ẏ, ż, μ) = orbital_radius(
333334
Returns the instantaneous velocity, v, for any orbital representation.
334335
"""
335336
function orbital_speed(x, y, z, ẋ, ẏ, ż, μ)
336-
r = norm((x, y, z))
337-
v = norm((ẋ, ẏ, ż))
337+
r = norm(SVector(x, y, z))
338+
v = norm(SVector(ẋ, ẏ, ż))
338339
return orbital_speed(r, semimajor_axis(r, v, μ), μ)
339340
end
340341

@@ -370,7 +371,7 @@ orbital_period(x, y, z, ẋ, ẏ, ż, μ) =
370371
Returns true anomaly, ν.
371372
"""
372373
function true_anomaly(x, y, z, ẋ, ẏ, ż, μ)
373-
r = (x, y, z)
374+
r = norm(SVector(x, y, z))
374375

375376
e = eccentricity(x, y, z, ẋ, ẏ, ż, μ)
376377
h = specific_angular_momentum(x, y, z, ẋ, ẏ, ż)

lib/AstrodynamicalCalculations/test/runtests.jl

Lines changed: 167 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,176 @@ Restricted Two-body Model tests.
33
"""
44
module AstrodynamicalCalculationsTests
55

6+
using LinearAlgebra
67
using Test, AstrodynamicalCalculations
78
using StaticArrays
89

10+
@testset verbose = false "R2BP Calculations" begin
11+
@test conic(0) == :Circular
12+
@test conic(1) == :Parabolic
13+
@test conic(0.999999) == :Elliptical
14+
@test conic(1.000001) == :Hyperbolic
15+
16+
@test cartesian_to_perifocal(
17+
0.9000000000000004,
18+
100000.00000000055,
19+
2.2442063995416452,
20+
1.1139736859596856,
21+
5.964076767085505,
22+
0.786172648028967,
23+
4.140536323401264,
24+
-2.892055315559945,
25+
6.2566039442009,
26+
) == (
27+
x = -1.8727989006070282,
28+
y = 2.645561295501541,
29+
z = 5.188722983436087,
30+
= 7.80864012260457,
31+
= -0.8041738032535248,
32+
ż = 1.7411380870180566,
33+
)
34+
35+
@test semimajor_axis(
36+
-1.8727989006070282,
37+
2.645561295501541,
38+
5.188722983436087,
39+
7.80864012260457,
40+
-0.8041738032535248,
41+
1.7411380870180566,
42+
398600.4355070226,
43+
) == 3.060489599980775
44+
45+
@test inclination(
46+
-1.8727989006070282,
47+
2.645561295501541,
48+
5.188722983436087,
49+
7.80864012260457,
50+
-0.8041738032535248,
51+
1.7411380870180566,
52+
398600.4355070226,
53+
) == 1.976005846038532
54+
55+
@test right_ascension_ascending_node(
56+
-1.8727989006070282,
57+
2.645561295501541,
58+
5.188722983436087,
59+
7.80864012260457,
60+
-0.8041738032535248,
61+
1.7411380870180566,
62+
398600.4355070226,
63+
) == 2.943683444332231
64+
65+
@test argument_of_periapsis(
66+
-1.8727989006070282,
67+
2.645561295501541,
68+
5.188722983436087,
69+
7.80864012260457,
70+
-0.8041738032535248,
71+
1.7411380870180566,
72+
398600.4355070226,
73+
) == 4.316849536012919
74+
75+
@test specific_angular_momentum_vector(
76+
-1.8727989006070282,
77+
2.645561295501541,
78+
5.188722983436087,
79+
7.80864012260457,
80+
-0.8041738032535248,
81+
1.7411380870180566,
82+
398600.4355070226,
83+
) == specific_angular_momentum_vector(
84+
-1.8727989006070282,
85+
2.645561295501541,
86+
5.188722983436087,
87+
7.80864012260457,
88+
-0.8041738032535248,
89+
1.7411380870180566,
90+
)
91+
92+
@test specific_angular_momentum(
93+
-1.8727989006070282,
94+
2.645561295501541,
95+
5.188722983436087,
96+
7.80864012260457,
97+
-0.8041738032535248,
98+
1.7411380870180566,
99+
) == norm(
100+
specific_angular_momentum_vector(
101+
-1.8727989006070282,
102+
2.645561295501541,
103+
5.188722983436087,
104+
7.80864012260457,
105+
-0.8041738032535248,
106+
1.7411380870180566,
107+
),
108+
)
109+
110+
@test specific_angular_momentum(
111+
-1.8727989006070282,
112+
2.645561295501541,
113+
5.188722983436087,
114+
7.80864012260457,
115+
-0.8041738032535248,
116+
1.7411380870180566,
117+
398600.4355070226,
118+
) == specific_angular_momentum(
119+
-1.8727989006070282,
120+
2.645561295501541,
121+
5.188722983436087,
122+
7.80864012260457,
123+
-0.8041738032535248,
124+
1.7411380870180566,
125+
)
126+
127+
@test specific_energy(100000.00000000055, 398600.4355070226) == -1.993002177535102
128+
@test specific_angular_momentum_vector(
129+
7501.390893889291,
130+
7868.393278511291,
131+
4087.9520744171814,
132+
4.140536323401264,
133+
-2.892055315559945,
134+
6.2566039442009,
135+
398600.4355070226,
136+
) == specific_angular_momentum_vector(
137+
7501.390893889291,
138+
7868.393278511291,
139+
4087.9520744171814,
140+
4.140536323401264,
141+
-2.892055315559945,
142+
6.2566039442009,
143+
)
144+
145+
@test specific_angular_momentum(
146+
7501.390893889291,
147+
7868.393278511291,
148+
4087.9520744171814,
149+
4.140536323401264,
150+
-2.892055315559945,
151+
6.2566039442009,
152+
398600.4355070226,
153+
) == norm(
154+
specific_angular_momentum_vector(
155+
7501.390893889291,
156+
7868.393278511291,
157+
4087.9520744171814,
158+
4.140536323401264,
159+
-2.892055315559945,
160+
6.2566039442009,
161+
),
162+
)
163+
164+
@test orbital_radius(
165+
7501.390893889291,
166+
7868.393278511291,
167+
4087.9520744171814,
168+
4.140536323401264,
169+
-2.892055315559945,
170+
6.2566039442009,
171+
398600.4355070226,
172+
) == 11279.041186710254
173+
174+
end
175+
9176
@testset verbose = false "R2BP Determination" begin
10177
r = [0.0, 11681.0, 0.0]
11178
v = [5.134, 4.226, 2.787]

lib/AstrodynamicalModels/README.md

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
[![Tests](https://github.com/cadojo/AstrodynamicalModels.jl/workflows/UnitTests/badge.svg)](https://github.com/cadojo/AstrodynamicalModels.jl/actions?query=workflow%3AUnitTests)
2-
[![Docs](https://github.com/cadojo/AstrodynamicalModels.jl/workflows/Documentation/badge.svg)](https://cadojo.github.io/AstrodynamicalModels.jl)
3-
41
# AstrodynamicalModels.jl
52

63
_An extension of

lib/AstrodynamicalModels/ext/AstrodynamicalCalculationsExt.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ function AC.keplerian_to_cartesian(state::KeplerianState, μ)
1515
end
1616
AC.keplerian_to_cartesian(orbit::CartesianOrbit) =
1717
Orbit(AC.keplerian_to_cartesian(orbit.state, orbit.parameters), orbit.parameters)
18+
AC.keplerian_to_cartesian(orbit::KeplerianOrbit) =
19+
Orbit(AC.keplerian_to_cartesian(orbit.state, orbit.parameters), orbit.parameters)
1820

1921
function AC.cartesian_to_keplerian(state::CartesianState, μ)
2022
p = μ isa Number ? R2BParameters(μ) : μ

lib/AstrodynamicalSolvers/LICENSE

Lines changed: 0 additions & 21 deletions
This file was deleted.

lib/AstrodynamicalSolvers/README.md

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
[![Tests](https://github.com/cadojo/AstrodynamicalSolvers.jl/workflows/Tests/badge.svg)](https://github.com/cadojo/AstrodynamicalSolvers.jl/actions?query=workflow%3ATests)
2-
[![Docs](https://github.com/cadojo/AstrodynamicalSolvers.jl/workflows/Documentation/badge.svg)](https://cadojo.github.io/AstrodynamicalSolvers.jl)
3-
41
# `AstrodynamicalSolvers.jl`
52

63
_Common solvers relating to orbital mechanics and astrodynamics._

0 commit comments

Comments
 (0)