Separate “science” from “code” as much as possible:
QUERIES = [ ("twomass", "http://dc.zah.uni-heidelberg.de/tap", """SELECT TOP 1000000 raj2000, dej2000, jmag, hmag, kmag ... ("allwise", "http://tapvizier.u-strasbg.fr/TAPVizieR/tap", """SELECT raj2000, dej2000, w1mag, w2mag, w3mag, w4mag ... with vohelper.SAMP_conn() as conn: topcat_id = vohelper.find_client(conn, "topcat") for short_name, access_url, query in QUERIES: service = pyvo.dal.TAPService(access_url) result = service.run_sync(query.format(**locals()), maxrec=90000) vohelper.send_table_to(conn, topcat_id, result.table, short_name)
Also new: send retrieved tables directly to TOPCAT.
We specify services and actions in a list QUERIES. Each list item is a tuple consisting of short name (which later is used as a label in TOPCAT), an access URL, and a query, which we’ve hand-crafted here. It is conceivable to automate this a lot by generating the queries based on metadata you get from the services, but that’s for later. Obviously, new services can simply be added by appending another triple to this list.
For a detailed introduction into TAP and ADQL please look at http://docs.g-vo.org/adql
Note the maxrec parameter – when you expect large result sets, always pass an explicit maxrec to the service, or it may truncate your results. Most services have rather moderate default maxrecs (our server software assumes 2000 unless the operators override it).
(1)
Use TOPCAT’s TAP data browser to locate services and table names for TGAS and RAVE (or just use the GAVO DC TAP service with tables tgas.main and rave.main). Also figure out where the positions and some usable magnitude are, plus the proper motions from TGAS and the radial velocities from RAVE (or just blindly use ra, dec, pmra, pmdec, phot_g_mean_mag for TGAS and raj2000, dej2000, rv, and hmag for RAVE).
Write queries to retrieve proper motions from TGAS and radial velocities from RAVE for all stars between 8 and 8.5 mags of some magnitude (don’t worry about the difference between H and G for this problem).
Then, re-write fetch3.py to query the two services, and change it to send the results to Aladin (which is known as Aladin in upper case on the SAMP bus). See if you can get a nice plot of rv, pmra, and pmdec (which, of course, would be particularly interesting for the stars that happen to be in both sets).