Skip to content

Commit f64b997

Browse files
authored
Merge pull request #3028 from cds-astro/maint-vizier-module
Maintenance for the VizieR module
2 parents de6260f + 9e85f4e commit f64b997

File tree

4 files changed

+210
-180
lines changed

4 files changed

+210
-180
lines changed

astroquery/vizier/core.py

+28-28
Original file line numberDiff line numberDiff line change
@@ -205,44 +205,44 @@ def find_catalogs(self, keywords, *, include_obsolete=False, verbose=False,
205205
Examples
206206
--------
207207
>>> from astroquery.vizier import Vizier
208-
>>> catalog_list = Vizier.find_catalogs('Kang W51') # doctest: +REMOTE_DATA +IGNORE_WARNINGS
209-
>>> catalog_list # doctest: +REMOTE_DATA +IGNORE_OUTPUT
210-
OrderedDict([('J/ApJ/684/1143', </>), ('J/ApJ/736/87', </>) ... ])
211-
>>> print({k:v.description for k,v in catalog_list.items()}) # doctest: +REMOTE_DATA +IGNORE_OUTPUT
212-
{'J/ApJ/684/1143': 'BHB candidates in the Milky Way (Xue+, 2008)',
213-
'J/ApJ/736/87': 'Abundances in G-type stars with exoplanets (Kang+, 2011)',
214-
'J/ApJ/738/79': "SDSS-DR8 BHB stars in the Milky Way's halo (Xue+, 2011)",
215-
'J/ApJ/760/12': 'LIGO/Virgo gravitational-wave (GW) bursts with GRBs (Abadie+, 2012)',
216-
...}
208+
>>> catalog_list = Vizier.find_catalogs('Mars') # doctest: +REMOTE_DATA +IGNORE_WARNINGS
209+
>>> for k, v in catalog_list.items(): # doctest: +REMOTE_DATA +IGNORE_OUTPUT
210+
... print(k, ":", v.description)
211+
J/A+A/572/A104 : Astrometric obs. of Phobos and Deimos in 1971 (Robert+, 2014)
212+
J/A+A/488/361 : Mars Express astrometric observations of Phobos (Willner+, 2008)
213+
J/A+A/603/A55 : WISE/NEOWISE Mars-crossing asteroids (Ali-Lagoa+, 2017)
214+
J/A+A/545/A144 : Astrometric observations of Deimos (Pasewaldt+, 2012)
215+
...
217216
"""
218217

219-
if isinstance(keywords, list):
220-
keywords = " ".join(keywords)
218+
# Note to devs: The ASU convention (http://vizier.u-strasbg.fr/doc/asu.html) has
219+
# parameters without values. This is a bit different from POST requests that have
220+
# key/values pairs. This is why we send a string formatted for ASU instead of a
221+
# dictionary in the POST request here.
221222

222-
data_payload = {'-words': keywords, '-meta.all': 1}
223+
if isinstance(keywords, list):
224+
keywords = "+".join(keywords)
225+
keywords = keywords.replace(" ", "+")
223226

224-
data_payload['-ucd'] = self.ucd
227+
data_payload = {'-words': keywords, "-meta": None}
225228

226229
if max_catalogs is not None:
227230
data_payload['-meta.max'] = max_catalogs
228-
response = self._request(
229-
method='POST', url=self._server_to_url(return_type=return_type),
230-
data=data_payload, timeout=self.TIMEOUT)
231231

232-
if 'STOP, Max. number of RESOURCE reached' in response.text:
233-
raise ValueError("Maximum number of catalogs exceeded. Try "
234-
"setting max_catalogs to a large number and"
235-
" try again")
236-
result = self._parse_result(response, verbose=verbose,
237-
get_catalog_names=True)
232+
if include_obsolete:
233+
data_payload["-obsolete"] = None
234+
235+
if self.ucd != "":
236+
data_payload["ucd"] = self.ucd
237+
238+
params = "&".join([k if v is None else f"{k}={v}" for k, v in data_payload.items()])
238239

239-
# Filter out the obsolete catalogs, unless requested
240-
if include_obsolete is False:
241-
for key in list(result):
242-
for info in result[key].infos:
243-
if (info.name == 'status') and (info.value == 'obsolete'):
244-
del result[key]
240+
response = self._request(method='POST',
241+
url=self._server_to_url(return_type=return_type),
242+
data=params, timeout=self.TIMEOUT)
245243

244+
result = self._parse_result(response, verbose=verbose,
245+
get_catalog_names=True)
246246
return result
247247

248248
def get_catalogs_async(self, catalog, *, verbose=False, return_type='votable',

astroquery/vizier/tests/test_vizier.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ def post_mockreturn(self, method, url, data=None, timeout=10, files=None,
5555
filename = data_path(VO_DATA[datad['-source']])
5656
elif '-words' in datad:
5757
# a find_catalog request/only metadata
58-
filename = data_path(VO_DATA['find_' + datad['-words']])
58+
filename = data_path(VO_DATA['find_' + datad['-words'].split("&")[0]])
5959

6060
with open(filename, 'rb') as infile:
6161
content = infile.read()

astroquery/vizier/tests/test_vizier_remote.py

+40-45
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import astropy.units as u
66
from astropy.coordinates import SkyCoord
77

8-
from astroquery import vizier
8+
from astroquery.vizier import Vizier
99
from astroquery.utils import commons
1010
from .conftest import scalar_skycoord, vector_skycoord
1111

@@ -14,110 +14,110 @@
1414
class TestVizierRemote:
1515

1616
def test_query_object(self):
17-
result = vizier.core.Vizier.query_object(
17+
result = Vizier.query_object(
1818
"HD 226868", catalog=["NOMAD", "UCAC"])
1919

2020
assert isinstance(result, commons.TableList)
2121

2222
def test_query_another_object(self):
23-
result = vizier.core.Vizier.query_region(
23+
result = Vizier.query_region(
2424
"AFGL 2591", radius='0d5m', catalog="B/iram/pdbi")
2525
assert isinstance(result, commons.TableList)
2626

2727
def test_query_object_async(self):
28-
response = vizier.core.Vizier.query_object_async(
28+
response = Vizier.query_object_async(
2929
"HD 226868", catalog=["NOMAD", "UCAC"])
3030
assert response is not None
3131

3232
def test_query_region(self):
33-
result = vizier.core.Vizier.query_region(
33+
result = Vizier.query_region(
3434
scalar_skycoord, radius=5 * u.deg, catalog=["HIP", "NOMAD", "UCAC"])
3535

3636
assert isinstance(result, commons.TableList)
3737

3838
def test_query_region_async(self):
39-
response = vizier.core.Vizier.query_region_async(
39+
response = Vizier.query_region_async(
4040
scalar_skycoord, radius=5 * u.deg, catalog=["HIP", "NOMAD", "UCAC"])
4141
assert response is not None
4242

4343
def test_query_region_async_galactic(self):
44-
response = vizier.core.Vizier.query_region_async(
44+
response = Vizier.query_region_async(
4545
scalar_skycoord, radius=0.5 * u.deg, catalog="HIP", frame="galactic")
4646
assert response is not None
47-
payload = vizier.core.Vizier.query_region_async(
47+
payload = Vizier.query_region_async(
4848
scalar_skycoord, radius=0.5 * u.deg, catalog="HIP",
4949
frame="galactic", get_query_payload=True)
5050
assert "-c=G" in payload
5151

5252
def test_query_Vizier_instance(self):
5353
with pytest.warns(UserWarning, match="xry : No such keyword"):
54-
v = vizier.core.Vizier(
54+
vizier = Vizier(
5555
columns=['_RAJ2000', 'DEJ2000', 'B-V', 'Vmag', 'Plx'],
5656
column_filters={"Vmag": ">10"}, keywords=["optical", "xry"])
5757

58-
result = v.query_object("HD 226868", catalog=["NOMAD", "UCAC"])
58+
result = vizier.query_object("HD 226868", catalog=["NOMAD", "UCAC"])
5959
assert isinstance(result, commons.TableList)
60-
result = v.query_region(
60+
result = vizier.query_region(
6161
scalar_skycoord, width="5d0m0s", height="3d0m0s", catalog=["NOMAD", "UCAC"])
6262
assert isinstance(result, commons.TableList)
6363

6464
def test_vizier_column_restriction(self):
6565
# Check that the column restriction worked. At least some of these
6666
# catalogs include Bmag's
67-
v = vizier.core.Vizier(
67+
vizier = Vizier(
6868
columns=['_RAJ2000', 'DEJ2000', 'B-V', 'Vmag', 'Plx'],
6969
column_filters={"Vmag": ">10"}, keywords=["optical", "X-ray"])
7070

71-
result = v.query_object("HD 226868", catalog=["NOMAD", "UCAC"])
71+
result = vizier.query_object("HD 226868", catalog=["NOMAD", "UCAC"])
7272
for table in result:
7373
assert 'Bmag' not in table.columns
7474

7575
@pytest.mark.parametrize('all', ('all', '*'))
7676
def test_alls_withaddition(self, all):
7777
# Check that all the expected columns are there plus the _r
7878
# (radius from target) that we've added
79-
v = vizier.core.Vizier(columns=[all, "+_r"], catalog="II/246")
80-
result = v.query_region("HD 226868", radius="20s")
79+
vizier = Vizier(columns=[all, "+_r"], catalog="II/246")
80+
result = vizier.query_region("HD 226868", radius="20s")
8181
table = result['II/246/out']
8282
assert 'Jmag' in table.columns
8383
assert '_r' in table.columns
8484

8585
def test_get_catalogs(self):
86-
result = vizier.core.Vizier.get_catalogs('J/ApJ/706/83')
86+
result = Vizier.get_catalogs('J/ApJ/706/83')
8787
assert isinstance(result, commons.TableList)
8888

8989
def test_get_catalog_metadata(self):
90-
meta = vizier.core.Vizier(catalog="I/324").get_catalog_metadata()
90+
meta = Vizier(catalog="I/324").get_catalog_metadata()
9191
assert meta['title'] == "The Initial Gaia Source List (IGSL)"
9292

9393
def test_query_two_wavelengths(self):
94-
v = vizier.core.Vizier(
94+
vizier = Vizier(
9595
columns=['_RAJ2000', 'DEJ2000', 'B-V', 'Vmag', 'Plx'],
9696
column_filters={"Vmag": ">10"}, keywords=["optical", "radio"])
97-
98-
v.query_object('M 31')
97+
vizier.ROW_LIMIT = 1
98+
vizier.query_object('M 31')
9999

100100
def test_regressiontest_invalidtable(self):
101-
V = vizier.core.Vizier(
101+
vizier = Vizier(
102102
columns=['all'], ucd='(spect.dopplerVeloc*|phys.veloc*)',
103103
keywords=['Radio', 'IR'], row_limit=5000)
104-
C = SkyCoord(359.61687 * u.deg, -0.242457 * u.deg, frame="galactic")
104+
coordinate = SkyCoord(359.61687 * u.deg, -0.242457 * u.deg, frame="galactic")
105105

106106
# With newer versions UnitsWarning may be issued as well
107-
with pytest.warns() as w:
108-
V.query_region(C, radius=2 * u.arcmin)
107+
with pytest.warns() as warnings:
108+
vizier.query_region(coordinate, radius=2 * u.arcmin)
109109

110-
for i in w:
110+
for i in warnings:
111111
message = str(i.message)
112112
assert ("VOTABLE parsing raised exception" in message or "not supported by the VOUnit standard" in message)
113113

114114
def test_multicoord(self):
115115

116116
# Regression test: the columns of the default should never
117117
# be modified from default
118-
assert vizier.core.Vizier.columns == ['*']
118+
assert Vizier.columns == ['*']
119119
# Coordinate selection is entirely arbitrary
120-
result = vizier.core.Vizier.query_region(
120+
result = Vizier.query_region(
121121
vector_skycoord, radius=10 * u.arcsec, catalog=["HIP", "NOMAD", "UCAC"])
122122

123123
assert len(result) >= 5
@@ -126,36 +126,31 @@ def test_multicoord(self):
126126
assert result['I/239/hip_main']['HIP'] == 98298
127127

128128
def test_findcatalog_maxcatalog(self):
129-
V = vizier.core.Vizier()
130-
cats = V.find_catalogs('eclipsing binary', max_catalogs=5000)
131-
assert len(cats) >= 468
132-
133-
# with pytest.raises(ValueError) as exc:
134-
# V.find_catalogs('eclipsing binary')
135-
# assert str(exc.value)==("Maximum number of catalogs exceeded."
136-
# " Try setting max_catalogs "
137-
# "to a large number and try again")
129+
vizier = Vizier()
130+
cats = vizier.find_catalogs('eclipsing binary planets', max_catalogs=5000)
131+
assert len(cats) >= 39 # as of 2024
138132

139133
def test_findcatalog_ucd(self):
140-
V = vizier.core.Vizier()
141-
ucdresult = V(ucd='time.age*').find_catalogs('eclipsing binary', max_catalogs=5000)
142-
result = V.find_catalogs('eclipsing binary', max_catalogs=5000)
134+
# this fails for VizieR 7.33.3, should work in next releases
135+
vizier = Vizier()
136+
ucdresult = vizier(ucd='phys.albedo').find_catalogs('mars', max_catalogs=5000)
137+
result = vizier.find_catalogs('mars', max_catalogs=5000)
143138

144-
assert len(ucdresult) >= 12 # count as of 1/15/2018
145-
assert len(result) >= 628
139+
assert len(ucdresult) >= 1
140+
assert len(result) >= 11
146141
# important part: we're testing that UCD is parsed and some catalogs are ruled out
147142
assert len(ucdresult) < len(result)
148143

149144
def test_asu_tsv_return_type(self):
150-
V = vizier.core.Vizier()
151-
result = V.query_object("HD 226868", catalog=["NOMAD", "UCAC"], return_type='asu-tsv', cache=False)
145+
vizier = Vizier()
146+
result = vizier.query_object("HD 226868", catalog=["NOMAD", "UCAC"], return_type='asu-tsv', cache=False)
152147

153148
assert isinstance(result, list)
154149
assert len(result) == 3
155150

156151
def test_query_constraints(self):
157-
V = vizier.core.Vizier(row_limit=3)
158-
result = V.query_constraints(catalog="I/130/main", mB2="=14.7")[0]
152+
vizier = Vizier(row_limit=3)
153+
result = vizier.query_constraints(catalog="I/130/main", mB2="=14.7")[0]
159154
# row_limit is taken in account
160155
assert len(result) == 3
161156
# the criteria is respected

0 commit comments

Comments
 (0)