Skip to main content

Reusable TOMToolkit app to support gravitational wave superevent and other nonlocalized event EM follow-up observations.

Project description

pypi run-tests Codacy Badge Coverage Status

tom_nonlocalizedevents

This reusable TOM Toolkit app supports electromagnetic (EM) follow-up observations of non-localized events: gravitational-wave (GW) superevents, gamma-ray bursts, neutrino events, and X-ray transients. GW events currently have the most support and are ingested from the IGWN alert stream or manually from GraceDB, their skymaps are processed into healpix credible regions, and candidate targets can be matched against those regions.

Requirements

  • PostgreSQL is required to support the healpix MOC volume-map lookups via healpix-alchemy.

  • tom-alertstreams is required to listen to the IGWN alert stream.

Installation

  1. Install the package into your TOM environment:

    pip install tom-nonlocalizedevents
    
  2. In your project's settings.py, add tom_nonlocalizedevents to INSTALLED_APPS. With TOM Toolkit 3's scaffold that looks like:

    INSTALLED_APPS = TOMTOOKIT_INSTALLED_APPS + [
        'tom_nonlocalizedevents',
    ]
    

    (TOMTOOKIT_INSTALLED_APPS is the (misspelled) literal variable name in the TOM Toolkit scaffold — don't "correct" the spelling.)

  3. Also in settings.py, add the settings this app reads:

    # required: the model layer builds Hermes links from this URL
    HERMES_API_URL = 'https://hermes.lco.global'
    
    # optional, shown with their defaults:
    GRACEDB_API_URL = 'https://gracedb.ligo.org/api/'  # for manual GraceDB ingestion
    SAVE_TEST_ALERTS = True  # ingest test events (event ids beginning with 'M')?
    
  4. Run python manage.py migrate to create the tom_nonlocalizedevents models.

  5. Optionally, set environment variables to tune the SQLAlchemy engine used for the healpix lookups:

    Env variable Description Default
    SA_DB_CONNECTION_URL Postgres connection URL for SQLAlchemy built from the Django default database
    POOL_SIZE Connections kept open in the pool (docs) 5
    MAX_OVERFLOW Connections allowed in pool "overflow" (docs) 10
    CREDIBLE_REGION_PROBABILITIES JSON list of credible-region probabilities checked for each candidate '[0.25, 0.5, 0.75, 0.9, 0.95]'

Features

  • The event list page (/nonlocalizedevents/): lazy-loading tabs — All, Gravitational Wave (the landing tab), Gamma-ray Burst, Neutrino, X-ray Transient, Unknown — each with its own sortable, filterable htmx table. The GW tab carries the science columns and filters (1/FAR, most-likely classification, distance, HasNS, HasRemnant); the other event types currently show a generic table awaiting type-specific columns.

  • Event detail pages, resolved per event type (type-specific templates with a generic fallback), showing the event's sequences, localization areas and distances, and external links (Hermes, GraceDB, Treasure Map).

  • Manual GraceDB ingestion: the Ingest event from GraceDB button on the list page (login required), or the equivalent management command:

    python manage.py ingest_LVK_event S230518h
    
  • REST API endpoints under /api/: nonlocalizedevents/, eventlocalizations/, and eventcandidates/ (with bulk-create and PATCH support for candidates).

Configuration to ingest GW events from the IGWN alert stream

To ingest GW events automatically, install and configure tom_alertstreams in your TOM (tom_alertstreams is intentionally not a dependency of this app — it is only needed for stream listening). Point the igwn.gwalert topic at this app's handler:

ALERT_STREAMS = [
    {
        'ACTIVE': True,
        'NAME': 'tom_alertstreams.alertstreams.hopskotch.HopskotchAlertStream',
        'OPTIONS': {
            'URL': 'kafka://kafka.scimma.org/',
            'USERNAME': os.getenv('SCIMMA_AUTH_USERNAME'),
            'PASSWORD': os.getenv('SCIMMA_AUTH_PASSWORD'),
            'TOPIC_HANDLERS': {
                'igwn.gwalert':
                    'tom_nonlocalizedevents.alertstream_handlers.igwn_event_handler.handle_igwn_message',
            },
        },
    },
]

Then run the stream listener: python manage.py readstreams.

Development

Extending for an event type

The per-event-type tabs and detail pages are extension points. To implement an event type (e.g. gamma-ray bursts), add its type-specific columns, filters, and detail content to its stub classes and template:

  • tables.pyGammaRayBurstEventTable: add type-specific columns.
  • filters.pyGammaRayBurstEventFilterSet: add type-specific filters.
  • templates/tom_nonlocalizedevents/detail/grb_detail.html — extend the generic detail page with type-specific content.

Running the tests

The test suite needs a reachable PostgreSQL. The repository's docker-compose.yml provides one whose credentials match the test harness defaults:

docker compose up -d
python tom_nonlocalizedevents/tests/run_tests.py   # from the repository root

Pointing a TOM at the docker-compose database

When developing a TOM (or developing tom_nonlocalizedevents in the context of a TOM), this Django DATABASES configuration dictionary matches the PostgreSQL database configured by the docker-compose.yml in this repo. Put it in settings.py or local_settings.py.

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.postgresql',
        'NAME': 'tom_nonlocalizedevents',  #  POSTGRES_DB in docker-compose.yml
        'USER': 'postgres',
        'PASSWORD': 'postgres',
        'HOST': '127.0.0.1',
        'PORT': '5432',
    },
}

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

tom_nonlocalizedevents-1.0.0.tar.gz (60.2 kB view details)

Uploaded Source

Built Distribution

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

tom_nonlocalizedevents-1.0.0-py3-none-any.whl (84.4 kB view details)

Uploaded Python 3

File details

Details for the file tom_nonlocalizedevents-1.0.0.tar.gz.

File metadata

  • Download URL: tom_nonlocalizedevents-1.0.0.tar.gz
  • Upload date:
  • Size: 60.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.0.1 CPython/3.12.8

File hashes

Hashes for tom_nonlocalizedevents-1.0.0.tar.gz
Algorithm Hash digest
SHA256 9ccdd0883e5cf078905de9f929c05f166904a521649850d47443954f404a6822
MD5 62b7df1b94493ab623dee0856a9cf15d
BLAKE2b-256 4b0ce1022999dc7d7fcf84b17c7ee77a60b7b463827dd288752ae34cbef50c9b

See more details on using hashes here.

Provenance

The following attestation bundles were made for tom_nonlocalizedevents-1.0.0.tar.gz:

Publisher: pypi-release.yml on TOMToolkit/tom_nonlocalizedevents

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

File details

Details for the file tom_nonlocalizedevents-1.0.0-py3-none-any.whl.

File metadata

File hashes

Hashes for tom_nonlocalizedevents-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 48beef287a41e8071fea04883fdbf892cfdc6b0538433d0156a29ac0aa0f8223
MD5 d0ab53a79bd1725f5e44a98d66c21bfa
BLAKE2b-256 c18f0a847f3b091d1ea38dd5c3f8f4e4a9b14905841dea45c17b37fb6b217881

See more details on using hashes here.

Provenance

The following attestation bundles were made for tom_nonlocalizedevents-1.0.0-py3-none-any.whl:

Publisher: pypi-release.yml on TOMToolkit/tom_nonlocalizedevents

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