From 8a8452f04d977e2b4d4a18cb3670bcb186828d37 Mon Sep 17 00:00:00 2001 From: Josh Dillon Date: Sat, 20 Apr 2024 09:39:54 -0700 Subject: [PATCH] avoid infinite loop with ping-ponging convergence --- notebooks/file_calibration.ipynb | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/notebooks/file_calibration.ipynb b/notebooks/file_calibration.ipynb index d52476f..908d752 100644 --- a/notebooks/file_calibration.ipynb +++ b/notebooks/file_calibration.ipynb @@ -493,6 +493,7 @@ "# Iteratively develop RFI mask, excess RFI classification, and autocorrelation shape classification\n", "stage = 1\n", "rfi_flags = np.array(array_flags)\n", + "prior_end_states = set()\n", "while True:\n", " # compute DPSS-filtered z-scores with current array-wide RFI mask\n", " zscores = auto_bl_zscores(data, rfi_flags)\n", @@ -504,7 +505,6 @@ " # use best half of the unflagged antennas\n", " med_rms = np.nanmedian([rms[bl] for bl in candidate_autos])\n", " autos_to_use = [bl for bl in candidate_autos if rms[bl] <= med_rms]\n", - " stage += 1 # advance to stage 2\n", " elif stage == 2:\n", " # use all unflagged antennas which are auto RFI good, or the best half, whichever is larger\n", " med_rms = np.nanmedian([rms[bl] for bl in candidate_autos])\n", @@ -512,7 +512,6 @@ " good_autos = [bl for bl in candidate_autos if (overall_class[utils.split_bl(bl)[0]] != 'bad')\n", " and (auto_rfi_class[utils.split_bl(bl)[0]] == 'good')]\n", " autos_to_use = (best_half_autos if len(best_half_autos) > len(good_autos) else good_autos)\n", - " stage += 1 # advance to stage 3\n", " elif stage == 3:\n", " # use all unflagged antennas which are auto RFI good or suspect\n", " autos_to_use = [bl for bl in candidate_autos if (overall_class[utils.split_bl(bl)[0]] != 'bad')]\n", @@ -529,12 +528,13 @@ " antenna_class=overall_class)\n", " overall_class += auto_shape_class\n", " \n", - " # check for convergence on flagged antennas and channels \n", + " # check for convergence by seeing whether we've previously gotten to this number of flagged antennas and channels\n", " if stage == 3:\n", - " if (len(overall_class.bad_ants) == n_current_bad_ants) and (np.sum(rfi_flags) == current_flagged_chan_times):\n", + " if (len(overall_class.bad_ants), np.sum(rfi_flags)) in prior_end_states:\n", " break\n", - " current_flagged_chan_times = np.sum(rfi_flags)\n", - " n_current_bad_ants = len(overall_class.bad_ants)" + " prior_end_states.add((len(overall_class.bad_ants), np.sum(rfi_flags)))\n", + " else:\n", + " stage += 1" ] }, {