Skip to content

Commit

Permalink
maint: switch from meta.all to meta to reduce response size
Browse files Browse the repository at this point in the history
we don't lose information, but ASU-style queries cannot get a dictionnary in the POST request's data
  • Loading branch information
ManonMarchand committed Jun 11, 2024
1 parent 947814b commit 73595e7
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 29 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 +ELLIPSIS
... 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

0 comments on commit 73595e7

Please sign in to comment.