Skip to content

Commit 7a84a5a

Browse files
Jorge Fernandez Hernandezbsipocz
authored andcommitted
EUCLIDPCR-1914 fix the method get_spectrum so the output_file is property used.
1 parent 12e304d commit 7a84a5a

File tree

1 file changed

+51
-19
lines changed

1 file changed

+51
-19
lines changed

astroquery/esa/euclid/core.py

Lines changed: 51 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,26 @@ 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',
45-
verbose=False, show_server_messages=True):
44+
def __init__(self, *, environment='PDR', tap_plus_conn_handler=None, datalink_handler=None, cutout_handler=None,
45+
euclid_tap_server=None, euclid_data_server=None, euclid_cutout_server=None, verbose=False,
46+
show_server_messages=True):
47+
"""Constructor for EuclidClass.
48+
49+
Parameters
50+
----------
51+
environment : str, mandatory if no tap, data or cutout hosts is specified, default 'PDR'
52+
The Euclid Science Archive environment: 'PDR', 'IDR', 'OTF' and 'REG'
53+
euclid_tap_server : str, optional, default None
54+
TAP URL
55+
euclid_data_server : str, optional, default None
56+
data URL
57+
euclid_cutout_server : str, optional, default None
58+
cutout URL
59+
verbose : bool, optional, default 'True'
60+
flag to display information about the process
61+
show_server_messages : bool, optional, default 'True'
62+
show the messages to inform users about the status of Euclid TAP
63+
"""
4664

4765
if environment not in conf.ENVIRONMENTS:
4866
raise ValueError(
@@ -457,8 +475,7 @@ def login(self, *, user=None, password=None, credentials_file=None, verbose=Fals
457475
flag to display information about the process
458476
"""
459477
try:
460-
log.info("Login to Euclid TAP server")
461-
log.info(f"Euclid TAP server url: {self._TapPlus__getconnhandler().get_host_url()}")
478+
log.info(f"Login to Euclid TAP server: {self._TapPlus__getconnhandler().get_host_url()}")
462479
super().login(user=user, password=password, credentials_file=credentials_file, verbose=verbose)
463480
except HTTPError as err:
464481
log.error('Error logging in TAP server: %s' % (str(err)))
@@ -468,11 +485,9 @@ def login(self, *, user=None, password=None, credentials_file=None, verbose=Fals
468485
tap_password = self._TapPlus__pwd
469486

470487
try:
471-
log.info("Login to Euclid data service")
472-
log.info(f"Euclid data server url: {self.__eucliddata._TapPlus__getconnhandler().get_host_url()}")
488+
log.info(f"Login to Euclid data service: {self.__eucliddata._TapPlus__getconnhandler().get_host_url()}")
473489
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()}")
490+
log.info(f"Login to Euclid cutout service: {self.__euclidcutout._TapPlus__getconnhandler().get_host_url()}")
476491
self.__euclidcutout.login(user=tap_user, password=tap_password, verbose=verbose)
477492
except HTTPError as err:
478493
log.error('Error logging in data or cutout services: %s' % (str(err)))
@@ -491,8 +506,7 @@ def login_gui(self, verbose=False):
491506
flag to display information about the process
492507
"""
493508
try:
494-
log.info("Login to Euclid TAP server")
495-
log.info(f"Euclid TAP server url: {self._TapPlus__getconnhandler().get_host_url()}")
509+
log.info(f"Login to Euclid TAP server: {self._TapPlus__getconnhandler().get_host_url()}")
496510
TapPlus.login_gui(self, verbose=verbose)
497511
except HTTPError as err:
498512
log.error('Error logging in TAP server: %s' % (str(err)))
@@ -502,17 +516,15 @@ def login_gui(self, verbose=False):
502516
tap_password = self._TapPlus__pwd
503517

504518
try:
505-
log.info("Login to Euclid data server")
506-
log.info(f"Euclid data server url: {self.__eucliddata._TapPlus__getconnhandler().get_host_url()}")
519+
log.info(f"Login to Euclid data server: {self.__eucliddata._TapPlus__getconnhandler().get_host_url()}")
507520
self.__eucliddata.login(user=tap_user, password=tap_password, verbose=verbose)
508521
except HTTPError as err:
509522
log.error('Error logging in data server: %s' % (str(err)))
510523
log.error("Logging out from TAP server")
511524
TapPlus.logout(self, verbose=verbose)
512525

513526
try:
514-
log.info("Login to Euclid cutout server")
515-
log.info(f"Euclid cutout server url: {self.__euclidcutout._TapPlus__getconnhandler().get_host_url()}")
527+
log.info(f"Login to Euclid cutout server: {self.__euclidcutout._TapPlus__getconnhandler().get_host_url()}")
516528
self.__euclidcutout.login(user=tap_user, password=tap_password, verbose=verbose)
517529
except HTTPError as err:
518530
log.error('Error logging in cutout server: %s' % (str(err)))
@@ -1159,16 +1171,18 @@ def get_spectrum(self, *, source_id, schema='sedm', retrieval_type="ALL", output
11591171
-----------
11601172
Downloads a spectrum with datalink.
11611173
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"
1174+
The spectrum associated to the source_id is downloaded as a compressed fits file, and the files it contains
1175+
are returned in a list. The compressed fits file is saved in the local path given by output_file. If this
1176+
parameter is not set, the result is saved in the file "<working
1177+
directory>/temp_<%Y%m%d_%H%M%S>/<source_id>.fits.zip". In any case, the content of the zip file is
1178+
automatically extracted.
11651179
11661180
Parameters
11671181
----------
11681182
source_id : str, mandatory, default None
11691183
source id for the spectrum
11701184
schema : str, mandatory, default 'sedm'
1171-
the data release, 'sedm'
1185+
the data release
11721186
retrieval_type : str, optional, default 'ALL' to retrieve all data from the list of sources
11731187
retrieval type identifier. Possible values are: 'SPECTRA_BGS' for the blue spectrum and 'SPECTRA_RGS' for
11741188
the red one.
@@ -1180,7 +1194,10 @@ def get_spectrum(self, *, source_id, schema='sedm', retrieval_type="ALL", output
11801194
11811195
Returns
11821196
-------
1183-
A list of files.
1197+
A list of files: the files contained in the downloaded compressed fits file. The format of the file is
1198+
SPECTRA_<colour>-<schema> <source_id>.fits', where <colour> is BGS or RGS, and <schema> and <source_id> are
1199+
taking from the input parameters.
1200+
11841201
"""
11851202

11861203
if source_id is None or schema is None:
@@ -1202,7 +1219,22 @@ def get_spectrum(self, *, source_id, schema='sedm', retrieval_type="ALL", output
12021219

12031220
fits_file = source_id + '.fits.zip'
12041221

1222+
if output_file is not None:
1223+
if not output_file.endswith('.zip'):
1224+
output_file = output_file + '.zip'
1225+
1226+
if os.path.dirname(output_file) == '':
1227+
output_file = os.path.join(os.getcwd(), output_file)
1228+
1229+
if verbose:
1230+
print(f"output file: {output_file}")
1231+
12051232
output_file_full_path, output_dir = self.__set_dirs(output_file=output_file, observation_id=fits_file)
1233+
1234+
if os.listdir(output_dir):
1235+
log.error(f'The directory is not empty: {output_dir}')
1236+
return
1237+
12061238
try:
12071239
self.__eucliddata.load_data(params_dict=params_dict, output_file=output_file_full_path, verbose=verbose)
12081240
except HTTPError as err:

0 commit comments

Comments
 (0)