### Type 1 SCLK Partition Only Example Source: https://github.com/andrewannex/spiceypy/blob/main/docs/sclk.md Shows an example of just the partition number and delimiter, indicating the start of a partition. ```text 4 / ``` -------------------------------- ### Install SpiceyPy from Local Source Source: https://github.com/andrewannex/spiceypy/blob/main/docs/installation.md After cloning the repository, navigate to the project's root directory and run this command to install SpiceyPy. This process builds the necessary shared library and installs the package. ```default pip install . ``` -------------------------------- ### CK Type 3 Interval Start Time Directory Example Source: https://github.com/andrewannex/spiceypy/blob/main/docs/ck.md The directory for interval start times contains INT ( (NUMINT-1) / 100 ) entries, storing every 100th start time. This structure helps in efficiently locating interval data within the segment. ```text Directory(1) = START(100) Directory(2) = START(200) . . . ``` -------------------------------- ### Meta-Kernel for getsta Example Source: https://github.com/andrewannex/spiceypy/blob/main/docs/remote_sensing.md This meta-kernel lists the necessary SPICE kernels for the 'getsta' example. Ensure these kernels are available in your SPICE system. ```python mk = r""" KPL/MK This is the meta-kernel used in the solution of the "Obtaining Target States and Positions" task in the Remote Sensing Hands On Lesson. The names and contents of the kernels referenced by this meta-kernel are as follows: File name Contents -------------------------- ----------------------------- naif0008.tls Generic LSK 981005_PLTEPH-DE405S.bsp Solar System Ephemeris 020514_SE_SAT105.bsp Saturnian Satellite Ephemeris 030201AP_SK_SM546_T45.bsp Cassini Spacecraft SPK """ ``` -------------------------------- ### List Installed Packages Source: https://github.com/andrewannex/spiceypy/blob/main/docs/basics.md Verify SpiceyPy installation by checking the list of installed Python packages. ```bash pip list ``` -------------------------------- ### Install SpiceyPy with micropip Source: https://github.com/andrewannex/spiceypy/blob/main/docs/pyodide.md Use this command to install the SpiceyPy library in a Pyodide environment that supports micropip. ```python import micropip await micropip.install("spiceypy") ``` -------------------------------- ### Install SpiceyPy using Pip Source: https://github.com/andrewannex/spiceypy/blob/main/docs/installation.md The standard method for installing SpiceyPy is via pip. This command fetches and installs the latest stable version. ```default pip install spiceypy ``` -------------------------------- ### Install SpiceyPy on Windows Source: https://github.com/andrewannex/spiceypy/wiki/Building-notes. This command installs SpiceyPy using pip. Ensure Visual Studio is installed and its build tools (cl.exe, link.exe) are on the system's PATH. The vcvarsall.bat script must be called with the appropriate architecture option (e.g., 'amd64'). ```bash python setup.py install ``` -------------------------------- ### Install SpiceyPy with piplite Source: https://github.com/andrewannex/spiceypy/blob/main/docs/pyodide.md Use this command to install the SpiceyPy library in a Pyodide environment that supports piplite. ```python import piplite await piplite.install("spiceypy") ``` -------------------------------- ### Install/Update Pip and Setuptools Source: https://github.com/andrewannex/spiceypy/blob/main/docs/installation.md Before installing SpiceyPy, it's recommended to update pip, setuptools, and wheel. This ensures you have the latest package management tools. ```default pip install -U pip setuptools ``` -------------------------------- ### Get Help for str2et Function Source: https://github.com/andrewannex/spiceypy/blob/main/docs/binary_pck.md This snippet demonstrates how to use Python's built-in help() function to get detailed information about the spiceypy.str2et function, including its parameters and usage. ```python import spiceypy help(spiceypy.str2et) ``` -------------------------------- ### Import SpiceyPy Source: https://github.com/andrewannex/spiceypy/blob/main/docs/basics.md Confirm SpiceyPy is installed and importable within a Python REPL. ```python import spiceypy as spice ``` -------------------------------- ### SPICE Text Kernel Structure Example Source: https://github.com/andrewannex/spiceypy/blob/main/docs/other_stuff.md This example shows the typical structure of a text kernel, with commentary information preceding the data assignments, separated by \begintext and \begindata tags. ```text \begintext ... commentary information on the data assignments ... \begindata ... data assignments ... ``` -------------------------------- ### Type 1 SCLK Partition Example Source: https://github.com/andrewannex/spiceypy/blob/main/docs/sclk.md Illustrates a Type 1 SCLK string with an explicit partition number and delimiter. ```text 3 / 10110007:09:6:1 ``` -------------------------------- ### Example CK Frame Specification Source: https://github.com/andrewannex/spiceypy/blob/main/docs/frames.md This example demonstrates how to define a CK frame named 'WALDO' for a fictional spacecraft. It includes the frame specification and the necessary CK_..._SCLK and CK_..._SPK variable definitions. ```text \begindata FRAME_WALDO = -100001 FRAME_-100001_NAME = 'WALDO' FRAME_-100001_CLASS = 3 FRAME_-100001_CLASS_ID = -100001 FRAME_-100001_CENTER = -1001 CK_-100001_SCLK = -1002 CK_-100001_SPK = -1001 \begintext ``` -------------------------------- ### Example Frame Specification Kernel Source: https://github.com/andrewannex/spiceypy/blob/main/docs/frames.md This is a concrete example of a Frame Specification Kernel (FK) defining the 'WALDO' frame. It includes the frame's ID, name, class, center, and class ID. ```text \begindata FRAME_WALDO = 1234567 FRAME_1234567_NAME = 'WALDO' FRAME_1234567_CLASS = 3 FRAME_1234567_CENTER = -10001 FRAME_1234567_CLASS_ID = -10000001 \begintext ``` -------------------------------- ### Execute SpiceyPy Version Script from Command Line Source: https://github.com/andrewannex/spiceypy/blob/main/docs/installation.md Run the 'tkvrsn.py' script from your terminal to verify the SpiceyPy installation and output the toolkit version. ```default $ python tkvrsn.py CSPICE_N0067 ``` -------------------------------- ### Load SpiceyPy Kernels Source: https://github.com/andrewannex/spiceypy/blob/main/docs/pyodide.md Loads leap seconds and planetary ephemeris kernels required for SpiceyPy calculations. This example loads 'naif0012.tls' and 'de440s_2000_to_2020_simplified.bsp'. ```python # Load kernels: leap seconds + planetary ephemeris spice.furnsh("naif0012.tls") spice.furnsh("de440s_2000_to_2020_simplified.bsp") print(f'Loaded {spice.ktotal("ALL")} kernels.') ``` -------------------------------- ### SpiceyPy Initialization and Setup Source: https://github.com/andrewannex/spiceypy/blob/main/docs/event_finding.md Sets up the SpiceyPy environment by loading a meta-kernel and defining necessary parameters for event finding. This includes setting time formats and maximum interval sizes. ```python import spiceypy def visibl(): METAKR = "visibl.tm" SCLKID = -82 TDBFMT = "YYYY MON DD HR:MN:SC.### TDB ::TDB" MAXIVL = 1000 MAXWIN = 2 * MAXIVL spiceypy.furnsh(METAKR) target = "Mars" obsfrm = "EARTH" abcorr = "LT+S" srfpt = "MOON" crdsys = "RECTAN" coord = "LATITUDINAL" relate = ">=" revlim = True adjust = True stepsz = 0.0 occtyp = "ANY" front = "Mars" fframe = "IAU_MARS" back = "Earth" bshape = "ELLIPSOID" bframe = "IAU_EARTH" etbeg = 0.0 etend = 100000.0 ``` -------------------------------- ### Import Libraries for Cassini Example Source: https://github.com/andrewannex/spiceypy/blob/main/docs/exampleone.md Imports necessary libraries including pyscript for display, numpy for numerical operations, matplotlib for plotting, and spiceypy for SPICE toolkit access. This setup is required for the Cassini position plotting example. ```python from pyscript import display import numpy as np import matplotlib matplotlib.use("AGG") import matplotlib.pyplot as plt from mpl_toolkits.mplot3d import Axes3D import spiceypy as spice ``` -------------------------------- ### SpiceyPy In-Situ Sensing Example Source: https://github.com/andrewannex/spiceypy/blob/main/docs/insitu_sensing.md Demonstrates loading a meta-kernel, converting UTC to Ephemeris Time (ET), calculating spacecraft state using SCLK, and determining target positions and sub-points. ```python import spiceypy def sscpnt(): mkfile = "sscpnt.tm" spiceypy.furnsh(mkfile) utc = "2004-06-11T19:32:00" et = spiceypy.str2et(utc) print(f"UTC = {utc:s}") print(f"ET = {et:20.6f}") scid = -82 sclk = "1465674964.105" et = spiceypy.scs2e(scid, sclk) print(f"SCLK = {sclk:s}") print(f"ET = {et:20.6f}") target = "CASSINI" frame = "ECLIPJ2000" corrtn = "NONE" observ = "SUN" state, ltime = spiceypy.spkezr(target, et, frame, corrtn, observ) print(f" X = {state[0]:20.6f}") print(f" Y = {state[1]:20.6f}") print(f" Z = {state[2]:20.6f}") print(f"VX = {state[3]:20.6f}") print(f"VY = {state[4]:20.6f}") print(f"VZ = {state[5]:20.6f}") target = "SUN" frame = "CASSINI_INMS" corrtn = "LT+S" observ = "CASSINI" sundir, ltime = spiceypy.spkpos(target, et, frame, corrtn, observ) sundir = spiceypy.vhat(sundir) print(f"SUNDIR(X) = {sundir[0]:20.6f}") print(f"SUNDIR(Y) = {sundir[1]:20.6f}") print(f"SUNDIR(Z) = {sundir[2]:20.6f}") method = "NEAR POINT: ELLIPSOID" target = "PHOEBE" frame = "IAU_PHOEBE" corrtn = "NONE" observ = "CASSINI" spoint, trgepc, srfvec = spiceypy.subpnt(method, target, et, frame, corrtn, observ) srad, slon, slat = spiceypy.reclat(spoint) fromfr = "IAU_PHOEBE" tofr = "CASSINI_INMS" m2imat = spiceypy.pxform(fromfr, tofr, et) sbpdir = spiceypy.mxv(m2imat, srfvec) sbpdir = spiceypy.vhat(sbpdir) ``` -------------------------------- ### Get Planetary Positions Source: https://github.com/andrewannex/spiceypy/blob/main/docs/pyodide.md Retrieves the position vectors of a celestial body relative to another for a given set of Ephemeris Times. This example calculates Venus's barycenter position relative to Earth in the ecliptic J2000 frame. ```python # Venus position relative to Earth in ecliptic J2000 (km) positions, _ = spice.spkpos("VENUS BARYCENTER", ets, "ECLIPJ2000", "NONE", "EARTH") print(f'Got {len(positions)} positions of the Venus Barycenter') ``` -------------------------------- ### SpiceyPy In Situ Sensing Example Source: https://github.com/andrewannex/spiceypy/blob/main/docs/insitu_sensing.md Demonstrates loading kernels, converting UTC to Ephemeris Time (ET) using both string and SCLK formats, retrieving spacecraft state vectors, and calculating the sun direction vector. Ensure the 'soldir.tm' meta-kernel is created and accessible. ```python import spiceypy def soldir(): mkfile = "soldir.tm" spiceypy.furnsh(mkfile) utc = "2004-06-11T19:32:00" et = spiceypy.str2et(utc) print(f"UTC = {utc:s}") print(f"ET = {et:20.6f}") scid = -82 sclk = "1465674964.105" et = spiceypy.scs2e(scid, sclk) print(f"SCLK = {sclk:s}") print(f"ET = {et:20.6f}") target = "CASSINI" frame = "ECLIPJ2000" corrtn = "NONE" observ = "SUN" state, ltime = spiceypy.spkezr(target, et, frame, corrtn, observ) print(f" X = {state[0]:20.6f}") print(f" Y = {state[1]:20.6f}") print(f" Z = {state[2]:20.6f}") print(f"VX = {state[3]:20.6f}") print(f"VY = {state[4]:20.6f}") print(f"VZ = {state[5]:20.6f}") target = "SUN" frame = "CASSINI_INMS" corrtn = "LT+S" observ = "CASSINI" sundir, ltime = spiceypy.spkpos(target, et, frame, corrtn, observ) sundir = spiceypy.vhat(sundir) print(f"SUNDIR(X) = {sundir[0]:20.6f}") print(f"SUNDIR(Y) = {sundir[1]:20.6f}") print(f"SUNDIR(Z) = {sundir[2]:20.6f}") spiceypy.unload(mkfile) ``` -------------------------------- ### Set CSPICE Source Directory for Offline Installation Source: https://github.com/andrewannex/spiceypy/blob/main/docs/installation.md For offline installations, set the CSPICE_SRC_DIR environment variable to the path of your extracted CSPICE toolkit before running pip install. ```bash export CSPICE_SRC_DIR="/tmp/cspice" pip install . ``` -------------------------------- ### Create Kernel Meta-File Source: https://github.com/andrewannex/spiceypy/blob/main/docs/other_stuff.md Writes a kernel meta-file named 'win.tm' with specified kernels to load. This is a setup step for using SPICE kernels. ```python mk = r""" KPL/MK \begindata KERNELS_TO_LOAD = ( 'kernels/lsk/naif0008.tls', 'kernels/spk/de405s.bsp', 'kernels/pck/pck00008.tpc') """ with open("win.tm", "w") as dst: dst.write(mk) print("Wrote kernel file win.tm") print("") # ``` -------------------------------- ### Set CSPICE Shared Library for Offline Installation Source: https://github.com/andrewannex/spiceypy/blob/main/docs/installation.md Alternatively, for offline installations with a prebuilt shared library, set the CSPICE_SHARED_LIB environment variable to the library's path before running pip install. ```bash export CSPICE_SHARED_LIB="/tmp/libcspice.so" pip install . ``` -------------------------------- ### Create and Manipulate SPICE Windows Source: https://github.com/andrewannex/spiceypy/blob/main/docs/other_stuff.md Demonstrates creating SPICE windows from string time tags, performing set operations (intersection), and extracting interval data. Requires loading a meta-kernel. ```python import spiceypy def win(): MAXSIZ = 8 # # Define a set of time intervals. For the purposes of this # tutorial program, define time intervals representing # an unobscured line of sight between a ground station # and some body. # los = [ "Jan 1, 2003 22:15:02", "Jan 2, 2003 4:43:29", "Jan 4, 2003 9:55:30", "Jan 4, 2003 11:26:52", "Jan 5, 2003 11:09:17", "Jan 5, 2003 13:00:41", "Jan 6, 2003 00:08:13", "Jan 6, 2003 2:18:01", ] # # A second set of intervals representing the times for which # an acceptable phase angle exists between the ground station, # the body and the Sun. # phase = [ "Jan 2, 2003 00:03:30", "Jan 2, 2003 19:00:00", "Jan 3, 2003 8:00:00", "Jan 3, 2003 9:50:00", "Jan 5, 2003 12:00:00", "Jan 5, 2003 12:45:00", "Jan 6, 2003 00:30:00", "Jan 6, 2003 23:00:00", ] # # Load our meta kernel for the leapseconds data. # spiceypy.furnsh("win.tm") # # SPICE windows consist of double precision values; convert # the string time tags defined in the 'los' and 'phase' # arrays to double precision ET. Store the double values # in the 'loswin' and 'phswin' windows. # los_et = spiceypy.str2et(los) phs_et = spiceypy.str2et(phase) loswin = spiceypy.stypes.SPICEDOUBLE_CELL(MAXSIZ) phswin = spiceypy.stypes.SPICEDOUBLE_CELL(MAXSIZ) for i in range(0, int(MAXSIZ / 2)): spiceypy.wninsd(los_et[2 * i], los_et[2 * i + 1], loswin) spiceypy.wninsd(phs_et[2 * i], phs_et[2 * i + 1], phswin) spiceypy.wnvald(MAXSIZ, MAXSIZ, loswin) spiceypy.wnvald(MAXSIZ, MAXSIZ, phswin) # # The issue for consideration, at what times do line of # sight events coincide with acceptable phase angles? # Perform the set operation AND on loswin, phswin, # (the intersection of the time intervals) # place the results in the window 'sched'. # sched = spiceypy.wnintd(loswin, phswin) print("Number data values in sched : {0:2d}".format(spiceypy.card(sched))) # # Output the results. The number of intervals in 'sched' # is half the number of data points (the cardinality). # print(" ") print("Time intervals meeting defined criterion.") for i in range(spiceypy.card(sched) // 2): # # Extract from the derived 'sched' the values defining the # time intervals. # [left, right] = spiceypy.wnfetd(sched, i) # # Convert the ET values to UTC for human comprehension. # utcstr_l = spiceypy.et2utc(left, "C", 3) utcstr_r = spiceypy.et2utc(right, "C", 3) # # Output the UTC string and the corresponding index # for the interval. # print("{0:2d} {1} {2}".format(i, utcstr_l, utcstr_r)) # # Summarize the 'sched' window. # [meas, avg, stddev, small, large] = spiceypy.wnsumd(sched) print("\nSummary of sched window\n") print("o Total measure of sched : {0:16.6f}".format(meas)) print("o Average measure of sched : {0:16.6f}".format(avg)) print("o Standard deviation of ") print(" the measures in sched : {0:16.6f}".format(stddev)) # # The values for small and large refer to the indexes of the # values in the window ('sched'). The shortest interval is # # [ sched.base[ sched.data + small] # sched.base[ sched.data + small +1] ]; # # the longest is # # [ sched.base[ sched.data + large] # sched.base[ sched.data + large +1] ]; # # Output the interval indexes for the shortest and longest # intervals. As Python bases an array index on 0, the interval # index is half the array index. # print("o Index of shortest interval: {0:2d}".format(int(small / 2))) print("o Index of longest interval : {0:2d}".format(int(large / 2))) # # Done. Unload the kernels. # spiceypy.kclear() if __name__ == "__main__": win() ``` ```text Number data values in sched : 6 ``` -------------------------------- ### Install NumPy Source: https://github.com/andrewannex/spiceypy/blob/main/docs/installation.md NumPy is a required dependency for SpiceyPy. Install or update it to the latest version. ```default pip install -U numpy ``` -------------------------------- ### Initialize Confinement and Result Windows Source: https://github.com/andrewannex/spiceypy/blob/main/docs/event_finding.md Set up the confinement window for the search interval and initialize the result window for storing found events. The cell sizes are determined by MAXWIN and MAXIVL. ```python cnfine = spiceypy.cell_double(2) spiceypy.wninsd(etbeg, etend, cnfine) riswin = spiceypy.cell_double(MAXWIN) ``` -------------------------------- ### Initialize CK Writing Parameters and Load Kernels Source: https://github.com/andrewannex/spiceypy/blob/main/docs/ck.md This section sets up constants for CK segment creation, including file names, segment ID, reference frame, body IDs, and time ranges. It then loads the necessary SPICE kernels (SPK, LSK, SCLK, PCK) into the kernel pool. ```python def main(): # Functions # # The functions get_dervrt and locvrt_m__ are left as stubs above. # Local constants # # Names of kernels: LSK, SCLK, PCK, SPK, CK. LSK = "leap.tls" SCLKKER = "mgs.tsc" PCK = "mgs.tpc" SPK = "mgs.bsp" CK = "mgs_predict_ck.bc" # Internal file name: just set this equal to the CK name. IFNAME = CK # Segment identifier. SEGID = "MGS PREDICT TYPE 3 SEGMENT" # The number of characters to reserve in the comment area when creating the file. NCOMCH = 0 # The reference frame of the segment is J2000. REF = "J2000" # NAIF body ID codes for the Mars Global Surveyor spacecraft and Mars. CENTERNAME = "Mars" SCNAME = "MGS" # The ID code for the MGS spacecraft bus. INST = -94000 # The angular velocity flag indicates that angular velocity data are available. AVFLAG = True # SPICETRUE # We will need about 2000 pointing instances. MAXREC = 2000 # The segment begin and end times. UTCBEG = "1994 JAN 21 00:00:00" UTCEND = "1994 JAN 21 02:00:00" # The time step separating the time tags of the pointing instances. # The units are ticks of encoded SCLK. SCLKSTEP = 1024.0 # Local variables # Pre-allocate arrays for the pointing data. avvs = np.zeros((MAXREC, 3)) quats = np.zeros((MAXREC, 4)) sclkdp = np.zeros(MAXREC) starts = np.zeros(MAXREC) # Translate the spacecraft and central body names to NAIF ID codes. scid = spice.bodn2c(SCNAME) centerID = spice.bodn2c(CENTERNAME) # Load the binary SPK file that provides states for MGS with respect # to Mars for the time period of interest. spice.furnsh(SPK) # Load the text leapseconds, spacecraft clock (sclk), and planetary # constants (pck) files into the kernel pool. spice.furnsh(LSK) spice.furnsh(SCLKKER) spice.furnsh(PCK) # Convert the segment begin and end times first to ET then to MGS # spacecraft clock. etBeg = spice.str2et(UTCBEG) etEnd = spice.str2et(UTCEND) scBeg = spice.sce2c(scid, etBeg) scEnd = spice.sce2c(scid, etEnd) ``` -------------------------------- ### Initialize SpicePy with Standard Includes Source: https://github.com/andrewannex/spiceypy/blob/main/docs/spk.md Initializes the SpicePy environment by importing necessary libraries like spiceypy and numpy. This is a common setup for most SpicePy applications. ```python # Standard includes import spiceypy as spice import numpy as np import math ``` -------------------------------- ### ckgr04_ - Get I'th Record from Type 4 Segment Source: https://github.com/andrewannex/spiceypy/blob/main/docs/ck.md Gets the I'th record from a Type 4 segment. ```APIDOC ## ckgr04_ ### Description Gets the I'th record from a Type 4 segment. ### Method Not specified (assumed to be a function call in a library) ### Endpoint Not applicable (library function) ### Parameters None explicitly documented. ### Request Example None provided. ### Response None explicitly documented. ``` -------------------------------- ### Import SpiceyPy Library (Python) Source: https://github.com/andrewannex/spiceypy/blob/main/docs/remote_sensing.md Initializes the SpiceyPy environment by importing the library. This is a prerequisite for all subsequent SpiceyPy operations. ```python # Solution subpts.py import spiceypy ``` -------------------------------- ### SpiceyPy Modules for Chapter 1 Source: https://github.com/andrewannex/spiceypy/blob/main/docs/remote_sensing.md Functions and kernels for Chapter 1 exercises, including time conversion and string-to-ephemeris time conversion. ```text CHAPTER EXERCISE FUNCTIONS NON-VOID KERNELS ------- --------- --------------- --------------- ---------- 1 convtm spiceypy.furnsh spiceypy.str2et 1,2 spiceypy.unload spiceypy.etcal spiceypy.timout spiceypy.sce2s extra (*) spiceypy.unitim 1,2 spiceypy.sct2e spiceypy.et2utc spiceypy.scs2e ``` -------------------------------- ### Execute Rotation Example Source: https://github.com/andrewannex/spiceypy/blob/main/docs/binary_pck.md This is the main execution block for the rotation example. It calls the erotat function when the script is run directly. ```python if __name__ == "__main__": erotat() ``` -------------------------------- ### Load Kernels Using a Meta-Kernel Source: https://github.com/andrewannex/spiceypy/blob/main/docs/kernel.md Illustrates loading multiple SPICE kernels by referencing a single meta-kernel file. This is the recommended approach for managing sets of kernels. ```python from spiceypy import * furnsh("kernels.tm") ``` -------------------------------- ### Equivalent Loading After Unloading Source: https://github.com/andrewannex/spiceypy/blob/main/docs/spk.md Demonstrates how unloading and then reloading files can simplify the set of loaded kernels, making it equivalent to a shorter loading sequence. ```python furnsh( "file.a" ) # Load kernel file furnsh( "file.d" ) # Load kernel file ``` -------------------------------- ### Install SpiceyPy using Conda Source: https://github.com/andrewannex/spiceypy/blob/main/docs/installation.md Install SpiceyPy using conda after configuring the 'conda-forge' channel. This is the recommended method for Anaconda/Miniconda users. ```default conda install spiceypy ``` -------------------------------- ### Setup Kernel File for SpiceyPy Source: https://github.com/andrewannex/spiceypy/blob/main/docs/other_stuff.md Creates a meta-kernel file ('aderr.tm') required by SpiceyPy to load necessary ephemeris and leap seconds kernels. This is a prerequisite for most SpiceyPy operations. ```python mk = r""" KPL/MK \begindata KERNELS_TO_LOAD = ( 'kernels/lsk/naif0008.tls', 'kernels/spk/de405s.bsp', 'kernels/pck/pck00008.tpc') """ with open("aderr.tm", "w") as dst: dst.write(mk) print("Wrote kernel file aderr.tm") print("") ``` -------------------------------- ### Configure Conda for SpiceyPy Installation Source: https://github.com/andrewannex/spiceypy/blob/main/docs/installation.md If you use Anaconda or a similar distribution, configure your conda channels to include 'conda-forge' before installing SpiceyPy. ```default conda config --add channels conda-forge ``` -------------------------------- ### Example Segment Identifier Source: https://github.com/andrewannex/spiceypy/blob/main/docs/ck.md An example of a segment identifier string found in a C-kernel file. This format helps users determine the origin of the segment. ```text NAIF CSMITHING RET LOGA151 ``` -------------------------------- ### SpiceyPy Modules for Chapter 4 Source: https://github.com/andrewannex/spiceypy/blob/main/docs/remote_sensing.md Functions and kernels for Chapter 4 exercises, related to surface points and illumination calculations. ```text 4 subpts spiceypy.furnsh spiceypy.str2et 1,3-5,8,9 spiceypy.unload spiceypy.subpnt spiceypy.vnorm spiceypy.subslr extra (*) spiceypy.kclear spiceypy.reclat 1,3-5,8 spiceypy.dpr spiceypy.bodvrd spiceypy.recpgr ``` -------------------------------- ### Get Help on SpiceyPy Function Source: https://github.com/andrewannex/spiceypy/blob/main/docs/installation.md Use Python's built-in 'help()' function to get detailed information about a specific SpiceyPy function, such as 'tkvrsn'. ```default >>> import spiceypy >>> help(spiceypy.tkvrsn) ``` -------------------------------- ### Verify SpiceyPy Installation with Python Import Source: https://github.com/andrewannex/spiceypy/blob/main/docs/installation.md Import SpiceyPy in a Python interpreter and call the 'tkvrsn' function to check the toolkit version. This confirms a successful installation. ```python import spiceypy # print out the toolkit version installed print(spiceypy.tkvrsn('TOOLKIT')) ``` -------------------------------- ### Load, Query, and Unload SPICE Kernels Source: https://github.com/andrewannex/spiceypy/blob/main/docs/other_stuff.md Demonstrates loading a meta-kernel, querying loaded kernels, unloading individual kernels, and finally unloading the meta-kernel. This is useful for managing the SPICE kernel subsystem during a program's execution. ```python # # Import the CSPICE-Python interface. # import spiceypy # Assign the path name of the meta kernel to META. def kpool(META="kpool.tm"): # # Load the meta kernel then use KTOTAL to interrogate the SPICE # kernel subsystem. # spiceypy.furnsh(META) count = spiceypy.ktotal("ALL") print(f"Kernel count after load: {count}\n") # # Loop over the number of files; interrogate the SPICE system # with spiceypy.kdata for the kernel names and the type. # 'found' returns a boolean indicating whether any kernel files # of the specified type were loaded by the kernel subsystem. # This example ignores checking 'found' as kernels are known # to be loaded. # for i in range(count): [file, type, source, handle] = spiceypy.kdata(i, "ALL") print("File {0}".format(file)) print("Type {0}".format(type)) print("Source {0}\n".format(source)) # # Unload one kernel then check the count. # spiceypy.unload("kernels/spk/de405s.bsp") count = spiceypy.ktotal("ALL") # # The subsystem should report one less kernel. # print(f"Kernel count after one unload: {count}\n") # # Now unload the meta kernel. This action unloads all # files listed in the meta kernel. # spiceypy.unload(META) # # Check the count; spiceypy should return a count of zero. # count = spiceypy.ktotal("ALL") print(f"Kernel count after meta unload: {count}") # # Done. Unload the kernels. # spiceypy.kclear() if __name__ == "__main__": kpool() kpool(META="kpool_generic.tm") ``` -------------------------------- ### String Continuation Example Source: https://github.com/andrewannex/spiceypy/blob/main/docs/kernel.md Demonstrates how to use a continuation marker (//) to concatenate consecutive string elements into a single string. Ensure all parts, including the marker and whitespace, adhere to the line length limit. ```text CONTINUED_STRINGS = ( 'This // ', 'is // ', 'just //', 'one long //', 'string.', 'Here"s a second //', 'continued //' 'string.' ) ``` -------------------------------- ### Galileo SCLK Time String Example Source: https://github.com/andrewannex/spiceypy/blob/main/docs/sclk.md Provides an example of a valid Type 1 SCLK time string for the Galileo spacecraft, without a partition number. ```text 16777214:90:9:7 ``` -------------------------------- ### Nominal SCLK Rate Examples Source: https://github.com/andrewannex/spiceypy/blob/main/docs/ck.md Provides examples of the nominal seconds per tick for various spacecraft, illustrating the conversion factor between SCLK ticks and seconds. ```text spacecraft seconds / tick ( sec ) --------------------- ---------------------- Galileo 1 / 120 Mars Global Surveyor 1 / 256 Voyager I and II 0.06 ``` -------------------------------- ### PLANET_POINT Example Program Source: https://github.com/andrewannex/spiceypy/blob/main/docs/ck.md This Python script uses SpiceyPy to find the intersection of an instrument's pointing vector with a target body. It requires a CK kernel, a planetary constants kernel, and user input for SCLK strings and tolerances. The program iterates until a blank SCLK string is entered. ```python import spiceypy as spice import numpy as np def main(): # Load kernels spice.furnsh("generic_kernels/naif0012.tls") spice.furnsh("generic_kernels/de430.bsp") spice.furnsh("generic_kernels/pck00010.tpc") spice.furnsh("ck/mar001.bc") # Constants sc = "Mars Express" inst = "Mars Express Orbiter + Sub-Instrument: MARS_EXPRESS_SUB_INSTRUMENT" targ = "Mars" REF = "J2000" # Get spacecraft name and target name scname = spice.bodstr(spice.bodn2c(sc)) targname = spice.bodstr(spice.bodn2c(targ)) # Check if target body name was recognized if targname == "": msg = "Target body name # was not recognized." msg = msg.replace("#", targname) raise Exception(msg) # Determine the input epoch. sclkch = input("\nEnter SCLK string (blank line to quit) > ") while sclkch.strip() != "": # Convert the input clock string to ticks. sclkdp = spice.scencd(sc, sclkch) # Determine the time tolerance. tolch = input("Enter the tolerance as an SCLK string > ") # Convert the tolerance to ticks. tol = spice.sctiks(sc, tolch) # Search the CK file for pointing data at the time sclkdp. cmat, clkout, found = spice.ckgp(inst, sclkdp, tol, REF) if not found: print("\n" \ "The C-kernel file does not contain " "data for time {} SCLK {}.\n".format(scname, sclkch)) # Compute the inertial pointing vector for the instrument # boresight. # # The boresight vector is assumed to define the z-axis of the # instrument-fixed frame. This axis vector can be picked off # from the third row of the C-matrix. # vpnt = np.array(cmat[2]) # For all other computations, use the ET time corresponding # to the input SCLK. et = spice.sct2e(sc, sclkdp) # Compute the target state vector (position and velocity). vtarg, tau = spice.spkez(targ, et, REF, "lt+s", sc) # Get the tibf matrix and radii of target ellipsoid model. # # We need tibf for the target as it appeared when the # instrument took its measurement at time et. The target # was at its apparent location tau seconds earlier. # # tipbod_c and bodvcd_c will read constants from the planetary # constants kernel file. # tibf = spice.tipbod(REF, targ, et - tau) r, n = spice.bodvcd(targ, "RADII", 3) # The position of the observer is just the negative of the # position part of the spacecraft-target vector, vtarg. # # Note that this is NOT the same as the apparent position of # the spacecraft as seen from the target. # vpos = -np.array(vtarg[0:3]) # Put both vectors in body-fixed coordinates. vpos = np.dot(tibf, vpos) vpnt = np.dot(tibf, vpnt) # Compute the point of intersection, if any. vsurf, found = spice.surfpt(vpos, vpnt, r[0], r[1], r[2]) if not found: print("\nThe line-of-sight pointing vector " "does not intersect the target " "at the epoch {} SCLK {}.\n".format(scname, sclkch)) else: # Convert intersection point from rectangular to lat-lon- # radius coordinates. radius, lon, lat = spice.reclat(vsurf) print("\n" "Radius (km) {}\n" "Longitude (deg) {}\n" "Latitude (deg) {}\n".format(radius, lon * spice.dpr(), lat * spice.dpr())) # Input next epoch. sclkch = input("\nEnter SCLK string (blank line to quit) > ") if __name__ == "__main__": main() ``` -------------------------------- ### Create Meta-Kernel File Source: https://github.com/andrewannex/spiceypy/blob/main/docs/insitu_sensing.md Generates a meta-kernel file ('soldir.tm') containing a list of SPICE kernels to be loaded. This is typically the first step before loading kernels into SpiceyPy. ```python mk = r""" KPL/MK The names and contents of the kernels referenced by this meta-kernel are as follows: File Name Description -------------------------- ---------------------------------- naif0008.tls Generic LSK. cas00084.tsc Cassini SCLK. 020514_SE_SAT105.bsp Saturnian Satellite Ephemeris SPK. 030201AP_SK_SM546_T45.bsp Cassini Spacecraft SPK. 981005_PLTEPH-DE405S.bsp Planetary Ephemeris SPK. sat128.bsp Saturnian Satellite Ephemeris SPK. 04135_04171pc_psiv2.bc Cassini Spacecraft CK. cas_v37.tf Cassini FK. \begindata KERNELS_TO_LOAD = ( 'kernels/lsk/naif0008.tls' 'kernels/sclk/cas00084.tsc' 'kernels/spk/020514_SE_SAT105.bsp' 'kernels/spk/030201AP_SK_SM546_T45.bsp' 'kernels/spk/981005_PLTEPH-DE405S.bsp' 'kernels/spk/sat128.bsp' 'kernels/ck/04135_04171pc_psiv2.bc' 'kernels/fk/cas_v37.tf' ) \endtext """ with open("soldir.tm", "w") as dst: dst.write(mk) print("Wrote kernel file soldir.tm") ``` -------------------------------- ### Example: Mars System Max Phase Degree Source: https://github.com/andrewannex/spiceypy/blob/main/docs/pck.md An example of setting the maximum polynomial degree for nutation precession angles for the Mars system to 2 in a text PCK file. ```text BODY4_MAX_PHASE_DEGREE = 2 ``` -------------------------------- ### Example Text Kernel Assignment Source: https://github.com/andrewannex/spiceypy/blob/main/docs/kernel.md This example demonstrates a direct assignment in a text kernel, where a variable name is associated with a vector value. This assignment replaces any previous values for BODY399_RADII. ```text BODY399_RADII = ( 6378.14 6378.14 6356.75 ) ``` -------------------------------- ### SpiceyPy Modules for Chapter 3 Source: https://github.com/andrewannex/spiceypy/blob/main/docs/remote_sensing.md Functions and kernels for Chapter 3 exercises, involving coordinate transformations and matrix operations. ```text 3 xform spiceypy.furnsh spiceypy.str2et 1-8 spiceypy.unload spiceypy.spkezr spiceypy.sxform spiceypy.mxvg spiceypy.spkpos spiceypy.pxform spiceypy.mxv spiceypy.convrt spiceypy.vsep extra (*) spiceypy.kclear 1-8 ``` -------------------------------- ### Define Switch Frame Start Times with String Dates Source: https://github.com/andrewannex/spiceypy/blob/main/docs/frames.md Specifies start times for a switch frame using TDB calendar date strings, which are recognized by the str2et() function. ```text \begindata FRAME_-123002_START = ( '2018 JAN 1 00:00:00.000 TDB' '2018 OCT 1 00:00:00.000 TDB' '2018 JAN 1 00:00:00.000 TDB' '2018 JAN 1 00:00:00.000 TDB' ) \begintext ```