Skip to content

Commit 0e2e700

Browse files
committed
Fixs for building docs etc
1 parent 4ba4685 commit 0e2e700

File tree

8 files changed

+134
-91
lines changed

8 files changed

+134
-91
lines changed

astroquery/esa/neocc/__init__.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,14 @@ class Conf(_config.ConfigNamespace):
1818

1919
BASE_URL = 'https://' + os.getenv('NEOCC_PORTAL_IP', default='neo.ssa.esa.int')
2020

21-
API_URL = _config.ConfigItem(BASE_URL + '/PSDB-portlet/download?file=')
21+
API_URL = _config.ConfigItem(BASE_URL + '/PSDB-portlet/download?file=',
22+
"Main API URL")
2223

23-
EPHEM_URL = _config.ConfigItem(BASE_URL + '/PSDB-portlet/ephemerides?des=')
24+
EPHEM_URL = _config.ConfigItem(BASE_URL + '/PSDB-portlet/ephemerides?des=',
25+
"Ephermerides URL")
2426

25-
SUMMARY_URL = _config.ConfigItem(BASE_URL + '/search-for-asteroids?sum=1&des=')
27+
SUMMARY_URL = _config.ConfigItem(BASE_URL + '/search-for-asteroids?sum=1&des=',
28+
"Object summary URL")
2629

2730
TIMEOUT = 60
2831

@@ -31,6 +34,6 @@ class Conf(_config.ConfigNamespace):
3134

3235
conf = Conf()
3336

34-
from .core import neocc, ESAneoccClass
37+
from .core import neocc, NEOCCClass
3538

36-
__all__ = ['neocc', 'ESAneoccClass', 'Conf', 'conf']
39+
__all__ = ['neocc', 'NEOCCClass', 'Conf', 'conf']

astroquery/esa/neocc/core.py

Lines changed: 40 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,11 @@
1313

1414
from astroquery.esa.neocc import lists, tabs
1515

16-
__all__ = ['neocc', 'ESAneoccClass']
16+
__all__ = ['neocc', 'NEOCCClass']
1717

1818

1919
@async_to_sync
20-
class ESAneoccClass(BaseQuery):
20+
class NEOCCClass(BaseQuery):
2121
"""
2222
Class to init ESA NEOCC Python interface library
2323
"""
@@ -130,7 +130,9 @@ def query_list(list_name):
130130
return neocc_list
131131

