Commit 88c99829 authored by Mattia Mancini's avatar Mattia Mancini

Add cone search shortcut

parent 546d58d9
......@@ -4,6 +4,11 @@ from pyvo.dal import TAPService, TAPResults
from pyvo.dal.tap import TAPRecord
import numpy
import json
import logging
import re
logger = logging.getLogger('inspect_vo_registry')
def list_tables(service: TAPService, args):
......@@ -53,13 +58,33 @@ def _save_result_set_to_file(result_set, path):
json.dump(result_set, f_stream, cls=TAPRecordEncode)
def _parse_cone_search_ra_dec_radius(cone_search_string):
cone_search_pattern = '^\s*\((.*),\s*(.*),\s*(.*)\)\s*$'
groups =, cone_search_string).groups()
ra, dec, radius = map(float, groups)
return ra, dec, radius
except Exception as e:
raise e
def print_table(service: TAPService, args):
table_name = args.table_name
limit = args.limit
where_statement = args.where
cone_search = args.cone_search
save =
result_set ='select top {} * from {} where {}'.format(limit, table_name,
if cone_search:
ra, dec, radius = _parse_cone_search_ra_dec_radius(cone_search)
where_statement = " and ".join(filter(lambda x: len(x), (where_statement,
"1=CONTAINS(POINT('ICRS', s_ra, s_dec), "
"CIRCLE('ICRS', {}, {}, {}))".format(ra, dec,
query = 'select top {} * from {} where {}'.format(limit, table_name, where_statement)
logging.debug('executing query %s', query)
result_set =
if save:
_save_result_set_to_file(result_set, save)
......@@ -83,6 +108,8 @@ def parse_arguments():
print_table_parser.add_argument('--save', help='path of file where to save result as json', default=None)
print_table_parser.add_argument('--limit', help='limit number of results', default=10)
print_table_parser.add_argument('--where', help='where statement', default='')
print_table_parser.add_argument('--cone_search', help='provide (ra [ICRS], dec [ICRS], radius[deg])', default=None)
parsed_arguments = parser.parse_args()
return parsed_arguments
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment