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_KAFKA_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}")
Development Setup
For development and testing, use a .env file to manage your credentials:
# 1. Copy the example file
cp tests/.env.example tests/.env
# 2. Edit tests/.env with your credentials
# Get credentials at: https://babamul.caltech.edu/signup
nano tests/.env
# 3. Load automatically when running tests
# The .env file is gitignored and will not be committed
Your tests/.env file should look like:
BABAMUL_KAFKA_USERNAME=your_username
BABAMUL_KAFKA_PASSWORD=your_password
BABAMUL_API_TOKEN=your_api_token
Most examples and tests will automatically load credentials from .env using python-dotenv.
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"], ...)
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file babamul-0.1.0a4.tar.gz.
File metadata
- Download URL: babamul-0.1.0a4.tar.gz
- Upload date:
- Size: 280.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0dc8145cac45a3a6f74aa655790f4731ed5e184481546904345f814040d233f8
|
|
| MD5 |
d492f73f5b1266d1f8279f426fb7659b
|
|
| BLAKE2b-256 |
c2e42a56ffefbf483201896e4d2a6384d995b488152467aa3f1d71fe40062d57
|
Provenance
The following attestation bundles were made for babamul-0.1.0a4.tar.gz:
Publisher:
publish.yml on boom-astro/babamul
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
babamul-0.1.0a4.tar.gz -
Subject digest:
0dc8145cac45a3a6f74aa655790f4731ed5e184481546904345f814040d233f8 - Sigstore transparency entry: 986769317
- Sigstore integration time:
-
Permalink:
boom-astro/babamul@d60ebec369a93a4681857aa7381cdc54ed66d89a -
Branch / Tag:
refs/tags/v0.1.0a4 - Owner: https://github.com/boom-astro
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@d60ebec369a93a4681857aa7381cdc54ed66d89a -
Trigger Event:
release
-
Statement type:
File details
Details for the file babamul-0.1.0a4-py3-none-any.whl.
File metadata
- Download URL: babamul-0.1.0a4-py3-none-any.whl
- Upload date:
- Size: 28.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4398d9c3ca9b7e8cb9b4d0c92db6da1cb37b2c71e402c23c6eeddf7d61d40740
|
|
| MD5 |
4ba62f1a2799cb8b00264fd36bdfa462
|
|
| BLAKE2b-256 |
207d68f09eabfb5540d5f1db7780ca933f32c19d95caafe410010bf35d98c18a
|
Provenance
The following attestation bundles were made for babamul-0.1.0a4-py3-none-any.whl:
Publisher:
publish.yml on boom-astro/babamul
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
babamul-0.1.0a4-py3-none-any.whl -
Subject digest:
4398d9c3ca9b7e8cb9b4d0c92db6da1cb37b2c71e402c23c6eeddf7d61d40740 - Sigstore transparency entry: 986769415
- Sigstore integration time:
-
Permalink:
boom-astro/babamul@d60ebec369a93a4681857aa7381cdc54ed66d89a -
Branch / Tag:
refs/tags/v0.1.0a4 - Owner: https://github.com/boom-astro
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@d60ebec369a93a4681857aa7381cdc54ed66d89a -
Trigger Event:
release
-
Statement type: