...
 
Commits (2)
......@@ -4,6 +4,11 @@ from pyvo.dal import TAPService, TAPResults
from pyvo.dal.tap import TAPRecord
import numpy
import json
import logging
import re
logging.basicConfig(level=logging.DEBUG)
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*$'
try:
groups = re.search(cone_search_pattern, 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 = args.save
result_set = service.search('select top {} * from {} where {}'.format(limit, table_name,
where_statement))
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,
radius))))
query = 'select top {} * from {} where {}'.format(limit, table_name, where_statement)
logging.debug('executing query %s', query)
result_set = service.search(query)
if save:
_save_result_set_to_file(result_set, save)
else:
......@@ -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
......