Skip to content

Commit

Permalink
INTEGRALSWRQ-158: remote tests for integral
Browse files Browse the repository at this point in the history
  • Loading branch information
jespinosaar committed Jan 22, 2025
1 parent 1cfe16a commit 651d103
Show file tree
Hide file tree
Showing 4 changed files with 305 additions and 36 deletions.
80 changes: 49 additions & 31 deletions astroquery/esa/integral/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ def logout(self):
"""
self.tap._session.logout(logout_url=conf.ISLA_LOGOUT_SERVER)

def query_tap(self, query, *, async_job=False, output_file=None, output_format=None):
def query_tap(self, query, *, async_job=False, output_file=None, output_format='votable'):
"""Launches a synchronous or asynchronous job to query the ISLA tap
Parameters
Expand Down Expand Up @@ -254,8 +254,10 @@ def get_observations(self, *, target_name=None, coordinates=None, radius=14.0, s
end time of the observation
start_revno: string, optional
start revolution number, as a four-digit string with leading zeros
e.g. 0352
end_revno: string, optional
end revolution number, as a four-digit string with leading zeros
e.g. 0353
async_job : bool, optional, default 'False'
executes the query (job) in asynchronous/synchronous mode (default
synchronous)
Expand Down Expand Up @@ -323,7 +325,7 @@ def get_observations(self, *, target_name=None, coordinates=None, radius=14.0, s
output_format=output_format)

def download_science_windows(self, *, science_windows=None, observation_id=None, revolution=None, proposal=None,
output_file=None):
output_file=None, read_fits=True):
"""Method to download science windows associated to one of these parameters:
science_windows, observation_id, revolution or proposal
Expand All @@ -339,6 +341,8 @@ def download_science_windows(self, *, science_windows=None, observation_id=None,
Proposal ID associated to science windows
output_file: str, optional
File name and path for the downloaded file
read_fits: bool, optional, default True
Open the downloaded file and parse the existing FITS files
Returns
-------
Expand All @@ -350,8 +354,13 @@ def download_science_windows(self, *, science_windows=None, observation_id=None,
params['RETRIEVAL_TYPE'] = 'SCW'
try:

return esautils.download_file(url=conf.ISLA_DATA_SERVER, session=self.tap._session,
filename=output_file, params=params, verbose=True)
downloaded_file = esautils.download_file(url=conf.ISLA_DATA_SERVER, session=self.tap._session,
filename=output_file, params=params, verbose=True)
if read_fits:
return esautils.read_downloaded_fits([downloaded_file])
else:
return downloaded_file

Check warning on line 362 in astroquery/esa/integral/core.py

View check run for this annotation

Codecov / codecov/patch

astroquery/esa/integral/core.py#L362

Added line #L362 was not covered by tests

except Exception as e:
log.error('No science windows have been found with these inputs. {}'.format(e))

Expand Down Expand Up @@ -386,22 +395,27 @@ def get_timeline(self, coordinates, *, radius=14):
"radius": radius
}

# Execute the request to the servlet
request_result = esautils.execute_servlet_request(url=conf.ISLA_SERVLET,
tap=self.tap,
query_params=query_params)
total_items = request_result['totalItems']
data = request_result['data']
fraFC = data['fraFC']
totEffExpo = data['totEffExpo']
timeline = Table({
"scwExpo": data["scwExpo"],
"scwRevs": data["scwRevs"],
"scwTimes": [datetime.fromtimestamp(scwTime / 1000) for scwTime in data["scwTimes"]],
"scwOffAxis": data["scwOffAxis"]
})

return {'total_items': total_items, 'fraFC': fraFC, 'totEffExpo': totEffExpo, 'timeline': timeline}
try:
# Execute the request to the servlet
request_result = esautils.execute_servlet_request(url=conf.ISLA_SERVLET,
tap=self.tap,
query_params=query_params)
total_items = request_result['totalItems']
data = request_result['data']
fraFC = data['fraFC']
totEffExpo = data['totEffExpo']
timeline = Table({
"scwExpo": data["scwExpo"],
"scwRevs": data["scwRevs"],
"scwTimes": [datetime.fromtimestamp(scwTime / 1000) for scwTime in data["scwTimes"]],
"scwOffAxis": data["scwOffAxis"]
})
return {'total_items': total_items, 'fraFC': fraFC, 'totEffExpo': totEffExpo, 'timeline': timeline}
except HTTPError as e:
if 'None science windows have been selected' in e.response.text:
raise ValueError(f"No timeline is available for the current coordinates and radius.")

Check warning on line 416 in astroquery/esa/integral/core.py

View check run for this annotation

Codecov / codecov/patch

astroquery/esa/integral/core.py#L414-L416

Added lines #L414 - L416 were not covered by tests
else:
raise e

Check warning on line 418 in astroquery/esa/integral/core.py

View check run for this annotation

Codecov / codecov/patch

astroquery/esa/integral/core.py#L418

Added line #L418 was not covered by tests

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


value = self.__get_instrument_or_band(instrument=instrument, band=band)
instrument_oid, band_oid = self.__get_oids(value)
if target_name:
Expand Down Expand Up @@ -503,11 +518,10 @@ def get_short_term_timeseries(self, target_name, epoch, instrument=None, band=No
"""

