@@ -41,8 +41,25 @@ class EuclidClass(TapPlus):
41
41
42
42
__VALID_DATALINK_RETRIEVAL_TYPES = conf .VALID_DATALINK_RETRIEVAL_TYPES
43
43
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 ,
45
45
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
+ """
46
63
47
64
if environment not in conf .ENVIRONMENTS :
48
65
raise ValueError (
@@ -457,8 +474,7 @@ def login(self, *, user=None, password=None, credentials_file=None, verbose=Fals
457
474
flag to display information about the process
458
475
"""
459
476
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 ()} " )
462
478
super ().login (user = user , password = password , credentials_file = credentials_file , verbose = verbose )
463
479
except HTTPError as err :
464
480
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
468
484
tap_password = self ._TapPlus__pwd
469
485
470
486
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 ()} " )
473
488
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 ()} " )
476
490
self .__euclidcutout .login (user = tap_user , password = tap_password , verbose = verbose )
477
491
except HTTPError as err :
478
492
log .error ('Error logging in data or cutout services: %s' % (str (err )))
@@ -491,8 +505,7 @@ def login_gui(self, verbose=False):
491
505
flag to display information about the process
492
506
"""
493
507
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 ()} " )
496
509
TapPlus .login_gui (self , verbose = verbose )
497
510
except HTTPError as err :
498
511
log .error ('Error logging in TAP server: %s' % (str (err )))
@@ -502,17 +515,15 @@ def login_gui(self, verbose=False):
502
515
tap_password = self ._TapPlus__pwd
503
516
504
517
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 ()} " )
507
519
self .__eucliddata .login (user = tap_user , password = tap_password , verbose = verbose )
508
520
except HTTPError as err :
509
521
log .error ('Error logging in data server: %s' % (str (err )))
510
522
log .error ("Logging out from TAP server" )
511
523
TapPlus .logout (self , verbose = verbose )
512
524
513
525
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 ()} " )
516
527
self .__euclidcutout .login (user = tap_user , password = tap_password , verbose = verbose )
517
528
except HTTPError as err :
518
529
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
1159
1170
-----------
1160
1171
Downloads a spectrum with datalink.
1161
1172
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.
1165
1178
1166
1179
Parameters
1167
1180
----------
1168
1181
source_id : str, mandatory, default None
1169
1182
source id for the spectrum
1170
1183
schema : str, mandatory, default 'sedm'
1171
- the data release, 'sedm'
1184
+ the data release
1172
1185
retrieval_type : str, optional, default 'ALL' to retrieve all data from the list of sources
1173
1186
retrieval type identifier. Possible values are: 'SPECTRA_BGS' for the blue spectrum and 'SPECTRA_RGS' for
1174
1187
the red one.
@@ -1180,7 +1193,10 @@ def get_spectrum(self, *, source_id, schema='sedm', retrieval_type="ALL", output
1180
1193
1181
1194
Returns
1182
1195
-------
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
+
1184
1200
"""
1185
1201
1186
1202
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
1202
1218
1203
1219
fits_file = source_id + '.fits.zip'
1204
1220
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
+
1205
1231
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
+
1206
1236
try :
1207
1237
self .__eucliddata .load_data (params_dict = params_dict , output_file = output_file_full_path , verbose = verbose )
1208
1238
except HTTPError as err :
0 commit comments