1111from pathlib import Path
1212
1313from astropy .io import fits
14+ from astropy .utils .console import ProgressBar
1415from astroquery import log
1516import astropy .units
1617from requests import HTTPError
@@ -639,10 +640,10 @@ def get_images_sso(self, *, sso_name=None, sso_type="ALL", table_list=None, miss
639640 self ._get_maps_for_mission (map_query_result [query_mission ], query_mission , download_dir , cache ,
640641 json , verbose = verbose ))
641642
642- if all ([maps [mission ].count (None ) == len (maps [mission ])
643+ if len ( map_query_result ) > 0 and all ([maps [mission ].count (None ) == len (maps [mission ])
643644 for mission in maps ]):
644645 log .info ("No maps got downloaded, check errors above." )
645- elif len (map_query_result ) > 0 :
646+ elif len (maps ) > 0 :
646647 log .info ("Maps available at {}" .format (os .path .abspath (download_dir )))
647648 else :
648649 log .info ("No maps found." )
@@ -1461,8 +1462,9 @@ def _get_maps_for_mission(self, maps_table, mission, download_dir, cache, json,
14611462 if len (maps_table [url_key ]) > 0 :
14621463 mission_directory = self ._create_mission_directory (mission ,
14631464 download_dir )
1464- log .info ("Starting download of {} data. ({} files)" .format (
1465- mission , len (maps_table [url_key ])))
1465+ log .info ("Starting download of {} data. ({} files)" .format (mission , len (maps_table [url_key ])))
1466+ progress_bar = ProgressBar (len (maps_table [url_key ]))
1467+
14661468 for index in range (len (maps_table )):
14671469 product_url = maps_table [url_key ][index ]
14681470 if isinstance (product_url , bytes ):
@@ -1476,8 +1478,7 @@ def _get_maps_for_mission(self, maps_table, mission, download_dir, cache, json,
14761478 maps_table [self ._get_json_data_for_mission (json , mission )["uniqueIdentifierField" ]][index ]
14771479 if isinstance (observation_id , bytes ):
14781480 observation_id = observation_id .decode ('utf-8' )
1479- log .info ("Downloading Observation ID: {} from {}"
1480- .format (observation_id , product_url ))
1481+ log .debug ("Downloading Observation ID: {} from {}" .format (observation_id , product_url ))
14811482 sys .stdout .flush ()
14821483 directory_path = mission_directory
14831484 if mission .lower () == self .__HERSCHEL_STRING :
@@ -1489,7 +1490,6 @@ def _get_maps_for_mission(self, maps_table, mission, download_dir, cache, json,
14891490 maps [key ] = self ._get_herschel_spectra (product_url , directory_path , cache , verbose = verbose )
14901491 else :
14911492 maps .append (self ._get_herschel_map (product_url , directory_path , cache , verbose = verbose ))
1492- log .info ("[Done]" )
14931493 except HTTPError as err :
14941494 log .error ("Download failed with {}." .format (err ))
14951495 if is_spectra :
@@ -1534,17 +1534,16 @@ def _get_maps_for_mission(self, maps_table, mission, download_dir, cache, json,
15341534 fits_file .flush ()
15351535 maps .append (
15361536 self ._open_fits (os .path .join (directory_path , file_name ), verbose = verbose ))
1537- log .info ("[Done]" )
15381537 except (HTTPError , ConnectionError ) as err :
15391538 log .error ("Download failed with {}." .format (err ))
15401539 maps .append (None )
15411540
1541+ progress_bar .update (index + 1 )
1542+
15421543 if None in maps :
15431544 log .error ("Some downloads were unsuccessful, please check "
15441545 "the warnings for more details" )
15451546
1546- log .info ("Downloading of {} data complete." .format (mission ))
1547-
15481547 return maps
15491548
15501549 def _open_fits (self , path , verbose = False ):
@@ -1773,7 +1772,7 @@ def _build_id_query(self, ids, row_limit, json):
17731772 if data_type in self ._NUMBER_DATA_TYPES :
17741773 valid_ids = [int (obs_id ) for obs_id in ids if obs_id .isdigit ()]
17751774 if not valid_ids :
1776- log . info ("Could not construct query for mission {}. Database column type is a number, "
1775+ raise ValueError ("Could not construct query for mission {}. Database column type is a number, "
17771776 "while none of the input id's could be interpreted as numbers." .format (json ['mission' ]))
17781777 return ""
17791778
0 commit comments