Exemplo n.º 1
0
 def single_position(self, time, observer='SUN', frame='ECLIPJ2000',
     abcorr=None):
     if isinstance(observer, Body):
         observer = observer.name
     if isinstance(frame, Body):
         frame = frame._frame or frame.name
     return numpy.array(spice.spkpos(self.name, Time.fromposix(time).et(),
         frame, abcorr or Body._ABCORR, observer)[0])
Exemplo n.º 2
0
    def position(self, times, observer='SUN', frame='ECLIPJ2000',
        abcorr=None):
        '''Get the position of this object relative to the observer in a
        specific reference frame.

        :type times: ``Iterable`` | has ``__float__()``
        :arg times: The point(s) in time for which to calculate the position.

        :type observer: :py:class:`~spiceminer.bodies.Body` | ``str``
        :arg observer: Object to use as (0,0,0).

        :type abcorr: ``str``
        :arg abcorr: Aberration correction to be applied. May be one of LT,
          LT+S, CN, CN+S, XLT, XLT+S, XCN, XCN+S. For explanation of these see
          `here <http://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/spkez_c.html#Detailed_Input>`_.

        :return: (``ndarray``) -- The nx4 array containing time and
          (x, y, z)-position.
        :raises:
          (``TypeError``) -- If an argument doesn't conform to the type
          requirements.

          (:py:class:`~spiceminer._spicewrapper.SpiceError`) -- If there is
          necessary information missing.
        '''
        if isinstance(observer, Body):
            observer = observer.name
        if isinstance(frame, Body):
            frame = frame._frame or frame.name
        if isinstance(times, numbers.Real):
            times = [float(times)]
        if isinstance(times, collections.Iterable):
            result = []
            for time in times:
                with ignored(spice.SpiceError):
                    result.append([time] + spice.spkpos(self.name,
                    Time.fromposix(time).et(), frame, abcorr or Body._ABCORR,
                    observer)[0])
            return numpy.array(result).transpose()
        msg = 'position() Real or Iterable argument expected, got {}.'
        raise TypeError(msg.format(type(times)))