Skip to main content

Python client for consuming ZTF/LSST alerts from BABAMUL Kafka streams

Project description

babamul

Python client for consuming ZTF/LSST astronomical transient alerts from Babamul Kafka streams.

Installation

pip install babamul

Quick Start

from babamul import AlertConsumer

# Iterate over alerts
for alert in AlertConsumer(username="your_username", password="your_password", topics=["babamul.ztf.lsst-match.hosted"]):
    print(f"{alert.objectId}: RA={alert.candidate.ra:.4f}, Dec={alert.candidate.dec:.4f}")
    break

Configuration

Via Constructor

from babamul import AlertConsumer

consumer = AlertConsumer(
    username="your_username",
    password="your_password",
    topics=["babamul.ztf.lsst-match.hosted"],  # Topic(s) to subscribe to
    offset="earliest",                     # "latest" or "earliest"
    timeout=30.0,                        # Seconds to wait for messages (None = forever)
    group_id="my-consumer-group",        # Optional, auto-generated if not set
)

Via Environment Variables

export BABAMUL_KAFKA_USERNAME="your_username"
export BABAMUL_KAFKA_PASSWORD="your_password"
export BABAMUL_SERVER="kaboom.caltech.edu:9093"  # Optional, defaults to kaboom.caltech.edu:9093

Then in Python:

from babamul import AlertConsumer

# Credentials loaded from environment
for alert in AlertConsumer(topics=["babamul.ztf.lsst-match.hosted"]):
    print(f"{alert.objectId}: RA={alert.candidate.ra:.4f}, Dec={alert.candidate.dec:.4f}")

Working with Alerts

Alert Properties

from babamul import AlertConsumer

consumer = AlertConsumer(topics=["babamul.ztf.lsst-match.hosted"])
for alert in consumer:
    # Basic info
    print(f"  Object ID: {alert.objectId}")
    print(f"  Candidate ID: {alert.candid}")
    print(f"  Position: RA={alert.candidate.ra:.6f}, Dec={alert.candidate.dec:.6f}")
    print(f"  Time: {alert.candidate.datetime.isoformat()} (JD={alert.candidate.jd:.5f})")
    print(f"  Magnitude: {alert.candidate.magpsf:.2f}±{alert.candidate.sigmapsf:.2f}")

Photometry / Light Curves

from babamul import AlertConsumer

consumer = AlertConsumer(topics=["babamul.ztf.lsst-match.hosted"])
for alert in consumer:
    for phot in alert.get_photometry(): # Full light curve
        if phot.magpsf is not None:
            print(f"  JD {phot.jd:.5f}: {phot.magpsf:.2f} mag ({phot.band})")
        else:
            print(f"  JD {phot.jd:.5f}: non-detection, limit={phot.diffmaglim:.2f} ({phot.band})")

Cutouts

from babamul import AlertConsumer

consumer = AlertConsumer(topics=["babamul.ztf.lsst-match.hosted"])
for alert in consumer:
    alert.show_cutouts()  # Displays science, template, and difference images

Context Manager

For proper resource cleanup:

from babamul import AlertConsumer

with AlertConsumer(username="user", password="pass", topics=["babamul.ztf.lsst-match.hosted"]) as consumer:
    for i, alert in enumerate(consumer):
        # process alerts
        if i >= 100:
            break
# Consumer is automatically closed

Error Handling

from babamul import AlertConsumer, AuthenticationError, BabamulConnectionError

consumer = None
try:
    consumer = AlertConsumer(username="user", password="pass", topics=["babamul.ztf.lsst-match.hosted"])
    for alert in consumer:
        # process alerts
        pass
except AuthenticationError:
    print("Invalid credentials")
except BabamulConnectionError:
    print("Cannot connect to Kafka server")
finally:
    if consumer:
        consumer.close()

Available Topics

Babamul provides several topic categories based on survey and classification:

LSST Topics

LSST-only (no ZTF counterpart):

Topic Description
babamul.lsst.no-ztf-match.stellar Alerts classified as stellar
babamul.lsst.no-ztf-match.hosted Alerts with a host galaxy
babamul.lsst.no-ztf-match.hostless Alerts without a host galaxy
babamul.lsst.no-ztf-match.unknown Unclassified alerts

LSST with ZTF match:

Topic Description
babamul.lsst.ztf-match.stellar Alerts classified as stellar
babamul.lsst.ztf-match.hosted Alerts with a host galaxy
babamul.lsst.ztf-match.hostless Alerts without a host galaxy
babamul.lsst.ztf-match.unknown Unclassified alerts

ZTF Topics

ZTF-only (no LSST counterpart):

Topic Description
babamul.ztf.no-lsst-match.stellar Alerts classified as stellar
babamul.ztf.no-lsst-match.hosted Alerts with a host galaxy
babamul.ztf.no-lsst-match.hostless Alerts without a host galaxy
babamul.ztf.no-lsst-match.unknown Unclassified alerts

ZTF with LSST match:

Topic Description
babamul.ztf.lsst-match.stellar Alerts classified as stellar
babamul.ztf.lsst-match.hosted Alerts with a host galaxy
babamul.ztf.lsst-match.hostless Alerts without a host galaxy
babamul.ztf.lsst-match.unknown Unclassified alerts

Wildcard Subscriptions

You can use wildcards to subscribe to multiple topics:

from babamul import AlertConsumer
# All LSST topics
consumer = AlertConsumer(topics=["babamul.lsst.*"], ...)

# All ZTF topics with LSST matches
consumer = AlertConsumer(topics=["babamul.ztf.lsst-match.*"], ...)

# All hosted alerts from both surveys
consumer = AlertConsumer(topics=["babamul.*.*.hosted"], ...)

Requirements

  • Python >= 3.10
  • confluent-kafka >= 2.3.0
  • fastavro >= 1.9.0
  • pydantic >= 2.0.0

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

babamul-0.1.0a2.tar.gz (360.2 kB view details)

Uploaded Source

Built Distribution

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

babamul-0.1.0a2-py3-none-any.whl (16.4 kB view details)

Uploaded Python 3

File details

Details for the file babamul-0.1.0a2.tar.gz.

File metadata

  • Download URL: babamul-0.1.0a2.tar.gz
  • Upload date:
  • Size: 360.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for babamul-0.1.0a2.tar.gz
Algorithm Hash digest
SHA256 5ddc370d5d2cfd5e89ff91559591c76cdfd41f6239059a5b864673b459609de6
MD5 222b35a7aedc98c3c84e3fb84e32c575
BLAKE2b-256 3349fbc44c15f87193fb7939282fb6cdf62b16381b9970594bc512b9500c6678

See more details on using hashes here.

Provenance

The following attestation bundles were made for babamul-0.1.0a2.tar.gz:

Publisher: publish.yml on boom-astro/babamul

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file babamul-0.1.0a2-py3-none-any.whl.

File metadata

  • Download URL: babamul-0.1.0a2-py3-none-any.whl
  • Upload date:
  • Size: 16.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for babamul-0.1.0a2-py3-none-any.whl
Algorithm Hash digest
SHA256 0d8edca40b2512726aaf6f67ce63b656064d114c0db174ef11bbe2783c1980c8
MD5 166673a1709ecf9f515bbee7b16af1d0
BLAKE2b-256 19d2ca12783923d62660d3772ec25d184461e2177f120ba3d1571e4014f26f68

See more details on using hashes here.

Provenance

The following attestation bundles were made for babamul-0.1.0a2-py3-none-any.whl:

Publisher: publish.yml on boom-astro/babamul

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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