def test_output_epochs(self): from astropy.utils.iers import IERSRangeError # transformed from ut1 to utc # this test sometimes causes trouble in remote tests, potentially # because it has to download some data, which might fail; # if that happens, skip the test try: epochs = Time(2437655.5, format='jd', scale='utc') a = Ephem.from_horizons(1, epochs=epochs) assert a['epoch'][0].scale == 'utc' except IERSRangeError: pass # all utc epochs = Time(2437675.5, format='jd', scale='utc') a = Ephem.from_horizons(1, epochs=epochs) assert a['epoch'][0].scale == 'utc' # mixed ut1 and utc # same as above try: epochs = Time([2437655.5, 2437675.5], format='jd', scale='utc') a = Ephem.from_horizons(1, epochs=epochs) assert a['epoch'].scale == 'utc' except IERSRangeError: pass
def test_minimum_working_columns(self): """Avoid assuming any particular columns are returned. Regression test for #242. """ e = Ephem.from_horizons(1, quantities='1') # just RA, Dec assert len(e) == 1 e = Ephem.from_horizons(1, quantities='19') # just rh and delta-rh assert len(e) == 1
def test_output_epochs(self): # transformed from ut1 to utc epochs = Time(2437655.5, format='jd', scale='utc') a = Ephem.from_horizons(1, epochs=epochs) assert a['epoch'][0].scale == 'utc' # all utc epochs = Time(2437675.5, format='jd', scale='utc') a = Ephem.from_horizons(1, epochs=epochs) assert a['epoch'][0].scale == 'utc' # mixed ut1 and utc epochs = Time([2437655.5, 2437675.5], format='jd', scale='utc') a = Ephem.from_horizons(1, epochs=epochs) assert a['epoch'].scale == 'utc'
def test_timescale(self): # test same timescale time = Time('2020-01-01 00:00', format='iso', scale='utc') a = Ephem.from_horizons(1, epochs=time) assert a['epoch'].scale == 'utc' assert a['epoch'].utc.jd == 2458849.5 # test different timescale (and check for warning) time = Time('2020-01-01 00:00', format='iso', scale='tdb') with warnings.catch_warnings(record=True) as w: a = Ephem.from_horizons(1, epochs=time) assert any([ "astroquery.jplhorizons" in str(w[i].message) for i in range(len(w)) ]) assert a['epoch'].scale == 'utc' assert_allclose(a['epoch'][0].utc.jd, 2458849.49919926)
def test_daterange_number(self): epochs = { 'start': Time('2018-01-02', format='iso'), 'stop': Time('2018-01-05', format='iso'), 'number': 10 } data = Ephem.from_horizons('Ceres', epochs=epochs) assert len(data.table) == 10
def test_daterange_step(self): epochs = { 'start': Time('2018-01-02', format='iso'), 'stop': Time('2018-01-05', format='iso'), 'step': 6 * u.hour } data = Ephem.from_horizons('Ceres', epochs=epochs) assert len(data.table) == 13
def test_from_oo(): """test from_oo method""" try: import pyoorb except ImportError: return None orbit = Orbit.from_horizons('Ceres') horizons_ephem = Ephem.from_horizons('Ceres', location='500') oo_ephem = Ephem.from_oo(orbit) u.isclose(horizons_ephem['ra'][0], oo_ephem['ra'][0]) u.isclose(horizons_ephem['dec'][0], oo_ephem['dec'][0]) u.isclose(horizons_ephem['RA*cos(Dec)_rate'][0], oo_ephem['RA*cos(Dec)_rate'][0]) u.isclose(horizons_ephem['dec_rate'][0], oo_ephem['dec_rate'][0]) u.isclose(horizons_ephem['alpha'][0], oo_ephem['alpha'][0]) u.isclose(horizons_ephem['r'][0], oo_ephem['r'][0]) u.isclose(horizons_ephem['delta'][0], oo_ephem['delta'][0]) u.isclose(horizons_ephem['V'][0], oo_ephem['V'][0]) u.isclose(horizons_ephem['hlon'][0], oo_ephem['hlon'][0]) u.isclose(horizons_ephem['hlat'][0], oo_ephem['hlat'][0]) u.isclose(horizons_ephem['EL'][0], oo_ephem['EL'][0]) # test manual orbit definition lacking units manorbit = Orbit.from_dict({ 'targetname': orbit['targetname'][0], 'a': orbit['a'].value[0], 'e': orbit['e'][0], 'i': orbit['i'].value[0], 'w': orbit['w'].value[0], 'Omega': orbit['Omega'].value[0], 'datetime_jd': orbit['datetime_jd'][0].value, 'M': orbit['M'].value[0], 'H': orbit['H'].value[0], 'G': orbit['G'][0], 'timescale': orbit['timescale'][0] }) oo_ephem = Ephem.from_oo(manorbit) u.isclose(horizons_ephem['ra'][0], oo_ephem['ra'][0]) u.isclose(horizons_ephem['dec'][0], oo_ephem['dec'][0]) u.isclose(horizons_ephem['RA*cos(Dec)_rate'][0], oo_ephem['RA*cos(Dec)_rate'][0]) u.isclose(horizons_ephem['dec_rate'][0], oo_ephem['dec_rate'][0]) u.isclose(horizons_ephem['alpha'][0], oo_ephem['alpha'][0]) u.isclose(horizons_ephem['r'][0], oo_ephem['r'][0]) u.isclose(horizons_ephem['delta'][0], oo_ephem['delta'][0]) u.isclose(horizons_ephem['V'][0], oo_ephem['V'][0]) u.isclose(horizons_ephem['hlon'][0], oo_ephem['hlon'][0]) u.isclose(horizons_ephem['hlat'][0], oo_ephem['hlat'][0]) u.isclose(horizons_ephem['EL'][0], oo_ephem['EL'][0])
def test_from_horizons(): """ test from_horizons method""" # current epoch now = Time.now() data = Ephem.from_horizons('Ceres') assert_allclose(data.datetime_jd, now.jd * u.d) # date range - astropy.time.Time objects epochs = { 'start': Time('2018-01-02', format='iso'), 'stop': Time('2018-01-05', format='iso'), 'step': '6h' } data = Ephem.from_horizons('Ceres', epochs=epochs) assert len(data.table) == 13 # date range - strings epochs = {'start': '2018-01-02', 'stop': '2018-01-05', 'step': '6h'} data = Ephem.from_horizons('Ceres', epochs=epochs) assert len(data.table) == 13 # astropy.time.Time object with list of Dates epochs = Time(['2018-01-01', '2018-01-02']) data = Ephem.from_horizons('Ceres', epochs=epochs) assert len(data.table) == 2 # query two objects data = Ephem.from_horizons(['Ceres', 'Pallas']) assert len(data.table) == 2 # test bib service bib.track() data = Ephem.from_horizons(['Ceres', 'Pallas']) assert 'sbpy.data.Ephem' in bib.to_text()
def test_queryfail(self): with pytest.raises(QueryError): Ephem.from_horizons('target does not exist')
def test_bib(self): bib.track() Ephem.from_horizons(['Ceres', 'Pallas']) assert 'sbpy.data.ephem.Ephem.from_horizons' in bib.to_text()
def test_Earthlocation(self): lowell = EarthLocation.of_site('Lowell Observatory') data = Ephem.from_horizons(1, epochs=Time('2018-01-01', format='iso'), location=lowell) assert len(data.table) == 1
def test_multiple_objects(self): data = Ephem.from_horizons(['Ceres', 'Pallas']) assert len(data.table) == 2
def test_Time_list(self): epochs = Time(['2018-01-01', '2018-01-02']) data = Ephem.from_horizons('Ceres', epochs=epochs) assert len(data.table) == 2
def test_current_epoch(self): now = Time.now() data = Ephem.from_horizons('Ceres') assert_allclose(data['epoch'].jd, now.jd)