Skip to content

Commit 8ff974b

Browse files
committed
removing pandas from tabs.py
1 parent 1a42547 commit 8ff974b

File tree

5 files changed

+771
-2055
lines changed

5 files changed

+771
-2055
lines changed

astroquery/esa/neocc/__init__.py

+8-8
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
1+
# Licensed under a 3-clause BSD style license - see LICENSE.rst
12
"""
3+
NEOCC Query Tool
4+
================
25
3-
@author: C. Álvaro Arroyo
4-
@contact: carlos.arroyo@deimos-space.com
5-
6-
European Space Agency (ESA)
7-
8-
Created on 16 Jun. 2021
9-
Last update 22 Aug. 2022
6+
Module to query the Near Earth Objects Coordination Centre (NEOCC).
107
118
"""
9+
1210
import os
1311
from astropy import config as _config
1412

13+
1514
class Conf(_config.ConfigNamespace):
1615
"""
1716
Configuration parameters for 'ESANEOCC'
1817
"""
18+
1919
BASE_URL = 'https://' + os.getenv('NEOCC_PORTAL_IP',
2020
default='neo.ssa.esa.int')
2121

@@ -30,10 +30,10 @@ class Conf(_config.ConfigNamespace):
3030

3131
TIMEOUT = 60
3232

33-
3433
SSL_CERT_VERIFICATION = bool(int(os.getenv('SSL_CERT_VERIFICATION',
3534
default="1")))
3635

36+
3737
conf = Conf()
3838

3939
from .core import neocc, ESAneoccClass

astroquery/esa/neocc/core.py

+32-82
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,9 @@
1-
# -*- coding: utf-8 -*-
1+
# Licensed under a 3-clause BSD style license - see LICENSE.rst
22
"""
33
Main module from ESA NEOCC library. This module contains the two main
44
methods of the library: *query_list* and *query_object*. The information
55
is obtained from ESA Near-Earth Object Coordination Centre's (NEOCC) web
66
portal: https://neo.ssa.esa.int/.
7-
8-
* Project: NEOCC portal Python interface
9-
* Property: European Space Agency (ESA)
10-
* Developed by: Elecnor Deimos
11-
* Author: C. Álvaro Arroyo Parejo
12-
* Issue: 2.2.0
13-
* Date: 19-08-2022
14-
* Purpose: Main module which gets NEAs data from https://neo.ssa.esa.int/
15-
* Module: core.py
16-
* History:
17-
18-
======== =========== ============================================
19-
Version Date Change History
20-
======== =========== ============================================
21-
1.0 26-02-2021 Initial version
22-
1.1 26-03-2021 Adding new docstrings
23-
1.2 17-05-2021 Adding new docstrings for *help*
24-
property in dataframes and *<tab>*
25-
specification for obtaining attributes.\n
26-
For orbit properties *orbit_elements*
27-
changes to *orbital_elements*.\n
28-
Adding impacted objects lists.\n
29-
Minor typos changes.
30-
1.3 16-06-2021 Renamed module from *neocc* to *core*.\n
31-
Adding class type as for astroquery
32-
implementation.\n
33-
Define methods as static.\n
34-
1.3.1 29-06-2021 No changes
35-
1.4.0 29-10-2021 Adding new docstrings.\n
36-
Change method for obtaining physical
37-
properties
38-
2.0.0 21-01-2022 Prepare module for Astroquery integration
39-
2.1.0 01-03-2022 Remove *parse* dependency
40-
2.2.0 19-08-2022 Impacted objects list format change
41-
======== =========== ============================================
42-
43-
44-
© Copyright [European Space Agency][2022]
45-
All rights reserved
467
"""
478

489
import time
@@ -54,6 +15,7 @@
5415

5516
__all__ = ['neocc', 'ESAneoccClass']
5617

