GithubHelp home page GithubHelp logo

roald87 / gracedb Goto Github PK

View Code? Open in Web Editor NEW
7.0 3.0 0.0 795 KB

Telegram bot which you can use to get information on gravitational wave events from LIGO/Virgo.

License: Apache License 2.0

Python 88.26% HTML 11.74%
gravitational-waves ligo virgo gracedb telegram-bot python37 telegram app science astronomy

gracedb's Introduction

GraceDbBot

A Telegram bot which you can use to get information on gravitational wave events from LIGO/Virgo.

Usage

Add the bot by searching for GraceDbBot on Telegram or click here. Bot is down and project is archived. To host it yourself see below

Currently the bot responds to the following commands:

/help or /start

Shows a welcome message and an overview of all possible commands.

/latest

Shows the latest measured event.

/event

Select an event where you want to see the details of.

/stats

Shows an overview of all measured events during observational run 3.

/status

Shows the current status of all three detectors.

/subscribe and /unsubscribe

After subscribing you will automatically receive a message when a new event was measured or an existing event was updated or retraced.

Installation for self hosting

If you want to host the bot yourself, you can install it as follows.

  1. Clone this repo

    [email protected]:Roald87/GraceDB.git
    
  2. Create a new virtual environment with pip or conda

    conda create -n gracebot python=3.7 
    conda activate gracebot
    # not all package are available for installation via conda
    pip install -r ~/path/to/gracebot/requirements.txt
    # Install venv to create virtual environments
    python3 -m pip install --user venv
    # Create a new virtual environment
    python3 -m venv gracebot
    # Activate the virtual environment you just created
    source gracebot/bin/activate
    # Install required packages 
    pip install -r ~/path/to/gracebot/requirements.txt
    
  3. Create a new telegram bot via the instructions here.

  4. Create a new file /path/to/gracebot/gracebot/config.py.

  5. Add the following five variables to config.py. For API_TOKEN use the token you were given when you registered the new bot. Do not share this api token or any of the other variables in this file with anyone, since it can be used to control your bot. Then secret, preliminary_command, update_command and retraction_command should be hard to guess randomized strings. You can generate these yourself. They are used to trigger bot commands.

    API_TOKEN = '110201543:AAHdqTcvCH1vGWJxfSeofSAs0K5PALDsaw'
    secret = '2eh4y5gqfliqoy2t'
    preliminary_command = 'fjsapdofih9328fhjdsa'
    update_command = 'adsfj933092hpajsvbdfa32'
    retraction_command = 'q23tgrgaqgn3ooq3g'
  6. Download ngrok and register an account to expose gracebot to the internet.

  7. Create a file /path/to/ngrok/config.yml and add your authtoken to the config file

    authtoken: dfasj8oiafh3fsadjfhsdjfha
    tunnels:
        default:
            proto: http
            addr: 8080
  8. Start the ngrok tunnel

    cd ~; nohup ngrok/ngrok start --all --config="ngrok/config.yml" &
  9. Start gracebot and the listener which listens for new events

    # Activate the virtual environment
    source ~/path/to/venvs/gracedb/bin/activate
    printf 'Starting GraceBot.'
    cd ~/path/to/gracebot/
    nohup python3 gracebot/main.py > gracebot.out 2>&1&
    sleep 3
    printf 'Starting GCN listener.'
    nohup python gracebot/listener.py > listener.out 2>&1&

Disclaimer

I'm not an expert on gravitational waves. So if you see something which doesn't make sense, please let me know.

gracedb's People

Contributors

dependabot[bot] avatar roald87 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

gracedb's Issues

Speed up /status command

/status command can easily be sped up by only retrieving the data from the source once, instead of once times for each detector.

Most likely event type stopped working for event S190701AH

The following error showed when /stats didn't work and /latest didn't show the event type. I think it was after event S190701AH was updated.

2019-07-06 21:03:47 	 aiohttp.server ERROR    Error handling request
Traceback (most recent call last):
  File "/root/venvs/gracedb/lib/python3.7/site-packages/aiohttp/web_protocol.py", line 418, in start
    resp = await task
  File "/root/venvs/gracedb/lib/python3.7/site-packages/aiohttp/web_app.py", line 458, in _handle
    resp = await handler(request)
  File "/root/venvs/gracedb/lib/python3.7/site-packages/aiohttp/web_urldispatcher.py", line 890, in _iter
    resp = await method()
  File "/root/venvs/gracedb/lib/python3.7/site-packages/aiogram/dispatcher/webhook.py", line 137, in post
    results = await self.process_update(update)
  File "/root/venvs/gracedb/lib/python3.7/site-packages/aiogram/dispatcher/webhook.py", line 188, in process_update
    return fut.result()
  File "/root/venvs/gracedb/lib/python3.7/site-packages/aiogram/dispatcher/handler.py", line 117, in notify
    response = await handler_obj.handler(*args, **partial_data)
  File "/root/venvs/gracedb/lib/python3.7/site-packages/aiogram/dispatcher/dispatcher.py", line 162, in process_update
    return await self.message_handlers.notify(update.message)
  File "/root/venvs/gracedb/lib/python3.7/site-packages/aiogram/dispatcher/handler.py", line 117, in notify
    response = await handler_obj.handler(*args, **partial_data)
  File "gracebot/main.py", line 36, in send_o3_stats
    await bot.send_o3_stats(message)
  File "/root/Projects/GraceDB/gracebot/gracebot.py", line 167, in send_o3_stats
    [info["most_likely"] for info in self.events.events.values()]
  File "/root/Projects/GraceDB/gracebot/gracebot.py", line 167, in <listcomp>
    [info["most_likely"] for info in self.events.events.values()]
