Skip to content

Commit 651d103

Browse files
committed
INTEGRALSWRQ-158: remote tests for integral
1 parent 1cfe16a commit 651d103

File tree

4 files changed

+305
-36
lines changed

4 files changed

+305
-36
lines changed

astroquery/esa/integral/core.py

Lines changed: 49 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ def logout(self):
158158
"""
159159
self.tap._session.logout(logout_url=conf.ISLA_LOGOUT_SERVER)
160160

161-
def query_tap(self, query, *, async_job=False, output_file=None, output_format=None):
161+
def query_tap(self, query, *, async_job=False, output_file=None, output_format='votable'):
162162
"""Launches a synchronous or asynchronous job to query the ISLA tap
163163
164164
Parameters
@@ -254,8 +254,10 @@ def get_observations(self, *, target_name=None, coordinates=None, radius=14.0, s
254254
end time of the observation
255255
start_revno: string, optional
256256
start revolution number, as a four-digit string with leading zeros
257+
e.g. 0352
257258
end_revno: string, optional
258259
end revolution number, as a four-digit string with leading zeros
260+
e.g. 0353
259261
async_job : bool, optional, default 'False'
260262
executes the query (job) in asynchronous/synchronous mode (default
261263
synchronous)
@@ -323,7 +325,7 @@ def get_observations(self, *, target_name=None, coordinates=None, radius=14.0, s
323325
output_format=output_format)
324326

325327
def download_science_windows(self, *, science_windows=None, observation_id=None, revolution=None, proposal=None,
326-
output_file=None):
328+
output_file=None, read_fits=True):
327329
"""Method to download science windows associated to one of these parameters:
328330
science_windows, observation_id, revolution or proposal
329331
@@ -339,6 +341,8 @@ def download_science_windows(self, *, science_windows=None, observation_id=None,
339341
Proposal ID associated to science windows
340342
output_file: str, optional
341343
File name and path for the downloaded file
344+
read_fits: bool, optional, default True
345+
Open the downloaded file and parse the existing FITS files
342346
343347
Returns
344348
-------
@@ -350,8 +354,13 @@ def download_science_windows(self, *, science_windows=None, observation_id=None,
350354
params['RETRIEVAL_TYPE'] = 'SCW'
351355
try:
352356

353-
return esautils.download_file(url=conf.ISLA_DATA_SERVER, session=self.tap._session,
354-
filename=output_file, params=params, verbose=True)
357+
downloaded_file = esautils.download_file(url=conf.ISLA_DATA_SERVER, session=self.tap._session,
358+
filename=output_file, params=params, verbose=True)
359+
if read_fits:
360+
return esautils.read_downloaded_fits([downloaded_file])
361+
else:
362+
return downloaded_file
363+
355364
except Exception as e:
356365
log.error('No science windows have been found with these inputs. {}'.format(e))
357366

@@ -386,22 +395,27 @@ def get_timeline(self, coordinates, *, radius=14):
386395
"radius": radius
387396
}
388397

389-
# Execute the request to the servlet
390-
request_result = esautils.execute_servlet_request(url=conf.ISLA_SERVLET,
391-
tap=self.tap,
392-
query_params=query_params)
393-
total_items = request_result['totalItems']
394-
data = request_result['data']
395-
fraFC = data['fraFC']
396-
totEffExpo = data['totEffExpo']
397-
timeline = Table({
398-
"scwExpo": data["scwExpo"],
399-
"scwRevs": data["scwRevs"],
400-
"scwTimes": [datetime.fromtimestamp(scwTime / 1000) for scwTime in data["scwTimes"]],
401-
"scwOffAxis": data["scwOffAxis"]
402-
})
403-
404-
return {'total_items': total_items, 'fraFC': fraFC, 'totEffExpo': totEffExpo, 'timeline': timeline}
398+
try:
399+
# Execute the request to the servlet
400+
request_result = esautils.execute_servlet_request(url=conf.ISLA_SERVLET,
401+
tap=self.tap,
402+
query_params=query_params)
403+
total_items = request_result['totalItems']
404+
data = request_result['data']
405+
fraFC = data['fraFC']
406+
totEffExpo = data['totEffExpo']
407+
timeline = Table({
408+
"scwExpo": data["scwExpo"],
409+
"scwRevs": data["scwRevs"],
410+
"scwTimes": [datetime.fromtimestamp(scwTime / 1000) for scwTime in data["scwTimes"]],
411+
"scwOffAxis": data["scwOffAxis"]
412+
})
413+
return {'total_items': total_items, 'fraFC': fraFC, 'totEffExpo': totEffExpo, 'timeline': timeline}
414+
except HTTPError as e:
415+
if 'None science windows have been selected' in e.response.text:
416+
raise ValueError(f"No timeline is available for the current coordinates and radius.")
417+
else:
418+
raise e
405419

406420
def get_epochs(self, *, target_name=None, instrument=None, band=None):
407421
"""Retrieve the INTEGRAL epochs associated to a target and an instrument or a band
@@ -420,6 +434,7 @@ def get_epochs(self, *, target_name=None, instrument=None, band=None):
420434
An astropy.table object containing the available epochs
421435
"""
422436

437+
423438
value = self.__get_instrument_or_band(instrument=instrument, band=band)
424439
instrument_oid, band_oid = self.__get_oids(value)
425440
if target_name:
@@ -503,11 +518,10 @@ def get_short_term_timeseries(self, target_name, epoch, instrument=None, band=No
503518
504519
"""
505520

