Skip to content

Commit

Permalink
Check ephemerides parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
migueldvb committed Aug 29, 2020
1 parent 3aae12c commit 2d22815
Show file tree
Hide file tree
Showing 2 changed files with 85 additions and 18 deletions.
83 changes: 66 additions & 17 deletions astroquery/imcce/core.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# Licensed under a 3-clause BSD style license - see LICENSE.rst
from __future__ import print_function

from collections import OrderedDict
import warnings
from io import BytesIO

Expand Down Expand Up @@ -29,6 +28,12 @@ class MiriadeClass(BaseQuery):
_query_uri = None # uri used in query
_get_raw_response = False

TYPES = ('Asteroid', 'Comet', 'Dwarf Planet', 'Planet', 'Satellite')
TSCALE = ('UTC', 'TT')
THEORY = ('INPOP', 'DE405', 'DE406')
RPLANE = {'equator': 1, 'ecliptic': 2}
OSCELEM = ('astorb', 'mpcorb', 'mpcorb/nea')

@property
def uri(self):
"""
Expand All @@ -38,7 +43,7 @@ def uri(self):

def get_ephemerides_async(self, targetname, objtype='asteroid',
epoch=None, epoch_step='1d', epoch_nsteps=1,
location=500, coordtype=1,
location='500', coordtype=1,
timescale='UTC',
planetary_theory='INPOP',
ephtype=1,
Expand Down Expand Up @@ -238,28 +243,72 @@ def get_ephemerides_async(self, targetname, objtype='asteroid',
URL = conf.ephemcc_server
TIMEOUT = conf.timeout

request_payload = dict()

# check for required information
if targetname is None:
raise ValueError("'targetname' parameter not set. Query aborted.")
else:
request_payload['-name'] = targetname

if objtype.title() in self.TYPES:
request_payload['-type'] = objtype
elif objtype is not None:
raise ValueError("Invalid objtype specified. Allowed types "
"are {0}".format(str(self.TYPES)))

if epoch_nsteps >= 1 and epoch_nsteps <= 5000:
request_payload['-nbd'] = epoch_nsteps
else:
raise ValueError("Invalid nbd specified. 1 <= epoch_nsteps <= 5000")

if (epoch_step[-1] in ('d', 'h', 'm', 's') and
epoch_step[:-1].replace('.', '', 1).isdigit()):
request_payload['-step'] = epoch_step
else:
raise ValueError("Invalid epoch_step specified. Step (float) "
"followed by one of (d)ays or (h)ours or "
"(m)inutes or (s)econds")

if timescale in self.TSCALE:
request_payload['-tscale'] = timescale
else:
raise ValueError("Invalid timescale specified. Allowed types "
"are {0}".format(str(self.TSCALE)))

if planetary_theory in self.THEORY:
request_payload['-theory'] = planetary_theory
else:
raise ValueError("Invalid planetary_theory specified. Allowed "
"types are {0}".format(str(self.THEORY)))

if ephtype in range(1, 5):
request_payload['-teph'] = ephtype
else:
raise ValueError("Invalid ephtype specified. 1 <= teph <= 4")

if coordtype in range(1, 7):
request_payload['-tcoor'] = coordtype
else:
raise ValueError("Invalid coordtype specified. 1 <= tcoor <= 6")

if refplane in self.RPLANE:
request_payload['-rplane'] = self.RPLANE[refplane]
else:
raise ValueError("Invalid refplane specified. Allowed "
"values are equator and ecliptic.")

if isinstance(epoch, (int, float)):
epoch = Time(epoch, format='jd')
elif isinstance(epoch, str):
epoch = Time(epoch, format='iso')
elif epoch is None:
epoch = Time.now()

request_payload = OrderedDict([
('-name', targetname),
('-type', objtype[0].upper()+objtype[1:]),
('-ep', str(epoch.jd)),
('-step', epoch_step),
('-nbd', epoch_nsteps),
('-observer', location),
('-output', '--jul'),
('-tscale', timescale),
('-theory', planetary_theory),
('-teph', ephtype),
('-tcoor', coordtype),
('-rplane', {'equator': 1, 'ecliptic': 2}[refplane]),
('-oscelem', elements),
('-mime', 'votable')])
request_payload['-ep'] = str(epoch.jd)
request_payload['-observer'] = location
request_payload['-output'] = "--jul"
request_payload['-mime'] = "votable"

if radial_velocity:
request_payload['-output'] += ',--rv'
Expand Down
20 changes: 19 additions & 1 deletion astroquery/imcce/tests/test_miriade_remote.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

import numpy.testing as npt
import pytest
import astropy.units as u

from .. import core

Expand All @@ -16,9 +17,26 @@ def test_ephemerides(self):
res = core.Miriade.get_ephemerides('Ceres', location='500',
epoch=2451544.5)

# check table columns
cols = (('target', None),
('epoch', u.d),
('RA', u.deg),
('DEC', u.deg),
('delta', u.au),
('V', u.mag),
('alpha', u.deg),
('elong', u.deg),
('RAcosD_rate', u.arcsec/u.minute),
('DEC_rate', u.arcsec/u.minute),
('delta_rate', u.km/u.s))

for i in cols:
assert i[0] in res.columns
assert res[i[0]].unit == i[1]

assert res['target'] == "Ceres"

npt.assert_allclose(
[2451544.5, 188.70280, 9.09829],
[res['epoch'][0], res['RA'][0], res['DEC'][0]],
list(res['epoch', 'RA', 'DEC'][0]),
rtol=1e-5)

0 comments on commit 2d22815

Please sign in to comment.