Skip to main content

GCN Notice Parser

gcn-notice-parser is a Python 3.11+ package for parsing GCN Kafka messages or raw notice bytes into Pydantic models with named, typed fields.

Installation

The package is on PyPI. You can install it with:

pip install gcn-notice-parser

Live Kafka examples also need gcn-kafka:

pip install gcn-notice-parser gcn-kafka

Quickstart

Parse Live GCN Messages

from gcn_kafka import Consumer

from gcn_notice_parser import ParseError
from gcn_notice_parser import parse
from gcn_notice_parser import supported_topics

consumer = Consumer(
    # fill blanks with your GCN credentials
    client_id="...",
    client_secret="...",
    config={"auto.offset.reset": "earliest"},
)
consumer.subscribe(supported_topics())

while True:
    for message in consumer.consume(timeout=1):
        try:
            notice = parse(message)
        except ParseError as exc:
            print(f"Failed to parse {message.topic()}: {exc}")
            continue

        print(f"{message.topic()}: {type(notice).__name__}")
        print(notice)

Parse Selected Topics

Subscribe to selected topics when you know which notice family you want. This example listens for Fermi GBM final-position and ground-position notices and prints the burst position.

from gcn_kafka import Consumer

from gcn_notice_parser import Topic
from gcn_notice_parser import parse

consumer = Consumer(
    # fill blanks with your GCN credentials
    client_id="...",
    client_secret="...",
    config={"auto.offset.reset": "earliest"},
)
consumer.subscribe([Topic.FERMI_GBM_FIN_POS, Topic.FERMI_GBM_GND_POS])

while True:
    for message in consumer.consume(timeout=1):
        notice = parse(message)

        print(f"RA: {notice.ra} deg")
        print(f"Dec: {notice.dec} deg")
        print(f"Error radius: {notice.error_radius} deg")

Mission-specific parsers

Use a mission-specific parser when you know the notice type in advance. This is useful when parsing a notice stored on disk.

from pathlib import Path

from gcn_notice_parser.fermi import parse_fermi_gbm_fin_pos

notice = parse_fermi_gbm_fin_pos(Path("fermi_gbm_fin_pos.xml").read_bytes())

print(f"RA: {notice.ra} deg")
print(f"Dec: {notice.dec} deg")
print(f"Error radius: {notice.error_radius} deg")

Supported Topics

Currently supported GCN topics are:

gcn.classic.voevent.FERMI_GBM_ALERT
gcn.classic.voevent.FERMI_GBM_FIN_POS
gcn.classic.voevent.FERMI_GBM_FLT_POS
gcn.classic.voevent.FERMI_GBM_GND_POS
gcn.classic.voevent.FERMI_LAT_OFFLINE
gcn.classic.voevent.FERMI_LAT_POS_DIAG
gcn.classic.voevent.FERMI_LAT_POS_INI
gcn.classic.voevent.FERMI_LAT_POS_UPD
gcn.notices.svom.voevent.grm
gcn.notices.svom.voevent.eclairs
gcn.notices.svom.voevent.mxt
gcn.notices.einstein_probe.wxt.alert

More will come. In need of a specific parser? Consider sending a PR, or asking in the discussion section.

Documentation

Looking for parse notices schema? For this and more, check out the documentation.

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

gcn_notice_parser-0.2.0.tar.gz (207.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

gcn_notice_parser-0.2.0-py3-none-any.whl (37.3 kB view details)

Uploaded Python 3

File details

Details for the file gcn_notice_parser-0.2.0.tar.gz.

File metadata

  • Download URL: gcn_notice_parser-0.2.0.tar.gz
  • Upload date:
  • Size: 207.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: python-httpx/0.27.0

File hashes

Hashes for gcn_notice_parser-0.2.0.tar.gz
Algorithm Hash digest
SHA256 b8bc3b2059d35d6147e3a50ee7fb316dfd68f7c1becc522bd534f1b04adbd474
MD5 aadd47d35a5989a0610b7f2a6b19b9b7
BLAKE2b-256 8a945b2f6dd25ddc5e5e4ae3a83f78912ef7c650fb42e906e79b47e82e8a9e60

See more details on using hashes here.

File details

Details for the file gcn_notice_parser-0.2.0-py3-none-any.whl.

File metadata

File hashes

Hashes for gcn_notice_parser-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 1fb50d5de432ede63641019c988cc67a98d01b0a2f412ed66436f930397a0a87
MD5 30479a03503a4e119bdbb74816d33d8b
BLAKE2b-256 2f506255872fa388ddf33a48e14c8e8e8089b478e4cd9daaae8b0724584b5c55

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

0.2.0 This release

2 files

0.1.1

2 files

0.1.0

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page