示例#1
0
 def __init__(self, body_id):
     self._id = body_id
     self._name = spice.bodc2n(body_id)
     self._frame = None
     if self._name is None:
         msg = 'Body() {} is not a valid ID.'
         raise ValueError(msg.format(body_id))
     Body._CACHE[body_id] = self
示例#2
0
def load(path='.', recursive=True, followlinks=False):
    '''Load a kernel file or a directory containing kernel files.

    :type path: ``str``
    :arg path: Relative or absolute path to the file/(root)directory to load.
    :type recursive: ``bool``
    :arg recursive: If *path* is a directory and *recursive* is ``True``,
      this will also search in child directories and not only the root.
    :type followlinks: ``bool``
    :arg followlinks: If *path* is a directory and *recursive* and
      *followlinks* are both ``True``, symlinked directories further up the
      directory tree will also be traversed.

      .. WARNING:: Setting *followlinks* to ``True`` may lead to infinite
         recursion.

    :return: (``set(str)``) -- The names of all loaded Ephimeris Objects.
    :raise: Nothing.

    Meta-kernels are not supported, because they would be parsed internally by
    the c-framework, therefore ignoring the feautures for time window
    extraction.

    At the moment only Ephimeris Objects defined in binary kernels are parsed,
    because of limitations in the c-framework.
    '''
    path = os.path.realpath(path)
    if os.path.isfile(path):
        dirname, basename = os.path.split(path)
        walker = [[dirname, [], [basename]]]
    elif recursive:
        walker = os.walk(path, followlinks=followlinks)
    else:
        walker = [next(os.walk(path, followlinks=followlinks))]
    queue = []
    for curdir, dirs, fnames in walker:
        for name in fnames:
            with ignored(ValueError):
                extension = _filter_extensions(name)
                filepath = os.path.join(curdir, name)
                # Load kernels with objects later
                if extension in ('sp', 'c', 'pc', 'f'):
                    queue.append((filepath, extension))
                else:
                    queue.insert(0, (filepath, extension))
    loaded_objects = set()
    for filepath, extension in queue:
        objects = _load_any(filepath, extension)
        loaded_objects.update(spice.bodc2n(code) for code in objects)
    with ignored(KeyError):
        loaded_objects.remove(None)
    LOADED_OBJECTS.update(loaded_objects)
    return loaded_objects