1
- # -*- coding: utf-8 -*-
1
+ # Licensed under a 3-clause BSD style license - see LICENSE.rst
2
2
"""
3
3
Main module from ESA NEOCC library. This module contains the two main
4
4
methods of the library: *query_list* and *query_object*. The information
5
5
is obtained from ESA Near-Earth Object Coordination Centre's (NEOCC) web
6
6
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
46
7
"""
47
8
48
9
import time
54
15
55
16
__all__ = ['neocc' , 'ESAneoccClass' ]
56
17
18
+
57
19
@async_to_sync
58
20
class ESAneoccClass (BaseQuery ):
59
21
"""
@@ -195,7 +157,7 @@ def query_list(list_name):
195
157
196
158
return neocc_list
197
159
198
- except ConnectionError : # pragma: no cover
160
+ except ConnectionError : # pragma: no cover
199
161
print ('Initial attempt to obtain list failed. Reattempting...' )
200
162
# Wait 5 seconds
201
163
time .sleep (5 )
@@ -442,12 +404,13 @@ def query_object(name, tab, **kwargs):
442
404
tab_list = ['impacts' , 'close_approaches' , 'observations' ,
443
405
'physical_properties' , 'orbit_properties' ,
444
406
'ephemerides' , 'summary' ]
407
+
445
408
# Check the input of the method if tab is not in the list
446
409
# print and error and show the valid names
447
410
if tab not in tab_list :
448
411
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 ]))
451
414
# Depending on the tab selected the information will be requested
452
415
# following different methods. Create "switch" for each case:
453
416
@@ -457,36 +420,34 @@ def query_object(name, tab, **kwargs):
457
420
# Get URL to obtain the data from NEOCC
458
421
url = tabs .get_object_url (name , tab )
459
422
423
+ print ("First" )
424
+ print (url )
425
+
460
426
# Request data two times if the first attempt fails
461
427
try :
462
428
# Get object data
463
429
data_obj = tabs .get_object_data (url )
464
- except ConnectionError : # pragma: no cover
430
+ except ConnectionError : # pragma: no cover
465
431
print ('Initial attempt to obtain object data failed. '
466
432
'Reattempting...' )
467
433
# Wait 5 seconds
468
434
time .sleep (5 )
469
435
# Get object data
470
436
data_obj = tabs .get_object_data (url )
471
437
438
+ resp_str = data_obj .decode ('utf-8' )
439
+
440
+ # TODO: check data here
441
+
472
442
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 )
443
+ neocc_obj = tabs .parse_impacts (resp_str )
477
444
elif tab == 'close_approaches' :
478
- # Parse the requested data using Close Approaches parser
479
- neocc_obj = tabs .CloseApproaches .clo_appr_parser (data_obj )
445
+ neocc_obj = tabs .parse_close_aproach (resp_str )
480
446
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 )
447
+ neocc_obj = tabs .parse_observations (resp_str )
485
448
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 )
449
+ neocc_obj = tabs .parse_physical_properties (resp_str )
450
+
490
451
# Orbit properties
491
452
elif tab == 'orbit_properties' :
492
453
# Raise error if no elements are provided
@@ -508,25 +469,16 @@ def query_object(name, tab, **kwargs):
508
469
try :
509
470
# Get object data
510
471
data_obj = tabs .get_object_data (url )
511
- except ConnectionError : # pragma: no cover
472
+ except ConnectionError : # pragma: no cover
512
473
print ('Initial attempt to obtain object data failed. '
513
474
'Reattempting...' )
514
475
# Wait 5 seconds
515
476
time .sleep (5 )
516
477
# Get object data
517
478
data_obj = tabs .get_object_data (url )
518
479
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 )
480
+ resp_str = data_obj .decode ('utf-8' )
481
+ neocc_obj = tabs .parse_orbital_properties (resp_str )
530
482
531
483
# Ephemerides
532
484
elif tab == 'ephemerides' :
@@ -539,21 +491,22 @@ def query_object(name, tab, **kwargs):
539
491
# Check if any kwargs is missing
540
492
for element in args_dict :
541
493
if element not in kwargs :
542
- raise KeyError ('Please specify ' + args_dict [element ]
543
- + ' for ephemerides' )
494
+ raise KeyError (f'Please specify { args_dict [element ]} for ephemerides.' )
544
495
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' ],
496
+ resp_str = tabs .get_ephemerides_data (name , observatory = kwargs ['observatory' ],
549
497
start = kwargs ['start' ], stop = kwargs ['stop' ],
550
498
step = kwargs ['step' ],
551
499
step_unit = kwargs ['step_unit' ])
500
+ neocc_obj = tabs .parse_ephemerides (resp_str )
501
+
552
502
elif tab == 'summary' :
503
+ resp_str = tabs .get_summary_data (name )
504
+
505
+ neocc_obj = tabs .parse_summary (resp_str )
553
506
# Create empty object with class Summary
554
- neocc_obj = tabs .Summary ()
507
+ # neocc_obj = tabs.Summary()
555
508
# Parse the requested data using Summary parser
556
- neocc_obj ._summary_parser (name )
509
+ # neocc_obj._summary_parser(name)
557
510
558
511
return neocc_obj
559
512
0 commit comments