Skip to content

Commit cb53152

Browse files
Merge pull request #57 from JuliaSpaceMissionDesign/dev
v2.1.0
2 parents a36949e + 5a9c781 commit cb53152

File tree

12 files changed

+241
-75
lines changed

12 files changed

+241
-75
lines changed

Project.toml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "FrameTransformations"
22
uuid = "5be70612-1674-42c4-a038-c376b6dc81ed"
33
authors = ["JSMD Team"]
4-
version = "2.0.0"
4+
version = "2.1.0"
55

66
[deps]
77
ForwardDiff = "f6369f11-7733-5829-9624-2563aa707210"
@@ -11,7 +11,6 @@ IERSConventions = "4e86e20e-879b-40dc-9e12-cee74f4cd199"
1111
JSMDInterfaces = "6b30ee2f-618e-4a15-bf4e-7df7b496e609"
1212
JSMDUtils = "67801824-9821-48b9-a814-9bfb19231086"
1313
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
14-
Logging = "56ddb016-857b-54e1-b83d-db4d58db5568"
1514
PrecompileTools = "aea7be01-6a6a-4083-8856-8a6e6704d82a"
1615
ReferenceFrameRotations = "74f56ac7-18b3-5285-802d-d4bd4f104033"
1716
SMDGraphs = "b792745b-7241-45be-ba96-70eb67e8468f"

ext/CalcephEphemerisExt.jl

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,13 @@ module CalcephEphemerisExt
22

33
import FrameTransformations: add_point_ephemeris!
44
using FrameTransformations: FrameSystem, add_point!, check_point_ephemeris,
5-
FramePointFunctions, POINT_CLASSID_DYNAMIC
5+
FramePointFunctions, POINT_CLASSID_DYNAMIC,
6+
SVectorNT
67
using JSMDInterfaces.Ephemeris: ephem_compute!
78
using CalcephEphemeris: CalcephProvider
89

10+
using StaticArrays
11+
912
function add_point_ephemeris!(
1013
frames::FrameSystem{O, N}, eph::CalcephProvider, name::Symbol, id::Int
1114
) where {O, N}
Lines changed: 65 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,18 @@
11

