#!/usr/bin/env python # sample of building and running an application import xmlrpclib as x import sys import os import time prefix = file(os.path.expanduser("~/.astrogrid-desktop")).next().rstrip() s = x.Server(prefix + "xmlrpc") # create a template tool structure print "Creating template from SDSS-DR3 application: " print " ivo://uk.ac.le.star/SDSS-DR3/images/CEA-application" struct = s.astrogrid.applications.createTemplateStruct("ivo://uk.ac.le.star/SDSS-DR3/images/CEA-application","default") home = s.astrogrid.myspace.getHome() # Set up a list of ra, decs. Could be read from a file. In this case # just a list of 10 equal ra, dec #ra=[249.0, 248.5, 248., 247.5, 247., 246.5, 246., 245.5, 245., 244.5] #dec=[42., 41.5, 41., 40.5, 40., 39.5, 39., 38.5, 38., 37.5] ra=[202.64] dec=[-1.6] i=0 while (i+1<=len(ra)): inputs = struct['input'] inputs['POS']['value'] = "%s,%s" % (ra[i], dec[i]) inputs['SIZE']['value'] = "1.0" inputs['FORMAT']['value'] = "ALL" inputs['BANDPASS']['value'] = "*" # setup a new timestamped file in myspace. newFile = home + "/agoc/sdss-results" + str(time.time()) +".vot" # send the output to this file struct['output']['IMAGES']['value'] = newFile struct['output']['IMAGES']['indirect'] = True # convert struct back to a tool document. doc = s.astrogrid.applications.convertStructToDocument(struct) #verify that the document is valid - i.e. we've supplied all the required parameters. # will throw an exception on error. s.astrogrid.applications.validate(doc) try: execId = s.astrogrid.applications.submit(doc) print "" print " Interface: ", struct['interface'] print " Inputs: " print " POS: ", inputs['POS'] print " SIZE: ", inputs['SIZE'] print " FORMAT: ", inputs['FORMAT'] print " BANDPASS: ", inputs['BANDPASS'] print " Output:" print " IMAGES: ", struct['output']['IMAGES']['value'] print " Execution Id: ", execId except: continue i=i+1 # example of linking back into the gui - add the new application to the job monitor. #add execId to the job monitor, and display the monitor. s.userInterface.jobMonitor.addApplication("scripted application",execId) # Showing the job window only needs to be done once if i==0: s.userInterface.jobMonitor.displayApplicationTab() s.userInterface.jobMonitor.show() # give it a refresh to find the status. s.userInterface.jobMonitor.refresh() # meanwhile, lets monitor the progress of the job programmatically # a busy-wait loop until it finishes. execInfo = s.astrogrid.applications.getExecutionInformation(execId) while execInfo['status'] == "RUNNING" or execInfo['status'] == "PENDING": time.sleep(15) execInfo = s.astrogrid.applications.getExecutionInformation(execId) if execInfo['status'] == "ERROR": print "Application ended in error" else: #print results from myspace. print s.astrogrid.myspace.read(newFile)