11. Step 1a: Synchronous Queries

Run queries via TAP:

access_url = "http://dc.g-vo.org/tap"

service = pyvo.dal.TAPService(access_url)
result = service.run_sync(
  """SELECT raj2000, dej2000, jmag, hmag, kmag
        FROM twomass.data
        WHERE jmag<3""")
for row in result:
  print(row["raj2000"], row["jmag"])

[See fetch3.py]

This is another instance of the PyVO pattern “create a service object, then call a method”. In this case, we’re calling run_sync – this is not called query as for the other services because TAP has two modes of operation; we’ll get to the other one (unsurprisingly called async) in a moment.

What’s coming back from run_sync is a sequence of dal.Record elements (well, the truth about TAPResults is a bit more complex, but that’s the gist of it).

result.to_table() is an astropy.table instance – here, we take a column from it. To save it, say:

with open("result.vot") as f:
  result.to_table().write(output=f, format="votable")

Problems

(1)

Write a program that prints the number of rows in the table arihip.main in the TAP service at http://dc.g-vo.org/tap (do not pull all the rows and use python’s len).

Hint: With ADQL’s AS construct you can control the names of table columns.


Markus Demleitner, Hendrik Heinl