예제 #1
0
def check_is_loaded(search):
    """
    Search the kernel pool variable names for a given string.
    """

    try:
        spice.gnpool(search, 0, 100)
    except(spice.support_types.SpiceyError):
        return False

    return True
예제 #2
0
파일: util.py 프로젝트: ladoramkershner/ale
def query_kernel_pool(matchstr="*"):
    """
    Collect multiple keywords from the naif kernel pool based on a
    template string

    Parameters
    ----------
    matchstr : str
               matchi_c formatted str

    Returns
    -------
    : dict
      python dictionary of naif keywords in {keyword:value} format.
    """

    try:
        svars = spice.gnpool(matchstr, 0, 100)
    except Exception as e:
        warnings.warn(f"kernel search for {matchstr} failed with {e}")
        svars = []

    svals = [duckpool(v) for v in svars]
    return dict(zip(svars, svals))
예제 #3
0
def gen_frame_dict(mk, report=False):
    #
    # Frame names are as follows:
    # r'FRAME_-?[0-9]*_NAME'
    #
    frame_dict = {}

    spiceypy.furnsh(mk)

    start = 1
    n_items = 9999
    template = 'FRAME_*_NAME'
    try:
        cvals = spiceypy.gnpool(template, start, n_items)
        if report: print(f'Number of reference frames defined: {len(cvals)}')
    except SpiceyError:
        print('No frames definitions present')
        return

    #
    # Okay, now we know something about the kernel pool
    # variables of interest to us. Let's find out more...
    #
    for cval in cvals:

        #
        # We check the type of variable:
        # C (character) or N (numeric), of each pool
        # variable name in the cvals array. It has to
        # be a character
        #
        start = 0
        n_items = 20
        [dim, type] = spiceypy.dtpool(cval)

        if type == 'C':
            cvars = spiceypy.gcpool(cval, start, n_items)
            #
            # The variable (list) should be unique
            #
            if len(cvars) > 1:
                spiceypy.kclear()
                raise Exception(f'Variable {cval} is incorrect')

            #
            # We build the frames dictionary
            #
            frmclass = spiceypy.gipool(cval.replace('NAME', 'CLASS'), start,
                                       n_items)
            frmid = spiceypy.gipool(cval.replace('NAME', 'CLASS_ID'), start,
                                       n_items)
            frmcentr = spiceypy.gipool(cval.replace('NAME', 'CENTER'), start,
                                       n_items)

            if frmclass[0] == 4:
                try:
                    varname = cval.replace('FRAME','TKFRAME').replace('NAME', 'RELATIVE')
                    frmrelat = spiceypy.gcpool(varname, start, n_items)
                except:
                    frmrelat = ['ERROR']
            else:
                frmrelat = ['N/A']


            frame_dict[cvars[0]] = { 'name': cvars[0],
                                     'class':frmclass[0],
                                     'id': frmid[0],
                                     'center': frmcentr[0],
                                     'relative': frmrelat[0]
                                    }

            if report:
                print(f'  CLASS: {frmclass[0]}  NAME: {cvars[0]} ')


        else:
            spiceypy.kclear()
            raise Exception(f'Variable {cval} is incorrect')

    spiceypy.kclear()

    return frame_dict