Skip to content

Commit

Permalink
Merge pull request #3028 from cds-astro/maint-vizier-module
Browse files Browse the repository at this point in the history
Maintenance for the VizieR module
  • Loading branch information
bsipocz committed Jun 20, 2024
2 parents de6260f + 9e85f4e commit f64b997
Show file tree
Hide file tree
Showing 4 changed files with 210 additions and 180 deletions.
56 changes: 28 additions & 28 deletions astroquery/vizier/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,44 +205,44 @@ def find_catalogs(self, keywords, *, include_obsolete=False, verbose=False,
Examples
--------
>>> from astroquery.vizier import Vizier
>>> catalog_list = Vizier.find_catalogs('Kang W51') # doctest: +REMOTE_DATA +IGNORE_WARNINGS
>>> catalog_list # doctest: +REMOTE_DATA +IGNORE_OUTPUT
OrderedDict([('J/ApJ/684/1143', </>), ('J/ApJ/736/87', </>) ... ])
>>> print({k:v.description for k,v in catalog_list.items()}) # doctest: +REMOTE_DATA +IGNORE_OUTPUT
{'J/ApJ/684/1143': 'BHB candidates in the Milky Way (Xue+, 2008)',
'J/ApJ/736/87': 'Abundances in G-type stars with exoplanets (Kang+, 2011)',
'J/ApJ/738/79': "SDSS-DR8 BHB stars in the Milky Way's halo (Xue+, 2011)",
'J/ApJ/760/12': 'LIGO/Virgo gravitational-wave (GW) bursts with GRBs (Abadie+, 2012)',
...}
>>> catalog_list = Vizier.find_catalogs('Mars') # doctest: +REMOTE_DATA +IGNORE_WARNINGS
>>> for k, v in catalog_list.items(): # doctest: +REMOTE_DATA +IGNORE_OUTPUT
... print(k, ":", v.description)
J/A+A/572/A104 : Astrometric obs. of Phobos and Deimos in 1971 (Robert+, 2014)
J/A+A/488/361 : Mars Express astrometric observations of Phobos (Willner+, 2008)
J/A+A/603/A55 : WISE/NEOWISE Mars-crossing asteroids (Ali-Lagoa+, 2017)
J/A+A/545/A144 : Astrometric observations of Deimos (Pasewaldt+, 2012)
...
"""

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

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

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

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

if 'STOP, Max. number of RESOURCE reached' in response.text:
raise ValueError("Maximum number of catalogs exceeded. Try "
"setting max_catalogs to a large number and"
" try again")
result = self._parse_result(response, verbose=verbose,
get_catalog_names=True)
if include_obsolete:
data_payload["-obsolete"] = None

if self.ucd != "":
data_payload["ucd"] = self.ucd

params = "&".join([k if v is None else f"{k}={v}" for k, v in data_payload.items()])

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

result = self._parse_result(response, verbose=verbose,
get_catalog_names=True)
return result

def get_catalogs_async(self, catalog, *, verbose=False, return_type='votable',
Expand Down
2 changes: 1 addition & 1 deletion astroquery/vizier/tests/test_vizier.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def post_mockreturn(self, method, url, data=None, timeout=10, files=None,
filename = data_path(VO_DATA[datad['-source']])
elif '-words' in datad:
# a find_catalog request/only metadata
filename = data_path(VO_DATA['find_' + datad['-words']])
filename = data_path(VO_DATA['find_' + datad['-words'].split("&")[0]])

with open(filename, 'rb') as infile:
content = infile.read()
Expand Down
85 changes: 40 additions & 45 deletions astroquery/vizier/tests/test_vizier_remote.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import astropy.units as u
from astropy.coordinates import SkyCoord

from astroquery import vizier
from astroquery.vizier import Vizier
from astroquery.utils import commons
from .conftest import scalar_skycoord, vector_skycoord

Expand All @@ -14,110 +14,110 @@
class TestVizierRemote:

def test_query_object(self):
result = vizier.core.Vizier.query_object(
result = Vizier.query_object(
"HD 226868", catalog=["NOMAD", "UCAC"])

assert isinstance(result, commons.TableList)

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

def test_query_object_async(self):
response = vizier.core.Vizier.query_object_async(
response = Vizier.query_object_async(
"HD 226868", catalog=["NOMAD", "UCAC"])
assert response is not None

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

assert isinstance(result, commons.TableList)

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

def test_query_region_async_galactic(self):
response = vizier.core.Vizier.query_region_async(
response = Vizier.query_region_async(
scalar_skycoord, radius=0.5 * u.deg, catalog="HIP", frame="galactic")
assert response is not None
payload = vizier.core.Vizier.query_region_async(
payload = Vizier.query_region_async(
scalar_skycoord, radius=0.5 * u.deg, catalog="HIP",
frame="galactic", get_query_payload=True)
assert "-c=G" in payload

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

result = v.query_object("HD 226868", catalog=["NOMAD", "UCAC"])
result = vizier.query_object("HD 226868", catalog=["NOMAD", "UCAC"])
assert isinstance(result, commons.TableList)
result = v.query_region(
result = vizier.query_region(
scalar_skycoord, width="5d0m0s", height="3d0m0s", catalog=["NOMAD", "UCAC"])
assert isinstance(result, commons.TableList)

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

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

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

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

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

def test_query_two_wavelengths(self):
v = vizier.core.Vizier(
vizier = Vizier(
columns=['_RAJ2000', 'DEJ2000', 'B-V', 'Vmag', 'Plx'],
column_filters={"Vmag": ">10"}, keywords=["optical", "radio"])

v.query_object('M 31')
vizier.ROW_LIMIT = 1
vizier.query_object('M 31')

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

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

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

def test_multicoord(self):

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

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

def test_findcatalog_maxcatalog(self):
V = vizier.core.Vizier()
cats = V.find_catalogs('eclipsing binary', max_catalogs=5000)
assert len(cats) >= 468

# with pytest.raises(ValueError) as exc:
# V.find_catalogs('eclipsing binary')
# assert str(exc.value)==("Maximum number of catalogs exceeded."
# " Try setting max_catalogs "
# "to a large number and try again")
vizier = Vizier()
cats = vizier.find_catalogs('eclipsing binary planets', max_catalogs=5000)
assert len(cats) >= 39 # as of 2024

def test_findcatalog_ucd(self):
V = vizier.core.Vizier()
ucdresult = V(ucd='time.age*').find_catalogs('eclipsing binary', max_catalogs=5000)
result = V.find_catalogs('eclipsing binary', max_catalogs=5000)
# this fails for VizieR 7.33.3, should work in next releases
vizier = Vizier()
ucdresult = vizier(ucd='phys.albedo').find_catalogs('mars', max_catalogs=5000)
result = vizier.find_catalogs('mars', max_catalogs=5000)

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

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

assert isinstance(result, list)
assert len(result) == 3

def test_query_constraints(self):
V = vizier.core.Vizier(row_limit=3)
result = V.query_constraints(catalog="I/130/main", mB2="=14.7")[0]
vizier = Vizier(row_limit=3)
result = vizier.query_constraints(catalog="I/130/main", mB2="=14.7")[0]
# row_limit is taken in account
assert len(result) == 3
# the criteria is respected
Expand Down
Loading

0 comments on commit f64b997

Please sign in to comment.