code: def mask_to_n_loudest_clustered_events(self, n_loudest=10,
                                             ranking_statistic="newsnr",
                                             cluster_window=10):
          
          # If this becomes memory intensive we can optimize
          stat_instance = sngl_statistic_dict[ranking_statistic]([])
          stat = stat_instance.single(self.trigs)[self.mask]
  
          # Used for naming in plots ... Seems an odd place for this to live!
          if ranking_statistic == "newsnr":
              self.stat_name = "Reweighted SNR"
          elif ranking_statistic == "newsnr_sgveto":
              self.stat_name = "Reweighted SNR (+sgveto)"
          elif ranking_statistic == "newsnr_sgveto_psdvar":
              self.stat_name = "Reweighted SNR (+sgveto+psdvar)"
          elif ranking_statistic == "snr":
              self.stat_name = "SNR"
          else:
              self.stat_name = ranking_statistic
  
          times = self.end_time
          index = stat.argsort()[::-1]
          new_times = []
          new_index = []
          for curr_idx in index:
              curr_time = times[curr_idx]
              for time in new_times:
                  if abs(curr_time - time) < cluster_window:
                      break
              else:
                  # Only get here if no other triggers within cluster window
                  new_index.append(curr_idx)
                  new_times.append(curr_time)
              if len(new_index) >= n_loudest:
                  break
          index = np.array(new_index)
          self.stat = stat[index]
          if self.mask.dtype == 'bool':
              orig_indices = np.flatnonzero(self.mask)[index]
              self.mask[:] = False
              self.mask[orig_indices] = True
          else:
              self.mask = self.mask[index]
docs: Edits the mask property of the class to point to the N loudest
          single detector events as ranked by ranking statistic. Events are
          clustered so that no more than 1 event within +/- cluster-window will
          be considered.