Skip to content

Commit 54d4b33

Browse files
committed
Modifications to get LCOGT support
1 parent 4eb250b commit 54d4b33

File tree

3 files changed

+43
-45
lines changed

3 files changed

+43
-45
lines changed

astroquery/lcogt/core.py

Lines changed: 25 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,9 @@
4141
'00 42 44.3 -41 16 08'
4242
'00h42m44.3s -41d16m08s'
4343
44-
catalog Required Catalog name in the IRSA database management system.
44+
catalog Required Catalog name in the LCOGT Archive. The database of photometry
45+
can be found using lco_cat and the database of image metadata is
46+
found using lco_img.
4547
4648
outfmt Optional Defines query's output format.
4749
6 - returns a program interface in XML
@@ -80,12 +82,11 @@
8082
from . import conf
8183
from ..exceptions import TableParseError
8284

83-
__all__ = ['Irsa', 'IrsaClass']
85+
__all__ = ['Lcogt', 'LcogtClass']
8486

8587

86-
class IrsaClass(BaseQuery):
87-
IRSA_URL = conf.server
88-
GATOR_LIST_URL = conf.gator_list_catalogs
88+
class LcogtClass(BaseQuery):
89+
LCOGT_URL = conf.server
8990
TIMEOUT = conf.timeout
9091
ROW_LIMIT = conf.row_limit
9192

