@@ -357,19 +357,20 @@ def query_region_async(self, coordinates, radius=None, inner_radius=None,
357
357
catalog = VizierClass ._schema_catalog .validate (catalog )
358
358
center = {}
359
359
columns = []
360
+
361
+ # Process coordinates
360
362
if isinstance (coordinates , (commons .CoordClasses ,) + six .string_types ):
361
363
c = commons .parse_coordinates (coordinates ).transform_to ('fk5' )
362
364
363
365
if not c .isscalar :
364
- pos_list = []
366
+ center [ "-c" ] = []
365
367
for pos in c :
366
368
ra_deg = pos .ra .to_string (unit = "deg" , decimal = True ,
367
369
precision = 8 )
368
370
dec_deg = pos .dec .to_string (unit = "deg" , decimal = True ,
369
371
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
373
374
else :
374
375
ra = c .ra .to_string (unit = 'deg' , decimal = True , precision = 8 )
375
376
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,
378
379
elif isinstance (coordinates , tbl .Table ):
379
380
if (("_RAJ2000" in coordinates .keys ()) and ("_DEJ2000" in
380
381
coordinates .keys ())):
381
- pos_list = []
382
+ center [ "-c" ] = []
382
383
sky_coord = coord .SkyCoord (coordinates ["_RAJ2000" ],
383
384
coordinates ["_DEJ2000" ],
384
385
unit = (coordinates ["_RAJ2000" ].unit ,
@@ -388,15 +389,15 @@ def query_region_async(self, coordinates, radius=None, inner_radius=None,
388
389
precision = 8 )
389
390
dec_deg = dec .to_string (unit = "deg" , decimal = True ,
390
391
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
394
394
else :
395
395
raise ValueError ("Table must contain '_RAJ2000' and "
396
396
"'_DEJ2000' columns!" )
397
397
else :
398
398
raise TypeError ("Coordinates must be one of: string, astropy "
399
399
"coordinates, or table containing coordinates!" )
400
+
400
401
# decide whether box or radius
401
402
if radius is not None :
402
403
# is radius a disk or an annulus?
@@ -434,6 +435,7 @@ def query_region_async(self, coordinates, radius=None, inner_radius=None,
434
435
raise Exception (
435
436
"At least one of radius, width/height must be specified" )
436
437
438
+ # Prepare payload
437
439
data_payload = self ._args_to_payload (center = center , columns = columns ,
438
440
catalog = catalog , column_filters = column_filters )
439
441
@@ -547,16 +549,13 @@ def _args_to_payload(self, *args, **kwargs):
547
549
# keyword names that can mean 'all'
548
550
alls = ['all' , '**' ]
549
551
if any (x in columns for x in alls ):
552
+ columns_all = True
550
553
for x in alls :
551
554
if x in columns :
552
555
columns .remove (x )
553
- body ['-out.all' ] = 2
554
- # keyword name that means default columns
555
- if '*' in columns :
556
- columns .remove ('*' )
557
- columns_default = True
556
+ body ['-out.all' ] = None
558
557
else :
559
- columns_default = False
558
+ columns_all = False
560
559
561
560
# process: columns - identify sorting requests
562
561
columns_out = []
@@ -571,16 +570,23 @@ def _args_to_payload(self, *args, **kwargs):
571
570
else :
572
571
columns_out += [column ]
573
572
574
- if columns_default :
575
- body ['-out' ] = '*'
576
- else :
577
- body ['-out' ] = columns_out
573
+ # calculated keyword names that start with an underscore
574
+ columns_calc = []
575
+ for column in columns_out :
576
+ if column [0 ] == '_' :
577
+ columns_calc .append (column )
578
+ for column in columns_calc :
579
+ columns_out .remove (column )
578
580
579
- if columns_out :
580
- body ['-out.add' ] = ',' .join (columns_out )
581
+ if columns_out and not columns_all :
582
+ body ['-out' ] = ',' .join (columns_out )
583
+
584
+ if columns_calc :
585
+ body ['-out.add' ] = ',' .join (columns_calc )
581
586
582
587
if len (sorts_out ) > 0 :
583
588
body ['-sort' ] = ',' .join (sorts_out )
589
+
584
590
# process: maximum rows returned
585
591
row_limit = kwargs .get ('row_limit' ) or self .ROW_LIMIT
586
592
if row_limit < 0 :
@@ -607,14 +613,26 @@ def _args_to_payload(self, *args, **kwargs):
607
613
if ucd :
608
614
body ['-ucd' ] = ucd
609
615
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
616
+ # create final script starting with keywords
617
+ script = []
614
618
if (not isinstance (self .keywords , property ) and
615
619
self .keywords is not None ):
616
- script += "\n " + str (self .keywords )
617
- return script
620
+ script += [str (self .keywords )]
621
+ # add all items that are not lists
622
+ for key , val in body .items ():
623
+ if type (val ) is not list :
624
+ if val :
625
+ script += ["{key}={val}" .format (key = key , val = val )]
626
+ else :
627
+ script += [key ]
628
+ # add list at the end
629
+ for key , val in body .items ():
630
+ if type (val ) is list :
631
+ script += ["{key}=<<====AstroqueryList" .format (key = key )]
632
+ script += val
633
+ script += ["====AstroqueryList" ]
634
+ # merge result
635
+ return "\n " .join (script )
618
636
619
637
def _parse_result (self , response , get_catalog_names = False , verbose = False ,
620
638
invalid = 'warn' ):
0 commit comments