Skip to content

Commit

Permalink
Update SpiceUtils initialisation to load the default kernels.
Browse files Browse the repository at this point in the history
  • Loading branch information
dpad committed Feb 27, 2021
1 parent 98c602f commit 29b24de
Showing 1 changed file with 15 additions and 14 deletions.
29 changes: 15 additions & 14 deletions src/SPICE/spice.jl
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,6 @@ module SpiceUtils
export state_to_synodic, state_from_synodic
export pos_to_synodic, pos_from_synodic

function __init__()
# Load the meta kernels
load_kernel_artifact("meta_kernels")
nothing
end

const artifacts_toml = find_artifacts_toml(@__DIR__)
const kernel_bodies = Dict(
# List of bodies included in each default kernel file (as specified in build.jl)
Expand All @@ -32,11 +26,14 @@ module SpiceUtils
"pluto" => tuple(901:905..., 999)
)
const body_to_kernel = Dict(idx => kernel for (kernel, bodies) in kernel_bodies for idx in bodies)

function __init__()
load_kernel_artifact("meta_kernels")
load_kernel_artifact("default_kernels")
nothing
end

@memoize function load_ephemerides(body_name)
# XXX: This is a bit of a hacky workaround of the existing Pkg.Artifacts system,
# which supports lazy artifact loading but assumes the files it downloads are
# gzipped. However, our kernels are just files straight from the NAIF site, so we
# instead load them lazily here. artifact"(body)_kernels" will only work after this.
body_name = lowercase(String(body_name))
body_ID = bodn2c(body_name)

Expand All @@ -47,11 +44,15 @@ module SpiceUtils
end

artifact_name = "$(body_to_kernel[body_ID])_kernels"
load_kernel_artifact(artifact_name)
return true
return load_kernel_artifact(artifact_name)
end

function load_kernel_artifact(artifact_name)
@memoize function load_kernel_artifact(artifact_name)
# XXX: This is a bit of a hacky workaround of the existing Pkg.Artifacts system,
# which supports lazy artifact loading but assumes the files it downloads are
# gzipped. However, our kernels are just files straight from the NAIF site, so we
# instead load them lazily here. artifact"(body)_kernels" will only work after this.

# Get artifact details.
meta = artifact_meta(artifact_name, artifacts_toml)
isnothing(meta) && error("Expected to find $(artifact_name) in Artifacts.toml, but could not find it!")
Expand Down Expand Up @@ -84,7 +85,7 @@ module SpiceUtils
furnsh(kernel)
end

nothing
return true
end

@doc "Get a target body position from SPICE kernels."
Expand Down

2 comments on commit 29b24de

@dpad
Copy link
Owner Author

@dpad dpad commented on 29b24de Feb 27, 2021

Choose a reason for hiding this comment

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

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

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

Registration pull request updated: JuliaRegistries/General/30854

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.1.0 -m "<description of version>" 29b24debc89d007d3ea7e2ad20d565c880a620c0
git push origin v0.1.0

Please sign in to comment.