KeyError: 'most_likely'

No update message was sent to user when event S190701AH was updated

After event S190701AH was updated user got no message that the event was updated. Probably the origin why #1 stopped working.

Error message after update was requested:

2019-07-05 03:40:46 	 root         INFO     Refreshing event database.

Updating events: [                              ] 0%2019-07-05 03:40:54 	 asyncio      ERROR    Task exception was never retrieved
future: <Task finished coro=<Events._periodic_event_updater() done, defined at /root/Projects/GraceDB/gracebot/gwevents.py:107> exception=<HTTPError 404: 'Not Found'>>
Traceback (most recent call last):
  File "/root/Projects/GraceDB/gracebot/gwevents.py", line 118, in _periodic_event_updater
    self.update_all_events()
  File "/root/Projects/GraceDB/gracebot/gwevents.py", line 46, in update_all_events
    self.update_single_event(_event["superevent_id"])
  File "/root/Projects/GraceDB/gracebot/gwevents.py", line 72, in update_single_event
    voevent.from_event_id(event_id)
  File "/root/Projects/GraceDB/gracebot/voevent.py", line 107, in from_event_id
    self._add_distance(self._data["skymap_fits"])
  File "/root/Projects/GraceDB/gracebot/voevent.py", line 59, in _add_distance
    with fits.open(url) as fit_data:
  File "/root/venvs/gracedb/lib/python3.7/site-packages/astropy/io/fits/hdu/hdulist.py", line 151, in fitsopen
    lazy_load_hdus, **kwargs)
  File "/root/venvs/gracedb/lib/python3.7/site-packages/astropy/io/fits/hdu/hdulist.py", line 390, in fromfile
    lazy_load_hdus=lazy_load_hdus, **kwargs)
  File "/root/venvs/gracedb/lib/python3.7/site-packages/astropy/io/fits/hdu/hdulist.py", line 1039, in _readfrom
    fileobj = _File(fileobj, mode=mode, memmap=memmap, cache=cache)
  File "/root/venvs/gracedb/lib/python3.7/site-packages/astropy/utils/decorators.py", line 521, in wrapper
    return function(*args, **kwargs)
  File "/root/venvs/gracedb/lib/python3.7/site-packages/astropy/io/fits/file.py", line 147, in __init__
    self.name = download_file(fileobj, cache=cache)
  File "/root/venvs/gracedb/lib/python3.7/site-packages/astropy/utils/data.py", line 1091, in download_file
    raise e
  File "/root/venvs/gracedb/lib/python3.7/site-packages/astropy/utils/data.py", line 1024, in download_file
    with urllib.request.urlopen(remote_url, timeout=timeout) as remote:
  File "/usr/lib/python3.7/urllib/request.py", line 222, in urlopen
    return opener.open(url, data, timeout)
  File "/usr/lib/python3.7/urllib/request.py", line 531, in open
    response = meth(req, response)
  File "/usr/lib/python3.7/urllib/request.py", line 641, in http_response
    'http', request, response, code, msg, hdrs)
  File "/usr/lib/python3.7/urllib/request.py", line 569, in error
    return self._call_chain(*args)
  File "/usr/lib/python3.7/urllib/request.py", line 503, in _call_chain
    result = func(*args)
  File "/usr/lib/python3.7/urllib/request.py", line 649, in http_error_default
    raise HTTPError(req.full_url, code, msg, hdrs, fp)
urllib.error.HTTPError: HTTP Error 404: Not Found

Detector status doesn't work when there is an unknow state

Command /status gives no reply when a detector status is in an state without a time.

  File "/root/Projects/GraceDB/gracebot/detector.py", line 44, in __post_init__
    self.duration = self._convert_to_time(duration)
  File "/root/Projects/GraceDB/gracebot/detector.py", line 67, in _convert_to_time
    hours, minutes = time_string.split(":")

Make /event user independent

If two users try to select an event simultaneously it sometimes skip pages, because the self.start_at parameter in GraceBot class is not unique per user.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.