@@ -229,10 +229,13 @@ def _match_rows_for_injection(
229229 ddm = np .full (n , np .inf )
230230
231231 if "ibeam" in tab .colnames :
232- dbeam0 = np .abs (tab ["ibeam" ] - inj_beam )
233- dbeam1 = np .abs (tab ["ibeam" ] - (inj_beam + 256 ))
234- dbeam_min = np .minimum (dbeam0 , dbeam1 )
235- which_arm = np .where (dbeam0 <= dbeam1 , 0 , 1 )
232+ base_local = int (inj_beam ) % 256 # normalize to 0..255
233+ ew_global = base_local # 0..255
234+ ns_global = base_local + 256 # 256..511
235+ dbeam_ew = np .abs (tab ["ibeam" ] - ew_global )
236+ dbeam_ns = np .abs (tab ["ibeam" ] - ns_global )
237+ dbeam_min = np .minimum (dbeam_ew , dbeam_ns )
238+ which_arm = np .where (dbeam_ew <= dbeam_ns , 0 , 1 ) # 0=EW match, 1=NS match
236239 else :
237240 dbeam_min = np .full (n , np .inf )
238241 which_arm = np .zeros (n , dtype = int )
@@ -263,11 +266,9 @@ def _match_rows_for_injection(
263266 best_idx = int (cand_ix [order [0 ]])
264267
265268 # report arm-corrected beam distance
266- arm = which_arm [best_idx ]
267- if arm == 0 :
268- dbeam_report = int (np .abs (tab ["ibeam" ][best_idx ] - inj_beam ))
269- else :
270- dbeam_report = int (np .abs (tab ["ibeam" ][best_idx ] - (inj_beam + 256 )))
269+ arm = int (which_arm [best_idx ]) # 0=EW, 1=NS
270+ matched_global = ew_global if arm == 0 else ns_global
271+ dbeam_report = int (abs (int (tab ["ibeam" ][best_idx ]) - matched_global ))
271272
272273 out = dict (
273274 t1_best_snr = float (tab ["snr" ][best_idx ]) if "snr" in tab .colnames else "" ,
0 commit comments