Skip to content

Commit b9caebf

Browse files
committed
completing the remote tests
1 parent bbb8b3e commit b9caebf

File tree

6 files changed

+32582
-27117
lines changed

6 files changed

+32582
-27117
lines changed

astroquery/esa/neocc/core.py

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -408,9 +408,8 @@ def query_object(name, tab, **kwargs):
408408
# Check the input of the method if tab is not in the list
409409
# print and error and show the valid names
410410
if tab not in tab_list:
411-
raise KeyError('Please introduce a valid tab name. '
412-
'valid tabs names are: '
413-
', '.join([str(elem) for elem in tab_list]))
411+
raise KeyError(("Please introduce a valid table name. "
412+
f"Valid names are: {', '.join(tab_list)}"))
414413
# Depending on the tab selected the information will be requested
415414
# following different methods. Create "switch" for each case:
416415

@@ -426,7 +425,7 @@ def query_object(name, tab, **kwargs):
426425
data_obj = tabs.get_object_data(url)
427426
except ConnectionError: # pragma: no cover
428427
print('Initial attempt to obtain object data failed. '
429-
'Reattempting...')
428+
'Reattempting...')
430429
# Wait 5 seconds
431430
time.sleep(5)
432431
# Get object data
@@ -500,10 +499,6 @@ def query_object(name, tab, **kwargs):
500499
resp_str = tabs.get_summary_data(name)
501500

502501
neocc_obj = tabs.parse_summary(resp_str)
503-
# Create empty object with class Summary
504-
#neocc_obj = tabs.Summary()
505-
# Parse the requested data using Summary parser
506-
#neocc_obj._summary_parser(name)
507502

508503
return neocc_obj
509504

astroquery/esa/neocc/lists.py

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -94,9 +94,12 @@ def get_list_data(url, list_name):
9494

9595
# Get data from URL
9696
response = requests.get(API_URL + url, timeout=TIMEOUT, verify=VERIFICATION)
97-
data_string = response.content.decode('utf-8')
97+
98+
# Raising error based on HTTP status if necessary
99+
response.raise_for_status()
98100

99101
# Parse decoded data
102+
data_string = response.content.decode('utf-8')
100103
neocc_list = parse_list(list_name, data_string)
101104

102105
return neocc_list
@@ -162,7 +165,8 @@ def parse_nea(resp_str):
162165
"""
163166

164167
resp_str = resp_str.replace('#', '')
165-
return Table.read(resp_str, data_start=0, format="ascii.fixed_width", names=["NEA"])
168+
resp_str = re.sub(' +', ' ', resp_str)
169+
return Table.read(resp_str, data_start=0, format="ascii.csv", names=["NEA"])
166170

167171

168172
def parse_risk(resp_str):
@@ -184,7 +188,8 @@ def parse_risk(resp_str):
184188
neocc_lst.rename_columns(("Num/des. Name", "m", "Vel km/s"),
185189
('Object Name', 'Diameter in m', 'Vel in km/s'))
186190

187-
neocc_lst['Date/Time'] = Time(neocc_lst['Date/Time'], scale="utc")
191+
neocc_lst['Date/Time'] = Time(neocc_lst['Date/Time'], scale="utc")
192+
neocc_lst['*=Y'] = neocc_lst['*=Y'].astype("<U1")
188193

189194
if "Years" in neocc_lst.colnames:
190195
first_year, last_year = np.array([x.split("-") for x in neocc_lst["Years"]]).swapaxes(0,1).astype(int)
@@ -224,9 +229,13 @@ def parse_clo(resp_str):
224229
neocc_lst = Table.read(resp_str, header_start=2, data_start=4, format="ascii.fixed_width",
225230
names=('Object Name', 'Date', 'Miss Distance in km', 'Miss Distance in au',
226231
'Miss Distance in LD', 'Diameter in m', '*=Yes', 'H', 'Max Bright',
227-
'Rel. vel in km/s'))
232+
'Rel. vel in km/s', "drop"))
233+
234+
# Remove last column
235+
neocc_lst.remove_column("drop")
228236

229237
neocc_lst['Date'] = Time(neocc_lst['Date'], scale="utc")
238+
neocc_lst["Diameter in m"] = neocc_lst["Diameter in m"].astype(float)
230239

231240
neocc_lst.meta = {'Object Name': 'name of the NEA',
232241
'Date': 'close approach date in datetime format',

astroquery/esa/neocc/tabs.py

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -810,15 +810,27 @@ def parse_summary(resp_str):
810810
Uses BeautifulSoup, since it is html data.
811811
"""
812812

813+
if "Object not found" in resp_str:
814+
raise ValueError('Object not found: the name of the object is wrong or misspelt')
815+
813816
parsed_html = BeautifulSoup(resp_str, 'lxml')
814817

815818
# Pull out the properties
816819
props = parsed_html.find_all("div", {"class": "simple-list__cell"})
817820
prop_list = [str(x.contents[0]).strip() for x in props]
818821

819-
# Seperate the ones that don't follow the same format (name followed by value followed by unit)
820-
obs_props = prop_list[-4:]
821-
prop_list = prop_list[:-4]
822+
# Pulling out Discovery data/Observatory if they are present
823+
# (These don't follow the name-value-unit format
824+
try:
825+
obs_ind = prop_list.index("Discovery Date")
826+
except ValueError:
827+
try:
828+
obs_ind = prop_list.index("Observatory")
829+
except:
830+
obs_ind = len(prop_list)
831+
832+
obs_props = prop_list[obs_ind:]
833+
prop_list = prop_list[:obs_ind]
822834

823835
# Building the table
824836
summary_tab = Table(names=["Physical Properties", "Value", "Units"],

0 commit comments

Comments
 (0)