18+
5719
@async_to_sync
5820
class ESAneoccClass(BaseQuery):
5921
"""
@@ -92,13 +54,13 @@ def query_list(list_name):
9254
9355
Returns
9456
-------
95-
neocc_lst : *pandas.Series* or *pandas.DataFrame*
96-
Data Frame which contains the information of the requested list
57+
neocc_lst : `~astropy.table.Table`
58+
Astropy Table which contains the data of the requested list.
9759
9860
Examples
9961
--------
10062
**NEA list, Updated NEA list, Monthly computation date:** The output
101-
of this list is a *pandas.Series* which contains the list of all NEAs
63+
of this list is a `~astropy.table.Table` which contains the list of all NEAs
10264
currently considered in the NEOCC system.
10365
10466
>>> from astroquery.esa.neocc import neocc
@@ -123,7 +85,7 @@ def query_list(list_name):
12385
>>> list_data[4]
12486
'1221 Amor'
12587
126-
**Other lists:** The output of this list is a *pandas.DataFrame* which
88+
**Other lists:** The output of this list is a `~astropy.table.Table` which
12789
contains the information of the requested list.
12890
12991
>>> from astroquery.esa.neocc import neocc
@@ -195,7 +157,7 @@ def query_list(list_name):
195157

196158
return neocc_list
197159

198-
except ConnectionError: # pragma: no cover
160+
except ConnectionError: # pragma: no cover
199161
print('Initial attempt to obtain list failed. Reattempting...')
200162
# Wait 5 seconds
201163
time.sleep(5)
@@ -442,12 +404,13 @@ def query_object(name, tab, **kwargs):
442404
tab_list = ['impacts', 'close_approaches', 'observations',
443405
'physical_properties', 'orbit_properties',
444406
'ephemerides', 'summary']
407+
445408
# Check the input of the method if tab is not in the list
446409
# print and error and show the valid names
447410
if tab not in tab_list:
448411
raise KeyError('Please introduce a valid tab name. '
449-
'valid tabs names are: ' +\
450-
', '.join([str(elem) for elem in tab_list]))
412+
'valid tabs names are: '
413+
', '.join([str(elem) for elem in tab_list]))
451414
# Depending on the tab selected the information will be requested
452415
# following different methods. Create "switch" for each case:
453416

@@ -461,32 +424,27 @@ def query_object(name, tab, **kwargs):
461424
try:
462425
# Get object data
463426
data_obj = tabs.get_object_data(url)
464-
except ConnectionError: # pragma: no cover
427+
except ConnectionError: # pragma: no cover
465428
print('Initial attempt to obtain object data failed. '
466429
'Reattempting...')
467430
# Wait 5 seconds
468431
time.sleep(5)
469432
# Get object data
470433
data_obj = tabs.get_object_data(url)
471434

435+
resp_str = data_obj.decode('utf-8')
436+
437+
# TODO: check data here
438+
472439
if tab == 'impacts':
473-
# Create empty object with class Impacts
474-
neocc_obj = tabs.Impacts()
475-
# Parse the requested data using Impacts parser
476-
neocc_obj._impacts_parser(data_obj)
440+
neocc_obj = tabs.parse_impacts(resp_str)
477441
elif tab == 'close_approaches':
478-
# Parse the requested data using Close Approaches parser
479-
neocc_obj = tabs.CloseApproaches.clo_appr_parser(data_obj)
442+
neocc_obj = tabs.parse_close_aproach(resp_str)
480443
elif tab == 'observations':
481-
# Create empty object
482-
neocc_obj = tabs.AsteroidObservations()
483-
# Get object with attributes from data
484-
neocc_obj._ast_obs_parser(data_obj)
444+
neocc_obj = tabs.parse_observations(resp_str)
485445
elif tab == 'physical_properties':
486-
# Create empty object with class Physical properties
487-
neocc_obj = tabs.PhysicalProperties()
488-
# Parse the requested data using Physical properties parser
489-
neocc_obj._phys_prop_parser(data_obj)
446+
neocc_obj = tabs.parse_physical_properties(resp_str)
447+
490448
# Orbit properties
491449
elif tab == 'orbit_properties':
492450
# Raise error if no elements are provided
@@ -508,25 +466,16 @@ def query_object(name, tab, **kwargs):
508466
try:
509467
# Get object data
510468
data_obj = tabs.get_object_data(url)
511-
except ConnectionError: # pragma: no cover
469+
except ConnectionError: # pragma: no cover
512470
print('Initial attempt to obtain object data failed. '
513471
'Reattempting...')
514472
# Wait 5 seconds
515473
time.sleep(5)
516474
# Get object data
517475
data_obj = tabs.get_object_data(url)
518476

519-
# Assign orbit properties depending on the elements requested
520-
if kwargs['orbital_elements'] == "keplerian":
521-
# Create empty object with class Orbit properties
522-
neocc_obj = tabs.KeplerianOrbitProperties()
523-
# Parse the requested data using Orbit properties parser
524-
neocc_obj._orb_kep_prop_parser(data_obj)
525-
elif kwargs['orbital_elements'] == "equinoctial":
526-
# Create empty object with class Orbit properties
527-
neocc_obj = tabs.EquinoctialOrbitProperties()
528-
# Parse the requested data using Orbit properties parser
529-
neocc_obj._orb_equi_prop_parser(data_obj)
477+
resp_str = data_obj.decode('utf-8')
478+
neocc_obj = tabs.parse_orbital_properties(resp_str)
530479

531480
# Ephemerides
532481
elif tab == 'ephemerides':
@@ -539,21 +488,22 @@ def query_object(name, tab, **kwargs):
539488
# Check if any kwargs is missing
540489
for element in args_dict:
541490
if element not in kwargs:
542-
raise KeyError ('Please specify ' + args_dict[element]
543-
+ ' for ephemerides')
491+
raise KeyError(f'Please specify {args_dict[element]} for ephemerides.')
544492

545-
# Create empty object with class Ephemerides
546-
neocc_obj = tabs.Ephemerides()
547-
# Parse the requested data using Ephemerides parser
548-
neocc_obj._ephem_parser(name, observatory=kwargs['observatory'],
493+
resp_str = tabs.get_ephemerides_data(name, observatory=kwargs['observatory'],
549494
start=kwargs['start'], stop=kwargs['stop'],
550495
step=kwargs['step'],
551496
step_unit=kwargs['step_unit'])
497+
neocc_obj = tabs.parse_ephemerides(resp_str)
498+
552499
elif tab == 'summary':
500+
resp_str = tabs.get_summary_data(name)
501+
502+
neocc_obj = tabs.parse_summary(resp_str)
553503
# Create empty object with class Summary
554-
neocc_obj = tabs.Summary()
504+
#neocc_obj = tabs.Summary()
555505
# Parse the requested data using Summary parser
556-
neocc_obj._summary_parser(name)
506+
#neocc_obj._summary_parser(name)
557507

558508
return neocc_obj
559509

astroquery/esa/neocc/lists.py

+18-19
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
from astropy.time import Time, TimeDelta
1414

1515
from astroquery.esa.neocc import conf
16+
from astroquery.esa.neocc.utils import convert_time
1617

1718
# Import BASE URL and TIMEOUT
1819
API_URL = conf.API_URL
@@ -87,8 +88,8 @@ def get_list_data(url, list_name):
8788
8889
Returns
8990
-------
90-
neocc_lst : *pandas.Series* or *pandas.DataDrame*
91-
Data frame which contains the data of the requested list.
91+
neocc_lst : `~astropy.table.Table`
92+
Astropy Table which contains the data of the requested list.
9293
"""
9394

