llama.listen.lvalert package

Tools for listening to LVAlerts, LIGO/Virgo’s internal GW trigger alert system.

class llama.listen.lvalert.Alert(*args, **kwargs)

Bases: dict

A JSON alert dictionary from LVAlert. Parses the alert and reads various properties.

property advok

Check whether the alert describes an ADVOK label being applied.

property advreq

Check whether the alert has received the advocate requested label (ADVREQ) and is therefore a promising trigger.

property eventid

Return the preferred event GraceID if this is a superevent or else return this event’s GraceID if it is just a normal event.

property graceid

Return the GraceID associated with this trigger; works for both events and superevents.

property is_superevent

Check whether the alert describes a superevent.

property json

Get the JSON value. If this was originally constructed as JSON, return that; otherwise, try to serialize it. Raises a TypeError if this Alert cannot be represented as a JSON string.

property new_skymap

Check whether the alert describes the availability of a new skymap.

property production

Return whether this LVAlert object is marked as “production”.

property superid

Return the superevent GraceID if this is a superevent. Raises a KeyError if not available.

class llama.listen.lvalert.Client(processor: function, server: str = 'lvalert.cgca.uwm.edu', nodes: Tuple[str] = ('cbc_mbtaonline', 'cbc_lowmass', 'stc-testnode', 'burst_cwb', 'test_superevent', 'cbc_pycbc', 'cbc_gstlal', 'superevent', 'cbc_spiir'), heartbeat_interval: float = 180)

Bases: object

A wrapper around LVAlertClient that provides an interface for subscribing to LVAlert nodes and starting a listener. Specify the new alert processor as processor and the URL of the LVAlert server to use as server.

HEARTBEAT_NODE = 'stc-testnode'
check_heartbeat(timeout=20)

Publish a test message to self.HEARTBEAT_NODE and wait for a that same message to be parotted back by this instance’s listen function to self.heartbeat_queue. If, after waiting for timeout seconds, nothing has been received, or if the received message does not match the random string sent out, return False; otherwise, return True. You should probably restart your subscriptions if check_heartbeat fails.

This heartbeat check creates a new LVAlertClient and reconnects each time it is called. It is therefore fairly slow and should only be called at most every few minutes or so.

heartbeat_message()

Get a random message with which to run a heartbeat check.

listen(sleep=3)

Connect to self.server, subscribe to desired self.nodes, and start listening for new LVAlerts, reacting with self.processor. Sleep for sleep seconds between checks for KeyboardInterrupt or SystemExit. Will keep checking to make sure all original subscriptions are still active. Will only quit on keyboard interrupt or system exit call.

llama.listen.lvalert.get_client(server: str)

Get an LVAlertClient at the specified server URL using the login credentials stored in the LVALERT_USERNAME and LVALERT_PASSWORD environmental variables (if available).

llama.listen.lvalert.process_alert_json(node, alert_json, rundir)

Process an LVAlert JSON string as read from stdin when called by lvalert-listen.