Skip to content

Commit

Permalink
removing pandas from tabs.py
Browse files Browse the repository at this point in the history
  • Loading branch information
ceb8 committed Jan 27, 2023
1 parent 1a42547 commit 8ff974b
Show file tree
Hide file tree
Showing 5 changed files with 771 additions and 2,055 deletions.
16 changes: 8 additions & 8 deletions astroquery/esa/neocc/__init__.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
# Licensed under a 3-clause BSD style license - see LICENSE.rst
"""
NEOCC Query Tool
================
@author: C. Álvaro Arroyo
@contact: [email protected]
European Space Agency (ESA)
Created on 16 Jun. 2021
Last update 22 Aug. 2022
Module to query the Near Earth Objects Coordination Centre (NEOCC).
"""

import os
from astropy import config as _config


class Conf(_config.ConfigNamespace):
"""
Configuration parameters for 'ESANEOCC'
"""

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

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

TIMEOUT = 60


SSL_CERT_VERIFICATION = bool(int(os.getenv('SSL_CERT_VERIFICATION',
default="1")))


conf = Conf()

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

import time
Expand All @@ -54,6 +15,7 @@

__all__ = ['neocc', 'ESAneoccClass']


@async_to_sync
class ESAneoccClass(BaseQuery):
"""
Expand Down Expand Up @@ -92,13 +54,13 @@ def query_list(list_name):
Returns
-------
neocc_lst : *pandas.Series* or *pandas.DataFrame*
Data Frame which contains the information of the requested list
neocc_lst : `~astropy.table.Table`
Astropy Table which contains the data of the requested list.
Examples
--------
**NEA list, Updated NEA list, Monthly computation date:** The output
of this list is a *pandas.Series* which contains the list of all NEAs
of this list is a `~astropy.table.Table` which contains the list of all NEAs
currently considered in the NEOCC system.
>>> from astroquery.esa.neocc import neocc
Expand All @@ -123,7 +85,7 @@ def query_list(list_name):
>>> list_data[4]
'1221 Amor'
**Other lists:** The output of this list is a *pandas.DataFrame* which
**Other lists:** The output of this list is a `~astropy.table.Table` which
contains the information of the requested list.
>>> from astroquery.esa.neocc import neocc
Expand Down Expand Up @@ -195,7 +157,7 @@ def query_list(list_name):

return neocc_list

except ConnectionError: # pragma: no cover
except ConnectionError: # pragma: no cover
print('Initial attempt to obtain list failed. Reattempting...')
# Wait 5 seconds
time.sleep(5)
Expand Down Expand Up @@ -442,12 +404,13 @@ def query_object(name, tab, **kwargs):
tab_list = ['impacts', 'close_approaches', 'observations',
'physical_properties', 'orbit_properties',
'ephemerides', 'summary']

# Check the input of the method if tab is not in the list
# print and error and show the valid names
if tab not in tab_list:
raise KeyError('Please introduce a valid tab name. '
'valid tabs names are: ' +\
', '.join([str(elem) for elem in tab_list]))
'valid tabs names are: '
', '.join([str(elem) for elem in tab_list]))
# Depending on the tab selected the information will be requested
# following different methods. Create "switch" for each case:

Expand All @@ -461,32 +424,27 @@ def query_object(name, tab, **kwargs):
try:
# Get object data
data_obj = tabs.get_object_data(url)
except ConnectionError: # pragma: no cover
except ConnectionError: # pragma: no cover
print('Initial attempt to obtain object data failed. '
'Reattempting...')
# Wait 5 seconds
time.sleep(5)
# Get object data
data_obj = tabs.get_object_data(url)

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

# TODO: check data here

if tab == 'impacts':
# Create empty object with class Impacts
neocc_obj = tabs.Impacts()
# Parse the requested data using Impacts parser
neocc_obj._impacts_parser(data_obj)
neocc_obj = tabs.parse_impacts(resp_str)
elif tab == 'close_approaches':
# Parse the requested data using Close Approaches parser
neocc_obj = tabs.CloseApproaches.clo_appr_parser(data_obj)
neocc_obj = tabs.parse_close_aproach(resp_str)
elif tab == 'observations':
# Create empty object
neocc_obj = tabs.AsteroidObservations()
# Get object with attributes from data
neocc_obj._ast_obs_parser(data_obj)
neocc_obj = tabs.parse_observations(resp_str)
elif tab == 'physical_properties':
# Create empty object with class Physical properties
neocc_obj = tabs.PhysicalProperties()
# Parse the requested data using Physical properties parser
neocc_obj._phys_prop_parser(data_obj)
neocc_obj = tabs.parse_physical_properties(resp_str)

# Orbit properties
elif tab == 'orbit_properties':
# Raise error if no elements are provided
Expand All @@ -508,25 +466,16 @@ def query_object(name, tab, **kwargs):
try:
# Get object data
data_obj = tabs.get_object_data(url)
except ConnectionError: # pragma: no cover
except ConnectionError: # pragma: no cover
print('Initial attempt to obtain object data failed. '
'Reattempting...')
# Wait 5 seconds
time.sleep(5)
# Get object data
data_obj = tabs.get_object_data(url)

# Assign orbit properties depending on the elements requested
if kwargs['orbital_elements'] == "keplerian":
# Create empty object with class Orbit properties
neocc_obj = tabs.KeplerianOrbitProperties()
# Parse the requested data using Orbit properties parser
neocc_obj._orb_kep_prop_parser(data_obj)
elif kwargs['orbital_elements'] == "equinoctial":
# Create empty object with class Orbit properties
neocc_obj = tabs.EquinoctialOrbitProperties()
# Parse the requested data using Orbit properties parser
neocc_obj._orb_equi_prop_parser(data_obj)
resp_str = data_obj.decode('utf-8')
neocc_obj = tabs.parse_orbital_properties(resp_str)

# Ephemerides
elif tab == 'ephemerides':
Expand All @@ -539,21 +488,22 @@ def query_object(name, tab, **kwargs):
# Check if any kwargs is missing
for element in args_dict:
if element not in kwargs:
raise KeyError ('Please specify ' + args_dict[element]
+ ' for ephemerides')
raise KeyError(f'Please specify {args_dict[element]} for ephemerides.')

# Create empty object with class Ephemerides
neocc_obj = tabs.Ephemerides()
# Parse the requested data using Ephemerides parser
neocc_obj._ephem_parser(name, observatory=kwargs['observatory'],
resp_str = tabs.get_ephemerides_data(name, observatory=kwargs['observatory'],
start=kwargs['start'], stop=kwargs['stop'],
step=kwargs['step'],
step_unit=kwargs['step_unit'])
neocc_obj = tabs.parse_ephemerides(resp_str)

elif tab == 'summary':
resp_str = tabs.get_summary_data(name)

neocc_obj = tabs.parse_summary(resp_str)
# Create empty object with class Summary
neocc_obj = tabs.Summary()
#neocc_obj = tabs.Summary()
# Parse the requested data using Summary parser
neocc_obj._summary_parser(name)
#neocc_obj._summary_parser(name)

return neocc_obj

Expand Down
37 changes: 18 additions & 19 deletions astroquery/esa/neocc/lists.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
from astropy.time import Time, TimeDelta

from astroquery.esa.neocc import conf
from astroquery.esa.neocc.utils import convert_time

# Import BASE URL and TIMEOUT
API_URL = conf.API_URL
Expand Down Expand Up @@ -87,8 +88,8 @@ def get_list_data(url, list_name):
Returns
-------
neocc_lst : *pandas.Series* or *pandas.DataDrame*
Data frame which contains the data of the requested list.
neocc_lst : `~astropy.table.Table`
Astropy Table which contains the data of the requested list.
"""

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

