{"library":"spiceypy","title":"SpiceyPy","type":"library","description":"SpiceyPy is a Python wrapper for NASA's NAIF CSPICE Toolkit, providing tools for computing ephemeris, attitude, event finding, and geometry for spacecraft and celestial bodies. It enables Python users to leverage the powerful CSPICE library. The library is actively maintained with frequent releases, currently at version 8.1.0, and often includes performance enhancements and new features.","language":"python","status":"active","last_verified":"Fri Apr 17","install":{"commands":["pip install spiceypy"],"cli":null},"imports":["import spiceypy as spice","from spiceypy import cyice"],"auth":{"required":false,"env_vars":[]},"links":{"homepage":null,"github":"https://github.com/AndrewAnnex/SpiceyPy","docs":"https://spiceypy.readthedocs.io","changelog":"https://github.com/AndrewAnnex/SpiceyPy/blob/main/CHANGELOG.md","pypi":"https://pypi.org/project/spiceypy/","npm":null,"openapi_spec":null,"status_page":null,"smithery":null},"quickstart":{"code":"import spiceypy as spice\nimport os\n\n# A simple kernel file for demonstration\n# In a real application, you would download these from NAIF\n# For local testing, ensure naif0012.tls is in the script's directory\n# or specify its full path.\nkernel_path = os.path.join(os.path.dirname(__file__), 'naif0012.tls')\nif not os.path.exists(kernel_path):\n    # This is a dummy for demonstration. You would fetch a real kernel.\n    print(f\"Warning: '{kernel_path}' not found. Please download from NAIF if this isn't a test.\")\n    # Example: You'd typically download like this (replace with actual URL and process)\n    # import urllib.request\n    # url = 'https://naif.jpl.nasa.gov/pub/naif/generic_kernels/lsk/naif0012.tls'\n    # urllib.request.urlretrieve(url, kernel_path)\n\n# Load a leap second kernel (LSK) to define Ephemeris Time (ET)\ntry:\n    spice.furnsh(kernel_path)\nexcept spice.exceptions.SpiceyPyError as e:\n    print(f\"Failed to load kernel: {e}. Skipping calculations.\")\n    exit()\n\n# Convert a UTC string to Ephemeris Time (ET)\nutc_time = '2023-01-01 T00:00:00'\net = spice.str2et(utc_time)\nprint(f\"UTC: {utc_time} -> ET: {et}\")\n\n# Get position of Earth relative to the Sun\n# Observer: SUN, Target: EARTH, Reference Frame: J2000, Aberration Correction: NONE\npos, lt = spice.spkpos('EARTH', et, 'J2000', 'NONE', 'SUN')\nprint(f\"Position of Earth relative to Sun (km): {pos}\")\n\n# Unload all kernels\nspice.unload(kernel_path)\n# Alternatively, spice.kclear() clears all loaded kernels\n","lang":"python","description":"This quickstart demonstrates loading a leap second kernel (LSK) using `spice.furnsh()`, converting a UTC time string to Ephemeris Time (ET) with `spice.str2et()`, and then calculating the position of Earth relative to the Sun using `spice.spkpos()`. It's crucial to download and correctly point to actual SPICE kernel files (LSK, PCK, SPK, FK, IK, CK) from the NAIF website for real applications. The example includes a placeholder for a kernel path.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}