Skip to content

Commit

Permalink
INTEGRALSWRQ-158: get_timeline with skycoords
Browse files Browse the repository at this point in the history
  • Loading branch information
jespinosaar committed Jan 21, 2025
1 parent a91ffca commit 1cfe16a
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 51 deletions.
17 changes: 9 additions & 8 deletions astroquery/esa/integral/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from astropy.table import Table
from astroquery.query import BaseQuery, BaseVOQuery
from astroquery import log
from astroquery.utils import commons
import pyvo
from requests import HTTPError

Expand Down Expand Up @@ -289,7 +290,7 @@ def get_observations(self, *, target_name=None, coordinates=None, radius=14.0, s
dec = coord['dec'][0]
conditions.append(conf.ISLA_COORDINATE_CONDITION.format(ra, dec, radius))
elif coordinates:
coord = esautils.get_coord_input(value=coordinates, msg=coordinates)
coord = commons.parse_coordinates(coordinates=coordinates)
ra = coord.ra.degree
dec = coord.dec.degree
conditions.append(conf.ISLA_COORDINATE_CONDITION.format(ra, dec, radius))
Expand Down Expand Up @@ -354,15 +355,13 @@ def download_science_windows(self, *, science_windows=None, observation_id=None,
except Exception as e:
log.error('No science windows have been found with these inputs. {}'.format(e))

def get_timeline(self, ra, dec, *, radius=14):
def get_timeline(self, coordinates, *, radius=14):
"""Retrieve the INTEGRAL timeline associated to coordinates and radius
Parameters
----------
ra: float, mandatory
Right ascension
dec: float, mandatory
Declination
coordinates: str or SkyCoord, mandatory
RA and Dec of the source
radius: float or quantity, optional, default value 14 degrees
radius in degrees (int, float) or quantity of the cone_search
Expand All @@ -378,10 +377,12 @@ def get_timeline(self, ra, dec, *, radius=14):
if radius:
radius = esautils.get_degree_radius(radius)

c = commons.parse_coordinates(coordinates=coordinates)

query_params = {
'REQUEST': 'timelines',
"ra": ra,
"dec": dec,
"ra": c.ra.degree,
"dec": c.dec.degree,
"radius": radius
}

Expand Down
18 changes: 2 additions & 16 deletions astroquery/esa/integral/tests/test_isla_tap.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
import os

from astropy.coordinates import SkyCoord

from astroquery.esa.integral import IntegralClass
from astroquery.esa.integral import conf
from unittest.mock import PropertyMock, patch, Mock
Expand Down Expand Up @@ -345,25 +344,12 @@ def test_download_science_windows(self, instrument_band_mock, download_mock):
@patch('astroquery.esa.integral.core.pyvo.dal.TAPService.capabilities', [])
@patch('astroquery.esa.utils.utils.execute_servlet_request')
@patch('astroquery.esa.integral.core.IntegralClass.get_instrument_band_map')
def test_get_timeline_no_distance(self, instrument_band_mock, servlet_mock):
instrument_band_mock.return_value = mocks.get_instrument_bands()
servlet_mock.return_value = mocks.get_mock_timeline()

isla = IntegralClass()
isla.get_timeline(ra=83.63320922851562, dec=22.01447105407715)

args, kwargs = servlet_mock.call_args
assert kwargs['query_params']['REQUEST'] == 'timelines'

@patch('astroquery.esa.integral.core.pyvo.dal.TAPService.capabilities', [])
@patch('astroquery.esa.utils.utils.execute_servlet_request')
@patch('astroquery.esa.integral.core.IntegralClass.get_instrument_band_map')
def test_get_timeline_distance(self, instrument_band_mock, servlet_mock):
def test_get_timeline(self, instrument_band_mock, servlet_mock):
instrument_band_mock.return_value = mocks.get_instrument_bands()
servlet_mock.return_value = mocks.get_mock_timeline()

isla = IntegralClass()
timeline = isla.get_timeline(ra=83.63320922851562, dec=22.01447105407715)
timeline = isla.get_timeline(coordinates='83.63320922851562 22.01447105407715')

assert len(timeline['timeline']['scwRevs']) > 0

Expand Down
26 changes: 0 additions & 26 deletions astroquery/esa/utils/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
from astropy.units import Quantity
from astropy.io import fits
from pyvo.auth.authsession import AuthSession
from astroquery.utils import commons

import requests
from requests import Response
Expand Down Expand Up @@ -151,31 +150,6 @@ def _request(self, method, url, *args, **kwargs):
return super()._request(method, url, **kwargs)


def get_coord_input(value, msg):
"""
Auxiliary method to parse the coordinates
Parameters
----------
value: str or SkyCoord, mandatory
coordinates to be parsed
msg: str, mandatory
Value to be shown in the error message
Returns
-------
The coordinates parsed
"""
if not (isinstance(value, str) or isinstance(value,
commons.CoordClasses)):
raise ValueError(f"{msg} must be either a string or astropy.coordinates")
if isinstance(value, str):
c = commons.parse_coordinates(value)
return c
else:
return value


def get_degree_radius(radius):
"""
Method to parse the radius and retrieve it in degrees
Expand Down
4 changes: 3 additions & 1 deletion docs/esa/integral/integral.rst
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,10 @@ to refine their search.
.. doctest-remote-data::

>>> from astroquery.esa.integral import IntegralClass
>>> from astropy.coordinates import SkyCoord
>>> isla = IntegralClass()
>>> timeline = isla.get_timeline(ra=83.63320922851562, dec=22.01447105407715)
>>> coordinates = SkyCoord(83.63320922851562, 22.01447105407715, unit="deg")
>>> timeline = isla.get_timeline(coordinates=coordinates)
>>> timeline # doctest: +IGNORE_OUTPUT
{'total_items': 8714, 'fraFC': 0.8510442965343126, 'totEffExpo': 16416293.994214607, 'timeline': <Table length=8714>
scwExpo scwRevs scwTimes scwOffAxis
Expand Down

0 comments on commit 1cfe16a

Please sign in to comment.