AstroGrid

Navigation
Log in


Forgot your password?
 
Document Actions

conesearch script

Click here to get the file

Size 1.1 kB - File type text/x-python

File contents

#!/usr/bin/python
"""
Given an input list od objects, queries the 2MASS catalogue returning a 
VOTable for each object.
"""

from astrogrid import ConeSearch
from astrogrid.utils import broadcast, read_votable

# Get the table from the web
import urllib
urllib.urlretrieve('http://www2.astrogrid.org/science/documentation/workbench-advanced/advanced-usage/scripting-user-s-guide/sample.vot', 'sample.vot')

# Read input list of ra, decs from VOTable
vot=read_votable('sample.vot')
id = vot['id']
ra = map(float, vot['ra'])
dec = map(float, vot['dec'])

# We are going to query 2MASS at RoE
ivorn = 'ivo://wfau.roe.ac.uk/twomass-dsa/cone'
cone = ConeSearch(ivorn)

nsrc = len(ra) # Number of sources
radius=20./3600.0  # Search radius in degrees

print 'Starting Query: %d objects' % nsrc

# However this is just an example so we select a couple
nsrc = 2

for i in range(nsrc):
	res = cone.execute(ra[i], dec[i], radius)
	# Uncomment the following line if you want to send the output to TOPCAT
	# broadcast(res)
	print 'Writting 2mass_%s.vot' % id[i]
	open('2mass_%s.vot' % id[i], 'w').write(res)