132132
@staticmethod
133-
def query_object(name, tab, **kwargs):
133+
def query_object(name, tab, *,
134+
orbital_elements=None, orbit_epoch=None,
135+
observatory=None, start=None, stop=None, step=None, step_unit=None):
134136
"""Get requested object data from ESA NEOCC.
135137
136138
Parameters
@@ -141,22 +143,27 @@ def query_object(name, tab, **kwargs):
141143
Name of the request tab. Valid names are: summary,
142144
orbit_properties, physical_properties, observations,
143145
ephemerides, close_approaches and impacts.
144-
**kwargs : str
145-
Tabs orbit_properties and ephemerides tabs required additional
146-
arguments to work:
147-
148-
* *orbit_properties*: the required additional arguments are:
149-
150-
* *orbital_elements* : str (keplerian or equinoctial)
151-
* *orbit_epoch* : str (present or middle)
152-
153-
* *ephemerides*: the required additional arguments are:
154-
155-
* *observatory* : str (observatory code, e.g. '500', 'J04', etc.)
156-
* *start* : str (start date in YYYY-MM-DD HH:MM)
157-
* *stop* : str (end date in YYYY-MM-DD HH:MM)
158-
* *step* : str (time step, e.g. '2', '15', etc.)
159-
* *step_unit* : str (e.g. 'days', 'minutes', etc.)
146+
orbital_elements : str
147+
Additional required argument for "orbit_properties" table.
148+
Valid arguments are: keplerian, equinoctial
149+
orbit_epoch : str
150+
Additional required argument for "orbit_properties" table.
151+
Valid arguments are: present, middle
152+
observatory : str
153+
Additional required argument for "ephemerides" table.
154+
Observatory code, e.g. '500', 'J04', etc.
155+
start : str
156+
Additional required argument for "ephemerides" table.
157+
Start date in YYYY-MM-DD HH:MM
158+
stop : str
159+
Additional required argument for "ephemerides" table.
160+
End date in YYYY-MM-DD HH:MM
161+
step : str
162+
Additional required argument for "ephemerides" table.
163+
Time step, e.g. '2', '15', etc.
164+
step_unit : str
165+
Additional required argument for "ephemerides" table.
166+
Unit for time step e.g. 'days', 'minutes', etc.
160167
161168
Returns
162169
-------
@@ -387,22 +394,14 @@ def query_object(name, tab, **kwargs):
387394

388395
# Orbit properties
389396
elif tab == 'orbit_properties':
390-
# Raise error if no elements are provided
391-
if 'orbital_elements' not in kwargs:
392-
raise KeyError('Please specify type of orbital_elements: '
393-
'keplerian or equinoctial '
394-
'(e.g., orbital_elements="keplerian")')
395-
396-
# Raise error if no epoch is provided
397-
if 'orbit_epoch' not in kwargs:
398-
raise KeyError('Please specify type of orbit_epoch: '
399-
'present or middle '
400-
'(e.g., orbit_epoch="middle")')
397+
398+
# Raise error if elements or epoch are not provided
399+
if not all([orbital_elements, orbit_epoch]):
400+
raise KeyError(("orbital_elements and orbit_epoch must be specified"
401+
"for an orbit_properties query."))
401402

402403
# Get URL to obtain the data from NEOCC
403-
url = tabs.get_object_url(name, tab,
404-
orbital_elements=kwargs['orbital_elements'],
405-
orbit_epoch=kwargs['orbit_epoch'])
404+
url = tabs.get_object_url(name, tab, orbital_elements=orbital_elements, orbit_epoch=orbit_epoch)
406405

407406
# Request data two times if the first attempt fails
408407
try:
@@ -423,21 +422,13 @@ def query_object(name, tab, **kwargs):
423422

424423
# Ephemerides
425424
elif tab == 'ephemerides':
426-
# Create dictionary for kwargs
427-
args_dict = {'observatory': 'observatory (e.g., observatory="500")',
428-
'start': 'start date (e.g., start="2021-05-17 00:00")',
429-
'stop': 'end date (e.g., stop="2021-05-18 00:00")',
430-
'step': 'time step (e.g., step="1")',
431-
'step_unit': 'step unit (e.g., step_unit="days")'}
432-
433-
# Check if any kwargs is missing
434-
for element in args_dict:
435-
if element not in kwargs:
436-
raise KeyError(f'Please specify {args_dict[element]} for ephemerides.')
437-
438-
resp_str = tabs.get_ephemerides_data(name, observatory=kwargs['observatory'],
439-
start=kwargs['start'], stop=kwargs['stop'],
440-
step=kwargs['step'], step_unit=kwargs['step_unit'])
425+
426+
if not all([observatory, start, stop, step, step_unit]):
427+
raise KeyError(("Ephemerides queries require the following arguments:"
428+
"observatory, start, stop, step, and step_unit"))
429+
430+
resp_str = tabs.get_ephemerides_data(name, observatory=observatory, start=start, stop=stop,
431+
step=step, step_unit=step_unit)
441432
neocc_obj = tabs.parse_ephemerides(resp_str)
442433

443434
elif tab == 'summary':
@@ -450,4 +441,4 @@ def query_object(name, tab, **kwargs):
450441
return neocc_obj
451442

452443

453-
neocc = ESAneoccClass()
444+
neocc = NEOCCClass()

astroquery/esa/neocc/tabs.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -466,7 +466,6 @@ def parse_observations(resp_str, verbose=False):
466466
"""
467467
Parse the close approach response string into the close approach tables.
468468
469-
TODO: document properly.
470469
Parameters
471470
----------
472471
resp_str : str

astroquery/esa/neocc/test/test_neocc.py

Lines changed: 32 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import os
99
import re
1010
import pytest
11+
import warnings
1112

1213
import numpy as np
1314
import requests
@@ -54,7 +55,6 @@ def get_mockreturn(name, timeout=TIMEOUT, verify=VERIFICATION):
5455
# Split name (the requested url) to obtain the name of the file location stored in \data
5556

5657
fileloc = name.split(r'=')[1]
57-
print(fileloc)
5858

5959
# Exception for ephemerides
6060
if '&oc' in fileloc:
@@ -63,6 +63,7 @@ def get_mockreturn(name, timeout=TIMEOUT, verify=VERIFICATION):
6363
filename = data_path(fileloc)
6464
with open(filename, 'rb') as FLE:
6565
content = FLE.read()
66+
content = content.replace(b"\r", b"") # For windows tests
6667

6768
return MockResponse(content)
6869

@@ -86,7 +87,12 @@ def test_bad_list_names():
8687

