Skip to content

Commit 4af0077

Browse files
author
Alvaro Arroyo Parejo
committed
update impacted objects parse list and bug fix in risk special list
1 parent 92a19ac commit 4af0077

File tree

1 file changed

+28
-17
lines changed

1 file changed

+28
-17
lines changed

astroquery/esa/neocc/lists.py

Lines changed: 28 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
* Property: European Space Agency (ESA)
88
* Developed by: Elecnor Deimos
99
* Author: C. Álvaro Arroyo Parejo
10-
* Issue: 2.1.0
11-
* Date: 01-03-2021
10+
* Issue: 2.2.0
11+
* Date: 19-08-2022
1212
* Purpose: Module which request and parse list data from ESA NEOCC
1313
* Module: lists.py
1414
* History:
@@ -31,6 +31,7 @@
3131
Update docstrings.
3232
2.0.0 21-01-2022 Prepare module for Astroquery integration
3333
2.1.0 01-03-2022 Remove *parse* dependency
34+
2.2.0 19-08-2022 Impacted objects list format change
3435
======== =========== ==========================================
3536
3637
© Copyright [European Space Agency][2022]
@@ -39,6 +40,8 @@
3940

4041
import io
4142
from datetime import timedelta
43+
from astropy.table import Table
44+
from astropy.time import Time
4245
import pandas as pd
4346
import requests
4447
from astroquery.esa.neocc import conf
@@ -83,7 +86,7 @@ def get_list_url(list_name):
8386
"priority_list": 'esa_priority_neo_list',
8487
"priority_list_faint": 'esa_faint_neo_list',
8588
"close_encounter" : 'close_encounter2.txt',
86-
"impacted_objects" : 'impactedObjectsList.txt',
89+
"impacted_objects" : 'past_impactors_list',
8790
"neo_catalogue_current" : 'neo_kc.cat',
8891
"neo_catalogue_middle" : 'neo_km.cat'
8992
}
@@ -231,10 +234,11 @@ def parse_risk(data_byte_d):
231234
neocc_lst = neocc_lst.drop(neocc_lst.columns[-1], axis=1)
232235

233236
# Convert column with date to datetime variable
234-
neocc_lst['Date/Time'] = pd.to_datetime(neocc_lst['Date/Time'])
237+
neocc_lst['Date/Time'] = pd.to_datetime(neocc_lst['Date/Time'],
238+
errors='ignore')
235239
# Split Years into 2 columns to avoid dashed between integers
236-
# Check dataframe is not empty (for special list)
237-
if len(neocc_lst.index.values) != 0:
240+
# Check dataframe column length is differnt from 8 (for special risk)
241+
if len(neocc_lst.columns) != 8:
238242
neocc_lst[['First year', 'Last year']] = neocc_lst['Years']\
239243
.str.split("-",
240244
expand=True)\
@@ -468,17 +472,25 @@ def parse_impacted(data_byte_d):
468472
Decoded StringIO object.
469473
Returns
470474
-------
471-
neocc_lst : *pandas.DataFrame*
472-
Data frame with impacted objects list data parsed.
475+
neocc_table : *astropy.table.table.Table*
476+
Astropy table with impacted objects list data parsed.
473477
"""
474-
# Read data as csv
475-
neocc_lst = pd.read_csv(data_byte_d, header=None,
476-
delim_whitespace=True)
477-
478-
# Convert column with date to datetime variable
479-
neocc_lst[1] = pd.to_datetime(neocc_lst[1])
480-
481-
return neocc_lst
478+
# Read data as csv using astropy.table
479+
neocc_table = Table.read(data_byte_d, format='pandas.csv',
480+
delimiter=r'\s+\|\s+|\s+\|',
481+
engine='python', header=1,
482+
dtype={'Object designator': str,
483+
'Diameter in m': str,
484+
'Impact date/time in UTC': str,
485+
'Impact Velocity in km/s': float,
486+
'Estimated energy in Mt': float,
487+
'Measured energy in Mt': float})
488+
neocc_table.remove_column('Unnamed: 6')
489+
# Convert column with date to astropy.time ISO format variable
490+
neocc_table['Impact date/time in UTC'] =\
491+
Time(neocc_table['Impact date/time in UTC'], scale='utc')
492+
493+
return neocc_table
482494

483495

484496
def parse_neo_catalogue(data_byte_d):
@@ -540,4 +552,3 @@ def parse_neo_catalogue(data_byte_d):
540552

541553

542554
return neocc_lst
543-

0 commit comments

Comments
 (0)