# Parse data for each type of list
Expand Down Expand Up @@ -156,8 +157,8 @@ def parse_nea(resp_str):
Decoded StringIO object.
Returns
-------
neocc_lst : *pandas.Series* or *pandas.DataFrame*
Data frame with NEA list data parsed.
neocc_lst : `~astropy.table.Table`
Astropy Table with NEA list data parsed.
"""

resp_str = resp_str.replace('#', '')
Expand All @@ -174,8 +175,8 @@ def parse_risk(resp_str):
Returns
-------
neocc_lst : *pandas.Series* or *pandas.DataFrame*
Data frame with risk list data parsed.
neocc_lst : `~astropy.table.Table`
Astropy Table with risk list data parsed.
"""

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

neocc_lst = Table.read(resp_str, header_start=2, data_start=4, format="ascii.fixed_width",
Expand Down Expand Up @@ -250,8 +251,8 @@ def parse_pri(resp_str):
Decoded StringIO object.
Returns
-------
neocc_lst : *pandas.Series* or *pandas.DataFrame*
Data frame with priority list data parsed.
neocc_lst : `~astropy.table.Table`
Astropy Table with priority list data parsed.
"""

neocc_lst = Table.read(resp_str, data_start=1, format="ascii.no_header",
Expand Down Expand Up @@ -281,14 +282,12 @@ def parse_encounter(resp_str):
Decoded StringIO object.
Returns
-------
neocc_lst : *pandas.Series* or *pandas.DataFrame*
Data frame with close encounter list data parsed.
neocc_lst : `~astropy.table.Table`
Astropy Table with close encounter list data parsed.
"""

neocc_lst = Table.read(resp_str, header_start=1, data_start=3, format="ascii.fixed_width")

day, tme = np.array([x.split(".") for x in neocc_lst['Date']]).swapaxes(0,1)
neocc_lst['Date'] = Time.strptime(day, '%Y/%m/%d') + TimeDelta(tme.astype(int)/1e5, format="jd")
neocc_lst['Date'] = convert_time(neocc_lst['Date'], conversion_string='%Y/%m/%d')

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

neocc_lst = Table.read(resp_str, data_start=6, format="ascii.no_header",
Expand Down
Loading

0 comments on commit 8ff974b

Please sign in to comment.