Skip to content

Commit

Permalink
Merge pull request #25 from AMONCode/dev
Browse files Browse the repository at this point in the history
Adding hop-client to master
  • Loading branch information
hayalaso authored Dec 14, 2021
2 parents 7110833 + 2709bf2 commit 52365ae
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 46 deletions.
18 changes: 9 additions & 9 deletions AmonPy/amonpy/analyses/HAWCGRB.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import netrc, jsonpickle
from amonpy.tools.config import AMON_CONFIG
from amonpy.tools.J2000 import J2000
from amonpy.tools.postAlerts import postAlertGCN, postAlertHop

import sys, shutil, os, subprocess

Expand Down Expand Up @@ -165,26 +166,25 @@ def hawc_burst(new_event=None):
f1.write(xmlForm)
f1.close()

if (prodMachine == True) and (false_pos<=12.0):
if (prodMachine == True):
title='AMON HAWC-GRBlike alert: URGENT!'
try:
print("HAWC Burst created, sending to GCN")
cmd = ['/home/ubuntu/Software/miniconda3/bin/comet-sendvo']
cmd.append('--file=' + os.path.join(AlertDir,fname))
subprocess.check_call(cmd)
postAlertGCN(os.path.join(AlertDir,fname))
#postAlertHop(os.path.join(AlertDir,fname),'hawc.simpleGRB')
if new_event.rev == 0:
post_on_websites.HAWCGRB_to_OpenAMON(new_event)
except subprocess.CalledProcessError as e:
print("Send HAWC Burst VOevent alert failed")
#logger.error("send_voevent failed")
slack_message(title+" FAILED TO SEND <!channel>\n"+"File: {}\n".format(os.path.join(AlertDir,fname))+content,channel,prodMachine,token=token)
raise e
else:
shutil.move(os.path.join(AlertDir,fname), os.path.join(AlertDir,"archive/"))
slack_message(title+" <!channel>\n"+content,channel,prodMachine,token=token)
else:
#postAlertHop(os.path.join(AlertDir,fname),'hawc.test')
shutil.move(os.path.join(AlertDir,fname), os.path.join(AlertDir,"archive/"))


# send slack message for alerts with FAR<12 per year
slack_message(title+"\n"+content,channel,prodMachine,token=token)
# send slack message for alerts with FAR<12 per year
slack_message(title+"\n"+content,channel,prodMachine,token=token)
#Send email after everything has been accomplished, all the events
email_alerts.alert_email_content([new_event],content,title)
12 changes: 5 additions & 7 deletions AmonPy/amonpy/analyses/ICCascade.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import amonpy.dbase.email_alerts as email_alerts
from amonpy.analyses.amon_streams import streams, alert_streams
from amonpy.tools.config import AMON_CONFIG
from amonpy.tools.postAlerts import postAlertGCN
from amonpy.monitoring.monitor_funcs import slack_message

from amonpy.ops.server.celery import app
Expand Down Expand Up @@ -167,24 +168,21 @@ def ic_cascade(new_event=None):
if (new_event.type == "observation") and (prodMachine is True) and (signalness != -1):
channel="alerts"
try:
cmd = ['/home/ubuntu/Software/miniconda3/bin/comet-sendvo']
cmd.append('--file=' + fname)
# just for dev to prevent sending hese both from dev and pro machine
# print "uncoment this if used on production"
subprocess.check_call(cmd)
postAlertGCN(fname)
if new_event.rev == 0:
post_on_websites.ICCascade_to_OpenAMON(new_event,params,skymaps)
except subprocess.CalledProcessError as e:
print("Send Cascade VOevent alert failed")
logger.error("send_voevent failed")
slack_message(title+" FAILED TO SEND <!channel>\n"+"File: {}\n".format(fname)+content,channel,prodMachine,token=token)
raise e
else:
shutil.move(fname, os.path.join(AlertDir, "archive/"))
slack_message(title+" <!channel>\n"+content, channel, prodMachine, token=token)
else:
channel="test-alerts"
shutil.move(fname, os.path.join(AlertDir, "archive/"))
slack_message(title+"\n"+content, channel, prodMachine, token=token)

#post_on_websites.ICCascade_to_OpenAMON(new_event,params,skymaps)
slack_message(title+"\n"+content, channel, prodMachine, token=token)
email_alerts.alert_email_content([new_event], content, title)
# email_alerts.alert_email([new_event],params)
12 changes: 5 additions & 7 deletions AmonPy/amonpy/analyses/ICGoldBronze.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import amonpy.dbase.email_alerts as email_alerts
from amonpy.analyses.amon_streams import streams, alert_streams
from amonpy.tools.config import AMON_CONFIG
from amonpy.tools.postAlerts import postAlertGCN
from amonpy.monitoring.monitor_funcs import slack_message

from amonpy.ops.server.celery import app
Expand Down Expand Up @@ -165,21 +166,18 @@ def ic_gold_bronze(new_event=None):

