Skip to content

Commit

Permalink
avoid infinite loop with ping-ponging convergence
Browse files Browse the repository at this point in the history
  • Loading branch information
jsdillon committed Apr 20, 2024
1 parent b24d429 commit 8a8452f
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions notebooks/file_calibration.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -504,15 +505,13 @@
" # 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",
" best_half_autos = [bl for bl in candidate_autos if rms[bl] <= med_rms]\n",
" 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",
Expand All @@ -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"
]
},
{
Expand Down

0 comments on commit 8a8452f

Please sign in to comment.