22. Higher SAMP Magic

Let’s say you’re debugging your pipeline and want to manually inspect “weird” objects by querying a set of other catalogs have on them.

Plan: Write a program that other clients

  • can send tables to (table.load.votable) and then
  • when a table row is selected, computes a new table
  • that’s then broadcast.
Pattern for listening:
conn.bind_receive_notification(
  "table.highlight.row",
  self.handle_selection)

SAMP is based on messages; there are several message types (MTypes), which are documented on the IVOA wiki.

To make our program ready to receive tables via SAMP, we have to listen to table.load.votable.

To react to row selections, we have to react to table.highlight.row. An alternative would be coord.pointAt.sky, which communicates where people are looking at; but in this case we’re looking for odd rows, not odd positions.

The SAMP client objects’s bind_receive_notification method arranges for the hub to call a function when a message of a certain MType comes in. The calling pattern is a bit complicated, but what really counts is a dictionary of the parameters passed to the originating call; according to what’s said on the wiki, you’ll be passed a table-id, a URL, and a row index.

Problems

(1)

The somewhat verbose argument list for a handler of a SAMP message is handler(privkey, sender_id, msg_id, mtype, params, extra). You can usually ignore all of these except the params, which are a dicitionary.

Write a little program that listens for coord.pointAt.sky messages and just prints the sky coordinate looked at. Test it by starting the program when TOPCAT or Aladin are already running. In Aladin, you can just pan around. In TOPCAT, you must configure an activation action to see something.

Hint 1: The basic code to obtain a client object as discussed on the “Add SAMP Magic” slide.

Hint 2: At least some versions of astropy don’t show exceptions raised within a handler function. To save yourself grief in such cases, decorate your handler function with vohelper.show_exception, that is, defined it like this:

@vohelper.show_exception
def print_coord(privkey, sender_id, msg_id, mtype, params, extra):

Hint 3: This program just waits for events from the outside, which is common for server programs but perhaps scary to you if you’ve mainly written “user code” so far. Astropy makes it easy for you, though – just have your program wait with raw_input and you’re fine.


Markus Demleitner, Hendrik Heinl