SCIMMA notices#

Here a couple of short examples of how to stream notices through SCIMMA infrastructure

See this page adn this page to see how to install hop

IGWN alert#

from hop import stream, Stream
from hop.io import StartPosition
from hop.auth import Auth

# # Kafka topic and Hop username
# TOPIC = "igwn.gwalert"
# HOP_USER = "##"   # replace if needed

# Output files
RAW_FILE = "gwalert_messages.txt"
PARSED_FILE = "gwalert_parsed.txt"

# auth = Auth(HOP_USER, '##')

stream = Stream(start_at=StartPosition.EARLIEST)

with stream.open("kafka://kafka.scimma.org/igwn.gwalert", "r") as s:

    for message in s:

        alert = message.content

        print(alert['superevent_id'])
        print(alert['alert_type'])

Monitoring status and range of each interferometer#

from hop import stream
import json

# Kafka topic and Hop username
TOPIC = "igwn.gwistat.H1.range_history"

# Output files
OUTPUT_FILE = "range_history_H1.txt"


# Use stream.open() instead of Stream context manager
with stream.open(f"kafka://kafka.scimma.org/{TOPIC}", "r") as s, \
     open(OUTPUT_FILE, "a") as f:

    for message in s:
        # message.content is a dict, convert to JSON string
        data_json = json.dumps(message.content)
        f.write(data_json + "\n")
        f.flush()  # make sure it's written immediately
        print(data_json)  # optional: print to terminals