Skip to main content

Parsers for the NASA GCN notices.

Project description

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

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_parser import ParseError
from gcn_parser import parse
from gcn_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_parser import Topic
from gcn_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")

Parse Notices on Disk

Use a mission-specific parser when you already know the notice type and have the raw notice stored on disk.

from pathlib import Path

from gcn_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")

Parsed notices are Pydantic models. Access fields directly, or inspect the full parsed payload with:

notice.model_dump()

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

Swift is not operational at the moment, support will be added as soon as it gets back to operations (🤞). 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.

Project details


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.1.0.tar.gz (209.4 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.1.0-py3-none-any.whl (37.0 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for gcn_notice_parser-0.1.0.tar.gz
Algorithm Hash digest
SHA256 0c0ccbb4592ce5f4d3d956a0ca31d04067e8ae3da7af7d01ebed2f83dd763842
MD5 200718f053cd993fcb21d45d7e96691b
BLAKE2b-256 bd68c8a446e058df55064353a7b38fee509c4f0e387e38894b5325b25fdab16c

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for gcn_notice_parser-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 8bd7c341d8005f32e00ae41aba8936e7dce84281b040df2b7d8040d3b83e5c0d
MD5 bb372108f51e6e107372527f6359de56
BLAKE2b-256 0eab39f637f07be4e798145325be12313d265f23c4005bfbd156b85b0688a712

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page