521+
value = self.__get_instrument_or_band(instrument=instrument, band=band)
506522
self.__validate_epoch(target_name=target_name, epoch=epoch,
507523
instrument=instrument, band=band)
508524

509-
value = self.__get_instrument_or_band(instrument=instrument, band=band)
510-
511525
params = {'RETRIEVAL_TYPE': 'short_timeseries',
512526
'source': target_name,
513527
'band_oid': self.instrument_band_map[value]['band_oid'],
@@ -556,11 +570,9 @@ def get_spectra(self, target_name, epoch, instrument=None, band=None, *, path=''
556570
If read_fits=False, return a list of paths of the downloaded files
557571
"""
558572

573+
value = self.__get_instrument_or_band(instrument=instrument, band=band)
559574
self.__validate_epoch(target_name=target_name, epoch=epoch,
560575
instrument=instrument, band=band)
561-
562-
value = self.__get_instrument_or_band(instrument=instrument, band=band)
563-
564576
query_params = {
565577
'REQUEST': 'spectra',
566578
"source": target_name,
@@ -675,9 +687,15 @@ def get_source_metadata(self, target_name):
675687
'REQUEST': 'sources',
676688
"SOURCE": target_name
677689
}
678-
return esautils.execute_servlet_request(url=conf.ISLA_SERVLET,
679-
tap=self.tap,
680-
query_params=query_params)
690+
try:
691+
return esautils.execute_servlet_request(url=conf.ISLA_SERVLET,
692+
tap=self.tap,
693+
query_params=query_params)
694+
except HTTPError as e:
695+
if 'Source not found in the database' in e.response.text:
696+
raise ValueError(f"Target {target_name} cannot be resolved for ISLA")
697+
else:
698+
raise e
681699

682700
def get_instrument_band_map(self):
683701
"""
@@ -792,7 +810,7 @@ def __get_science_window_parameter(self, science_windows, observation_id, revolu
792810
793811
Parameters
794812
----------
795-
science_windows : list of str, mandat
813+
science_windows : list of str or str, mandatory
796814
Science Windows to download
797815
observation_id: str, optional
798816
Observation ID associated to science windows
@@ -823,10 +841,10 @@ def __get_science_window_parameter(self, science_windows, observation_id, revolu
823841
if observation_id is not None and isinstance(observation_id, str):
824842
return {'obsid': observation_id}
825843

826-
if revolution is not None and isinstance(observation_id, str):
844+
if revolution is not None and isinstance(revolution, str):
827845
return {'REVID': revolution}
828846

829-
if proposal is not None and isinstance(observation_id, str):
847+
if proposal is not None and isinstance(proposal, str):
830848
return {'PROPID': proposal}
831849

832850
raise ValueError("Input parameters are wrong")

0 commit comments

Comments
 (0)