This website (www2.astrogrid.org) is now deprecated - please go to www.astrogrid.org for up to date information.
Example Uses
Remeber, in order to run this examples you will need the workbench running. You will get some errors if not.
Getting Help
Remeber that you can get help on the classes and methods using the standard Python help procedures, e.g. help(ConeSearch). If using IPython (recommended for interactive use) just type:
>>> ConeSearch?
Configuration
This step is optional. You can write configuration values into the file '~/.python-acr'. These are mine:
debug = True verbose = True autologin = True [community] username = *your username here* password = *your password here* community = *your community here*
With these values you will not need to login to your account, that will be handled automatically. Also all debug flags are on to see what is happening.
Example 1: Performing a cone search
The following example searches the registry for the NED identifier and performs a cone search around a position:
>>> from astrogrid import Registry, ConeSearch
>>> reg = Registry()
>>> items = reg.searchCone('NED') # Perform basic search for cones
>>> print len(items) # How many results we have got?
1
>>> ned = item[0]['id']; print ned
ivo://ned.ipac/Basic_Data_Near_Position
>>> cone = ConeSearch(ned)
>>> votable = cone.execute(180.0, 0.0, 0.2)
>>> from astrogrid.utils import broadcast # If TOPCAT is running we can send the
>>> broadcast(votable) # result using Plastic
>>> from astrogrid.utils import read_votable # We can also operate with the votable
>>> vot = read_votable(votable) # First we parse the output into a more
>>> ra = vot['pos_ra_equ'] # convenient structure and then we can read
>>> dec = vot['pos_dec_equ'] # the columns.
>>> # We can save the results to MySpace instead of getting them to the local computer
>>> ivorn = cone.execute(180.0, 0.0, 0.2, saveAs='#test1/ned.vot')
>>> print ivorn
'ivo://ukidss.roe.ac.uk/egonzales#test1/ned.vot'
>>> broadcast(ivorn) # We can still send the table to TOPCAT
Example 2: Performing a SIAP search
The basics of performing a SIAP search are similar to the previous cone search example:
>>> from astrogrid import Registry, SiapSearch
>>> reg = Registry()
>>> items = reg.searchSiap('SDSSDR4') # Perform the search
>>> print [r['id'] for r in items] # We have several items now
['ivo://sdss.jhu/services/SIAPDR4-images',
'ivo://sdss.jhu/services/SIAPDR4-CutOut']
>>> sdss = items[0]['id'] # We want the first one
>>> siap = SiapSearch(sdss)
>>> votable = siap.execute(180.0, 2.0, 1.0) # Execute the query
>>> votable, thread = siap.execute(180.0, 2.0, 0.1, \ # Something different. We save the
... saveAs='#sdss1/sdss.vot', saveDatasets='#sdss1') # images to MySpace.
>>> print thread.isAlive() # The process returns a pointer to the thread
True # which is saving the images so you can poll
>>> print thread.isAlive() # the status.
False
Example 3: Working with MySpace
The class 'MySpace' provides methods to work with MySpace:
>>> from astrogrid import MySpace
>>> m = MySpace()
>>> m.ls()
>>> m.rm('#test1')
ERRIR: Cannot delete a folder without first deleting all its children
>>> m.rm('#test1', recursive=True)
>>> data = m.readfile('#sdss1/data-0.fits')
Example 4: Running an application
For this example we are going to create a mosaic from 2MASS images using Montage. First we create an instance of the Applications class with the IVORN of the Montage application obtained from a registry search. The we fill in the app.inputs and app.outputs values and submit the application. Then we poll the status of the application until it is completed and we read the result which has been saved to MySpace.:
>>> from astrogrid import Applications, MySpace
>>> m = MySpace() # We are going to use MySpace
>>> app = Applications('ivo://astrogrid.cam/Montage/prototype/2MASS-mosaic')
>>> app.inputs['ra']['value'] = 312.75 # We fill in the inputs. Information is
>>> app.inputs['dec']['value'] = 44.37 # available by printing app.info
>>> app.inputs['size']['value'] = 0.3
>>> app.inputs['band']['value'] = 'K'
>>> app.outputs['out.fits']['value'] = m.home()+'2mass/mosaic.fits'
>>> app.outputs['out.fits']['indirect'] = True
>>> thread = app.submit() # Submit the application
>>> thread.status() # and check status
'PENDING'
>>> thread.status()
'RUNNING'
>>> thread.status()
'COMPLETED'
After some minutes, we can read the results and save them to local disk:
>>> ofile = thread.results()[1]
>>> image = m.readfile(ofile)
>>> open('image.fits', 'w').write(image)
