-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathRapidSedm.py
executable file
·127 lines (110 loc) · 3.91 KB
/
RapidSedm.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# File: Ampel-contrib-HU/ampel/contrib/hu/t3/RapidSedm.py
# License: BSD-3-Clause
# Author: [email protected]
# Date: 05.08.2019
# Last Modified Date: 06.02.2020
# Last Modified By: valery brinnel <[email protected]>
import datetime
from typing import Any
import requests
from ampel.contrib.hu.t3.RapidBase import RapidBase
from ampel.secret.NamedSecret import NamedSecret
from ampel.view.TransientView import TransientView
from ampel.ztf.util.ZTFIdMapper import to_ztf_id
class RapidSedm(RapidBase):
"""
Select transients for rapid reactions. Intended as base class where the react method can be
implemented as wished and a testreact method posts test reactions to Slack.
This version reacts by setting a target for SEDM observatoins
"""
# Base SEDM trigger info
sedm_url: str = "http://pharos.caltech.edu/request"
sedm_payload: dict[str, Any] = {
"obj_ra": None,
"obj_dec": None,
"obj_epoch": 2000,
"obj_mag": None,
"obj_name": None,
"allocation": 20180319205302725,
"status": "PENDING",
"inidate": None,
"enddate": None,
"priority": 5.0,
"ifu": True,
"ab": "n",
"ifu_use_mag": "y",
"rc": False,
"rc_use_mag": "y",
"do_r": "y",
"r_exptime": 0,
"r_repeats": 1,
"do_g": "y",
"g_exptime": 0,
"g_repeats": 1,
"do_i": "y",
"i_exptime": 0,
"i_repeats": 1,
"do_u": "y",
"u_exptime": 0,
"u_repeats": 1,
"maxairmass": 2.5,
"min_moon_dist": 30,
"user_id": 284,
}
sedm_username: str
sedm_password: NamedSecret[str]
# maximum redshift from T2 CATALOGMATCH catalogs (e.g. NEDz and SDSSspec)
max_redshift: float = 0.05
# arcsec, maximum distance
max_dist: float = 30.0
# range of peak magnitudes for submission
min_peak_mag: float = 19.25
# Minimal median RB.
drb_minmed: float = 0.995
# Limiting magnitude to consider upper limits as 'significant'
maglim_min: float = 19.25
def post_init(self):
""""""
self.name = "RapidSedm"
super().post_init()
def react(
self, tran_view: TransientView, info: None | dict[str, Any]
) -> tuple[bool, None | dict[str, Any]]:
"""
Send a trigger to the SEDM. Note that we have no good way of investigating the queue at this time
"""
if not info:
return False, {"success": False}
assert isinstance(tran_view.id, int)
# Assemble required information. These *should* already be present in the default info
# provided by the info dict returned for a sucessfull accept_tview
react_dict = {}
react_dict.update(self.sedm_payload)
react_dict["obj_ra"] = info["ra"]
react_dict["obj_dec"] = info["dec"]
react_dict["obj_mag"] = info[
"latest_mag"
] # Assuming that the object is not declining?
react_dict["obj_name"] = to_ztf_id(tran_view.id)
react_dict["inidate"] = datetime.datetime.now(tz=datetime.timezone.utc)
react_dict["enddate"] = datetime.datetime.now(
tz=datetime.timezone.utc
) + datetime.timedelta(days=2)
# We are still in debug stage, turn down priority
# react_dict['priority'] = 1
self.logger.debug(
f"SEDM trigger for {to_ztf_id(tran_view.id)} w dict {react_dict}"
)
# Make the post
response = requests.post(
self.sedm_url,
data=react_dict,
auth=(self.sedm_username, self.sedm_password.get()),
)
# Check result
success = response.status_code == 200
# Document what we did
jcontent = {"reactDict": react_dict, "success": success}
return success, jcontent