Skip to content

Commit d96f066

Browse files
committed
Fix list handling in Vizier.
1 parent 1a89486 commit d96f066

File tree

1 file changed

+23
-12
lines changed

1 file changed

+23
-12
lines changed

astroquery/vizier/core.py

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -357,19 +357,20 @@ def query_region_async(self, coordinates, radius=None, inner_radius=None,
357357
catalog = VizierClass._schema_catalog.validate(catalog)
358358
center = {}
359359
columns = []
360+
361+
# Process coordinates
360362
if isinstance(coordinates, (commons.CoordClasses,) + six.string_types):
361363
c = commons.parse_coordinates(coordinates).transform_to('fk5')
362364

363365
if not c.isscalar:
364-
pos_list = []
366+
center["-c"] = []
365367
for pos in c:
366368
ra_deg = pos.ra.to_string(unit="deg", decimal=True,
367369
precision=8)
368370
dec_deg = pos.dec.to_string(unit="deg", decimal=True,
369371
precision=8, alwayssign=True)
370-
pos_list += ["{}{}".format(ra_deg, dec_deg)]
371-
center["-c"] = "<<;" + ";".join(pos_list)
372-
columns += ["_q"] # request a reference to the input table
372+
center["-c"] += ["{}{}".format(ra_deg, dec_deg)]
373+
columns += ["_q"] # Always request reference to input table
373374
else:
374375
ra = c.ra.to_string(unit='deg', decimal=True, precision=8)
375376
dec = c.dec.to_string(unit="deg", decimal=True, precision=8,
@@ -378,7 +379,7 @@ def query_region_async(self, coordinates, radius=None, inner_radius=None,
378379
elif isinstance(coordinates, tbl.Table):
379380
if (("_RAJ2000" in coordinates.keys()) and ("_DEJ2000" in
380381
coordinates.keys())):
381-
pos_list = []
382+
center["-c"] = []
382383
sky_coord = coord.SkyCoord(coordinates["_RAJ2000"],
383384
coordinates["_DEJ2000"],
384385
unit=(coordinates["_RAJ2000"].unit,
@@ -388,15 +389,15 @@ def query_region_async(self, coordinates, radius=None, inner_radius=None,
388389
precision=8)
389390
dec_deg = dec.to_string(unit="deg", decimal=True,
390391
precision=8, alwayssign=True)
391-
pos_list += ["{}{}".format(ra_deg, dec_deg)]
392-
center["-c"] = "<<;" + ";".join(pos_list)
393-
columns += ["_q"] # request a reference to the input table
392+
center["-c"] += ["{}{}".format(ra_deg, dec_deg)]
393+
columns += ["_q"] # Always request reference to input table
394394
else:
395395
raise ValueError("Table must contain '_RAJ2000' and "
396396
"'_DEJ2000' columns!")
397397
else:
398398
raise TypeError("Coordinates must be one of: string, astropy "
399399
"coordinates, or table containing coordinates!")
400+
400401
# decide whether box or radius
401402
if radius is not None:
402403
# is radius a disk or an annulus?
@@ -434,6 +435,7 @@ def query_region_async(self, coordinates, radius=None, inner_radius=None,
434435
raise Exception(
435436
"At least one of radius, width/height must be specified")
436437

438+
# Prepare payload
437439
data_payload = self._args_to_payload(center=center, columns=columns,
438440
catalog=catalog, column_filters=column_filters)
439441

@@ -607,13 +609,22 @@ def _args_to_payload(self, *args, **kwargs):
607609
if ucd:
608610
body['-ucd'] = ucd
609611

610-
# create final script
611-
script = "\n".join(["{key}={val}".format(key=key, val=val)
612-
for key, val in body.items()])
613-
# add keywords
612+
# create final script starting with keywords
613+
script = ""
614614
if (not isinstance(self.keywords, property) and
615615
self.keywords is not None):
616616
script += "\n" + str(self.keywords)
617+
# add all items that are not lists
618+
for key, val in body.items():
619+
if type(val) is not list:
620+
script += "\n{key}={val}".format(key=key, val=val)
621+
# add list at the end
622+
for key, val in body.items():
623+
if type(val) is list:
624+
script += "\n{key}=<<====AstroqueryList".format(key=key)
625+
script += "\n" + "\n".join(val)
626+
script += "\n====AstroqueryList"
627+
# add keywords
617628
return script
618629

619630
def _parse_result(self, response, get_catalog_names=False, verbose=False,

0 commit comments

Comments
 (0)