Science With the Virtual Observatory
2006 Summer School

 

Python VO Client Library - Version 1.0

The Python VO Client Library is a collection of Python classes that provide simple access to astronomical data via VO protocols. This library is entirely written in Python (see http://www.python.org). Only client-side access functionality is included in this package. It is assumed that users have already been acquainted with VO protocols, web-services, and object-oriented programming in general.

Requirements

Python version 2.4.3 was used to develop and test this package. Earlier versions of Python may work but have not tested. For XML processing, the Python packages xml.sax.* are used. These packages are included in the standard Python installation. The package SOAPpy is required for SOAP and WSDL handling. Also the Python Imaging Library is needed for voAgent. See GettingPythonSOAPpy.html for more information on download information.

Directories

Source code of this package is included in the directory $NVOSS_HOME/python and contains the following subdirectories:

The PYTHONPATH environment variable should include the path of volib and sample.

Summary of core classes

The current version includes the following files in the directory volib:

Sesame.py

The Sesame class implements the interface to the Sesame name resolver service. See http://cdsweb.u-strasbg.fr/doc/sesame.htx for more information. Sesame uses the services of Simbad, NED and Vizier to resolve names. It returns RA and DEC, as well as aliases.

VOTable.py

The VOTable class provides methods to parse a VOTable source, which can be a file, a URL or a string, as well as methods to access the nodes within the VOTable. Convenient functions such as getFields() and getFieldAttrs() hide the internal complexity of VOTables. These methods return the fields of the first table of the first resource in a VOTable. More complex VOTables contains multiple resources and each resource can contain multiple tables. In those cases, getNode() or getNodesByPath() shall be used.

The VONode class represents a node in the XML file corresponding to one tag. VOTable uses Python's xml.sax parser.

ConeSearch.py

The class ConeSearch offers two main methods: getRaw() and getVOTable(). They build the query string and submit it to the ConeSearch service provider and retrieve results in raw form (string) and as VOTable. ConeSearch is a subclass of VOWebService, which is a generic class for accessing web services that are based on HTTP-GET. The class VOWebService uses Python's built-in urllib package to perform HTTP GET queries and VOTable class to store results from queries.

SIAP.py

The SIAP class is similar to ConeSearch. It also offers getRaw() and getVOTable (). Results of SIAP queries are returned in VOTable format with links to the actual images.

SkyNode.py

The current implementation is based on http://www.openskyquery/nodes/SDSS/nodeb.asmx?wsdl, and uses ADQL 0.7.4 instead of 1.0. This may change in order to be in sync with the service providers, once they switch to http://www.ivoa.net/xml/SNI/SkyNode-v1.0.wsdl . SkyNode requires the SOAPpy package and WSDLs from the corresponding services. The current implementation of this class is incomplete. In particular, SkyNode requires that ADQL query be in XML format instead of in string format. This means that an ADQL/s to ADQL/x converter is needed. However, because in general SkyNodes can be accessed from SkyPortal, and an ADQL/s to ADQL/x conversion is perform within the SkyPortal, queries to specific SkyNodes can be submitted to SkyPortal instead of directly to the SkyNodes.

SkyPortal.py

The SkyPortal class implements the interface as defined in http://www.openskyquery.net/Sky/SkyPortal/SkyPortal.asmx?WSDL. This interface offers methods to retrieve information about SkyNodes, and their tables, and columns, as well as the SubmitQuery() method, which takes a ADQL select statement, performs the query, and stores result in a VOTable. SkyPortal requires SOAPpy. The methods UploadTable() and SubmitDistributedQuery() can be used to cross-correlate a user uploaded table and one or more catalog tables.

VORegistry.py

The VORegistry class implements the interface as defined in http://nvo.stsci.edu/VORegistry/registry.asmx?WSDL. This interface provides only retrieval methods. Registration and modification methods are not available. VORegistry requires SOAPpy. Currently, the NVO Registry also supports HTTP-GET and HTTP-POST as transport protocol for its web services. It is possible to use the VOWebService class to build VORegistry instead of using SOAPpy. This can be a student exercise.

printStruct.py

This module provides a class InspectStruct and a convenient method printStruct() to output the content of a given structure, as well as the names of the variables.

__init__.py

Dummy module to make volib a Python package.

Summary of examples

Examples in the directory samples show simple ways to consume VO services. Each core class has a corresponding example file. Examples are implemented as functions that can be invoked directly from the command line. To run the example, printVOTable of VOTableEx.py, enter the command:

 Python VOTableEx.py printVOTable ../data/votable.xml outputFile.txt

where VOTableEx.py is the Python file containing the example printVOTable. This example reads the given XML file, ../data/votable.xml, and saves it in the file outputFile.txt.

Included in each example file is a special function, called runAll, which executes all examples in that file.

The following example files are in the directory samples.

SesameEx.py

Examples of how to use the Sesame class to find RA/DEC for given targets, as well as to find aliases.

nvoss2006/python/samples> python SesameEx.py resolve ngc4711 orion m80
ngc4711,192.191333,35.332250
orion,83.822083,-5.391111
m80,244.260458,-22.975111

nvoss2006/python/samples> python SesameEx.py aliases ngc4711 orion m80
ngc4711,NGC 4711,IC 3804,IRAS 12463+3536,IRAS F12463+3536,LEDA 43286,
MCG+06-28-033,NGP9 F268-1034516,UGC 7973,Z 1246.4+3536,Z 188 - 22,
IC 3804 =[G],UGC 07973 =[G],CGCG 188-022 =[G],CGCG 1246.4+3536 =[G],
MCG +06-28-033 =[G],2MASX J12484584+3519581 =[IrS],2MASXi J1248458+351957 =[IrS],IRAS  12463+3536 =[IrS],IRAS F12463+3536 =[IrS],MAPS-NGP O_268_1030434 =[G],
NGP9 F268-1034516 =[G],PGC 043286 =[G],UZC J124845.9+351958 =[G],
[M98j] 182 NED02 =[G],LEDA 043286 =[G]
orion,M 42,NGC 1976,LBN 209.13-19.35,3C 145,4C-05.21,CTA 37,
[DGW65] 26,LBN 974,Mills 05+0A,MSH 05-0-11,NAME ORI A,NAME ORI NEBULA
,NAME ORION A,NAME ORION NEBULA,NAME GREAT ORION NEBULA,NRL 6,
PKS 0532-054,PKS 0532-05,[PT56] 6,XSS J05351-0519
m80,M 80,NGC 6093,GCl 39,C 1614-228,NGC 6093 =[!*Cl],ESO 516-SC 011 =[!*Cl],
1WGA J1617.0-2258 =[XrayS]

VOTableEx.py

Examples of how to use the VOTable class.

nvoss2006/python/samples> python VOTableEx.py printCSV ../data/l.xml
Id,RA,DEC,V,B-V,U-B,V-R,R-I,V-I,Nobs,Nights,err(V),err(B-V),err(U-B),err(V-R),err(R-I),err(V-I),Distance,Position Angle
GD_108,150.19583,-7.55861,13.561,-0.215,-0.942,-0.098,-0.122,-0.220,21,12,0.0028,0.0041,0.0039,0.0041,0.0050,0.0055,18.00,139.64
GD_108,150.19583,-7.55861,13.561,-0.215,-0.942,-0.098,-0.122,-0.220,21,12,0.0028,0.0041,,0.0141,0.0050,0.0055,18.00,139.64

nvoss2006/python/samples>python VOTableEx.py printFields ../data/l.xml
Field[0]= Id,ID_MAIN,Landolt Object Identifier
Field[1]= RA,POS_EQ_RA_MAIN,Right Ascension of Object (J2000)
Field[2]= DEC,POS_EQ_DEC_MAIN,Declination of Object (J2000)
Field[3]= V,PHOT_JHN_V,Johnson V Magnitude
Field[4]= B-V,PHOT_JHN_B-V,Johnson B-V color index
Field[5]= U-B,PHOT_JHN_U-B,Johnson U-B color index
Field[6]= V-R,PHOT_COUS_V-R,Kron-Cousins V-R color index
Field[7]= R-I,PHOT_COUS_R-I,Kron-Cousins R-I color index
Field[8]= V-I,PHOT_COUS_V-I,Kron-Cousins V-I color index
Field[9]= Nobs,NUMBER,Number of Observations
Field[10]= Nights,NUMBER,Number of Unique Nights
Field[11]= err(V),ERROR,Mean error in Johnson V magnitude
Field[12]= err(B-V),ERROR,Mean error in Johnson B-V color index
Field[13]= err(U-B),ERROR,Mean error in Johnson U-B color index
Field[14]= err(V-R),ERROR,Mean error in Kron-Cousins V-R color index
Field[15]= err(R-I),ERROR,Mean error in Kron-Cousins R-I color index
Field[16]= err(V-I),ERROR,Mean error in Kron-Cousins V-I color index
Field[17]= Distance,POS_AND_DIST,Radial distance from requested position
Field[18]= Position Angle,POS_ANG-ANG,Position Angle from requested position

ConeSearchEx.py

Examples of how to use the ConeSearch class to perform queries.

nvoss2006/python/samples> python ConeSearchEx.py coneSearchCSV "http://archive.stsci.edu/hst/search.php" 53.084 -27.873 0.01 1
Dataset,Target Name,RA (J2000),Dec (J2000),Ref,Start Time,Exp Time,Instrument,Apertures,Filters/Gratings,Proposal ID,High-Level Science Products,Ang Sep (')
U8ITZU01M,GOODS,53.085416666667,-27.873166666667,2,2003-09-06 18:15:00,1000.000,WFPC2,WFALL-FIX,F300W,9481,,0.076
U8ITZU02M,GOODS,53.085416666667,-27.873166666667,2,2003-09-06 18:34:00,700.000,WFPC2,WFALL-FIX,F300W,9481,,0.076
U8LP9A01M,GOODS,53.085416666667,-27.871888888889,1,2003-09-02 19:50:00,1000.000,WFPC2,WFALL-FIX,F300W,9712,,0.101
....

VORegistryEx.py

Examples of querying the VO registry.

nvoss2006/python/samples> python VORegistryEx.py keywordSearch hubble constant
Resource Nr: 0 
Title: Groups of Galaxies (Ramella+ 1997) - List of the values of group parameters for d{rho}/{rho}=80 and V_0_=350km/s 
Description: We use a friends-of-friends algorithm to identify loose groups from
 the northern CfA2 survey covering the region 8h<={alpha}_(1950)_<=17h and
 8.5{deg}<={delta}_(1950)_<=44.5{deg}. There are 406 groups; 149 of these 
contains five or more members within the survey. Geometric simulations guide our
 choice of the selection parameters; {delta}{rho}/{rho}=80 is the limiting densi
ty contrast and V0=350km/s is the fiducial velocity linking parameter. The geome
tric simulations are particularly important for evaluating the impact of large-s
cale structure (e.g., the Great Wall) on group selection. The physical parameter
s of this large sample are coincident with our earlier results [126 groups in Ra
mella et al. (1989ApJ...344...57R)]: the median velocity dispersion in 192 (156;
 229)km/s and the median blue log(M/L) is 2.38 (2.20; 2.52). The mass-to-light r
atio (M/L) is in units of Msun/Lsun for an assumed Hubble constant, H0=100km/s/M
pc. The numbers in parentheses are 99% confidence limits. This gr 

Resource Nr: 1 
..... and 22 more resources

SIAPEx.py

Examples of how to perform SIAP queries.

nvoss2006/python/samples> python SIAPEx.py printFields "http://casjobs.sdss.org/vo/DR3SIAP/SIAP.aspx?bandpass=*" 180 0 0.2  2 

Field[0]= Title (VOX:Image_Title)
Field[1]= width (VOX:Image_Pix_Width)
Field[2]= height (VOX:Image_Pix_Height)
Field[3]= size (VOX:Image_Size)
Field[4]= RA (POS_EQ_RA_MAIN)
Field[5]= DEC (POS_EQ_DEC_MAIN)
Field[6]= scale (VOX:Image_Scale)
Field[7]= format (VOX:Image_Format)
Field[8]= url (VOX:Image_AccessReference)
Field[9]= equinox (VOX:Image_Equinox)
Field[10]= naxes (VOX:Image_Naxes)
Field[11]= naxis (VOX:Image_Naxis)
Field[12]= crtype (VOX:WCS_CoordProjection)
Field[13]= crpix (VOX:WCS_CoordRefPixel)
Field[14]= crval (VOX:WCS_CoordRefValue)
Field[15]= cdval (VOX:WCS_CDMatrix)

SkyNodeEx.py

Examples of how to access a SkyNode service.

nvoss2006/python/samples>python SkyNodeEx.py listColumns "http://openskyquery.net/nodes/SDSS/nodeb.asmx?wsdl" PhotoPrimary
Col 0) camcol, INST_ID []
Camera column

Col 1) colc, POS_CCD_X [pix]
Column center position (r' coordinates)

Col 2) colc_g, POS_CCD_X [pix]
Column center