value = self.__get_instrument_or_band(instrument=instrument, band=band)
self.__validate_epoch(target_name=target_name, epoch=epoch,
instrument=instrument, band=band)

value = self.__get_instrument_or_band(instrument=instrument, band=band)

params = {'RETRIEVAL_TYPE': 'short_timeseries',
'source': target_name,
'band_oid': self.instrument_band_map[value]['band_oid'],
Expand Down Expand Up @@ -556,11 +570,9 @@ def get_spectra(self, target_name, epoch, instrument=None, band=None, *, path=''
If read_fits=False, return a list of paths of the downloaded files
"""

value = self.__get_instrument_or_band(instrument=instrument, band=band)
self.__validate_epoch(target_name=target_name, epoch=epoch,
instrument=instrument, band=band)

value = self.__get_instrument_or_band(instrument=instrument, band=band)

query_params = {
'REQUEST': 'spectra',
"source": target_name,
Expand Down Expand Up @@ -675,9 +687,15 @@ def get_source_metadata(self, target_name):
'REQUEST': 'sources',
"SOURCE": target_name
}
return esautils.execute_servlet_request(url=conf.ISLA_SERVLET,
tap=self.tap,
query_params=query_params)
try:
return esautils.execute_servlet_request(url=conf.ISLA_SERVLET,
tap=self.tap,
query_params=query_params)
except HTTPError as e:
if 'Source not found in the database' in e.response.text:
raise ValueError(f"Target {target_name} cannot be resolved for ISLA")

Check warning on line 696 in astroquery/esa/integral/core.py

View check run for this annotation

Codecov / codecov/patch

astroquery/esa/integral/core.py#L694-L696

Added lines #L694 - L696 were not covered by tests
else:
raise e

Check warning on line 698 in astroquery/esa/integral/core.py

View check run for this annotation

Codecov / codecov/patch

astroquery/esa/integral/core.py#L698

Added line #L698 was not covered by tests

def get_instrument_band_map(self):
"""
Expand Down Expand Up @@ -792,7 +810,7 @@ def __get_science_window_parameter(self, science_windows, observation_id, revolu
Parameters
----------
science_windows : list of str, mandat
science_windows : list of str or str, mandatory
Science Windows to download
observation_id: str, optional
Observation ID associated to science windows
Expand Down Expand Up @@ -823,10 +841,10 @@ def __get_science_window_parameter(self, science_windows, observation_id, revolu
if observation_id is not None and isinstance(observation_id, str):
return {'obsid': observation_id}

Check warning on line 842 in astroquery/esa/integral/core.py

View check run for this annotation

Codecov / codecov/patch

astroquery/esa/integral/core.py#L842

Added line #L842 was not covered by tests

if revolution is not None and isinstance(observation_id, str):
if revolution is not None and isinstance(revolution, str):
return {'REVID': revolution}

Check warning on line 845 in astroquery/esa/integral/core.py

View check run for this annotation

Codecov / codecov/patch

astroquery/esa/integral/core.py#L845

Added line #L845 was not covered by tests

if proposal is not None and isinstance(observation_id, str):
if proposal is not None and isinstance(proposal, str):
return {'PROPID': proposal}

Check warning on line 848 in astroquery/esa/integral/core.py

View check run for this annotation

Codecov / codecov/patch

astroquery/esa/integral/core.py#L848

Added line #L848 was not covered by tests

raise ValueError("Input parameters are wrong")
Expand Down
Loading

0 comments on commit 651d103

Please sign in to comment.