Skip to content

Commit c5113dc

Browse files
author
Joey Carpinelli
committed
Moves SPICEKernels types into base package
1 parent 506795f commit c5113dc

File tree

5 files changed

+156
-2
lines changed

5 files changed

+156
-2
lines changed

lib/EphemerisSourcesBase/Project.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "EphemerisSourcesBase"
22
uuid = "b8f1d712-e88d-4f2a-8498-e66ce688ee29"
33
authors = ["Joey Carpinelli <[email protected]>"]
4-
version = "0.1.2"
4+
version = "0.2.0"
55

66
[deps]
77
AstroTime = "c61b5328-d09d-5e37-a9a8-0eb41c39009c"

lib/EphemerisSourcesBase/docs/src/reference/index.md

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ _All docstrings!_
55
```@autodocs
66
Modules = [
77
EphemerisSourcesBase,
8+
EphemerisSourcesBase.Types
89
]
910
Order = [:module, :type, :function, :constant]
1011
```

lib/EphemerisSourcesBase/src/EphemerisSourcesBase.jl

+2
Original file line numberDiff line numberDiff line change
@@ -52,5 +52,7 @@ function naifcode(name::Union{<:AbstractString,Symbol})
5252
end
5353
end
5454

55+
include("types.jl")
56+
5557

5658
end # module EphemerisSourcesBase

lib/EphemerisSourcesBase/src/types.jl

+151
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,151 @@
1+
#
2+
# Abstract and concrete types, and methods, for SPICE kernels
3+
#
4+
5+
module Types
6+
7+
"""
8+
A supertype for all SPICE Kernels! To satisfy the `SPICEKernel` interface, your new type
9+
must implement each of the methods below.
10+
11+
- `SPICEKernels.type(kernel)::AbstractString`
12+
- `SPICEKernels.path(kernel)::AbstractString`
13+
"""
14+
abstract type SPICEKernel end
15+
16+
17+
function (kernel::SPICEKernel)(; ignorecache = false, directory = SPICE_KERNEL_DIR)
18+
return fetchkernel(path(kernel); ignorecache = ignorecache, directory = directory)
19+
end
20+
21+
"""
22+
Return the underlying SPICE kernel type.
23+
"""
24+
function type end
25+
26+
"""
27+
Return the path to the kernel. This can be a URL!
28+
"""
29+
function path end
30+
31+
"""
32+
A supertype representing Digital Shape Kernels (DSK).
33+
"""
34+
abstract type DigitalShapeKernel <: SPICEKernel end
35+
36+
"""
37+
A supertype representing Frames Kernels (FK).
38+
"""
39+
abstract type FramesKernel <: SPICEKernel end
40+
41+
"""
42+
A supertype representing Leapseconds Kernels (LSK).
43+
"""
44+
abstract type LeapSecondsKernel <: SPICEKernel end
45+
46+
"""
47+
A supertype representing Planetary Constants Kernels (PCK).
48+
"""
49+
abstract type PlanetaryConstantsKernel <: SPICEKernel end
50+
51+
"""
52+
A supertype representing Spacecraft and Planet Kernels, also known as ephemeris kernels (SPK).
53+
"""
54+
abstract type EphemerisKernel <: SPICEKernel end
55+
56+
57+
const SPICE_EXTENSIONS = Base.ImmutableDict(
58+
".bsp" => EphemerisKernel,
59+
".dsk" => DigitalShapeKernel,
60+
".pck" => PlanetaryConstantsKernel,
61+
".bds" => DigitalShapeKernel,
62+
".tf" => FramesKernel,
63+
".tpc" => PlanetaryConstantsKernel,
64+
".bpc" => PlanetaryConstantsKernel,
65+
".tls" => LeapSecondsKernel,
66+
".pc" => LeapSecondsKernel,
67+
)
68+
69+
"""
70+
Fallback method to inspect the file extension of the provided kernel, and
71+
return the expected kernel type. If the file extension is not recognized,
72+
a `KeyError` is thrown.
73+
"""
74+
function type(kernel::Union{<:SPICEKernel,<:AbstractString})
75+
if kernel isa SPICEKernel
76+
name = basename(path(kernel))
77+
else
78+
name = basename(kernel)
79+
end
80+
81+
ext = last(splitext(name))
82+
83+
return SPICE_EXTENSIONS[ext]
84+
end
85+
86+
"""
87+
A planetary & spacecraft ephemeris kernel.
88+
"""
89+
struct SPK <: EphemerisKernel
90+
source::String
91+
SPK(source::AbstractString) = new(convert(String, source))
92+
end
93+
type(::SPK) = EphemerisKernel
94+
path(kernel::SPK) = kernel.source
95+
96+
"""
97+
A digital shape kernel.
98+
"""
99+
struct DSK <: DigitalShapeKernel
100+
source::String
101+
DSK(source::AbstractString) = new(convert(String, source))
102+
end
103+
type(::DSK) = DigitalShapeKernel
104+
path(kernel::DSK) = kernel.source
105+
106+
"""
107+
A planetary constants kernel.
108+
"""
109+
struct PCK <: PlanetaryConstantsKernel
110+
source::String
111+
PCK(source::AbstractString) = new(convert(String, source))
112+
end
113+
type(::PCK) = PlanetaryConstantsKernel
114+
path(kernel::PCK) = kernel.source
115+
116+
"""
117+
A coordinate frames kernel.
118+
"""
119+
struct FK <: FramesKernel
120+
source::String
121+
FK(source::AbstractString) = new(convert(String, source))
122+
end
123+
type(::FK) = FramesKernel
124+
path(kernel::FK) = kernel.source
125+
126+
"""
127+
A leapseconds kernel.
128+
"""
129+
struct LSK <: LeapSecondsKernel
130+
source::String
131+
LSK(source::AbstractString) = new(convert(String, source))
132+
end
133+
type(::LSK) = LeapSecondsKernel
134+
path(kernel::LSK) = kernel.source
135+
136+
export EphemerisKernel,
137+
FramesKernel,
138+
PlanetaryConstantsKernel,
139+
LeapSecondsKernel,
140+
DigitalShapeKernel,
141+
SPICEKernel,
142+
SPICE_EXTENSIONS,
143+
type,
144+
path,
145+
SPK,
146+
DSK,
147+
LSK,
148+
PCK,
149+
FK
150+
151+
end
+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
using Test, EphemerisSourcesBase
1+
using Test, EphemerisSourcesBase, EphemerisSourcesBase.Types

0 commit comments

Comments
 (0)