Skip to content

Commit e77643e

Browse files
committed
INTEGRALSWRQ-158: tests fixed
1 parent d4e38f9 commit e77643e

File tree

3 files changed

+131
-39
lines changed

3 files changed

+131
-39
lines changed

astroquery/esa/integral/core.py

Lines changed: 59 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ class IntegralClass(BaseVOQuery, BaseQuery):
2828
Class to init ESA Integral Module and communicate with isla
2929
"""
3030

31-
def __init__(self, tap_handler=None, auth_session=None):
31+
def __init__(self, auth_session=None):
3232
super().__init__()
3333

3434
# Checks if auth session has been defined. If not, create a new session
@@ -38,16 +38,22 @@ def __init__(self, tap_handler=None, auth_session=None):
3838
self._auth_session = esautils.ESAAuthSession()
3939

4040
self._auth_session.timeout = conf.TIMEOUT
41+
self._tap = None
42+
self._tap_url = conf.ISLA_TAP_SERVER
4143

42-
if tap_handler is None:
43-
self.tap = pyvo.dal.TAPService(
44+
self.instruments = []
45+
self.bands = []
46+
self.instrument_band_map = {}
47+
48+
@property
49+
def tap(self) -> pyvo.dal.TAPService:
50+
if self._tap is None:
51+
self._tap = pyvo.dal.TAPService(
4452
conf.ISLA_TAP_SERVER, session=self._auth_session)
45-
else:
46-
self.tap = tap_handler
47-
self._data = None
53+
# Retrieve the instruments and bands available within ISLA Archive
54+
self.get_instrument_band_map()
4855

49-
# Retrieve the instruments and bands available within ISLA Archive
50-
self.instruments, self.bands, self.instrument_band_map = self.get_instrument_band_map()
56+
return self._tap
5157

5258
def get_tables(self, *, only_names=False):
5359
"""
@@ -217,13 +223,15 @@ def get_sources(self, target_name, *, async_job=False, output_file=None, output_
217223
# Second attempt, resolve using a Resolver Service and cone search to the source catalogue
218224
try:
219225
coordinates = esautils.resolve_target(conf.ISLA_TARGET_RESOLVER, self.tap._session, target_name, 'ALL')
220-
query = conf.ISLA_CONE_TARGET_CONDITION.format(coordinates.ra.degree, coordinates.dec.degree, 0.0833)
221-
result = self.query_tap(query=query, async_job=async_job, output_file=output_file,
222-
output_format=output_format)
226+
if coordinates:
227+
query = conf.ISLA_CONE_TARGET_CONDITION.format(coordinates.ra.degree, coordinates.dec.degree, 0.0833)
228+
result = self.query_tap(query=query, async_job=async_job, output_file=output_file,
229+
output_format=output_format)
223230

224-
if len(result) > 0:
225-
return result[0]
231+
if len(result) > 0:
232+
return result[0]
226233

234+
raise ValueError(f"Target {target_name} cannot be resolved for ISLA")
227235
except ValueError:
228236
raise ValueError(f"Target {target_name} cannot be resolved for ISLA")
229237

@@ -900,20 +908,39 @@ def get_instrument_band_map(self):
900908
"""
901909
Maps the bands and instruments included in ISLA
902910
"""
903-
instrument_band_table = self.query_tap(conf.ISLA_INSTRUMENT_BAND_QUERY)
904-
instrument_band_map = {}
905911

906-
for row in instrument_band_table:
907-
instrument_band_map[row['instrument']] = {'band': row['band'],
908-
'instrument_oid': row['instrument_oid'],
909-
'band_oid': row['band_oid']}
910-
instrument_band_map[row['band']] = {'instrument': row['instrument'],
911-
'instrument_oid': row['instrument_oid'],
912-
'band_oid': row['band_oid']}
912+
if len(self.instrument_band_map) == 0:
913+
instrument_band_table = self.query_tap(conf.ISLA_INSTRUMENT_BAND_QUERY)
914+
instrument_band_map = {}
915+
916+
for row in instrument_band_table:
917+
instrument_band_map[row['instrument']] = {'band': row['band'],
918+
'instrument_oid': row['instrument_oid'],
919+
'band_oid': row['band_oid']}
920+
instrument_band_map[row['band']] = {'instrument': row['instrument'],
921+
'instrument_oid': row['instrument_oid'],
922+
'band_oid': row['band_oid']}
923+
924+
instruments = instrument_band_table['instrument']
925+
bands = instrument_band_table['band']
926+
927+
self.instruments = instruments
928+
self.bands = bands
929+
self.instrument_band_map = instrument_band_map
913930

914-
instruments = instrument_band_table['instrument']
915-
bands = instrument_band_table['band']
916-
return instruments, bands, instrument_band_map
931+
def get_instruments(self):
932+
"""
933+
Get the instruments available in ISLA
934+
"""
935+
self.get_instrument_band_map()
936+
return self.instruments
937+
938+
def get_bands(self):
939+
"""
940+
Get the bands available in ISLA
941+
"""
942+
self.get_instrument_band_map()
943+
return self.bands
917944

918945
def __get_instrument_or_band(self, instrument, band):
919946
if instrument and band:
@@ -928,12 +955,16 @@ def __get_instrument_or_band(self, instrument, band):
928955
else:
929956
value = band
930957

958+
# Retrieve the available instruments or bands if not loaded yet
959+
self.get_instrument_band_map()
960+
961+
# Validate the value is in the list of allowed ones
931962
if value in self.instrument_band_map:
932963
return value
933964

934965
raise ValueError(f"This is not a valid value for instrument or band. Valid values are:\n"
935-
f"Instruments: {self.instruments}\n"
936-
f"Bands: {self.bands}")
966+
f"Instruments: {self.get_instruments()}\n"
967+
f"Bands: {self.get_bands()}")
937968

938969
def __get_oids(self, value):
939970
"""
@@ -1027,7 +1058,7 @@ def __get_science_window_parameter(self, science_windows, observation_id, revolu
10271058

10281059
def __log_warning_message(self, get_method, download_method, show_warning=True):
10291060
if show_warning:
1030-
warnings.warn(
1061+
log.warning(
10311062
f"The plots and data provided by '{get_method}' have been developed using the automatic reduction "
10321063
f"pipeline at ISDC, using INTEGRAL OSA version 11.2. No manual scientific validation has been "
10331064
f"performed on these outputs. They should be examined and validated before being used for scientific "

0 commit comments

Comments
 (0)