This website (www2.astrogrid.org) is now deprecated - please go to www.astrogrid.org for up to date information.
Astrogrid Recipes
This page describes recipes to access Astrogrid from Python. All XMLRPC calls and other convenience functions are hidden inside a module which is imported from Python.
While XMLRPC provides a good bridge between python and the java ACR, it is not user friendly and even users who know python may feel unconfortable. For this reason a more pythonic interface to ACR is being written which hides the xmlrpc calls. It is also a way of wrapping common blocks of calls to the ACR into a single command. The cone search example would be written as:
from astrogrid import ConeSearch
cone = ConeSearch("ivo://ned.ipac/Basic_Data_Near_Position")
result = cone.execute(ra, dec, radius)
open("result.vot","w").write(result)
Note that all the xmlrpc library calls are hidden within the ConeSearch class. One can still perform those calls using:
from astrogrid import acr
Help on the command is also available using standard python procedures, the output of help(ConeSearch) being like:
Help on class ConeSearch in module astrogrid.cone:
class ConeSearch
| Execute cone searches.
|
| Examples:
|
| The following example sends a cone search query to NED and saves the
| resulting VOTable in the local disk.
|
| >>> from astrogrid import ConeSearch
| >>> cone = ConeSearch("ivo://ned.ipac/Basic_Data_Near_Position")
| >>> result = cone.execute(242.811, 54.596, 0.1)
| >>> open("ned.vot",'w').write(result)
|
| Methods defined here:
|
| __init__(self, service, debug=False)
| Inputs:
| service - URI of service to be queried
| (e.g. "ivo://ned.ipac/Basic_Data_Near_Position")
|
| Optional keywords:
| debug - Print debugging information. Default = False
|
| execute(self, ra, dec, radius, saveAs=None)
| Execute the cone search.
|
| Inputs:
| ra - R.A. in degrees
| dec - Dec in degrees
| radius - Radius in degrees
|
| Option keywords:
| saveAs - Saves the query to a file. This is only available if
| the output format is a votable. Useful to save the result
| of the query to MySpace without sending the data back
| to the computer.
Also a dir(cone) would reveal the availability of the cone.info variable which provides information about the selected cone search (e.g. print cone.info)
In order to send the table to TOPCAT, then one can do:
from astrogrid.utils import broadcast broadcast(result)
The votable commands to read a table are also simplified:
from astrogrid import read_votable # Here input_format is the format of the input table, i.e., # it could be votable or fits or csv vot = read_votable(user_votable, input_format) name = vot['Name'] ra = vot['POS_EQ_RA_MAIN'] dec = vot['POS_EQ_DEC_MAIN'] for i in range(vot.nelements): print name[i], ra[i], dec[i]
In order to try this module download astrogrid.tar.gz and uncompress it into your disk. Then follow the README file and read the doc/examples.txt file (also available online in examples).
The API documentation for this module can be downloaded as a PDF file here.