Example script to query a data base
See Scripting with Python for AstroGrid for full details. This example assumes that you have already followed the one-time set up intructions and got the AstroGrid Desktop running. It uses the STILTS tmatch2 command to crossmatch two files held in VOSpace.
The expected system responses are commented for your convenience if you cut and paste the script, or you can edit them out.
python
from astrogrid import acr, MySpace, Applications
acr.login()
# You should see messages like
# DEBUG:root:Trying connection with running AR
# DEBUG:root:getattr:astrogrid
# True
# Set input and output file locations
inf1 = '#Output/IRAS.vot'
inf2 = '#Output/2MASS-PSC.vot'
outf = '#Output/IRAS_2M_OrionKL.vot'
# Set search radius in arcsec
radius = 30
# The default sky matcher is being used, as in the example
# using STILTS tmatch2 from Task Runner
app = Applications('ivo://starlink.ac.uk/stilts', 'tmatch2')
app.inputs['tmatch2_in1']['value'] = inf1
app.inputs['tmatch2_in2']['value'] = inf2
app.inputs['tmatch2_values1']['value'] = 'ra dec'
app.inputs['tmatch2_values2']['value'] = 'ra dec'
app.inputs['tmatch2_params']['value'] = radius
app.inputs['tmatch2_ifmt1']['value'] = '(auto)'
app.inputs['tmatch2_ifmt2']['value'] = '(auto)'
app.inputs['tmatch2_ofmt']['value'] = 'votable-tabledata'
app.inputs.pop('tmatch2_icmd1')
app.inputs.pop('tmatch2_icmd2')
app.inputs.pop('tmatch2_ocmd')
app.outputs['tmatch2_out']['value'] = outf
job = app.submit()
# CEA delegate - running execute()...
job.status()
# 'UNKNOWN'
# wait a bit
job.status()
# 'COMPLETED'
# You can now perform further scripting operations on the
# output file as outf or open a VO Desktop File Explorer
# and view IRAS_2M_OrionKL.vot, send it to TopCat etc.
