@@ -218,19 +218,22 @@ def run_single_simulation(
218218 evolved_stds .append (stats ["std" ])
219219
220220 # Cluster analysis (at end of measurement)
221- if step == measurement_steps - 1 and prey >= min_count and pred >= ( min_count // 4 ) :
222- prey_stats = get_cluster_stats_fast ( model . grid , 1 )
223- pred_stats = get_cluster_stats_fast ( model . grid , 2 )
221+ if step == measurement_steps - 1 :
222+ prey_survived = prey_pops [ - 1 ] > min_count
223+ pred_survived = pred_pops [ - 1 ] > ( min_count // 4 )
224224
225- cluster_sizes_prey = prey_stats ['sizes' ].tolist ()
226- cluster_sizes_pred = pred_stats ['sizes' ].tolist ()
225+ if prey_survived :
226+ prey_stats = get_cluster_stats_fast (model .grid , 1 )
227+ cluster_sizes_prey = prey_stats ['sizes' ].tolist ()
228+ largest_fractions_prey .append (prey_stats ['largest_fraction' ])
227229
228- largest_fractions_prey .append (prey_stats ['largest_fraction' ])
229- largest_fractions_pred .append (pred_stats ['largest_fraction' ])
230- # NOTE: Change in largest fraction calculation if needed for critical point location
230+ if pred_survived :
231+ pred_stats = get_cluster_stats_fast (model .grid , 2 )
232+ cluster_sizes_pred = pred_stats ['sizes' ].tolist ()
233+ largest_fractions_pred .append (pred_stats ['largest_fraction' ])
231234
232- # PCF
233- if compute_pcf :
235+ # PCF requires both
236+ if compute_pcf and prey_survived and pred_survived :
234237 max_dist = min (grid_size / 2 , cfg .pcf_max_distance )
235238 pcf_data = compute_all_pcfs_fast (model .grid , max_dist , cfg .pcf_n_bins )
236239 pcf_samples ['prey_prey' ].append (pcf_data ['prey_prey' ])
0 commit comments