Skip to content

Commit 1a5a015

Browse files
committed
completing the monkey-patched tests
1 parent b9caebf commit 1a5a015

25 files changed

+86000
-52818
lines changed

CHANGES.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@
44
New Tools and Services
55
----------------------
66

7+
esa.neocc
8+
^^^^^^^^^
9+
10+
- New module to provide access too the ESA near-earth objects coordination centre. [#2254]
11+
712
ipac.irsa
813
^^^^^^^^^
914

astroquery/esa/neocc/__init__.py

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,22 +16,17 @@ class Conf(_config.ConfigNamespace):
1616
Configuration parameters for 'ESANEOCC'
1717
"""
1818

19-
BASE_URL = 'https://' + os.getenv('NEOCC_PORTAL_IP',
20-
default='neo.ssa.esa.int')
19+
BASE_URL = 'https://' + os.getenv('NEOCC_PORTAL_IP', default='neo.ssa.esa.int')
2120

22-
API_URL = _config.ConfigItem(BASE_URL +
23-
'/PSDB-portlet/download?file=')
21+
API_URL = _config.ConfigItem(BASE_URL + '/PSDB-portlet/download?file=')
2422

25-
EPHEM_URL = _config.ConfigItem(BASE_URL +
26-
'/PSDB-portlet/ephemerides?des=')
23+
EPHEM_URL = _config.ConfigItem(BASE_URL + '/PSDB-portlet/ephemerides?des=')
2724

28-
SUMMARY_URL = _config.ConfigItem(BASE_URL +
29-
'/search-for-asteroids?sum=1&des=')
25+
SUMMARY_URL = _config.ConfigItem(BASE_URL + '/search-for-asteroids?sum=1&des=')
3026

3127
TIMEOUT = 60
3228

33-
SSL_CERT_VERIFICATION = bool(int(os.getenv('SSL_CERT_VERIFICATION',
34-
default="1")))
29+
SSL_CERT_VERIFICATION = bool(int(os.getenv('SSL_CERT_VERIFICATION', default="1")))
3530

3631

3732
conf = Conf()

astroquery/esa/neocc/core.py

Lines changed: 24 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -426,15 +426,15 @@ def query_object(name, tab, **kwargs):
426426
except ConnectionError: # pragma: no cover
427427
print('Initial attempt to obtain object data failed. '
428428
'Reattempting...')
429+
429430
# Wait 5 seconds
430431
time.sleep(5)
432+
431433
# Get object data
432434
data_obj = tabs.get_object_data(url)
433435

434436
resp_str = data_obj.decode('utf-8')
435437

436-
# TODO: check data here
437-
438438
if tab == 'impacts':
439439
neocc_obj = tabs.parse_impacts(resp_str)
440440
elif tab == 'close_approaches':
@@ -443,33 +443,37 @@ def query_object(name, tab, **kwargs):
443443
neocc_obj = tabs.parse_observations(resp_str)
444444
elif tab == 'physical_properties':
445445
neocc_obj = tabs.parse_physical_properties(resp_str)
446-
446+
447447
# Orbit properties
448448
elif tab == 'orbit_properties':
449449
# Raise error if no elements are provided
450450
if 'orbital_elements' not in kwargs:
451451
raise KeyError('Please specify type of orbital_elements: '
452-
'keplerian or equinoctial '
453-
'(e.g., orbital_elements="keplerian")')
452+
'keplerian or equinoctial '
453+
'(e.g., orbital_elements="keplerian")')
454+
454455
# Raise error if no epoch is provided
455456
if 'orbit_epoch' not in kwargs:
456457
raise KeyError('Please specify type of orbit_epoch: '
457-
'present or middle '
458-
'(e.g., orbit_epoch="middle")')
458+
'present or middle '
459+
'(e.g., orbit_epoch="middle")')
460+
459461
# Get URL to obtain the data from NEOCC
460462
url = tabs.get_object_url(name, tab,
461-
orbital_elements=kwargs['orbital_elements'],
462-
orbit_epoch=kwargs['orbit_epoch'])
463+
orbital_elements=kwargs['orbital_elements'],
464+
orbit_epoch=kwargs['orbit_epoch'])
463465

464466
# Request data two times if the first attempt fails
465467
try:
466468
# Get object data
467469
data_obj = tabs.get_object_data(url)
468470
except ConnectionError: # pragma: no cover
469471
print('Initial attempt to obtain object data failed. '
470-
'Reattempting...')
472+
'Reattempting...')
473+
471474
# Wait 5 seconds
472475
time.sleep(5)
476+
473477
# Get object data
474478
data_obj = tabs.get_object_data(url)
475479

@@ -480,26 +484,28 @@ def query_object(name, tab, **kwargs):
480484
elif tab == 'ephemerides':
481485
# Create dictionary for kwargs
482486
args_dict = {'observatory': 'observatory (e.g., observatory="500")',
483-
'start': 'start date (e.g., start="2021-05-17 00:00")',
484-
'stop': 'end date (e.g., stop="2021-05-18 00:00")',
485-
'step': 'time step (e.g., step="1")',
486-
'step_unit': 'step unit (e.g., step_unit="days")'}
487+
'start': 'start date (e.g., start="2021-05-17 00:00")',
488+
'stop': 'end date (e.g., stop="2021-05-18 00:00")',
489+
'step': 'time step (e.g., step="1")',
490+
'step_unit': 'step unit (e.g., step_unit="days")'}
491+
487492
# Check if any kwargs is missing
488493
for element in args_dict:
489494
if element not in kwargs:
490495
raise KeyError(f'Please specify {args_dict[element]} for ephemerides.')
491496

492497
resp_str = tabs.get_ephemerides_data(name, observatory=kwargs['observatory'],
493-
start=kwargs['start'], stop=kwargs['stop'],
494-
step=kwargs['step'],
495-
step_unit=kwargs['step_unit'])
498+
start=kwargs['start'], stop=kwargs['stop'],
499+
step=kwargs['step'], step_unit=kwargs['step_unit'])
496500
neocc_obj = tabs.parse_ephemerides(resp_str)
497501

498502
elif tab == 'summary':
499503
resp_str = tabs.get_summary_data(name)
500-
501504
neocc_obj = tabs.parse_summary(resp_str)
502505

506+
if not isinstance(neocc_obj, list):
507+
neocc_obj = [neocc_obj]
508+
503509
return neocc_obj
504510

505511

astroquery/esa/neocc/lists.py

Lines changed: 31 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,13 @@
33
obtain it from the ESA NEOCC portal and parse it to show it properly.
44
"""
55

6-
import io
76
import re
87
import requests
98

109
import numpy as np
1110

1211
from astropy.table import Table, Column
13-
from astropy.time import Time, TimeDelta
12+
from astropy.time import Time
1413

1514
from astroquery.esa.neocc import conf
1615
from astroquery.esa.neocc.utils import convert_time
@@ -59,7 +58,7 @@ def get_list_url(list_name):
5958
"impacted_objects": 'past_impactors_list',
6059
"neo_catalogue_current": 'neo_kc.cat',
6160
"neo_catalogue_middle": 'neo_km.cat'
62-
}
61+
}
6362

