@@ -534,15 +534,15 @@ def __init__(self):
534
534
# Sources
535
535
self .sources = []
536
536
537
- @staticmethod
538
- def _get_prop_sources (url ):
537
+ @staticmethod
538
+ def _get_prop_sources (contents ):
539
539
"""
540
540
Obtain the sources parsed
541
541
542
542
Parameters
543
543
----------
544
- url : str
545
- Complete url for physical properties
544
+ contents : object
545
+ Content of the requested url
546
546
547
547
Returns
548
548
-------
@@ -551,7 +551,7 @@ def _get_prop_sources(url):
551
551
"""
552
552
# Read html for obtaining different tables from the portal
553
553
try :
554
- df_p = pd .read_html (url , keep_default_na = False )
554
+ df_p = pd .read_html (contents , keep_default_na = False )
555
555
except df_p .DoesNotExist as df_not_exist :
556
556
logging .warning ('Object not found: the name of the '
557
557
'object is wrong or misspelt' )
@@ -565,14 +565,14 @@ def _get_prop_sources(url):
565
565
return sources
566
566
567
567
@staticmethod
568
- def _get_property_names (url ):
568
+ def _get_property_names (contents ):
569
569
"""
570
570
Check and obtain dataframe names
571
571
572
572
Parameters
573
573
----------
574
- url : str
575
- Complete url for physical properties
574
+ contents : object
575
+ Content of the requested url
576
576
577
577
Returns
578
578
-------
@@ -581,8 +581,6 @@ def _get_property_names(url):
581
581
parsed_html : object
582
582
BeautifulSoup object with the requested information
583
583
"""
584
- # Get contents from url
585
- contents = requests .get (url , timeout = TIMEOUT ).content
586
584
# Parse html using BS
587
585
parsed_html = BeautifulSoup (contents , 'lxml' )
588
586
# Check if there is a tag sub for term A1 and A2 if so,
@@ -607,7 +605,6 @@ def _get_property_names(url):
607
605
'object. Re-attempting...' )
608
606
# Wait and re-try
609
607
time .sleep (5 )
610
- contents = requests .get (url , timeout = TIMEOUT ).content
611
608
parsed_html = BeautifulSoup (contents , 'lxml' )
612
609
for i in range (2 ):
613
610
subtag = parsed_html .find ('sub' )
@@ -634,7 +631,7 @@ def _get_property_names(url):
634
631
return parsed_html , df_names
635
632
636
633
@staticmethod
637
- def _get_physical_props (url ):
634
+ def _get_physical_props (contents ):
638
635
"""
639
636
Obtain the physical properties from the portal
640
637
@@ -649,8 +646,9 @@ def _get_physical_props(url):
649
646
Data structure containing the physical properties
650
647
"""
651
648
# Obtain DataFrame with the obtained properties and html parsed
652
- parsed_html = PhysicalProperties ._get_property_names (url )[0 ]
653
- df_names = PhysicalProperties ._get_property_names (url )[1 ]
649
+ parsed_html , df_names = PhysicalProperties \
650
+ ._get_property_names (contents )
651
+ #df_names = PhysicalProperties._get_property_names(url)[1]
654
652
# Search for property values, units and sources
655
653
props_value = parsed_html .find_all ("div" ,
656
654
{"class" : "col-12" })
@@ -721,10 +719,11 @@ def _phys_prop_parser(self, name):
721
719
# Final url = PROPERTIES_URL + desig in which white spaces,
722
720
# if any, are replaced by %20 to complete the designator
723
721
url = PROPERTIES_URL + str (name ).replace (' ' , '%20' )
724
-
722
+ # Get contents to optimize times
723
+ contents = requests .get (url ).content
725
724
# Sources
726
- self .physical_properties = self ._get_physical_props (url )
727
- self .sources = self ._get_prop_sources (url )
725
+ self .physical_properties = self ._get_physical_props (contents )
726
+ self .sources = self ._get_prop_sources (contents )
728
727
729
728
730
729
class AsteroidObservations :
@@ -1135,15 +1134,15 @@ def _ast_obs_parser(self, data_obj):
1135
1134
if not get_indexes (df_p , '! Object' ):
1136
1135
# Set length of asteriod observations to zero
1137
1136
diff = 0
1137
+ # Get observations
1138
+ total_observations = self ._get_opt_info (data_obj , diff ,
1139
+ head )
1138
1140
# Set attributes
1139
- self .optical_observations = self ._get_opt_info (data_obj , diff ,
1140
- head )[0 ]
1141
+ self .optical_observations = total_observations [0 ]
1141
1142
self .radar_observations = 'There is no relevant radar ' \
1142
1143
'information'
1143
- self .roving_observations = self ._get_opt_info (data_obj , diff ,
1144
- head )[1 ]
1145
- self .sat_observations = self ._get_opt_info (data_obj , diff ,
1146
- head )[2 ]
1144
+ self .roving_observations = total_observations [1 ]
1145
+ self .sat_observations = total_observations [2 ]
1147
1146
1148
1147
else :
1149
1148
# # Decode data for optical and radar observations
@@ -1152,14 +1151,14 @@ def _ast_obs_parser(self, data_obj):
1152
1151
index = get_indexes (df_p , '! Object' )
1153
1152
# Set lenght of radar obsrevations to remove footer
1154
1153
diff = len (df_p ) - index [0 ][0 ]
1154
+ # Get observations
1155
+ total_observations = self ._get_opt_info (data_obj , diff ,
1156
+ head )
1155
1157
# Set attributes
1156
- self .optical_observations = self ._get_opt_info (data_obj , diff ,
1157
- head )[0 ]
1158
+ self .optical_observations = total_observations [0 ]
1158
1159
self .radar_observations = self ._get_rad_info (df_rad , index )
1159
- self .roving_observations = self ._get_opt_info (data_obj , diff ,
1160
- head )[1 ]
1161
- self .sat_observations = self ._get_opt_info (data_obj , diff ,
1162
- head )[2 ]
1160
+ self .roving_observations = total_observations [1 ]
1161
+ self .sat_observations = total_observations [2 ]
1163
1162
1164
1163
1165
1164
class OrbitProperties :
@@ -2022,12 +2021,14 @@ def _ephem_parser(self, name, observatory, start, stop, step, step_unit):
2022
2021
'-The Sky plane error with the long axis (Err1),'
2023
2022
' short axis (Err2) and Position Angle (PA) '
2024
2023
'values' )
2024
+ # Get header data
2025
+ header_date = self ._get_head_ephem (data_obj )
2025
2026
# Assign attributes
2026
2027
self .ephemerides = ephem
2027
- self .observatory = self . _get_head_ephem ( data_obj ) [0 ]
2028
- self .tinit = self . _get_head_ephem ( data_obj ) [1 ]
2029
- self .tfinal = self . _get_head_ephem ( data_obj ) [2 ]
2030
- self .tstep = self . _get_head_ephem ( data_obj ) [3 ]
2028
+ self .observatory = header_date [0 ]
2029
+ self .tinit = header_date [1 ]
2030
+ self .tfinal = header_date [2 ]
2031
+ self .tstep = header_date [3 ]
2031
2032
2032
2033
2033
2034
class Summary :
0 commit comments