docstr: Detect anomalies using a threshold on anomaly scores.
docstr_tok: ["Detect","anomalies","using","a","threshold","on","anomaly","scores","."]
code: 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
  
file_path: luminol/src/luminol/anomaly_detector.py
imports: from luminol import exceptions, utils
  from luminol.algorithms.anomaly_detector_algorithms.all import anomaly_detector_algorithms
  from luminol.modules.anomaly import Anomaly
  from luminol.modules.time_series import TimeSeries
  from luminol.constants import ANOMALY_DETECTOR_ALGORITHM, ANOMALY_THRESHOLD, ANOMALY_DETECTOR_REFINE_ALGORITHM, DEFAULT_SCORE_PERCENT_THRESHOLD
label_desc: Use image node_id 5 for calling the AnomalyDetector obj's underlying member method code with example usage: obj._detect_anomalies() without return types