appspice.spice_bspbodyΒΆ

Find body ID in BSP file

Usage: irfpy-spice-bspbody kernel.bsp

Todo: Support of OptionParser. Particularly, it needs additional kernels to load. For example, leap-second kernel, then UTC output can be done.

""" Find body ID in BSP file

Usage:  irfpy-spice-bspbody kernel.bsp

Todo: Support of OptionParser. Particularly, it needs additional kernels to load. For example, leap-second kernel, then UTC output can be done.

"""
import sys
from optparse import OptionParser

from irfpy.spice import spice

def main(k):
    c = spice.spkobj(k)
    for code in c:
        ### Get the code in SPK
        print(code, end='')

        ### Get the name in SPK
        try:
            name = spice.bodc2n(code)
        except:
            name = '<UNKNOWN>'
            
        print(': {}'.format(name))

        ### Coverage in SPK
        
        cover = spice.stypes.SPICEDOUBLE_CELL(2000)
        spice.spkcov(k, -69, cover)

        labels = ['start:', 'end:']
        for ispan, span in enumerate(cover):
            label = labels[ispan % 2]
            try:
                t = spice.et2utc(span, 'ISOC', 3) + ' (UTC)'
            except spice.stypes.SpiceyError as e:
                t = spice.etcal(span) + ' (ET)'
            print('\t{} {}'.format(label, t))
                

def argmain():

    usage = "Usage: %prog [options] kernel.bsp [kernel1 kernel2 ...]"
    parser = OptionParser(usage)

    options, args = parser.parse_args()

    main(args[0])

if __name__ == '__main__':
    argmain()