66import sys
77import re
88from io import BytesIO
9+ from zipfile import ZipFile
910
1011from astropy .io import fits
1112from astroquery import log
@@ -1141,7 +1142,7 @@ def _get_maps_for_mission(self, maps_table, mission, download_dir, cache, json,
11411142 url_key = self .__PRODUCT_URL_STRING
11421143 if url_key == "" and self .__ACCESS_URL_STRING in maps_table .keys ():
11431144 url_key = self .__ACCESS_URL_STRING
1144- if url_key == "" or mission == "ALMA" or mission == "INTEGRAL" :
1145+ if url_key == "" or mission == "ALMA" :
11451146 log .info (mission + " does not yet support downloading of fits files" )
11461147 return maps
11471148
@@ -1203,20 +1204,26 @@ def _get_maps_for_mission(self, maps_table, mission, download_dir, cache, json,
12031204
12041205 response .raise_for_status ()
12051206
1206- file_name = self ._extract_file_name_from_response_header (response .headers )
1207- if (file_name == "" ):
1208- file_name = self ._extract_file_name_from_url (product_url )
1209- if (file_name .lower ().endswith (self .__TAR_STRING )):
1210- with tarfile .open (fileobj = BytesIO (response .content )) as tar :
1211- for member in tar .getmembers ():
1212- tar .extract (member , directory_path )
1213- maps .append (fits .open (directory_path + member .name ))
1207+ if mission .lower () == "integral" :
1208+ with ZipFile (file = BytesIO (response .content )) as zip :
1209+ for info in zip .infolist ():
1210+ if self ._ends_with_fits_like_extentsion (info .filename ):
1211+ maps .append (fits .open (zip .extract (info .filename )))
12141212 else :
1215- fits_data = response .content
1216- with open (directory_path + file_name , 'wb' ) as fits_file :
1217- fits_file .write (fits_data )
1218- fits_file .flush ()
1219- maps .append (fits .open (directory_path + file_name ))
1213+ file_name = self ._extract_file_name_from_response_header (response .headers )
1214+ if (file_name == "" ):
1215+ file_name = self ._extract_file_name_from_url (product_url )
1216+ if (file_name .lower ().endswith (self .__TAR_STRING )):
1217+ with tarfile .open (fileobj = BytesIO (response .content )) as tar :
1218+ for member in tar .getmembers ():
1219+ tar .extract (member , directory_path )
1220+ maps .append (fits .open (directory_path + member .name ))
1221+ else :
1222+ fits_data = response .content
1223+ with open (directory_path + file_name , 'wb' ) as fits_file :
1224+ fits_file .write (fits_data )
1225+ fits_file .flush ()
1226+ maps .append (fits .open (directory_path + file_name ))
12201227 log .info ("[Done]" )
12211228 except (HTTPError , ConnectionError ) as err :
12221229 log .error ("Download failed with {}." .format (err ))
@@ -1230,6 +1237,18 @@ def _get_maps_for_mission(self, maps_table, mission, download_dir, cache, json,
12301237
12311238 return maps
12321239
1240+ def _ends_with_fits_like_extentsion (self , name ):
1241+ lower_case_name = name .lower ()
1242+ return (lower_case_name .endswith ("fits" )
1243+ or lower_case_name .endswith ("fits.gz" )
1244+ or lower_case_name .endswith ("ftz" )
1245+ or lower_case_name .endswith ("ftz.gz" )
1246+ or lower_case_name .endswith ("fit" )
1247+ or lower_case_name .endswith ("fit.gz" )
1248+ or lower_case_name .endswith ("fts" )
1249+ or lower_case_name .endswith ("fts.gz" )
1250+ )
1251+
12331252 def _get_herschel_map (self , product_url , directory_path , cache ):
12341253 observation = dict ()
12351254 response = self ._request ('GET' , product_url , cache = cache ,
0 commit comments