Col 3) colc_i, POS_CCD_X [pix]
Column center

Col 4) colc_r, POS_CCD_X [pix]
Column center

... and 440 more columns

SkyPortalEx.py

Examples of how to use the SkyPortal interface.

nvoss2006/python/samples> python queryCSV 'SELECT TOP 10 s.expMag_z,s.expMag_g,s.expMag_i,s.expMag_u,s.expMag_r FROM photoobjall s' sdss
15.21213,16.61618,15.39664,18.54292,15.73994
15.21213,16.61618,15.39664,18.54292,15.74276
-9999,-9999,-9999,-9999,-9999
17.56878,18.30377,17.65186,19.24952,17.84935
17.58227,18.30776,17.66469,19.26507,17.85563
15.65058,17.78935,16.84226,19.15916,17.12633
16.63845,17.79172,16.84789,19.16779,17.13016
14.73903,15.97923,14.91371,17.49847,15.24516
12.04593,14.4198,13.47173,15.26097,14.11868
12.04648,14.36346,13.4342,15.25988,14.12265


nvoss2006/python/samples> python SkyPortalEx.py xMatch test1.csv
Upload table
****************************************
Temp table name: TMP_144662

Query Distributed CSV:
****************************************
587729652356153879,259.717784834927,25.6622309288343,259.717782786004,25.6622296171871
587729652356154640,259.721098936996,25.6648023820338,259.721099546249,25.6648094400192
587729652356154899,259.726632532715,25.6674951056152,259.7266508356,25.6674890743119
587729652356154342,259.722604756496,25.6670996653449,259.722602975049,25.6670984433228
587729652356154106,259.741107512853,25.6757341188591,259.741105598172,25.6757329621483
587729652356154343,259.737179987455,25.6753064294825,259.737180295526,25.675305780907
587729652356154635,259.738719909168,25.6768869845372,259.738716367207,25.6768855982933
587729652356154105,259.748405154499,25.6821998396252,259.748946684833,25.6819240558371
587729652356154814,259.72846145683,25.6747162418879,259.728661478031,25.6743529419369

Summary of sample data files

Running the documentation web server locally

The companion program pydoc can be used to run a documentation server on any machine. From the parent directory of volib and samples run the command:

 pydoc -p 5000

where -p 5000 indicates the a Web server be run on TCP port 5000. Using a web browser pointing to http://localhost:5000/ , one can see the Python main documentation page. All the installed packages are listed together with packages included in the PYTHONPATH environment variable. The packages volib and samples should be listed also. The inline documentation of ConeSearch for example can be reached by following the link to volib/ConeSearch.

Shui Hung Kwok
NVO Summer School 2006

The NVO Summer School is made possible through the support of the National Science Foundation and the National Aeronautics and Space Administration.