docs: def _detect_anomalies(self):
          """
          Detect anomalies using a threshold on anomaly scores.
          """
          anom_scores = self.anom_scores
          max_anom_score = anom_scores.max()
          anomalies = []
  
          if max_anom_score:
              threshold = self.threshold or max_anom_score * self.score_percent_threshold
              # Find all the anomaly intervals.
              intervals = []
              start, end = None, None
              for timestamp, value in anom_scores.iteritems():
                  if value > threshold:
                      end = timestamp
                      if not start:
                          start = timestamp
                  elif start and end is not None:
                      intervals.append([start, end])
                      start = None
                      end = None
              if start is not None:
                  intervals.append([start, end])
  
              # Locate the exact anomaly point within each anomaly interval.
              for interval_start, interval_end in intervals:
                  interval_series = anom_scores.crop(interval_start, interval_end)
  
                  self.refine_algorithm_params['time_series'] = interval_series
                  refine_algorithm = self.refine_algorithm(**self.refine_algorithm_params)
                  scores = refine_algorithm.run()
                  max_refine_score = scores.max()
  
                  # Get the timestamp of the maximal score.
                  max_refine_timestamp = scores.timestamps[scores.values.index(max_refine_score)]
                  anomaly = Anomaly(interval_start, interval_end, interval_series.max(), max_refine_timestamp)
                  anomalies.append(anomaly)
  
          self.anomalies = anomalies