if (new_event.type=="observation") and (prodMachine is True):
try:
cmd = ['comet-sendvo']
cmd.append('--file=' + fname)
# just for dev to prevent sending hese both from dev and pro machine
# print "uncoment this if used on production"
subprocess.check_call(cmd)
slack_message(title+"\n"+content,"alerts",prodMachine,token=token)
postAlertGCN(fname)
if new_event.rev == 0:
post_on_websites.ICgoldbronze_to_OpenAMON(new_event,params)
except subprocess.CalledProcessError as e:
print("Send Gold/Bronze VOevent alert failed")
logger.error("send_voevent failed")
slack_message(title+" FAILED TO SEND <!channel>\n"+"File: {}\n".format(fname)+content,"alerts",prodMachine,token=token)
raise e
else:
shutil.move(fname, os.path.join(AlertDir,"archive/"))
slack_message(title+" <!channel>\n"+content,"alerts",prodMachine,token=token)
else:
slack_message(title+"\n"+content,"test-alerts",prodMachine,token=token)
shutil.move(fname, os.path.join(AlertDir,"archive/"))


Expand Down
39 changes: 16 additions & 23 deletions AmonPy/amonpy/analyses/ICHAWC.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
from amonpy.tools.IC_FPRD import *
from amonpy.tools.angularsep import spcang
from amonpy.tools.config import AMON_CONFIG
from amonpy.tools.postAlerts import postAlertGCN, postAlertHop

from amonpy.ops.server.celery import app
from amonpy.ops.server.buffer import EventBuffer
Expand Down Expand Up @@ -576,7 +577,6 @@ def ic_hawc(new_event=None):

f1.write(xmlForm)
f1.close()
MOVEFILE=True

content = 'Times: '
print(content)
Expand All @@ -597,43 +597,36 @@ def ic_hawc(new_event=None):
emails2=['[email protected]','[email protected]','[email protected]','[email protected]','[email protected]','[email protected]','[email protected]','[email protected]','[email protected]','[email protected]','[email protected]','[email protected]','[email protected]','[email protected]','[email protected]','[email protected]','[email protected]']

title='AMON IC-HAWC alert'
# TEMPORAL UNITL GCN IS ON
if far<=4.0:
if far<=365.0 and prodMachine == False:
email_alerts.alert_email_content([new_alert],content,title)
email_alerts.alert_email_content_emails(content2,title,emails2)
slack_message(title+"\n"+content+"\n"+filen,channel,prodMachine,token=token)
slack_message(title+"\n"+content+"\n"+filen,channel,False,token=token)
postAlertHop(filen,channel='amon.test')

if far<=4.0 and far>0.01:
if far<=4.0 and far>0.1:
print("ID: %d"%new_alert.id)
print("Alert Stream: %s"%inv_alert_streams[new_alert.stream])
#fname.write(alert_to_voevent(new_alert))
if (prodMachine == True and send == True):
try:
cmd = ['/home/ubuntu/Software/miniconda3/bin/comet-sendvo','-f',filen]
#cmd.append('--file=' + filen)
# just for dev to prevent sending hese both from dev and pro machine
#print "uncoment this if used on production"
subprocess.check_call(cmd)
#shutil.move(filen, os.path.join(AlertDir,"archive/",fname))
postAlertGCN(filen)
postAlertHop(filen,channel='amon.nuem')

except subprocess.CalledProcessError as e:
print("Send alert failed")
logger.error("send_voevent failed")
logger.error("File: {}".format(fname))
MOVEFILE=False
slack_message(title+" FAILED TO SEND <!channel>\n"+"File: {}\n".format(filen)+content,channel,prodMachine,token=token)
raise e
#else:
#shutil.move(filen, os.path.join(AlertDir,"archive/",fname))
#else:
email_alerts.alert_email_content_emails(content2,title,emails)
slack_message(title+"\n"+content+"\n"+filen,"test-alerts",False,token=token)
else:
shutil.move(filen, os.path.join(AlertDir,"archive/",fname))
slack_message(title+" <!channel>\n"+content+"\n"+filen,channel,prodMachine,token=token)
email_alerts.alert_email_content_emails(content2,title,emails2)
elif far<0.1:
email_alerts.alert_email_content_emails(content2,title+" LOWFAR",emails)
slack_message(title+"\n"+content2+"\n"+fname,channel,prodMachine,token=token)

if MOVEFILE:
slack_message(title+" <!channel>\n"+content2+"\n"+fname,channel,prodMachine,token=token)
#shutil.move(filen, os.path.join(AlertDir,"archive/",fname))
else:
shutil.move(filen, os.path.join(AlertDir,"archive/",fname))


#alertLine for HAWC
al = AlertLine(new_alert.stream,new_alert.id,new_alert.rev,streams['HAWC-DM'],phEvent[-2],phEvent[-1])
alertline_lst.append(al)
Expand Down
15 changes: 15 additions & 0 deletions AmonPy/amonpy/tools/postAlerts.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import subprocess
import shutil

from hop import stream as hop_publisher
from hop.models import VOEvent


def postAlertGCN(filename):
cmd = ['/home/ubuntu/Software/miniconda3/bin/comet-sendvo','-f',filename]
subprocess.check_call(cmd)

def postAlertHop(filename,channel='amon.test'):
voevent = VOEvent(filename)
with hop_publisher.open("kafka://kafka.scimma.org/{}".format(channel),"w") as s:
s.write(voevent)

0 comments on commit 52365ae

Please sign in to comment.