33obtain it from the ESA NEOCC portal and parse it to show it properly.
44"""
55
6- import io
76import re
87import requests
98
109import numpy as np
1110
1211from astropy .table import Table , Column
13- from astropy .time import Time , TimeDelta
12+ from astropy .time import Time
1413
1514from astroquery .esa .neocc import conf
1615from 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