@@ -56,16 +56,20 @@ def run() -> tuple[str, int]:
5656 # extract the envelope from the request that triggered the endpoint
5757 # this contains a single Pub/Sub message with the alert to be processed
5858 envelope = flask .request .get_json ()
59+
60+ # unpack the alert. raises a `BadRequest` if the envelope does not contain a valid message
5961 try :
6062 alert_lite = pittgoogle .Alert .from_cloud_run (envelope , "default" )
6163 except pittgoogle .exceptions .BadRequest as exc :
6264 return str (exc ), HTTP_400
6365
64- alert_lite_df = _create_lite_dataframe ( alert_lite . dict [ "alert_lite" ])
65- upsilon_dict = _classify_with_upsilon ( alert_lite_df )
66+ # classify
67+ upsilon_dict = _classify ( alert_lite )
6668 has_min_detections_in_any_band = any (
6769 upsilon_dict .get (f"n_data_points_{ band } _band" ) >= 80 for band in SURVEY_BANDS
6870 )
71+
72+ # publish
6973 TOPIC .publish (
7074 pittgoogle .Alert .from_dict (
7175 {"alert_lite" : alert_lite .dict ["alert_lite" ], "upsilon" : upsilon_dict },
@@ -92,8 +96,19 @@ def run() -> tuple[str, int]:
9296 return "" , HTTP_204
9397
9498
95- def _classify_with_upsilon ( alert_lite_df : pd . DataFrame ) -> dict :
99+ def _classify ( alert_lite : pittgoogle . Alert ) -> dict :
96100 upsilon_dict = {}
101+
102+ # check to see if the alert has a ssObjectId
103+ if alert_lite .attributes ["ssSource_ssObjectId" ]:
104+ for band in SURVEY_BANDS :
105+ upsilon_dict [f"{ band } _label" ] = None
106+ upsilon_dict [f"{ band } _probability" ] = None
107+ upsilon_dict [f"{ band } _flag" ] = None
108+ return upsilon_dict
109+
110+ alert_lite_df = _create_lite_dataframe (alert_lite .dict ["alert_lite" ])
111+
97112 for band in SURVEY_BANDS :
98113 # ---Extract data
99114 filter_diaSources = alert_lite_df [alert_lite_df ["band" ] == band ]
0 commit comments