Skip to content

Commit 2d22815

Browse files
committed
Check ephemerides parameters
1 parent 3aae12c commit 2d22815

File tree

2 files changed

+85
-18
lines changed

2 files changed

+85
-18
lines changed

astroquery/imcce/core.py

+66-17
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
# Licensed under a 3-clause BSD style license - see LICENSE.rst
22
from __future__ import print_function
33

4-
from collections import OrderedDict
54
import warnings
65
from io import BytesIO
76

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

31+
TYPES = ('Asteroid', 'Comet', 'Dwarf Planet', 'Planet', 'Satellite')
32+
TSCALE = ('UTC', 'TT')
33+
THEORY = ('INPOP', 'DE405', 'DE406')
34+
RPLANE = {'equator': 1, 'ecliptic': 2}
35+
OSCELEM = ('astorb', 'mpcorb', 'mpcorb/nea')
36+
3237
@property
3338
def uri(self):
3439
"""
@@ -38,7 +43,7 @@ def uri(self):
3843

3944
def get_ephemerides_async(self, targetname, objtype='asteroid',
4045
epoch=None, epoch_step='1d', epoch_nsteps=1,
41-
location=500, coordtype=1,
46+
location='500', coordtype=1,
4247
timescale='UTC',
4348
planetary_theory='INPOP',
4449
ephtype=1,
@@ -238,28 +243,72 @@ def get_ephemerides_async(self, targetname, objtype='asteroid',
238243
URL = conf.ephemcc_server
239244
TIMEOUT = conf.timeout
240245

246+
request_payload = dict()
247+
248+
# check for required information
249+
if targetname is None:
250+
raise ValueError("'targetname' parameter not set. Query aborted.")
251+
else:
252+
request_payload['-name'] = targetname
253+
254+
if objtype.title() in self.TYPES:
255+
request_payload['-type'] = objtype
256+
elif objtype is not None:
257+
raise ValueError("Invalid objtype specified. Allowed types "
258+
"are {0}".format(str(self.TYPES)))
259+
260+
if epoch_nsteps >= 1 and epoch_nsteps <= 5000:
261+
request_payload['-nbd'] = epoch_nsteps
262+
else:
263+
raise ValueError("Invalid nbd specified. 1 <= epoch_nsteps <= 5000")
264+
265+
if (epoch_step[-1] in ('d', 'h', 'm', 's') and
266+
epoch_step[:-1].replace('.', '', 1).isdigit()):
267+
request_payload['-step'] = epoch_step
268+
else:
269+
raise ValueError("Invalid epoch_step specified. Step (float) "
270+
"followed by one of (d)ays or (h)ours or "
271+
"(m)inutes or (s)econds")
272+
273+
if timescale in self.TSCALE:
274+
request_payload['-tscale'] = timescale
275+
else:
276+
raise ValueError("Invalid timescale specified. Allowed types "
277+
"are {0}".format(str(self.TSCALE)))
278+
279+
if planetary_theory in self.THEORY:
280+
request_payload['-theory'] = planetary_theory
281+
else:
282+
raise ValueError("Invalid planetary_theory specified. Allowed "
283+
"types are {0}".format(str(self.THEORY)))
284+
285+
if ephtype in range(1, 5):
286+
request_payload['-teph'] = ephtype
287+
else:
288+
raise ValueError("Invalid ephtype specified. 1 <= teph <= 4")
289+
290+
if coordtype in range(1, 7):
291+
request_payload['-tcoor'] = coordtype
292+
else:
293+
raise ValueError("Invalid coordtype specified. 1 <= tcoor <= 6")
294+
295+
if refplane in self.RPLANE:
296+
request_payload['-rplane'] = self.RPLANE[refplane]
297+
else:
298+
raise ValueError("Invalid refplane specified. Allowed "
299+
"values are equator and ecliptic.")
300+
241301
if isinstance(epoch, (int, float)):
242302
epoch = Time(epoch, format='jd')
243303
elif isinstance(epoch, str):
244304
epoch = Time(epoch, format='iso')
245305
elif epoch is None:
246306
epoch = Time.now()
247307

248-
request_payload = OrderedDict([
249-
('-name', targetname),
250-
('-type', objtype[0].upper()+objtype[1:]),
251-
('-ep', str(epoch.jd)),
252-
('-step', epoch_step),
253-
('-nbd', epoch_nsteps),
254-
('-observer', location),
255-
('-output', '--jul'),
256-
('-tscale', timescale),
257-
('-theory', planetary_theory),
258-
('-teph', ephtype),
259-
('-tcoor', coordtype),
260-
('-rplane', {'equator': 1, 'ecliptic': 2}[refplane]),
261-
('-oscelem', elements),
262-
('-mime', 'votable')])
308+
request_payload['-ep'] = str(epoch.jd)
309+
request_payload['-observer'] = location
310+
request_payload['-output'] = "--jul"
311+
request_payload['-mime'] = "votable"
263312

264313
if radial_velocity:
265314
request_payload['-output'] += ',--rv'

astroquery/imcce/tests/test_miriade_remote.py

+19-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
import numpy.testing as npt
55
import pytest
6+
import astropy.units as u
67

78
from .. import core
89

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

20+
# check table columns
21+
cols = (('target', None),
22+
('epoch', u.d),
23+
('RA', u.deg),
24+
('DEC', u.deg),
25+
('delta', u.au),
26+
('V', u.mag),
27+
('alpha', u.deg),
28+
('elong', u.deg),
29+
('RAcosD_rate', u.arcsec/u.minute),
30+
('DEC_rate', u.arcsec/u.minute),
31+
('delta_rate', u.km/u.s))
32+
33+
for i in cols:
34+
assert i[0] in res.columns
35+
assert res[i[0]].unit == i[1]
36+
1937
assert res['target'] == "Ceres"
2038

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

0 commit comments

Comments
 (0)