6463
# Raise error is input is not in dictionary
6564
if list_name not in lists_dict:
@@ -185,30 +184,30 @@ def parse_risk(resp_str):
185184

186185
neocc_lst = Table.read(resp_str, header_start=2, data_start=4, format="ascii.fixed_width")
187186

188-
neocc_lst.rename_columns(("Num/des. Name", "m", "Vel km/s"),
187+
neocc_lst.rename_columns(("Num/des. Name", "m", "Vel km/s"),
189188
('Object Name', 'Diameter in m', 'Vel in km/s'))
190189

191190
neocc_lst['Date/Time'] = Time(neocc_lst['Date/Time'], scale="utc")
192191
neocc_lst['*=Y'] = neocc_lst['*=Y'].astype("<U1")
193192

194193
if "Years" in neocc_lst.colnames:
195-
first_year, last_year = np.array([x.split("-") for x in neocc_lst["Years"]]).swapaxes(0,1).astype(int)
196-
yr_index = neocc_lst.index_column("Years")
194+
first_year, last_year = np.array([x.split("-") for x in neocc_lst["Years"]]).swapaxes(0, 1).astype(int)
195+
yr_index = neocc_lst.index_column("Years")
197196
neocc_lst.remove_column("Years")
198197
neocc_lst.add_column(Column(name="Last Year", data=last_year), index=yr_index)
199198
neocc_lst.add_column(Column(name="First Year", data=first_year), index=yr_index)
200199

201-
neocc_lst.meta = {'Object Name': 'name of the NEA',
202-
'Diamater in m': 'approximate diameter in meters',
203-
'*=Y': 'recording an asterisk if the value has been estimated from the absolute magnitude',
204-
'Date/Time': 'predicted impact date in datetime format',
205-
'IP max': 'Maximum Impact Probability',
206-
'PS max': 'Palermo scale rating',
207-
'Vel in km/s': 'Impact velocity at atmospheric entry in km/s',
208-
'First year': 'first year of possible impacts',
209-
'Last year': 'last year of possible impacts',
210-
'IP cum': 'Cumulative Impact Probability',
211-
'PS cum': 'Cumulative Palermo Scale'}
200+
neocc_lst.meta = {'Object Name': 'name of the NEA',
201+
'Diamater in m': 'approximate diameter in meters',
202+
'*=Y': 'recording an asterisk if the value has been estimated from the absolute magnitude',
203+
'Date/Time': 'predicted impact date in datetime format',
204+
'IP max': 'Maximum Impact Probability',
205+
'PS max': 'Palermo scale rating',
206+
'Vel in km/s': 'Impact velocity at atmospheric entry in km/s',
207+
'First year': 'first year of possible impacts',
208+
'Last year': 'last year of possible impacts',
209+
'IP cum': 'Cumulative Impact Probability',
210+
'PS cum': 'Cumulative Palermo Scale'}
212211

213212
return neocc_lst
214213

@@ -226,13 +225,10 @@ def parse_clo(resp_str):
226225
Astropy Table with close approaches list data parsed.
227226
"""
228227

229-
neocc_lst = Table.read(resp_str, header_start=2, data_start=4, format="ascii.fixed_width",
230-
names=('Object Name', 'Date', 'Miss Distance in km', 'Miss Distance in au',
231-
'Miss Distance in LD', 'Diameter in m', '*=Yes', 'H', 'Max Bright',
232-
'Rel. vel in km/s', "drop"))
233-
234-
# Remove last column
235-
neocc_lst.remove_column("drop")
228+
neocc_lst = Table.read(resp_str, header_start=2, data_start=4, format="ascii.fixed_width",
229+
names=('Object Name', 'Date', 'Miss Distance in km', 'Miss Distance in au',
230+
'Miss Distance in LD', 'Diameter in m', '*=Yes', 'H', 'Max Bright',
231+
'Rel. vel in km/s', "CAI index"))
236232

237233
neocc_lst['Date'] = Time(neocc_lst['Date'], scale="utc")
238234
neocc_lst["Diameter in m"] = neocc_lst["Diameter in m"].astype(float)
@@ -264,10 +260,11 @@ def parse_pri(resp_str):
264260
Astropy Table with priority list data parsed.
265261
"""
266262

267-
neocc_lst = Table.read(resp_str, data_start=1, format="ascii.no_header",
268-
names=['Priority', 'Object', 'R.A. in arcsec', 'Decl. in deg',
269-
'Elong. in deg', 'V in mag', 'Sky uncert.', 'End of Visibility'])
263+
neocc_lst = Table.read(resp_str, data_start=1, format="ascii.no_header",
264+
names=['Priority', 'Object', 'R.A. in arcsec', 'Decl. in deg',
265+
'Elong. in deg', 'V in mag', 'Sky uncert.', 'End of Visibility'])
270266

267+
neocc_lst["Object"] = [x.replace(' ', '') for x in neocc_lst["Object"]]
271268
neocc_lst['End of Visibility'] = Time.strptime(neocc_lst['End of Visibility'], '%Y/%m/%d')
272269

273270
neocc_lst.meta = {'Priority': '0=UR: Urgent, 1=NE: Necessary, 2=US: Useful, 3=LP: Low Priority',
@@ -324,14 +321,14 @@ def parse_impacted(resp_str):
324321
----------
325322
data_byte_d : object
326323
Decoded StringIO object.
327-
324+
328325
Returns
329326
-------
330327
neocc_table : *astropy.table.table.Table*
331328
Astropy table with impacted objects list data parsed.
332329
"""
333330

334-
neocc_table = Table.read(resp_str, header_start=1, format="ascii.fixed_width", fill_values = ['n/a', np.nan])
331+
neocc_table = Table.read(resp_str, header_start=1, format="ascii.fixed_width", fill_values=['n/a', np.nan])
335332
neocc_table['Impact date/time in UTC'] = Time(neocc_table['Impact date/time in UTC'], scale='utc')
336333

337334
return neocc_table
@@ -350,8 +347,8 @@ def parse_neo_catalogue(resp_str):
350347
Astropy Table with catalogues of NEAs list data parsed.
351348
"""
352349

353-
neocc_lst = Table.read(resp_str, data_start=6, format="ascii.no_header",
354-
names=['Name', 'Epoch (MJD)', 'a', 'e', 'i', 'long. node', 'arg. peric.',
350+
neocc_lst = Table.read(resp_str, data_start=6, format="ascii.no_header",
351+
names=['Name', 'Epoch (MJD)', 'a', 'e', 'i', 'long. node', 'arg. peric.',
355352
'mean anomaly', 'absolute magnitude', 'slope param.', 'non-grav param.'])
356353

357354
neocc_lst.meta = {'Name': 'designator of the NEA',
@@ -362,9 +359,10 @@ def parse_neo_catalogue(resp_str):
362359
'slope param': 'Slope parameter',
363360
'non-grav param.': 'Number of non-gravitational parameters'}
364361

365-
regex = re.search("(format) += '(.+)'.+\n(rectype) += '(.+)'.+\n(elem) += '(.+)'.+\n(refsys) += (\w+ \w+)", resp_str)
362+
regex = re.search(r"(format) += '(.+)'.+\n(rectype) += '(.+)'.+\n(elem) "
363+
r"+= '(.+)'.+\n(refsys) += (\w+ \w+)", resp_str)
366364
keyvals = zip(regex.groups()[::2], regex.groups()[1::2])
367-
for k,v in keyvals:
365+
for k, v in keyvals:
368366
neocc_lst.meta[k] = v
369367

370368
return neocc_lst

0 commit comments

Comments
 (0)