AstroUniverse

The AstroUniverse module provides models for celestial bodies, their physical properties, and related utilities for astrodynamics applications. It includes predefined celestial body objects with standard gravitational parameters and other physical constants commonly used in orbital mechanics.

The module automatically downloads and manages SPICE kernels (NASA's ephemeris data) to provide accurate celestial body positions and orientations using Scratch.jl.

Quick Start

The example below shows how to access predefined celestial bodies and their properties and how to add a celestial body:

using AstroUniverse

# Access predefined celestial bodies
earth.mu
venus.naifid

# Create a custom body
phobos = CelestialBody(
    name = "Phobos",
    naifid = 401,                    # NAIF ID for Phobos
    mu = 7.0875e-4,       # km³/s² (gravitational parameter)
    equatorial_radius = 11.1,                   # km (mean radius)
)

# Define a texture map for 3D graphics
custom_body = CelestialBody(
    texture_file = "/path/to/texture.jpg"
)

Note: built-in bodies include sun, mercury, venus, earth, moon, mars, jupiter, saturn, uranus, neptune, and pluto.

SPICE Kernels and Ephemeris Data

AstroUniverse uses NASA's SPICE system for high-fidelity ephemeris calculations. SPICE provides accurate positions and orientations of celestial bodies across time.

Default Kernels

The following kernels are automatically downloaded and loaded when you first use AstroUniverse:

  • naif0012.tls: Leap second kernel for time conversions
  • de440.bsp: Planetary ephemeris covering years 1550-2650

These kernels are stored using Scratch.jl and persist across Julia sessions, so they only download once.

Basic Workflow

Loading additional SPICE kernels is a two-step process:

using AstroUniverse

# Step 1: Download kernel to persistent storage (only happens once)
download_spice_kernel("de440s.bsp",
    "https://naif.jpl.nasa.gov/pub/naif/generic_kernels/spk/planets/de440s.bsp")

# Step 2: Load kernel into SPICE system
load_spice_kernel("de440s.bsp")

This separation allows you to download kernels once and selectively load different combinations in different sessions.

Common Use Cases

Large File Downloads

The examples below download ephemeris files ranging from ~13 MB to ~114 MB. These files are stored locally and only download once, but be aware of the initial download time and bandwidth usage.

Extended Planetary Ephemeris:

# Smaller file size, same time range as de440 (1550-2650)
download_spice_kernel("de440s.bsp",
    "https://naif.jpl.nasa.gov/pub/naif/generic_kernels/spk/planets/de440s.bsp")
load_spice_kernel("de440s.bsp")

# Extended time range planetary ephemeris (1550-2650, larger file)
download_spice_kernel("de430.bsp",
    "https://naif.jpl.nasa.gov/pub/naif/generic_kernels/spk/planets/de430.bsp")
load_spice_kernel("de430.bsp")

Satellite Ephemerides:

# Mars satellites (Phobos, Deimos)
download_spice_kernel("mar099.bsp",
    "https://naif.jpl.nasa.gov/pub/naif/generic_kernels/spk/satellites/mar099.bsp")
load_spice_kernel("mar099.bsp")

# Jupiter satellites (Io, Europa, Ganymede, Callisto)
download_spice_kernel("jup365.bsp",
    "https://naif.jpl.nasa.gov/pub/naif/generic_kernels/spk/satellites/jup365.bsp")
load_spice_kernel("jup365.bsp")

# Saturn satellites
download_spice_kernel("sat441.bsp",
    "https://naif.jpl.nasa.gov/pub/naif/generic_kernels/spk/satellites/sat441.bsp")
load_spice_kernel("sat441.bsp")

Browse all available kernels:

  • Planetary: https://naif.jpl.nasa.gov/pub/naif/generic_kernels/spk/planets/
  • Satellites: https://naif.jpl.nasa.gov/pub/naif/generic_kernels/spk/satellites/
  • Leap seconds: https://naif.jpl.nasa.gov/pub/naif/generic_kernels/lsk/

Managing Kernels

List downloaded kernels (files on disk):

list_downloaded_spice_kernels()
# Output:
# Downloaded SPICE Kernels:
#   naif0012.tls              (5.3 KB)
#   de440.bsp                 (114.0 MB)
#   de440s.bsp                (31.0 MB)
#   jup365.bsp                (13.2 MB)

List loaded kernels (in SPICE memory):

list_cached_spice_kernels()
# Output:
# Cached SPICE Kernels (3 loaded):
#   naif0012.tls
#   de440.bsp
#   jup365.bsp

Get storage directory:

cache_dir = get_spice_directory()
println("Kernels stored at: ", cache_dir)

Unload specific kernel:

# Swap ephemeris versions
unload_spice_kernel("de440.bsp")
load_spice_kernel("de440s.bsp")

Clear all loaded kernels:

# Start fresh with custom configuration
unload_all_spice_kernels()
load_spice_kernel("naif0012.tls")
load_spice_kernel("de440s.bsp")
load_spice_kernel("jup365.bsp")

Custom Configurations

For specialized analyses, you can create custom kernel configurations:

using AstroUniverse

# Clear default kernels
unload_all_spice_kernels()

# Load only what you need
load_spice_kernel("naif0012.tls")      # Required for time conversions
load_spice_kernel("de440s.bsp")        # Smaller planetary ephemeris
load_spice_kernel("mar099.bsp")        # Mars satellites only

# Your analysis code here...

Advanced Usage

Manual file placement:

# Get storage directory
storage_dir = get_spice_directory()

# Copy a local kernel file to storage
cp("my_custom_kernel.bsp", joinpath(storage_dir, "my_custom_kernel.bsp"))

# Load it
load_spice_kernel("my_custom_kernel.bsp")

Delete downloaded kernels:

Kernels persist across sessions. To remove them, use standard filesystem operations:

storage_dir = get_spice_directory()
rm(joinpath(storage_dir, "old_kernel.bsp"))

The storage directory is managed by Scratch.jl and will be automatically cleaned if the package is removed.

Texture Maps

Relatively small texture files for the Sun and planets are distributed with AstroUniverse in the AstroUniverse/data folder. Thanks to https://www.solarsystemscope.com/ for texture maps which are licensed using the Creative Commons 4.0 BY license.

Table of Contents

API Reference

AstroUniverse.CelestialBodyType

CelestialBody(name::AbstractString, mu::Real, equatorialradius::Real, flattening::Real, naifid::Integer, texturefile::AbstractString)

Positional outer constructor that promotes numeric fields to a common type.

source
AstroUniverse.CelestialBodyType
CelestialBody(name::AbstractString, mu::Real, equatorial_radius::Real, flattening::Real, naifid::Integer)

Represents a celestial body with physical parameters.

Fields (units):

  • name::String
  • mu::T — gravitational parameter
  • equatorial_radius::T — equatorial radius
  • flattening::T — geometric flattening
  • naifid::Int — NAIF body ID
  • texture_file::String — path to texture image file for visualization (optional)

Notes:

  • Numeric fields (mu, equatorial_radius, flattening) are promoted to a common element type T to ensure type stability (e.g., passing a BigFloat will promote the others to BigFloat).
  • Units default to km and seconds for built-in celestial bodies. If changing units, be consistent throughout the simulation.

Examples

using AstroUniverse
moon_like = CelestialBody(name="MyMoon", 
                                 mu=4902.8, 
                                 equatorial_radius=1737.4, 
                                 flattening=0.0,
                                 naifid=301,
                                 texture_file="path/to/moon_texture.jpg");
show(moon_like)

# output
CelestialBody:
  name               = MyMoon
  μ                  = 4902.8
  Equatorial Radius  = 1737.4
  Flattening         = 0.0
  NAIF ID            = 301
  Texture File       = path/to/moon_texture.jpg
source
AstroUniverse.CelestialBodyMethod
CelestialBody(; name="unnamed", mu=earth.mu,
                equatorial_radius=earth.equatorial_radius,
                flattening=earth.flattening, naifid=earth.naifid,
                texture_file="")

Keyword outer constructor that defaults all fields to Earth's values. Numeric fields are promoted to a common element type.

source
AstroUniverse.download_spice_kernelMethod
download_spice_kernel(filename::AbstractString, url::AbstractString)

Download a SPICE kernel from the given URL to the cache directory.

The kernel is cached in the AstroUniverse managed scratch directory, so it will only be downloaded once and persist across Julia sessions. This function does NOT load the kernel into SPICE - use load_spice_kernel after downloading.

Arguments

  • filename: Name of the kernel file (e.g., "de441.bsp")
  • url: Full URL to download the kernel from

Examples

using AstroUniverse

# Download Mars satellite ephemeris (Phobos, Deimos)
download_spice_kernel("mar099.bsp",
    "https://naif.jpl.nasa.gov/pub/naif/generic_kernels/spk/satellites/mar099.bsp")

# Then load it
load_spice_kernel("mar099.bsp")

All kernels available at: https://naif.jpl.nasa.gov/pub/naif/generic_kernels/

See also: load_spice_kernel, get_spice_directory

source
AstroUniverse.get_spice_directoryMethod
get_spice_directory()

Return the path to the AstroUniverse SPICE kernel cache directory.

This directory persists across Julia sessions and is managed by Scratch.jl. You can manually place kernel files here to avoid downloading them.

Examples

using AstroUniverse

dir = get_spice_directory()
println("SPICE kernels cached at: ", dir)

# Manually copy a kernel file to the cache
# cp("my_kernel.bsp", joinpath(dir, "my_kernel.bsp"))
# Then load it
# load_spice_kernel("my_kernel.bsp")

See also: download_spice_kernel, list_downloaded_spice_kernels

source
AstroUniverse.list_cached_spice_kernelsMethod
list_cached_spice_kernels()

List all SPICE kernels currently loaded in memory.

Displays the filenames of kernels that have been furnished to SPICE and are actively being used. This shows what's actually in the SPICE kernel pool, not what's downloaded to disk.

Examples

using AstroUniverse

list_cached_spice_kernels()

# output
Cached SPICE Kernels (2 loaded):
  naif0012.tls
  de440.bsp

See also: load_spice_kernel, unload_spice_kernel, list_downloaded_spice_kernels

source
AstroUniverse.list_downloaded_spice_kernelsMethod
list_downloaded_spice_kernels()

List all SPICE kernel files (.bsp and .tls) downloaded to the persistent storage directory.

Displays kernel filenames with their file sizes in a formatted table. These are files available for loading, not necessarily currently loaded in SPICE memory. Use list_cached_spice_kernels to see which kernels are currently loaded.

Examples

using AstroUniverse

list_downloaded_spice_kernels()

# output
Downloaded SPICE Kernels:
  naif0012.tls              (5.3 KB)
  de440.bsp                 (114.0 MB)
  mar099.bsp                (2.1 MB)

Storage location: /path/to/scratch/spice_kernels

See also: download_spice_kernel, list_cached_spice_kernels, get_spice_directory

source
AstroUniverse.load_spice_kernelMethod
load_spice_kernel(filename::AbstractString)

Load a SPICE kernel from the cache directory into the SPICE system.

The kernel file must already exist in the cache (use download_spice_kernel first if needed). This calls SPICE.furnsh() to register the kernel.

Arguments

  • filename: Name of the kernel file in the cache (e.g., "de441.bsp")

Examples

using AstroUniverse

# Download then load
download_spice_kernel("de440.bsp",
    "https://naif.jpl.nasa.gov/pub/naif/generic_kernels/spk/planets/de440.bsp")
load_spice_kernel("de440.bsp")

# Or just load if already downloaded
load_spice_kernel("naif0012.tls")  # Default kernel

See also: download_spice_kernel, unload_spice_kernel, unload_all_spice_kernels

source
AstroUniverse.translateMethod
function translate(from::CelestialBody, to::CelestialBody, jd_tdb::Real)

Compute the ICRF position vector from one body to another at a given TDB Julian date.

Arguments

  • from: Observing/origin body.
  • to: Target body.
  • jd_tdb: Julian date in the TDB time scale.

Notes:

  • Requires SPICE kernels to be loaded with SPICE.furnsh before calling.
  • Uses the J2000/ICRF frame; distances are kilometers.

Returns

  • 3-element position vector [x, y, z] in kilometers, from from to to, in ICRF (J2000).

Examples

# vector from Earth to Moon
using AstroUniverse
r_em = translate(earth, moon, 2458018.0)
println(r_em)

# output (may differ slightly due to SPICE kernel versions):
3-element Vector{Real}:
 -375694.5992365016
  -96115.68241892057
  -12226.882894748915
source
AstroUniverse.unload_all_spice_kernelsMethod
unload_all_spice_kernels()

Unload all SPICE kernels from memory.

This calls SPICE.kclear() to remove all loaded kernels. Useful for creating custom kernel configurations. The files remain in the storage directory.

Examples

using AstroUniverse

# Create custom configuration
unload_all_spice_kernels()
list_cached_spice_kernels()  # Shows none loaded

See also: load_spice_kernel, unload_spice_kernel

source
AstroUniverse.unload_spice_kernelMethod
unload_spice_kernel(filename::AbstractString)

Unload a specific SPICE kernel from the SPICE system.

This calls SPICE.unload() to remove the kernel from memory. The file remains in the cache.

Arguments

  • filename: Name of the kernel file to unload (e.g., "de440.bsp")

Examples

using AstroUniverse

# Swap planetary ephemeris versions
unload_spice_kernel("de440.bsp")
load_spice_kernel("de440.bsp")

See also: load_spice_kernel, unload_all_spice_kernels

source
Base.showMethod
Base.show(io::IO, body::CelestialBody)

Delegate show to MIME"text/plain" output.

source
Base.showMethod
function show(io::IO, ::MIME"text/plain", body::CelestialBody)

Show method for text/plain output.

source