code: def detect_events(dat, method, value=None):
      if 'thresh' in method or 'custom' == method:
          if method == 'above_thresh':
              above_det = dat >= value
              detected = _detect_start_end(above_det)
          if method == 'below_thresh':
              below_det = dat < value
              detected = _detect_start_end(below_det)
          if method == 'between_thresh':
              above_det = dat >= value[0]
              below_det = dat < value[1]
              between_det = logical_and(above_det, below_det)
              detected = _detect_start_end(between_det)
          if method == 'custom':
              detected = _detect_start_end(dat)
          if detected is None:
              return None
          if method in ['above_thresh', 'custom']:    
              detected = insert(detected, 1, 0, axis=1)
              for i in detected:
                  i[1] = i[0] + argmax(dat[i[0]:i[2]])
          if method in ['below_thresh', 'between_thresh']:
              detected = insert(detected, 1, 0, axis=1)
              for i in detected:
                  i[1] = i[0] + argmin(dat[i[0]:i[2]])
      if method == 'maxima':
          peaks = argrelmax(dat)[0]
          detected = vstack((peaks, peaks, peaks)).T
          if value is not None:
              detected = detected[dat[peaks] > value, :]
      return detected