22
"""
3-
add_direction!(frames, name::Symbol, funs)
3+
add_direction!(frames, name::Symbol, axesid, funs)
44
55
Add a new direction node to `frames`.
66
77
### Inputs
88
- `frames` -- Target frame system
99
- `name` -- Direction name, must be unique within `frames`
10+
- `axesid` -- ID of the axes the direction is expressed in
1011
- `funs` -- `DirectionFunctions` object storing the functions to compute the direction and,
1112
eventually, its time derivatives. It must match the type and order of `frames`.
1213
"""
1314
function add_direction!(
14-
frames::FrameSystem{O, N}, name::Symbol, funs::DirectionFunctions{O, N}
15+
frames::FrameSystem{O, N}, name::Symbol, axesid::Int, funs::DirectionFunctions{O, N}
1516
) where {O, N <: Number}
1617
if name in directions(frames)
1718
throw(
@@ -21,13 +22,13 @@ function add_direction!(
2122
)
2223
end
2324

24-
dir = Direction{O, N}(name, length(directions(frames))+1, funs)
25+
dir = Direction{O, N}(name, length(directions(frames))+1, axesid, funs)
2526
push!(directions_map(frames), Pair(name, dir))
2627
nothing
2728
end
2829

2930
"""
30-
add_direction!(frames, name::Symbol, fun, δfun=nothing, δ²fun=nothing, δ³fun=nothing)
31+
add_direction!(frames, name::Symbol, axes, fun, δfun=nothing, δ²fun=nothing, δ³fun=nothing)
3132
3233
Add a new direction node to `frames`. The orientation of these direction depends only
3334
on time and is computed through the custom functions provided by the user.
@@ -46,7 +47,7 @@ If `δfun`, `δ²fun` or `δ³fun` are not provided, they are computed via autom
4647
function does not perform any checks on the output types.
4748
"""
4849
function add_direction!(
49-
frames::FrameSystem{O, N}, name::Symbol, fun::Function,
50+
frames::FrameSystem{O, N}, name::Symbol, ax, fun::Function,
5051
δfun = nothing, δ²fun = nothing, δ³fun = nothing
5152
) where {O, N}
5253

@@ -98,16 +99,16 @@ function add_direction!(
9899
t -> SVectorNT{3O, N}(δ³fun(t))
99100
end,
100101
)
101-
return add_direction!(frames, name, funs)
102+
return add_direction!(frames, name, axes_id(frames, ax), funs)
102103
end
103104

104105
"""
105-
add_direction_fixed!(frames, name, offset::AbstractVector)
106+
add_direction_fixed!(frames, name, axes, offset::AbstractVector)
106107
107108
Add a fixed direction to `frames`.
108109
"""
109110
function add_direction_fixed!(
110-
frames::FrameSystem{O, N}, name::Symbol, offset::AbstractVector{T}
111+
frames::FrameSystem{O, N}, name::Symbol, ax, offset::AbstractVector{T}
111112
) where {O, N, T}
112113

113114
if length(offset) != 3
@@ -121,77 +122,75 @@ function add_direction_fixed!(
121122
voffset = SVectorNT{3O, N}(SVector(offset...))
122123
funs = DirectionFunctions{O, N}(t -> voffset, t -> voffset, t -> voffset, t -> voffset)
123124

124-
return add_direction!(frames, name, funs)
125+
return add_direction!(frames, name, ax, funs)
125126
end
126127

127128
"""
128-
add_direction_position!(frames, name::Symbol, origin, target, ax)
129+
add_direction_position!(frames, name::Symbol, origin, target, axes)
129130
130-
Add a direction based on the position vector from `origin` to `target` in the specified `ax`.
131+
Add a direction based on the position vector from `origin` to `target` in the specified `axes`.
131132
"""
132133
function add_direction_position!(
133-
frames::FrameSystem{O, N}, name::Symbol, from::Symbol, to::Symbol, ax::Symbol
134+
frames::FrameSystem{O, N}, name::Symbol, from, to, ax
134135
) where {O, N}
135-
return add_direction_position!(
136-
frames, name, points(frames)[from], points(frames)[to], axes(frames)[ax]
137-
)
138-
end
139136

140-
function add_direction_position!(
141-
frames::FrameSystem{O, N}, name::Symbol, from::Int, to::Int, ax::Int
142-
) where {O, N}
137+
fromid, toid = point_id(frames, from), point_id(frames, to)
138+
axid = axes_id(frames, ax)
143139

144-
for id in (from, to)
140+
for id in (fromid, toid)
145141
!has_point(frames, id) && throw(
146-
ErrorException(
142+
ArgumentError(
147143
"no points with id $id registered in the given frame system."
148144
)
149145
)
150146
end
151147

152-
!has_axes(frames, ax) && throw(
153-
ErrorException(
148+
!has_axes(frames, axid) && throw(
149+
ArgumentError(
154150
"no axes with id $ax registered in the given frame system"
155151
)
156152
)
157153

158154
funs = DirectionFunctions{O, N}(
159-
t->SVectorNT{3O, N}(vector3(frames, from, to, ax, t)),
160-
t->SVectorNT{3O, N}(vector6(frames, from, to, ax, t)),
161-
t->SVectorNT{3O, N}(vector9(frames, from, to, ax, t)),
162-
t->SVectorNT{3O, N}(vector12(frames, from, to, ax, t))
155+
t->SVectorNT{3O, N}(vector3(frames, fromid, toid, axid, t)),
156+
t->SVectorNT{3O, N}(vector6(frames, fromid, toid, axid, t)),
157+
t->SVectorNT{3O, N}(vector9(frames, fromid, toid, axid, t)),
158+
t->SVectorNT{3O, N}(vector12(frames, fromid, toid, axid, t))
163159
)
164-
return add_direction!(frames, name, funs)
160+
return add_direction!(frames, name, axid, funs)
165161
end
166162

167163
"""
168-
add_direction_velocity!(frames, name::Symbol, origin, target, ax)
164+
add_direction_velocity!(frames, name::Symbol, origin, target, axes)
169165
170-
Add a direction based on the velocity vector from `origin` to `target` in the specified `ax`.
166+
Add a direction based on the velocity vector from `origin` to `target` in the specified `axes`.
171167
"""
172168
function add_direction_velocity!(
173-
frames::FrameSystem{O, N}, name::Symbol, from::Int, to::Int, ax::Int
169+
frames::FrameSystem{O, N}, name::Symbol, from, to, ax
174170
) where {O, N}
175171

176-
for id in (from, to)
172+
fromid, toid = point_id(frames, from), point_id(frames, to)
173+
axid = axes_id(frames, ax)
174+
175+
for id in (fromid, toid)
177176
!has_point(frames, id) && throw(
178-
ErrorException(
177+
ArgumentError(
179178
"no points with id $id registered in the given frame system."
180179
)
181180
)
182181
end
183182

184-
!has_axes(frames, ax) && throw(
185-
ErrorException(
183+
!has_axes(frames, axid) && throw(
184+
ArgumentError(
186185
"no axes with id $ax registered in the given frame system"
187186
)
188187
)
189188

190-
fun = t->SVectorNT{3O, N}(@views(vector6(frames, from, to, ax, t)[4:end]))
191-
dfun = t->SVectorNT{3O, N}(@views(vector9(frames, from, to, ax, t)[4:end]))
192-
ddfun= t->SVectorNT{3O, N}(@views(vector12(frames, from, to, ax, t)[4:end]))
189+
fun = t->SVectorNT{3O, N}(@views(vector6(frames, fromid, toid, axid, t)[4:end]))
190+
dfun = t->SVectorNT{3O, N}(@views(vector9(frames, fromid, toid, axid, t)[4:end]))
191+
ddfun= t->SVectorNT{3O, N}(@views(vector12(frames, fromid, toid, axid, t)[4:end]))
193192

194-
return add_direction!(frames, name, fun, dfun , ddfun)
193+
return add_direction!(frames, name, axid, fun, dfun , ddfun)
195194
end
196195

197196
"""
@@ -200,33 +199,41 @@ end
200199
Add a direction as the cross product between two existing directions (i.e. `dir1` and `dir2`).
201200
"""
202201
function add_direction_orthogonal!(
203-
frames::FrameSystem{O, N}, name::Symbol, dir1::Symbol, dir2::Symbol
202+
frames::FrameSystem{O, N}, name::Symbol, dir1::Symbol, dir2::Symbol, ax
204203
) where {O, N}
205204

206205
for d in (dir1, dir2)
207206
if !(d in directions(frames))
208207
throw(
209-
ErrorException(
208+
ArgumentError(
210209
"no direction with name $d registered in the given frame system"
211210
)
212211
)
213212
end
214213
end
215214

215+
axid = axes_id(frames, ax)
216+
217+
!has_axes(frames, axid) && throw(
218+
ArgumentError(
219+
"no axes with id $ax registered in the given frame system"
220+
)
221+
)
222+
216223
fun = t->SVectorNT{3O, N}(
217-
cross3(direction3(frames, dir1, t), direction3(frames, dir2, t))
224+
cross3(direction3(frames, dir1, axid, t), direction3(frames, dir2, axid, t))
218225
)
219226
dfun = t->SVectorNT{3O, N}(
220-
cross6(direction6(frames, dir1, t), direction6(frames, dir2, t))
227+
cross6(direction6(frames, dir1, axid, t), direction6(frames, dir2, axid, t))
221228
)
222229
ddfun = t->SVectorNT{3O, N}(
223-
cross9(direction9(frames, dir1, t), direction9(frames, dir2, t))
230+
cross9(direction9(frames, dir1, axid, t), direction9(frames, dir2, axid, t))
224231
)
225232
dddfun = t->SVectorNT{3O, N}(
226-
cross12(direction12(frames, dir1, t), direction12(frames, dir2, t))
233+
cross12(direction12(frames, dir1, axid, t), direction12(frames, dir2, axid, t))
227234
)
228235

229-
return add_direction!(frames, name, fun, dfun, ddfun, dddfun)
236+
return add_direction!(frames, name, axid, fun, dfun, ddfun, dddfun)
230237
end
231238

232239
"""
@@ -244,27 +251,29 @@ function add_direction_normalize!(
244251
)
245252
)
246253
end
247-
fun = t->SVectorNT{3O, N}(unitvec(direction3(frames, dir, t)))
248-
dfun = t->SVectorNT{3O, N}(_normalize6(frames, dir, t))
249-
ddfun = t->SVectorNT{3O, N}(_normalize9(frames, dir, t))
250-
dddfun = t->SVectorNT{3O, N}(_normalize12(frames, dir, t))
254+
axid = directions_map(frames)[dir].axesid
255+
256+
fun = t->SVectorNT{3O, N}(unitvec(direction3(frames, dir, axid, t)))
257+
dfun = t->SVectorNT{3O, N}(_normalize6(frames, dir, axid, t))
258+
ddfun = t->SVectorNT{3O, N}(_normalize9(frames, dir, axid, t))
259+
dddfun = t->SVectorNT{3O, N}(_normalize12(frames, dir, axid, t))
251260
return add_direction!(frames, name, fun, dfun, ddfun, dddfun)
252261
end
253262

254-
function _normalize6(frames, dir, t)
255-
d = direction6(frames, dir, t)
263+
function _normalize6(frames, dir, axid, t)
264+
d = direction6(frames, dir, axid, t)
256265
@views nd = vcat(unitvec(d[1:3]), δunitvec(d[4:6]))
257266
return nd
258267
end
259268

260-
function _normalize9(frames, dir, t)
261-
d = direction9(frames, dir, t)
269+
function _normalize9(frames, dir, axid, t)
270+
d = direction9(frames, dir, axid, t)
262271
@views nd = vcat(unitvec(d[1:3]), δunitvec(d[4:6]), δ²unitvec(d[7:9]))
263272
return nd
264273
end
265274

266-
function _normalize12(frames, dir, t)
267-
d = direction12(frames, dir, t)
275+
function _normalize12(frames, dir, axid, t)
276+
d = direction12(frames, dir, axid, t)
268277
@views nd = vcat(unitvec(d[1:3]), δunitvec(d[4:6]), δ²unitvec(d[7:9]), δ³unitvec(d[10:12]))
269278
return nd
270279
end

src/Core/nodes.jl

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -308,17 +308,18 @@ Define a new direction.
308308
struct Direction{O, N, D}
309309
name::Symbol
310310
id::Int
311+
axesid::Int
311312

312313
# internals
313314
f::DirectionFunctions{O, N, D}
314315
end
315316

316317
function Direction{O, N}(
317-
name::Symbol, id::Int, dfun::DirectionFunctions{O, N, D}
318+
name::Symbol, id::Int, axesid::Int, dfun::DirectionFunctions{O, N, D}
318319
) where {O, N, D}
319-
return Direction{O, N, 3O}(name, id, dfun)
320+
return Direction{O, N, 3O}(name, id, axesid, dfun)
320321
end
321322

322323
function Base.show(io::IO, d::Direction{O, N, D}) where {O, N, D}
323-
return println(io, "Direction{$O, $N}(name=$(d.name), id=$(d.id))")
324+
return println(io, "Direction{$O, $N}(name=$(d.name), id=$(d.id), axesid=$(d.axesid))")
324325
end

src/Core/transform.jl

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -271,27 +271,28 @@ for (order, axfun, _axfun, pfun, _pfun, _pfwd, _pbwd, dfun) in zip(
271271
@eval begin
272272

273273
"""
274-
$($dfun)(frame::FrameSystem, name::Symbol, ep::Epoch)
274+
$($dfun)(frames::FrameSystem, name::Symbol, axes, ep::Epoch)
275275
276-
Compute the direction vector `name` of order $(3*$order) at epoch `ep`.
276+
Compute the direction vector `name` of order $(3*$order) at epoch `ep` expressed in
277+
the `axes` frame.
277278
278279
Requires a frame system of order ≥ $($order).
279280
"""
280281
@inline function ($dfun)(
281-
frame::FrameSystem{<:Any,<:Any,S}, name::Symbol, ep::Epoch{S}
282+
frames::FrameSystem{<:Any,<:Any,S}, name::Symbol, ax, ep::Epoch{S}
282283
) where {S}
283-
return $(dfun)(frame, name, j2000s(ep))
284+
return $(dfun)(frames, name, j2000s(ep))
284285
end
285286

286287
"""
287-
$($dfun)(frame::FrameSystem, name::Symbol, t::Number)
288+
$($dfun)(frames::FrameSystem, name::Symbol, axes, t::Number)
288289
289290
Compute the direction vector `name` of order $(3*$order) at epoch `t`, where `t` is
290291
expressed in seconds since `J2000`.
291292
292293
Requires a frame system of order ≥ $($order).
293294
"""
294-
function ($dfun)(frame::FrameSystem{O, N}, name::Symbol, t::Number) where {O, N}
295+
function ($dfun)(frames::FrameSystem{O, N}, name::Symbol, ax, t::Number) where {O, N}
295296
if O < $order
296297
throw(
297298
ErrorException(
@@ -301,17 +302,27 @@ for (order, axfun, _axfun, pfun, _pfun, _pfwd, _pbwd, dfun) in zip(
301302
)
302303
end
303304

304-
if !has_direction(frame, name)
305+
if !has_direction(frames, name)
305306
throw(
306307
ErrorException(
307308
"No direction with name $(name) registered in the frame system."
308309
)
309310
)
310311
end
311312

312-
stv = directions_map(frame)[name].f[$order](t)
313+
node = directions_map(frames)[name]
314+
stv = node.f[$order](t)
313315
D = 3 * $order
314-
@views return SA[(stv[1:D])...]
316+
y = @views SA[(stv[1:D])...]
317+
318+
thisaxid = node.axesid
319+
axid = axes_id(frames, ax)
320+
321+
if thisaxid == axid
322+
return y
323+
end
324+
return ($axfun)(frames, thisaxid, axid, t) * y
325+
315326
end
316327

317328
end

src/Definitions/ephemeris.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ function add_point_ephemeris!(
4040
) where {O, N}
4141
records = ephem_position_records(eph)
4242
for id in sort(ephem_available_points(eph))
43-
!haskey(book, id) && throw(KeyError("Cannot find point with ID $id in the names book"))
43+
!haskey(book, id) && @warn "Cannot find point with ID $id in the names book" continue
4444

4545
if id == 0
4646
if length(points_graph(frames).nodes) == 0

0 commit comments

Comments
 (0)