Skip to content

Commit 838bfb4

Browse files
authored
new slack posters (#64)
Changes : new event "id" parameter for LvkNuTrackSearch schema, updated slack posters using slack apps, add new SSM search parameters for new LVK notices, + minor fixes
1 parent 698afe4 commit 838bfb4

17 files changed

Lines changed: 288 additions & 461 deletions

File tree

‎.readthedocs.yaml‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,6 @@ python:
2020
sphinx:
2121
configuration: doc/source/conf.py
2222
fail_on_warning: true
23+
24+
formats:
25+
- pdf

‎doc/source/alert.rst‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ Track Followups (Gold and Bronze)
1313
.. autoclass:: fast_response.AlertFollowup.TrackFollowup
1414
:members:
1515

16+
.. autoclass:: fast_response.AlertFollowup.TrackFollowupLLH
17+
:members:
18+
1619
Cascade Followups
1720
-------------------------
1821
.. autoclass:: fast_response.AlertFollowup.CascadeFollowup

‎doc/source/conf.py‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@
1414
# https://www.sphinx-doc.org/en/master/usage/configuration.html#project-information
1515

1616
project = 'FastResponseAnalysis'
17-
copyright = '2023, Alex Pizzuto, Jessie Thwaites'
17+
copyright = '2025, Alex Pizzuto, Jessie Thwaites'
1818
author = 'Alex Pizzuto, Jessie Thwaites'
19-
release = '1.3.0'
19+
release = '1.4.0'
2020

2121
# -- General configuration ---------------------------------------------------
2222
# https://www.sphinx-doc.org/en/master/usage/configuration.html#general-configuration

‎doc/source/index.rst‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ Contents
4949
reports
5050
web_utils
5151
plotting
52+
slack
5253

5354
Index
5455
==================

‎doc/source/slack.rst‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
Slack Posters
2+
=======================================================
3+
.. note::
4+
class for posting results, links, and files to slack
5+
6+
slackbot class
7+
--------------------------------
8+
.. autoclass:: fast_response.slack_posters.slack
9+
:members:

‎fast_response/FastResponseAnalysis.py‎

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -896,6 +896,7 @@ def find_coincident_events(self, print_events=False):
896896
print("[run, event, ra, dec, sigma, logE, time]")
897897
for e in self.llh.exp[t_mask][msk3]:
898898
print([e[k] for k in ['run', 'event', 'ra', 'dec', 'sigma', 'logE', 'time']])
899+
self.nearby = self.llh.exp[t_mask][msk3]
899900

900901
if len(events) == 0:
901902
coincident_events = []
@@ -1106,7 +1107,10 @@ def make_dNdE(self):
11061107
plt.axvline(median_max_dec, c = sns.xkcd_rgb['dark navy blue'], alpha = 0.75, label = "Median (max dec.)", ls = '--')
11071108
plt.xlim(1e1, 1e8)
11081109
plt.legend(loc=4, fontsize=18)
1109-
plt.savefig(self.analysispath + '/central_90_dNdE.png',bbox_inches='tight')
1110+
try:
1111+
plt.savefig(self.analysispath + '/central_90_dNdE.png',bbox_inches='tight')
1112+
except:
1113+
print('Failed to save dNdE plot')
11101114

11111115
self.energy_range = (np.min([low_5_min_dec, low_5_max_dec]),
11121116
np.max([high_5_min_dec, high_5_max_dec]))
@@ -1222,7 +1226,7 @@ def unblind_TS(self):
12221226
self.save_items['ns'] = ns
12231227
return ts, ns
12241228

1225-
def find_coincident_events(self):
1229+
def find_coincident_events(self, print_events=False):
12261230
r"""Find "coincident events" for the analysis.
12271231
These are ontime events that satisfy:
12281232
@@ -1250,6 +1254,20 @@ def find_coincident_events(self):
12501254
self.coincident_events[-1]['delta_psi'] = del_psi
12511255
self.coincident_events[-1]['spatial_w'] = s_w
12521256
self.coincident_events[-1]['energy_w'] = en_w
1257+
1258+
if print_events:
1259+
t_mask=(self.llh.exp['time']<=self.stop)&(self.llh.exp['time']>=self.start)
1260+
# print nearby events, as a check (if needed)
1261+
msk1 = (self.llh.exp[t_mask]['ra'] < (self.ra+np.radians(10)))*(self.llh.exp[t_mask]['ra'] > (self.ra-np.radians(10)))
1262+
msk2 = (self.llh.exp[t_mask]['dec'] < (self.dec+np.radians(10)))*((self.llh.exp[t_mask]['dec'] > self.dec-np.radians(10)))
1263+
msk3 = msk1*msk2
1264+
if np.count_nonzero(msk3) > 0:
1265+
print('Events within 10 deg of best-fit:')
1266+
print("[run, event, ra, dec, sigma, logE, time]")
1267+
for e in self.llh.exp[t_mask][msk3]:
1268+
print([e[k] for k in ['run', 'event', 'ra', 'dec', 'sigma', 'logE', 'time']])
1269+
self.nearby = self.llh.exp[t_mask]
1270+
12531271
self.save_items['coincident_events'] = self.coincident_events
12541272

12551273
def ns_scan(self, params = {'spectrum': 'dN/dE = 1.00e+00 * (E / 1.00e+03 GeV)^-2.00 [GeV^-1cm^-2s^-1]'}):
@@ -1316,6 +1334,16 @@ def upper_limit(self, n_per_sig=100, p0=None):
13161334
msk = results['TS'] > self.ts
13171335
npass = len(results['TS'][msk])
13181336
passing.append((n, npass, n_per_sig))
1337+
1338+
if (passing[-1][1] / passing[-1][2]) < 0.92:
1339+
#run a few more if the last point is close to 0.9
1340+
for n in np.array([7., 8.]):
1341+
results = self.llh.do_trials(
1342+
n_per_sig, src_ra=self.ra, src_dec=self.dec,
1343+
injector=self.inj, mean_signal=n, poisson=True)
1344+
msk = results['TS'] > self.ts
1345+
npass = len(results['TS'][msk])
1346+
passing.append((n, npass, n_per_sig))
13191347

13201348
signal_fluxes, passing, number = list(zip(*passing))
13211349
signal_fluxes = np.array(signal_fluxes)

‎fast_response/MonitoringAndMocks/Data_Display.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,7 @@ def find_ts(i, ts_list):
315315
ax = fig.add_axes([0, 0, 1, 1])
316316
plt.plot([0,5],[0,100],color='white')
317317
ax.text(-0.1, 15, "Page Last Updated: {} UTC".format(now))
318-
plt.savefig(save_path)
318+
plt.savefig('/home/mromfoe/public_html/O4_followup_monitoring/Update_Time.png')
319319

320320
df = pd.DataFrame({"Name": ed["Name"][-15::-1],
321321
"Merger Time": ed["Trigger_Time"][-15::-1],

‎fast_response/circular_templates/gw_gcn_template_high.txt‎

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,14 @@ The reported p-values can differ due to the estimated distance of the GW candida
2525
The distance is used as a prior in the Bayesian binary merger search, while it is not
2626
taken into account in the generic transient point-like source search. The false alarm rate of these
2727
coincidences can be obtained by multiplying the p-values with their corresponding GW trigger rates.
28-
Further details are available at https://gcn.nasa.gov/missions/icecube.
28+
Further details are available at https://gcn.nasa.gov/missions/icecube. Additional details
29+
and updates will be posted at https://roc.icecube.wisc.edu/public/LvkNuTrackSearch/.
2930

3031
Properties of the coincident events are shown below.
3132

32-
dt(s) RA(deg) Dec(deg) Angular uncertainty(deg) p-value(generic transient) p-value(Bayesian)
33-
-----------------------------------------------------------------------------------------------------
34-
<dt> <ra> <dec> <angErr> <pvalue> <pvalue>
33+
| dt(s) | RA(deg) | Dec(deg) | Angular uncertainty(deg)| p-value(generic transient)| p-value(Bayesian) |
34+
|-------|----------|----------|-------------------------|---------------------------|-----------------------|
35+
|<dt> | <ra> | <dec> | <angErr> | <pvalue> | <pvalue> |
3536
...
3637

3738
where:

‎fast_response/listeners/gcn_listener.py‎

Lines changed: 16 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -55,13 +55,11 @@ def process_gcn(payload, root):
5555
event_id = params['event_id']
5656
run_id = params['run_id']
5757
event_mjd = Time(eventtime, format='isot').mjd
58-
try:
59-
bot.send_message(f'Listener found {alert_type} type alert, {event_name} \n'+
60-
'Waiting 1 day to run FRA', 'blanket_blob')
61-
print(' - slack message sent \n')
62-
except Exception as e:
63-
print(e)
64-
print('Cannot post to slack (testing?)')
58+
59+
# send message to slack with alert info
60+
bot = slackbot('fra-shifting')
61+
message =f'Listener found {alert_type} type alert, {event_name}. Waiting 1 day to run FRA'
62+
bot.post_short_msg(message)
6563

6664
if alert_type == 'cascade':
6765
command = analysis_path + 'run_cascade_followup.py'
@@ -82,7 +80,7 @@ def process_gcn(payload, root):
8280
if alert_type == 'track':
8381
base_skymap_path = '/home/followup/output_plots/'
8482
skymap_f = glob(base_skymap_path \
85-
+ f'run{int(run_id):08d}.evt{int(event_id):012d}.*.fits.gz')
83+
+ f'run{int(run_id):08d}.evt{int(event_id):012d}.*probability.fits.gz')
8684
if len(skymap_f) == 0:
8785
print("COULD NOT FIND THE SKYMAP FILE FOR V2 TRACK ALERT EVENT")
8886
return
@@ -135,22 +133,20 @@ def process_gcn(payload, root):
135133
if shifters['start'][i]<datetime.utcnow()<shifters['stop'][i]:
136134
on_shift+='<@{}> '.format(shifters['slack_id'][i])
137135
link = 'https://user-web.icecube.wisc.edu/~jthwaites/FastResponse/webpage/output/'
138-
wp_link_1000 = '{}{}_{}_1.0e+03_s.html'.format(link, eventtime[0:10].replace('-','_'),event_name)
136+
start_1000 = Time(event_mjd -500./86400., format='mjd').iso
137+
wp_link_1000 = '{}{}_{}_1.0e+03_s.html'.format(link, start_1000[:10].replace('-','_'),event_name)
139138

140-
day_before = '{}'.format(int(eventtime[8:10])-1)
141-
if len(day_before)==1: day_before='0'+day_before
142-
str_2d = '{}_{}'.format(eventtime[0:7].replace('-','_'),day_before)
143-
wp_link_2d = '{}{}_{}_1.7e+05_s.html'.format(link, str_2d, event_name)
144-
bot.send_message(f'Done running FRA for {alert_type} alert, {event_name}.\n '+ on_shift +'on shift',
145-
'blanket_blob')
139+
start_2d = Time(event_mjd-1., format='mjd').iso
140+
wp_link_2d = '{}{}_{}_1.7e+05_s.html'.format(link, start_2d[:10].replace('-','_'), event_name)
141+
done_message = f'Done running FRA for {alert_type} alert, {event_name}.\n '+ on_shift +'on shift'
142+
146143
if doc:
147-
bot.send_message("-Results for 1000s: <{}|link> \n-Results for 2d: <{}|link>".format(
148-
wp_link_1000, wp_link_2d),
149-
'blanket_blob')
150-
print(' - slack message sent \n')
144+
done_message = done_message + "\n - Results for 1000s: <{}|link>\n - Results for 2d: <{}|link>".format(
145+
wp_link_1000, wp_link_2d)
146+
147+
bot.post_short_msg(done_message)
151148
except Exception as e:
152149
print(e)
153-
print('No slack message sent.')
154150

155151
if __name__ == '__main__':
156152
import os, subprocess
@@ -183,20 +179,8 @@ def process_gcn(payload, root):
183179
help='flag to raise to push results to internal webpage')
184180
args = parser.parse_args()
185181

186-
#for now, testing
187-
#with open('../slack_posters/internal_alert_slackbot.txt') as f:
188-
# channel = f.readline()
189-
# webhook = f.readline()
190-
# bot_name = f.readline()
191-
#bot = slackbot(channel, bot_name, webhook)
192-
193182
if args.run_live:
194183
print("Listening for GCNs . . . ")
195-
with open('../slack_posters/internal_alert_slackbot.txt') as f:
196-
channel = f.readline().rstrip('\n')
197-
webhook = f.readline().rstrip('\n')
198-
bot_name = f.readline().rstrip('\n')
199-
bot = slackbot(channel, bot_name, webhook)
200184
gcn.listen(handler=process_gcn)
201185
else:
202186
try:

‎fast_response/listeners/gw_gcn_listener.py‎

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,8 @@ def process_gcn(payload, root):
6666
try:
6767
if params['Group'] == 'Burst':
6868
merger_type = 'Burst'
69+
elif params['Search'] == 'SSM':
70+
merger_type='SSM'
6971
else:
7072
k = ['BNS','NSBH','BBH']
7173
probs = {j: float(params[j]) for j in k}
@@ -189,14 +191,10 @@ def process_gcn(payload, root):
189191
wp_link = 'https://user-web.icecube.wisc.edu/~jthwaites/FastResponse/gw-webpage/output/'+\
190192
'{}.html'.format(analysis_start[0:10].replace('-','_')+'_'+name)
191193
slack_message = "UML GW analysis finished running for event {}: <{}|link>.".format(name, wp_link)
192-
with open('../slack_posters/internal_alert_slackbot.txt') as f:
193-
chan = f.readline().rstrip('\n')
194-
webhook = f.readline().rstrip('\n')
195-
bot_name = f.readline().rstrip('\n')
196194

197195
for channel in ['#fra-shifting','#gwnu-heartbeat']:
198-
bot = slackbot(channel, bot_name, webhook)
199-
bot.send_message(slack_message,'gw')
196+
bot = slackbot(channel)
197+
bot.post_short_msg(slack_message)
200198

201199
except Exception as e:
202200
print('Failed to push to (private) webpage.')

0 commit comments

Comments
 (0)