8788
def check_table_structure(data_table, table_len, table_cols, float_cols=[], int_cols=[], str_cols=[], time_cols=[]):
8889
"""
89-
TODO
90+
Given a data table, checks:
91+
- Table length matches given table_len
92+
- Table column names match the given table_cols list
93+
- All the columns with indices given in float_cols are of float type
94+
- Equivalent checks for int_cols, and string_cols
95+
- Checks that columns with indices given in time_cols are `~astropy.time.Time` objects
9096
"""
9197

9298
table_cols = np.array(table_cols)
@@ -96,15 +102,20 @@ def check_table_structure(data_table, table_len, table_cols, float_cols=[], int_
96102

97103
assert all([x == y for x, y in zip(data_table.colnames, table_cols)])
98104

99-
assert all([data_table[x].dtype == np.dtype('float64') for x in table_cols[float_cols]])
100-
assert all([data_table[x].dtype == np.dtype('int64') for x in table_cols[int_cols]])
101-
assert all([data_table[x].dtype.type == np.str_ for x in table_cols[str_cols]])
105+
# Ignore the FutureWarning that only comes up with the oldest dependencies
106+
warnings.filterwarnings("ignore", category=FutureWarning,
107+
message="Conversion of the second argument of issubdtype*")
108+
assert all([np.issubdtype(data_table[x].dtype, float) for x in table_cols[float_cols]])
109+
assert all([np.issubdtype(data_table[x].dtype, int) for x in table_cols[int_cols]])
110+
assert all([np.issubdtype(data_table[x].dtype, str) for x in table_cols[str_cols]])
111+
102112
assert all([isinstance(data_table[x], Time) for x in table_cols[time_cols]])
103113

104114

105115
def check_table_values(data_table, true_value_dict):
106116
"""
107-
TODO
117+
Checks data_table rows against true values given in true_value_dict.
118+
The format of true_value_dict is {<row number>: [true row data], ...}
108119
"""
109120

110121
for row, values in true_value_dict.items():
@@ -178,8 +189,11 @@ def test_parse_nea(patch_get):
178189
assert re.match(r'\w{3} \w{3} \d{2} \d{2}:\d{2}:\d{2} \w{3} \d{4}', monthly_update["NEA"][0])
179190

180191

192+
@pytest.mark.filterwarnings('ignore:ERFA function *:erfa.core.ErfaWarning')
181193
def test_parse_risk(patch_get):
182194
"""Check data: risk_list, risk_list_special
195+
196+
Ignore ERFA 'dubious year' warnings because they are expected.
183197
"""
184198
# Risk and risk special lists
185199
risk_list = neocc.neocc.query_list("risk_list")
@@ -293,8 +307,11 @@ def test_parse_pri(patch_get):
293307
check_table_values(faint_list, faint_dict)
294308

295309

310+
@pytest.mark.filterwarnings('ignore:ERFA function *:erfa.core.ErfaWarning')
296311
def test_parse_encounter(patch_get):
297312
"""Check data: encounter_list
313+
314+
Ignore ERFA 'dubious year' warnings because they are expected.
298315
"""
299316

300317
encounter_list = neocc.neocc.query_list("close_encounter")
@@ -377,8 +394,11 @@ def check_tab_result_basic(results, num_tabs):
377394
assert len(results) == num_tabs
378395

379396

397+
@pytest.mark.filterwarnings('ignore:ERFA function *:erfa.core.ErfaWarning')
380398
def test_tabs_impacts(patch_get):
381399
"""Check data: asteroid impacts tab
400+
401+
Ignore ERFA 'dubious year' warnings because they are expected.
382402
"""
383403

384404
# 433 Eros has no tab "impacts"
@@ -418,8 +438,11 @@ def test_tabs_impacts(patch_get):
418438
check_table_values(impact_table, impact_dict)
419439

420440

441+
@pytest.mark.filterwarnings('ignore:ERFA function *:erfa.core.ErfaWarning')
421442
def test_tabs_close_approach(patch_get):
422443
"""Check data: asteroid close approaches tab
444+
445+
Ignore ERFA 'dubious year' warnings because they are expected.
423446
"""
424447

425448
# Check opbject with no close approaches
@@ -503,8 +526,11 @@ def test_tabs_physical_properties(patch_get):
503526
check_table_values(phys_props, phys_dict)
504527

505528

529+
@pytest.mark.filterwarnings('ignore:ERFA function *:erfa.core.ErfaWarning')
506530
def test_tabs_observations(patch_get):
507531
"""Check data: asteroid observations tab
532+
533+
Ignore ERFA 'dubious year' warnings because they are expected.
508534
"""
509535

510536
with pytest.raises(ValueError):

0 commit comments

Comments
 (0)