@@ -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,17 +96,21 @@ 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+ alert_lite_df = _create_lite_dataframe (alert_lite .dict ["alert_lite" ])
102+ is_ssobject = bool (alert_lite .attributes .get ("ssSource_ssObjectId" ))
103+
97104 for band in SURVEY_BANDS :
98105 # ---Extract data
99106 filter_diaSources = alert_lite_df [alert_lite_df ["band" ] == band ]
100107 flux_gt_zero = filter_diaSources ["psfFlux" ].to_numpy () > 0
101108 upsilon_dict [f"n_data_points_{ band } _band" ] = flux_gt_zero .sum ().item ()
109+ # skip classification if the object has a ssObjectId
102110 # skip band if no detections or too few valid data points.
103111 # to avoid scipy's leastsq error: ("input vector length N=7 must not exceed output length M"), we require
104112 # that flux_gt_zero.sum() > 7
105- if filter_diaSources .empty or flux_gt_zero .sum () <= 7 :
113+ if is_ssobject or ( filter_diaSources .empty or flux_gt_zero .sum () <= 7 ) :
106114 upsilon_dict [f"{ band } _label" ] = None
107115 upsilon_dict [f"{ band } _probability" ] = None
108116 upsilon_dict [f"{ band } _flag" ] = None
0 commit comments