示例#1
0
 def miriademoon(self, epoch, location):
     """
     Returns the table of RA, DEC and markers with Miriade calulator
     Attributes:
             target (string)         : target
             epoch (Time)            : epoch
             epoch_step (string)     : Miriade definition
             epoch_nsteps (int)      : Iteration Number
             coordtype (int)         : Miriade definition
             location (string)       : Miriade definition
     """
     epoch_iso = Time(epoch, format='fits')
     epoch_iso.format = 'iso'
     eph = Miriade.get_ephemerides('p:moon',
                                   epoch=epoch_iso.value,
                                   epoch_step='1m',
                                   epoch_nsteps=1,
                                   coordtype=1,
                                   location=location)
     ra = []
     dec = []
     marker = []
     for line in eph:
         ra.append(line['RA'])
         dec.append(line['DEC'])
         if line['V'] < -1:
             marker.append(-int(line['V']))
         else:
             marker.append(1)
     return Table([ra, dec, marker], names=['RA', 'DEC', 'MARKER'])
示例#2
0
文件: ephem.py 项目: maxmahlke/sbpy
    def from_miriade(cls,
                     targetids,
                     objtype='asteroid',
                     epochs=None,
                     location='500',
                     **kwargs):
        """Load target ephemerides from
        `IMCCE Miriade <http://vo.imcce.fr/webservices/miriade/>`_ using
        `astroquery.imcce.MiriadeClass.get_ephemerides`

        Parameters
        ----------
        targetids : str or iterable of str
            Target identifier, i.e., a number, name, designation, or JPL
            Horizons record number, for one or more targets.
        objtype : str, optional
            The nature of ``targetids`` provided; possible values are
            ``'asteroid'``, ``'comet'``, ``'dwarf planet'``,
            ``'planet'``, or ``'satellite'``. Default: ``'asteroid'``
        epochs : `~astropy.time.Time` object, or dictionary, optional
            Epochs of elements to be queried; `~astropy.time.Time` objects
            support single and multiple epochs;
            a dictionary including keywords ``start`` and ``stop``, as well
            as either ``step`` or ``number``, can be used to generate a range
            of epochs. ``start`` and ``stop`` have to be
            `~astropy.time.Time` objects (see :ref:`epochs`).
            If ``step`` is provided, a range
            of epochs will be queried starting at ``start`` and ending at
            ``stop`` in steps of ``step``; ``step`` has to be provided as
            a `~astropy.units.Quantity` object with integer value and a
            unit of either seconds, minutes, hours, or days. If
            ``number`` is provided as an integer, the
            interval defined by
            ``start`` and ``stop`` is split into ``number`` equidistant
            intervals. If ``None`` is
            provided, current date and time are
            used. All epochs should be provided in UTC; if not, they will be
            converted to UTC and a `~sbpy.data.TimeScaleWarning` will be
            raised. Default: ``None``
        location : str or `~astropy.coordinates.EarthLocation`, optional
            Location of the observer using IAU observatory codes
            (see `IAU observatory codes
            <https://www.minorplanetcenter.net/iau/lists/ObsCodesF.html>`__)
            or as `~astropy.coordinates.EarthLocation`.
            Default: ``'500'`` (geocentric)
        **kwargs : optional
            Arguments that will be provided to
            `astroquery.imcce.MiriadeClass.get_ephemerides`.

        Notes
        -----
        * For detailed explanations of the queried fields, refer to
          `astroquery.imcce.MiriadeClass.get_ephemerides` and the
          `Miriade documentation
          <http://vo.imcce.fr/webservices/miriade/?documentation>`_.
        * By default, all properties are provided in the J2000.0 reference
          system. Different settings can be chosen using
          additional keyword arguments as used by
          `astroquery.imcce.MiriadeClass.get_ephemerides`.

        Returns
        -------
        `~Ephem` object
            The resulting object will be populated with columns as
            defined in
            `~astroquery.imcce.MiriadeClass.get_ephemerides`; refer
            to that document on information on how to modify the list
            of queried parameters.

        Examples
        --------
        >>> from sbpy.data import Ephem
        >>> from astropy.time import Time
        >>> epoch = Time('2018-05-14', scale='utc')
        >>> eph = Ephem.from_horizons('ceres', epochs=epoch) # doctest: +SKIP
        """

        # modify epoch input to make it work with astroquery.imcce.Miriade
        if epochs is None:
            epochs = {'start': Time.now().utc.jd}
        elif isinstance(epochs, Time):
            if epochs.scale is not 'utc':
                warn(('converting {} epochs to utc for use in '
                      'astroquery.imcce').format(epochs.scale),
                     TimeScaleWarning)
                epochs = epochs.utc
            epochs = {'start': epochs}
        elif isinstance(epochs, dict):
            if epochs['start'].scale is not 'utc':
                warn(('converting {} start epoch to utc for use in '
                      'astroquery.imcce').format(epochs['start'].scale),
                     TimeScaleWarning)
                epochs['start'] = epochs['start'].utc
            if 'stop' in epochs and epochs['stop'].scale is not 'utc':
                warn(('converting {} stop epoch to utc for use in '
                      'astroquery.imcce').format(epochs['stop'].scale),
                     TimeScaleWarning)
                epochs['stop'] = epochs['stop'].utc
            if 'number' in epochs:
                # turn interval/number into step size based on full minutes
                epochs['step'] = int(
                    (Time(epochs['stop']) - Time(epochs['start'])).jd * 86400 /
                    (epochs['number'] - 1)) * u.s
            elif 'step' in epochs:
                epochs['number'] = (
                    (Time(epochs['stop']) - Time(epochs['start'])).jd * 86400 /
                    epochs['step'].to('s').value) + 1
            if 'step' in epochs:
                epochs['step'] = '{:f}{:s}'.format(epochs['step'].value, {
                    u.s: 's',
                    u.minute: 'm',
                    u.hour: 'h',
                    u.day: 'd'
                }[epochs['step'].unit])

        # if targetids is a list, run separate Horizons queries and append
        if not isinstance(targetids, (list, ndarray, tuple)):
            targetids = [targetids]

        # turn EarthLocation into dictionary of strings as used by
        # astroquery.jplhorizons

        if isinstance(location, EarthLocation):
            location = '{:+f} {:+f} {:.1f}'.format(
                location.lon.deg, location.lat.deg,
                location.height.to('m').value)

        # append ephemerides table for each targetid
        all_eph = None
        for targetid in targetids:
            query = Miriade()
            try:
                if 'step' not in epochs and 'number' not in epochs:
                    if not iterable(epochs['start']):
                        # single epoch
                        eph = query.get_ephemerides(targetname=targetid,
                                                    objtype=objtype,
                                                    location=location,
                                                    epoch=epochs['start'],
                                                    **kwargs)
                    else:
                        # multiple epochs
                        eph = []
                        for i in range(len(epochs['start'])):
                            e = query.get_ephemerides(targetname=targetid,
                                                      objtype=objtype,
                                                      location=location,
                                                      epoch=epochs['start'][i],
                                                      **kwargs)
                            e['epoch'] = Time(e['epoch'],
                                              format='jd',
                                              scale='utc').iso
                            eph.append(e)
                        eph = vstack(eph)
                        eph['epoch'] = Time(eph['epoch'],
                                            scale='utc',
                                            format='iso')
                else:
                    # dictionary
                    eph = query.get_ephemerides(targetname=targetid,
                                                objtype=objtype,
                                                location=location,
                                                epoch=epochs['start'],
                                                epoch_step=epochs['step'],
                                                epoch_nsteps=epochs['number'],
                                                **kwargs)
            except RuntimeError as e:
                raise QueryError(
                    ('Error raised by astroquery.imcce: {:s}\n'
                     'The following query was attempted: {:s}').format(
                         str(e), query.uri))

            if all_eph is None:
                all_eph = eph
            else:
                all_eph = vstack([all_eph, eph])

        self = cls.from_table(all_eph)

        # turn epochs into astropy.time.Time and apply timescale
        self.table['epoch'] = Time(self.table['epoch'],
                                   format='jd',
                                   scale='utc')

        return self