Most commonly used functions will be available from the top pyvo module
import pyvo as vo
We want to create a catalog of available X-ray images of our favorite source (supernova remnant, Cas A).
First we look for archives that have x-ray images:
# find archives with x-ray images
archives = vo.regsearch(servicetype='image', waveband='xray')
archives
now contains a list of archives with data
len(archives)
Next, we'll search each archive to find out if they have images of our source. For that, we need to get its position:
pos = vo.object2pos('Cas A')
pos
As we search, we will write our results to a CSV file. We need to make sure that be prepared for failures by catching the DALAccessError
. This example was run in October the day after the US goverment shutdown and NASA went off-line; consequently, most of the archive queries failed.
# find images and list them in a CSV file
with open('cas-a.csv', 'w') as csv:
csv.write("Archive short name,Archive title,Image title,RA,Dec,URL\n")
for arch in archives:
print("searching %s..." % arch.shortname)
try:
matches = arch.search(pos=pos, size=0.25)
except vo.DALAccessError as ex:
print("Trouble accesing %s archive (%s)" %
(arch.shortname, str(ex)))
continue
print("...found %d images" % matches.nrecs)
for image in matches:
csv.write(','.join( (arch.shortname, arch.title, image.title,
str(image.ra), str(image.dec),
image.getdataurl()) ))
Iteration as a natural, pythonic way to process results
The interface tries to be self-explanatory
archives[0].title
archives[0].publisher
An archive service is queried via its access URL.
archives[0].accessurl
(slide)
usnob = 'http://www.nofs.navy.mil/cgi-bin/vo_cone.cgi?CAT=USNO-B1&'
srcs = vo.conesearch(usnob, pos=(45.31, 74.0), radius=0.05)
len(srcs)
srcs.fieldnames()
srcs[0]['sRa']
at = srcs.votable.to_table()
b1 = at['B1']
b1
# obtain your list of positions from somewhere
sourcenames = ["ngc4258", "m101", "m51"]
mysources = {}
for src in sourcenames:
mysources[src] = vo.object2pos(src)
# create an output directory for cutouts
import os
os.mkdir("NVSSimages")
We will use a query object to save and re-use query constraints
# setup a query object for NVSS
nvss = "http://skyview.gsfc.nasa.gov/cgi-bin/vo/sia.pl?survey=nvss&"
query = vo.sia.SIAQuery(nvss)
query.size = 0.2 # degrees square
query.format = 'image/fits'
for name, pos in mysources.items():
query.pos = pos
results = query.execute()
for image in results:
image.cachedataset(filename="NVSSimages/%s.fits" % name)
query.pos = mysources['m101']
print query.getqueryurl()