@@ -41,8 +41,25 @@ class EuclidClass(TapPlus):
4141
4242 __VALID_DATALINK_RETRIEVAL_TYPES = conf .VALID_DATALINK_RETRIEVAL_TYPES
4343
44- def __init__ (self , * , tap_plus_conn_handler = None , datalink_handler = None , cutout_handler = None , environment = 'PDR' ,
44+ def __init__ (self , * , environment = 'PDR' , tap_plus_conn_handler = None , datalink_handler = None , cutout_handler = None ,
4545 verbose = False , show_server_messages = True ):
46+ """Constructor for EuclidClass.
47+
48+ Parameters
49+ ----------
50+ environment : str, mandatory if no tap, data or cutout hosts is specified, default 'PDR'
51+ The Euclid Science Archive environment: 'PDR', 'IDR', 'OTF' and 'REG'
52+ tap_plus_conn_handler : tap connection handler object, optional, default None
53+ HTTP(s) connection hander (creator). If no handler is provided, a new one is created.
54+ datalink_handler : dataliink connection handler object, optional, default None
55+ HTTP(s) connection hander (creator). If no handler is provided, a new one is created.
56+ cutout_handler : cutout connection handler object, optional, default None
57+ HTTP(s) connection hander (creator). If no handler is provided, a new one is created.
58+ verbose : bool, optional, default 'True'
59+ flag to display information about the process
60+ show_server_messages : bool, optional, default 'True'
61+ show the messages to inform users about the status of Euclid TAP
62+ """
4663
4764 if environment not in conf .ENVIRONMENTS :
4865 raise ValueError (
@@ -457,8 +474,7 @@ def login(self, *, user=None, password=None, credentials_file=None, verbose=Fals
457474 flag to display information about the process
458475 """
459476 try :
460- log .info ("Login to Euclid TAP server" )
461- log .info (f"Euclid TAP server url: { self ._TapPlus__getconnhandler ().get_host_url ()} " )
477+ log .info (f"Login to Euclid TAP server: { self ._TapPlus__getconnhandler ().get_host_url ()} " )
462478 super ().login (user = user , password = password , credentials_file = credentials_file , verbose = verbose )
463479 except HTTPError as err :
464480 log .error ('Error logging in TAP server: %s' % (str (err )))
@@ -468,11 +484,9 @@ def login(self, *, user=None, password=None, credentials_file=None, verbose=Fals
468484 tap_password = self ._TapPlus__pwd
469485
470486 try :
471- log .info ("Login to Euclid data service" )
472- log .info (f"Euclid data server url: { self .__eucliddata ._TapPlus__getconnhandler ().get_host_url ()} " )
487+ log .info (f"Login to Euclid data service: { self .__eucliddata ._TapPlus__getconnhandler ().get_host_url ()} " )
473488 self .__eucliddata .login (user = tap_user , password = tap_password , verbose = verbose )
474- log .info ("Login to Euclid cutout service" )
475- log .info (f"Euclid cutout server url: { self .__euclidcutout ._TapPlus__getconnhandler ().get_host_url ()} " )
489+ log .info (f"Login to Euclid cutout service: { self .__euclidcutout ._TapPlus__getconnhandler ().get_host_url ()} " )
476490 self .__euclidcutout .login (user = tap_user , password = tap_password , verbose = verbose )
477491 except HTTPError as err :
478492 log .error ('Error logging in data or cutout services: %s' % (str (err )))
@@ -491,8 +505,7 @@ def login_gui(self, verbose=False):
491505 flag to display information about the process
492506 """
493507 try :
494- log .info ("Login to Euclid TAP server" )
495- log .info (f"Euclid TAP server url: { self ._TapPlus__getconnhandler ().get_host_url ()} " )
508+ log .info (f"Login to Euclid TAP server: { self ._TapPlus__getconnhandler ().get_host_url ()} " )
496509 TapPlus .login_gui (self , verbose = verbose )
497510 except HTTPError as err :
498511 log .error ('Error logging in TAP server: %s' % (str (err )))
@@ -502,17 +515,15 @@ def login_gui(self, verbose=False):
502515 tap_password = self ._TapPlus__pwd
503516
504517 try :
505- log .info ("Login to Euclid data server" )
506- log .info (f"Euclid data server url: { self .__eucliddata ._TapPlus__getconnhandler ().get_host_url ()} " )
518+ log .info (f"Login to Euclid data server: { self .__eucliddata ._TapPlus__getconnhandler ().get_host_url ()} " )
507519 self .__eucliddata .login (user = tap_user , password = tap_password , verbose = verbose )
508520 except HTTPError as err :
509521 log .error ('Error logging in data server: %s' % (str (err )))
510522 log .error ("Logging out from TAP server" )
511523 TapPlus .logout (self , verbose = verbose )
512524
513525 try :
514- log .info ("Login to Euclid cutout server" )
515- log .info (f"Euclid cutout server url: { self .__euclidcutout ._TapPlus__getconnhandler ().get_host_url ()} " )
526+ log .info (f"Login to Euclid cutout server: { self .__euclidcutout ._TapPlus__getconnhandler ().get_host_url ()} " )
516527 self .__euclidcutout .login (user = tap_user , password = tap_password , verbose = verbose )
517528 except HTTPError as err :
518529 log .error ('Error logging in cutout server: %s' % (str (err )))
@@ -1159,16 +1170,18 @@ def get_spectrum(self, *, source_id, schema='sedm', retrieval_type="ALL", output
11591170 -----------
11601171 Downloads a spectrum with datalink.
11611172
1162- The spectrum associated to the source_id is downloaded as fits file, and returned in a list. The file is
1163- saved in the local path given by output_file. If this parameter is not set, the result is saved in the
1164- file "<working directory>/temp_<%Y%m%d_%H%M%S>/<source_id>.fits"
1173+ The spectrum associated with the source_id is downloaded as a compressed fits file, and the files it contains
1174+ are returned in a list. The compressed fits file is saved in the local path given by output_file. If this
1175+ parameter is not set, the result is saved in the file "<working
1176+ directory>/temp_<%Y%m%d_%H%M%S>/<source_id>.fits.zip". In any case, the content of the zip file is
1177+ automatically extracted.
11651178
11661179 Parameters
11671180 ----------
11681181 source_id : str, mandatory, default None
11691182 source id for the spectrum
11701183 schema : str, mandatory, default 'sedm'
1171- the data release, 'sedm'
1184+ the data release
11721185 retrieval_type : str, optional, default 'ALL' to retrieve all data from the list of sources
11731186 retrieval type identifier. Possible values are: 'SPECTRA_BGS' for the blue spectrum and 'SPECTRA_RGS' for
11741187 the red one.
@@ -1180,7 +1193,10 @@ def get_spectrum(self, *, source_id, schema='sedm', retrieval_type="ALL", output
11801193
11811194 Returns
11821195 -------
1183- A list of files.
1196+ A list of files: the files contained in the downloaded compressed fits file. The format of the file is
1197+ SPECTRA_<colour>-<schema> <source_id>.fits', where <colour> is BGS or RGS, and <schema> and <source_id> are
1198+ taken from the input parameters.
1199+
11841200 """
11851201
11861202 if source_id is None or schema is None :
@@ -1202,7 +1218,21 @@ def get_spectrum(self, *, source_id, schema='sedm', retrieval_type="ALL", output
12021218
12031219 fits_file = source_id + '.fits.zip'
12041220
1221+ if output_file is not None :
1222+ if not output_file .endswith ('.zip' ):
1223+ output_file = output_file + '.zip'
1224+
1225+ if os .path .dirname (output_file ) == '' :
1226+ output_file = os .path .join (os .getcwd (), output_file )
1227+
1228+ if verbose :
1229+ print (f"output file: { output_file } " )
1230+
12051231 output_file_full_path , output_dir = self .__set_dirs (output_file = output_file , observation_id = fits_file )
1232+
1233+ if os .listdir (output_dir ):
1234+ raise IOError (f'The directory is not empty: { output_dir } ' )
1235+
12061236 try :
12071237 self .__eucliddata .load_data (params_dict = params_dict , output_file = output_file_full_path , verbose = verbose )
12081238 except HTTPError as err :
0 commit comments