11
11
from pathlib import Path
12
12
13
13
from astropy .io import fits
14
+ from astropy .utils .console import ProgressBar
14
15
from astroquery import log
15
16
import astropy .units
16
17
from requests import HTTPError
@@ -639,10 +640,10 @@ def get_images_sso(self, *, sso_name=None, sso_type="ALL", table_list=None, miss
639
640
self ._get_maps_for_mission (map_query_result [query_mission ], query_mission , download_dir , cache ,
640
641
json , verbose = verbose ))
641
642
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 ])
643
644
for mission in maps ]):
644
645
log .info ("No maps got downloaded, check errors above." )
645
- elif len (map_query_result ) > 0 :
646
+ elif len (maps ) > 0 :
646
647
log .info ("Maps available at {}" .format (os .path .abspath (download_dir )))
647
648
else :
648
649
log .info ("No maps found." )
@@ -1461,8 +1462,9 @@ def _get_maps_for_mission(self, maps_table, mission, download_dir, cache, json,
1461
1462
if len (maps_table [url_key ]) > 0 :
1462
1463
mission_directory = self ._create_mission_directory (mission ,
1463
1464
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
+
1466
1468
for index in range (len (maps_table )):
1467
1469
product_url = maps_table [url_key ][index ]
1468
1470
if isinstance (product_url , bytes ):
@@ -1476,8 +1478,7 @@ def _get_maps_for_mission(self, maps_table, mission, download_dir, cache, json,
1476
1478
maps_table [self ._get_json_data_for_mission (json , mission )["uniqueIdentifierField" ]][index ]
1477
1479
if isinstance (observation_id , bytes ):
1478
1480
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 ))
1481
1482
sys .stdout .flush ()
1482
1483
directory_path = mission_directory
1483
1484
if mission .lower () == self .__HERSCHEL_STRING :
@@ -1489,7 +1490,6 @@ def _get_maps_for_mission(self, maps_table, mission, download_dir, cache, json,
1489
1490
maps [key ] = self ._get_herschel_spectra (product_url , directory_path , cache , verbose = verbose )
1490
1491
else :
1491
1492
maps .append (self ._get_herschel_map (product_url , directory_path , cache , verbose = verbose ))
1492
- log .info ("[Done]" )
1493
1493
except HTTPError as err :
1494
1494
log .error ("Download failed with {}." .format (err ))
1495
1495
if is_spectra :
@@ -1534,17 +1534,16 @@ def _get_maps_for_mission(self, maps_table, mission, download_dir, cache, json,
1534
1534
fits_file .flush ()
1535
1535
maps .append (
1536
1536
self ._open_fits (os .path .join (directory_path , file_name ), verbose = verbose ))
1537
- log .info ("[Done]" )
1538
1537
except (HTTPError , ConnectionError ) as err :
1539
1538
log .error ("Download failed with {}." .format (err ))
1540
1539
maps .append (None )
1541
1540
1541
+ progress_bar .update (index + 1 )
1542
+
1542
1543
if None in maps :
1543
1544
log .error ("Some downloads were unsuccessful, please check "
1544
1545
"the warnings for more details" )
1545
1546
1546
- log .info ("Downloading of {} data complete." .format (mission ))
1547
-
1548
1547
return maps
1549
1548
1550
1549
def _open_fits (self , path , verbose = False ):
@@ -1773,7 +1772,7 @@ def _build_id_query(self, ids, row_limit, json):
1773
1772
if data_type in self ._NUMBER_DATA_TYPES :
1774
1773
valid_ids = [int (obs_id ) for obs_id in ids if obs_id .isdigit ()]
1775
1774
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, "
1777
1776
"while none of the input id's could be interpreted as numbers." .format (json ['mission' ]))
1778
1777
return ""
1779
1778
0 commit comments