9495
# Get data from URL
@@ -113,8 +114,8 @@ def parse_list(list_name, data_string):
113114
114115
Returns
115116
-------
116-
neocc_lst : *pandas.Series* or *pandas.DataFrame*
117-
Data frame with data from the list parsed.
117+
neocc_lst : `~astropy.table.Table`
118+
Astropy Table which contains the data of the requested list.
118119
"""
119120

120121
# Parse data for each type of list
@@ -156,8 +157,8 @@ def parse_nea(resp_str):
156157
Decoded StringIO object.
157158
Returns
158159
-------
159-
neocc_lst : *pandas.Series* or *pandas.DataFrame*
160-
Data frame with NEA list data parsed.
160+
neocc_lst : `~astropy.table.Table`
161+
Astropy Table with NEA list data parsed.
161162
"""
162163

163164
resp_str = resp_str.replace('#', '')
@@ -174,8 +175,8 @@ def parse_risk(resp_str):
174175
175176
Returns
176177
-------
177-
neocc_lst : *pandas.Series* or *pandas.DataFrame*
178-
Data frame with risk list data parsed.
178+
neocc_lst : `~astropy.table.Table`
179+
Astropy Table with risk list data parsed.
179180
"""
180181

181182
neocc_lst = Table.read(resp_str, header_start=2, data_start=4, format="ascii.fixed_width")
@@ -216,8 +217,8 @@ def parse_clo(resp_str):
216217
Decoded StringIO object.
217218
Returns
218219
-------
219-
neocc_lst : *pandas.Series* or *pandas.DataFrame*
220-
Data frame with close approaches list data parsed.
220+
neocc_lst : `~astropy.table.Table`
221+
Astropy Table with close approaches list data parsed.
221222
"""
222223

223224
neocc_lst = Table.read(resp_str, header_start=2, data_start=4, format="ascii.fixed_width",
@@ -250,8 +251,8 @@ def parse_pri(resp_str):
250251
Decoded StringIO object.
251252
Returns
252253
-------
253-
neocc_lst : *pandas.Series* or *pandas.DataFrame*
254-
Data frame with priority list data parsed.
254+
neocc_lst : `~astropy.table.Table`
255+
Astropy Table with priority list data parsed.
255256
"""
256257

257258
neocc_lst = Table.read(resp_str, data_start=1, format="ascii.no_header",
@@ -281,14 +282,12 @@ def parse_encounter(resp_str):
281282
Decoded StringIO object.
282283
Returns
283284
-------
284-
neocc_lst : *pandas.Series* or *pandas.DataFrame*
285-
Data frame with close encounter list data parsed.
285+
neocc_lst : `~astropy.table.Table`
286+
Astropy Table with close encounter list data parsed.
286287
"""
287288

288289
neocc_lst = Table.read(resp_str, header_start=1, data_start=3, format="ascii.fixed_width")
289-
290-
day, tme = np.array([x.split(".") for x in neocc_lst['Date']]).swapaxes(0,1)
291-
neocc_lst['Date'] = Time.strptime(day, '%Y/%m/%d') + TimeDelta(tme.astype(int)/1e5, format="jd")
290+
neocc_lst['Date'] = convert_time(neocc_lst['Date'], conversion_string='%Y/%m/%d')
292291

293292
neocc_lst.meta = {'Name/design': 'designator of the NEA',
294293
'Planet': 'planet or massive asteroid is involved in the close approach',
@@ -338,8 +337,8 @@ def parse_neo_catalogue(resp_str):
338337
Decoded StringIO object.
339338
Returns
340339
-------
341-
neocc_lst : *pandas.DataFrame*
342-
Data frame with catalogues of NEAs list data parsed.
340+
neocc_lst : `~astropy.table.Table`
341+
Astropy Table with catalogues of NEAs list data parsed.
343342
"""
344343

345344
neocc_lst = Table.read(resp_str, data_start=6, format="ascii.no_header",

0 commit comments

Comments
 (0)