@@ -94,8 +95,8 @@ def query_region(self, coordinates=None, catalog=None, spatial='Cone',
9495
get_query_payload=False, verbose=False):
9596
"""
9697
This function can be used to perform either cone, box, polygon or
97-
all-sky search in the catalogs hosted by the NASA/IPAC Infrared
98-
Science Archive (IRSA).
98+
all-sky search in the LCOGT public archive hosted by the NASA/IPAC Infrared
99+
Science Archive.
99100
100101
Parameters
101102
----------
@@ -108,7 +109,8 @@ def query_region(self, coordinates=None, catalog=None, spatial='Cone',
108109
details). Required if spatial is ``'Cone'`` or ``'Box'``. Optional
109110
if spatial is ``'Polygon'``.
110111
catalog : str
111-
The catalog to be used (see the *Notes* section below).
112+
The catalog to be used. Either ``lco_img`` for image metadata or ``lco_cat``
113+
for photometry.
112114
spatial : str
113115
Type of spatial query: ``'Cone'``, ``'Box'``, ``'Polygon'``, and
114116
``'All-Sky'``. If missing then defaults to ``'Cone'``.
@@ -151,7 +153,7 @@ def query_region_async(self, coordinates=None, catalog=None,
151153
polygon=None, get_query_payload=False):
152154
"""
153155
This function serves the same purpose as
154-
:meth:`~astroquery.irsa.IrsaClass.query_region`, but returns the raw
156+
:meth:`~astroquery.irsa.LcogtClass.query_region`, but returns the raw
155157
HTTP response rather than the results in a `~astropy.table.Table`.
156158
157159
Parameters
@@ -165,7 +167,8 @@ def query_region_async(self, coordinates=None, catalog=None,
165167
details). Required if spatial is ``'Cone'`` or ``'Box'``. Optional
166168
if spatial is ``'Polygon'``.
167169
catalog : str
168-
The catalog to be used (see the *Notes* section below).
170+
The catalog to be used. Either ``lco_img`` for image metadata or ``lco_cat``
171+
for photometry.
169172
spatial : str
170173
Type of spatial query: ``'Cone'``, ``'Box'``, ``'Polygon'``, and
171174
``'All-Sky'``. If missing then defaults to ``'Cone'``.
@@ -202,8 +205,8 @@ def query_region_async(self, coordinates=None, catalog=None,
202205

203206
if get_query_payload:
204207
return request_payload
205-
response = commons.send_request(Irsa.IRSA_URL, request_payload,
206-
Irsa.TIMEOUT, request_type='GET')
208+
response = commons.send_request(Lcogt.LCOGT_URL, request_payload,
209+
Lcogt.TIMEOUT, request_type='GET')
207210
return response
208211

209212
def _parse_spatial(self, spatial, coordinates, radius=None, width=None,
@@ -228,11 +231,11 @@ def _parse_spatial(self, spatial, coordinates, radius=None, width=None,
228231
The string must be parsable by `~astropy.coordinates.Angle`. The
229232
appropriate `~astropy.units.Quantity` object from `astropy.units`
230233
may also be used. Defaults to 10 arcsec.
231-
width : str, `~astropy.units.Quantity` object [Required for spatial is ``'Polygon'``.]
234+
width : str, `~astropy.units.Quantity` object [Required for spatial is ``'Polygon'``.]
232235
The string must be parsable by `~astropy.coordinates.Angle`. The
233236
appropriate `~astropy.units.Quantity` object from `astropy.units`
234237
may also be used.
235-
polygon : list, [Required for spatial is ``'Polygon'``]
238+
polygon : list, [Required for spatial is ``'Polygon'``]
236239
A list of ``(ra, dec)`` pairs as tuples of
237240
`astropy.coordinates.Angle`s outlinining the polygon to search in.
238241
It can also be a list of `astropy.coordinates` object or strings
@@ -290,7 +293,7 @@ def _args_to_payload(self, catalog):
290293
"""
291294
request_payload = dict(catalog=catalog,
292295
outfmt=3,
293-
outrows=Irsa.ROW_LIMIT)
296+
outrows=Lcogt.ROW_LIMIT)
294297
return request_payload
295298

296299
def _parse_result(self, response, verbose=False):
@@ -325,7 +328,7 @@ def _parse_result(self, response, verbose=False):
325328

326329
# Check that the results are not of length zero
327330
if len(content) == 0:
328-
raise Exception("The IRSA server sent back an empty reply")
331+
raise Exception("The LCOGT server sent back an empty reply")
329332

330333
# Read it in using the astropy VO table reader
331334
try:
@@ -334,7 +337,7 @@ def _parse_result(self, response, verbose=False):
334337
except Exception as ex:
335338
self.response = response
336339
self.table_parse_error = ex
337-
raise TableParseError("Failed to parse IRSA votable! The raw response can be found "
340+
raise TableParseError("Failed to parse LCOGT votable! The raw response can be found "
338341
"in self.response, and the error in self.table_parse_error.")
339342

340343
# Convert to astropy.table.Table instance
@@ -348,7 +351,7 @@ def _parse_result(self, response, verbose=False):
348351

349352
def list_catalogs(self):
350353
"""
351-
Return a dictionary of the catalogs in the IRSA Gator tool.
354+
Return a dictionary of the catalogs in the LCOGT Gator tool.
352355
353356
Returns
354357
-------
@@ -357,24 +360,19 @@ def list_catalogs(self):
357360
be used in query functions, and the value is the verbose description
358361
of the catalog.
359362
"""
360-
response = commons.send_request(Irsa.GATOR_LIST_URL, dict(mode='xml'), Irsa.TIMEOUT, request_type="GET")
361-
root = tree.fromstring(response.content)
362-
catalogs = {}
363-
for catalog in root.findall('catalog'):
364-
catname = catalog.find('catname').text
365-
desc = catalog.find('desc').text
366-
catalogs[catname] = desc
363+
catalogs = {'lco_cat' : 'Photometry archive from LCOGT',
364+
'lco_img' : 'Image metadata archive from LCOGT'}
367365
return catalogs
368366

369367
def print_catalogs(self):
370368
"""
371-
Display a table of the catalogs in the IRSA Gator tool.
369+
Display a table of the catalogs in the LCOGT Gator tool.
372370
"""
373371
catalogs = self.list_catalogs()
374372
for catname in catalogs:
375373
print("{:30s} {:s}".format(catname, catalogs[catname]))
376374

377-
Irsa = IrsaClass()
375+
Lcogt = LcogtClass()
378376

379377

380378
def _parse_coordinates(coordinates):

astroquery/lcogt/tests/setup_package.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@
55
def get_package_data():
66
paths = [os.path.join('data', '*.xml'),
77
]
8-
return {'astroquery.irsa.tests': paths}
8+
return {'astroquery.lcogt.tests': paths}

astroquery/lcogt/tests/test_lcogt.py

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@
1212

1313
from ...utils.testing_tools import MockResponse
1414
from ...utils import commons
15-
from ... import irsa
16-
from ...irsa import conf
15+
from ... import lcogt
16+
from ...lcogt import conf
1717

1818
DATA_FILES = {'Cone': 'Cone.xml',
1919
'Box': 'Box.xml',
@@ -44,7 +44,7 @@ def get_mockreturn(url, params=None, timeout=10, **kwargs):
4444
@pytest.mark.parametrize(('dim'), ['5d0m0s', 0.3 * u.rad, '5h0m0s', 2 * u.arcmin])
4545
def test_parse_dimension(dim):
4646
# check that the returned dimension is always in units of 'arcsec', 'arcmin' or 'deg'
47-
new_dim = irsa.core._parse_dimension(dim)
47+
new_dim = lcogt.core._parse_dimension(dim)
4848
assert new_dim.unit in ['arcsec', 'arcmin', 'deg']
4949

5050

@@ -53,15 +53,15 @@ def test_parse_dimension(dim):
5353
(10.0, -11, '10.0 -11')
5454
])
5555
def test_format_decimal_coords(ra, dec, expected):
56-
out = irsa.core._format_decimal_coords(ra, dec)
56+
out = lcogt.core._format_decimal_coords(ra, dec)
5757
assert out == expected
5858

5959

6060
@pytest.mark.parametrize(('coordinates', 'expected'),
6161
[("5h0m0s 0d0m0s", "75.0 +0.0")
6262
])
6363
def test_parse_coordinates(coordinates, expected):
64-
out = irsa.core._parse_coordinates(coordinates)
64+
out = lcogt.core._parse_coordinates(coordinates)
6565
for a, b in zip(out.split(), expected.split()):
6666
try:
6767
a = float(a)
@@ -72,41 +72,41 @@ def test_parse_coordinates(coordinates, expected):
7272

7373

7474
def test_args_to_payload():
75-
out = irsa.core.Irsa._args_to_payload("fp_psc")
75+
out = lcogt.core.Lcogt._args_to_payload("fp_psc")
7676
assert out == dict(catalog='fp_psc', outfmt=3, outrows=conf.row_limit)
7777

7878

7979
@pytest.mark.parametrize(("coordinates"), OBJ_LIST)
8080
def test_query_region_cone_async(coordinates, patch_get):
81-
response = irsa.core.Irsa.query_region_async(coordinates, catalog='fp_psc', spatial='Cone',
81+
response = lcogt.core.Lcogt.query_region_async(coordinates, catalog='fp_psc', spatial='Cone',
8282
radius=2 * u.arcmin, get_query_payload=True)
8383
assert response['radius'] == 2
8484
assert response['radunits'] == 'arcmin'
85-
response = irsa.core.Irsa.query_region_async(coordinates, catalog='fp_psc', spatial='Cone',
85+
response = lcogt.core.Lcogt.query_region_async(coordinates, catalog='fp_psc', spatial='Cone',
8686
radius=2 * u.arcmin)
8787
assert response is not None
8888

8989

9090
@pytest.mark.parametrize(("coordinates"), OBJ_LIST)
9191
def test_query_region_cone(coordinates, patch_get):
92-
result = irsa.core.Irsa.query_region(coordinates, catalog='fp_psc', spatial='Cone',
92+
result = lcogt.core.Lcogt.query_region(coordinates, catalog='fp_psc', spatial='Cone',
9393
radius=2 * u.arcmin)
9494
assert isinstance(result, Table)
9595

9696

9797
@pytest.mark.parametrize(("coordinates"), OBJ_LIST)
9898
def test_query_region_box_async(coordinates, patch_get):
99-
response = irsa.core.Irsa.query_region_async(coordinates, catalog='fp_psc', spatial='Box',
99+
response = lcogt.core.Lcogt.query_region_async(coordinates, catalog='fp_psc', spatial='Box',
100100
width=2 * u.arcmin, get_query_payload=True)
101101
assert response['size'] == 120
102-
response = irsa.core.Irsa.query_region_async(coordinates, catalog='fp_psc', spatial='Box',
102+
response = lcogt.core.Lcogt.query_region_async(coordinates, catalog='fp_psc', spatial='Box',
103103
width=2 * u.arcmin)
104104
assert response is not None
105105

106106

107107
@pytest.mark.parametrize(("coordinates"), OBJ_LIST)
108108
def test_query_region_box(coordinates, patch_get):
109-
result = irsa.core.Irsa.query_region(coordinates, catalog='fp_psc', spatial='Box',
109+
result = lcogt.core.Lcogt.query_region(coordinates, catalog='fp_psc', spatial='Box',
110110
width=2 * u.arcmin)
111111
assert isinstance(result, Table)
112112

@@ -121,7 +121,7 @@ def test_query_region_box(coordinates, patch_get):
121121
poly2
122122
])
123123
def test_query_region_async_polygon(polygon, patch_get):
124-
response = irsa.core.Irsa.query_region_async("m31", catalog="fp_psc", spatial="Polygon",
124+
response = lcogt.core.Lcogt.query_region_async("m31", catalog="fp_psc", spatial="Polygon",
125125
polygon=polygon, get_query_payload=True)
126126

127127
for a, b in zip(re.split("[ ,]", response["polygon"]),
@@ -131,7 +131,7 @@ def test_query_region_async_polygon(polygon, patch_get):
131131
b1 = float(b1)
132132
np.testing.assert_almost_equal(a1, b1)
133133

134-
response = irsa.core.Irsa.query_region_async("m31", catalog="fp_psc", spatial="Polygon",
134+
response = lcogt.core.Lcogt.query_region_async("m31", catalog="fp_psc", spatial="Polygon",
135135
polygon=polygon)
136136
assert response is not None
137137

@@ -141,19 +141,19 @@ def test_query_region_async_polygon(polygon, patch_get):
141141
poly2,
142142
])
143143
def test_query_region_polygon(polygon, patch_get):
144-
result = irsa.core.Irsa.query_region("m31", catalog="fp_psc", spatial="Polygon",
144+
result = lcogt.core.Lcogt.query_region("m31", catalog="fp_psc", spatial="Polygon",
145145
polygon=polygon)
146146
assert isinstance(result, Table)
147147

148148

149149
@pytest.mark.parametrize(('spatial', 'result'), zip(('Cone', 'Box', 'Polygon', 'All-Sky'), ('Cone', 'Box', 'Polygon', 'NONE')))
150150
def test_spatial_valdi(spatial, result):
151-
out = irsa.core.Irsa._parse_spatial(spatial, coordinates='m31', radius=5 * u.deg, width=5 * u.deg, polygon=[(5 * u.hour, 5 * u.deg)] * 3)
151+
out = lcogt.core.Lcogt._parse_spatial(spatial, coordinates='m31', radius=5 * u.deg, width=5 * u.deg, polygon=[(5 * u.hour, 5 * u.deg)] * 3)
152152
assert out['spatial'] == result
153153

154154

155155
@pytest.mark.parametrize(('spatial'), [('cone', 'box', 'polygon', 'all-Sky', 'All-sky', 'invalid', 'blah')])
156156
def test_spatial_invalid(spatial):
157157
with pytest.raises(ValueError):
158-
irsa.core.Irsa._parse_spatial(spatial, coordinates='m31')
158+
lcogt.core.Lcogt._parse_spatial(spatial, coordinates='m31')
159159

0 commit comments

Comments
 (0)