Skip to content

Commit 7a11c5e

Browse files
committed
All tests successful. Basic image meta data lookup
1 parent 54d4b33 commit 7a11c5e

File tree

3 files changed

+80
-28
lines changed

3 files changed

+80
-28
lines changed

astroquery/lcogt/core.py

Lines changed: 53 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@
7171

7272
import warnings
7373
import xml.etree.ElementTree as tree
74+
import logging
7475

7576
from astropy.extern import six
7677
import astropy.units as u
@@ -90,13 +91,55 @@ class LcogtClass(BaseQuery):
9091
TIMEOUT = conf.timeout
9192
ROW_LIMIT = conf.row_limit
9293

93-
def query_region(self, coordinates=None, catalog=None, spatial='Cone',
94-
radius=10 * u.arcsec, width=None, polygon=None,
94+
def query_object(self, objstr, catalog=None, verbose=False):
95+
"""
96+
Queries the LCOGT public archive hosted at NASA/IPAC archive on target name
97+
and returns the result as a `~astropy.table.Table`.
98+
See examples below.
99+
100+
Parameters
101+
----------
102+
objstr : str
103+
name of object to be queried
104+
catalog : str
105+
name of the catalog to use. 'lco_img' for image meta data; 'lco_cat' for photometry.
106+
107+
Returns
108+
-------
109+
table : `~astropy.table.Table`
110+
Query results table
111+
"""
112+
response = self.query_object_async(objstr, catalog=catalog)
113+
return self._parse_result(response, verbose=verbose)
114+
115+
def query_object_async(self, objstr, catalog=None):
116+
"""
117+
Serves the same function as `query_object`, but
118+
only collects the reponse from the LCOGT IPAC archive and returns.
119+
120+
Parameters
121+
----------
122+
objstr : str
123+
name of object to be queried
124+
125+
Returns
126+
-------
127+
response : `requests.Response`
128+
Response of the query from the server
129+
"""
130+
if catalog is None:
131+
raise Exception("Catalogue name is required!")
132+
request_payload = self._args_to_payload(catalog)
133+
request_payload['objstr'] = objstr
134+
response = commons.send_request(Lcogt.LCOGT_URL, request_payload,
135+
Lcogt.TIMEOUT, request_type='GET')
136+
return response
137+
138+
def query_region(self, coordinates=None, catalog=None, spatial=None, radius=None, width=None, polygon=None,
95139
get_query_payload=False, verbose=False):
96140
"""
97141
This function can be used to perform either cone, box, polygon or
98-
all-sky search in the LCOGT public archive hosted by the NASA/IPAC Infrared
99-
Science Archive.
142+
all-sky search in the LCOGT public archive hosted by the NASA/IPAC Archive.
100143
101144
Parameters
102145
----------
@@ -167,7 +210,7 @@ def query_region_async(self, coordinates=None, catalog=None,
167210
details). Required if spatial is ``'Cone'`` or ``'Box'``. Optional
168211
if spatial is ``'Polygon'``.
169212
catalog : str
170-
The catalog to be used. Either ``lco_img`` for image metadata or ``lco_cat``
213+
The catalog to be used. Either ``'lco_img'`` for image metadata or ``'lco_cat'``
171214
for photometry.
172215
spatial : str
173216
Type of spatial query: ``'Cone'``, ``'Box'``, ``'Polygon'``, and
@@ -195,7 +238,7 @@ def query_region_async(self, coordinates=None, catalog=None,
195238
The HTTP response returned from the service
196239
"""
197240
if catalog is None:
198-
raise Exception("Catalog name is required!")
241+
raise Exception("Catalogue name is required!")
199242

200243
request_payload = self._args_to_payload(catalog)
201244
request_payload.update(self._parse_spatial(spatial=spatial,
@@ -293,6 +336,7 @@ def _args_to_payload(self, catalog):
293336
"""
294337
request_payload = dict(catalog=catalog,
295338
outfmt=3,
339+
spatial=None,
296340
outrows=Lcogt.ROW_LIMIT)
297341
return request_payload
298342

@@ -317,10 +361,11 @@ def _parse_result(self, response, verbose=False):
317361
commons.suppress_vo_warnings()
318362

319363
content = response.text
364+
logging.debug(content)
320365

321366
# Check if results were returned
322-
if 'The catalog is not on the list' in content:
323-
raise Exception("Catalog not found")
367+
if 'The catalog is not in the list' in content:
368+
raise Exception("Catalogue not found")
324369

325370
# Check that object name was not malformed
326371
if 'Either wrong or missing coordinate/object name' in content:

astroquery/lcogt/tests/test_lcogt.py

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -72,41 +72,40 @@ def test_parse_coordinates(coordinates, expected):
7272

7373

7474
def test_args_to_payload():
75-
out = lcogt.core.Lcogt._args_to_payload("fp_psc")
76-
assert out == dict(catalog='fp_psc', outfmt=3, outrows=conf.row_limit)
77-
75+
out = lcogt.core.Lcogt._args_to_payload("lco_img")
76+
assert out == dict(catalog='lco_img', outfmt=3, outrows=conf.row_limit, spatial=None)
7877

7978
@pytest.mark.parametrize(("coordinates"), OBJ_LIST)
8079
def test_query_region_cone_async(coordinates, patch_get):
81-
response = lcogt.core.Lcogt.query_region_async(coordinates, catalog='fp_psc', spatial='Cone',
80+
response = lcogt.core.Lcogt.query_region_async(coordinates, catalog='lco_img', spatial='Cone',
8281
radius=2 * u.arcmin, get_query_payload=True)
8382
assert response['radius'] == 2
8483
assert response['radunits'] == 'arcmin'
85-
response = lcogt.core.Lcogt.query_region_async(coordinates, catalog='fp_psc', spatial='Cone',
84+
response = lcogt.core.Lcogt.query_region_async(coordinates, catalog='lco_img', spatial='Cone',
8685
radius=2 * u.arcmin)
8786
assert response is not None
8887

8988

9089
@pytest.mark.parametrize(("coordinates"), OBJ_LIST)
9190
def test_query_region_cone(coordinates, patch_get):
92-
result = lcogt.core.Lcogt.query_region(coordinates, catalog='fp_psc', spatial='Cone',
91+
result = lcogt.core.Lcogt.query_region(coordinates, catalog='lco_img', spatial='Cone',
9392
radius=2 * u.arcmin)
9493
assert isinstance(result, Table)
9594

9695

9796
@pytest.mark.parametrize(("coordinates"), OBJ_LIST)
9897
def test_query_region_box_async(coordinates, patch_get):
99-
response = lcogt.core.Lcogt.query_region_async(coordinates, catalog='fp_psc', spatial='Box',
98+
response = lcogt.core.Lcogt.query_region_async(coordinates, catalog='lco_img', spatial='Box',
10099
width=2 * u.arcmin, get_query_payload=True)
101100
assert response['size'] == 120
102-
response = lcogt.core.Lcogt.query_region_async(coordinates, catalog='fp_psc', spatial='Box',
101+
response = lcogt.core.Lcogt.query_region_async(coordinates, catalog='lco_img', spatial='Box',
103102
width=2 * u.arcmin)
104103
assert response is not None
105104

106105

107106
@pytest.mark.parametrize(("coordinates"), OBJ_LIST)
108107
def test_query_region_box(coordinates, patch_get):
109-
result = lcogt.core.Lcogt.query_region(coordinates, catalog='fp_psc', spatial='Box',
108+
result = lcogt.core.Lcogt.query_region(coordinates, catalog='lco_img', spatial='Box',
110109
width=2 * u.arcmin)
111110
assert isinstance(result, Table)
112111

@@ -121,7 +120,7 @@ def test_query_region_box(coordinates, patch_get):
121120
poly2
122121
])
123122
def test_query_region_async_polygon(polygon, patch_get):
124-
response = lcogt.core.Lcogt.query_region_async("m31", catalog="fp_psc", spatial="Polygon",
123+
response = lcogt.core.Lcogt.query_region_async("m31", catalog="lco_img", spatial="Polygon",
125124
polygon=polygon, get_query_payload=True)
126125

127126
for a, b in zip(re.split("[ ,]", response["polygon"]),
@@ -131,7 +130,7 @@ def test_query_region_async_polygon(polygon, patch_get):
131130
b1 = float(b1)
132131
np.testing.assert_almost_equal(a1, b1)
133132

134-
response = lcogt.core.Lcogt.query_region_async("m31", catalog="fp_psc", spatial="Polygon",
133+
response = lcogt.core.Lcogt.query_region_async("m31", catalog="lco_img", spatial="Polygon",
135134
polygon=polygon)
136135
assert response is not None
137136

@@ -141,7 +140,7 @@ def test_query_region_async_polygon(polygon, patch_get):
141140
poly2,
142141
])
143142
def test_query_region_polygon(polygon, patch_get):
144-
result = lcogt.core.Lcogt.query_region("m31", catalog="fp_psc", spatial="Polygon",
143+
result = lcogt.core.Lcogt.query_region("m31", catalog="lco_img", spatial="Polygon",
145144
polygon=polygon)
146145
assert isinstance(result, Table)
147146

astroquery/lcogt/tests/test_lcogt_remote.py

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,44 +10,52 @@
1010
import imp
1111
imp.reload(requests)
1212

13-
from ... import irsa
13+
from ... import lcogt
1414

1515
OBJ_LIST = ["m31", "00h42m44.330s +41d16m07.50s", coord.Galactic(l=121.1743, b=-21.5733, unit=(u.deg, u.deg))]
1616

1717

1818
@remote_data
19-
class TestIrsa:
19+
class TestLcogt:
20+
21+
def test_query_object_meta(self):
22+
response = lcogt.core.Lcogt.query_object_async('M1', catalog='lco_img')
23+
assert response is not None
24+
25+
def test_query_object_phot(self):
26+
response = lcogt.core.Lcogt.query_object_async('M1', catalog='lco_cat')
27+
assert response is not None
2028

2129
def test_query_region_cone_async(self):
22-
response = irsa.core.Irsa.query_region_async('m31', catalog='fp_psc', spatial='Cone',
30+
response = lcogt.core.Lcogt.query_region_async('m31', catalog='lco_img', spatial='Cone',
2331
radius=2 * u.arcmin)
2432
assert response is not None
2533

2634
def test_query_region_cone(self):
27-
result = irsa.core.Irsa.query_region('m31', catalog='fp_psc', spatial='Cone',
35+
result = lcogt.core.Lcogt.query_region('m31', catalog='lco_img', spatial='Cone',
2836
radius=2 * u.arcmin)
2937
assert isinstance(result, Table)
3038

3139
def test_query_region_box_async(self):
32-
response = irsa.core.Irsa.query_region_async("00h42m44.330s +41d16m07.50s", catalog='fp_psc', spatial='Box',
40+
response = lcogt.core.Lcogt.query_region_async("00h42m44.330s +41d16m07.50s", catalog='lco_img', spatial='Box',
3341
width=2 * u.arcmin)
3442
assert response is not None
3543

3644
def test_query_region_box(self):
37-
result = irsa.core.Irsa.query_region("00h42m44.330s +41d16m07.50s", catalog='fp_psc', spatial='Box',
45+
result = lcogt.core.Lcogt.query_region("00h42m44.330s +41d16m07.50s", catalog='lco_img', spatial='Box',
3846
width=2 * u.arcmin)
3947
assert isinstance(result, Table)
4048

4149
def test_query_region_async_polygon(self):
4250
polygon = [coord.ICRS(ra=10.1, dec=10.1, unit=(u.deg, u.deg)),
4351
coord.ICRS(ra=10.0, dec=10.1, unit=(u.deg, u.deg)),
4452
coord.ICRS(ra=10.0, dec=10.0, unit=(u.deg, u.deg))]
45-
response = irsa.core.Irsa.query_region_async("m31", catalog="fp_psc", spatial="Polygon",
53+
response = lcogt.core.Lcogt.query_region_async("m31", catalog="lco_img", spatial="Polygon",
4654
polygon=polygon)
4755
assert response is not None
4856

4957
def test_query_region_polygon(self):
5058
polygon = [(10.1, 10.1), (10.0, 10.1), (10.0, 10.0)]
51-
result = irsa.core.Irsa.query_region("m31", catalog="fp_psc", spatial="Polygon",
59+
result = lcogt.core.Lcogt.query_region("m31", catalog="lco_img", spatial="Polygon",
5260
polygon=polygon)
5361
assert isinstance(result, Table)

0 commit comments

Comments
 (0)