code: def _max_p2t(data, delta):
      
      turning_points = []  # A list of tuples of (amplitude, sample)
      for i in range(1, len(data) - 1):
          if (data[i] < data[i - 1] and data[i] < data[i + 1]) or\
             (data[i] > data[i - 1] and data[i] > data[i + 1]):
              turning_points.append((data[i], i))
      if len(turning_points) >= 1:
          amplitudes = np.empty([len(turning_points) - 1],)
          half_periods = np.empty([len(turning_points) - 1],)
      else:
          print('Turning points has length: ' + str(len(turning_points)) +
                ' data have length: ' + str(len(data)))
          return 0.0, 0.0, 0.0
      for i in range(1, len(turning_points)):
          half_periods[i - 1] = (delta * (turning_points[i][1] -
                                          turning_points[i - 1][1]))
          amplitudes[i - 1] = np.abs(turning_points[i][0] -
                                     turning_points[i - 1][0])
      amplitude = np.max(amplitudes)
      period = 2 * half_periods[np.argmax(amplitudes)]
      return amplitude, period, delta * turning_points[np.argmax(amplitudes)][1]
docs: Finds the maximum peak-to-trough amplitude and period.
      Originally designed to be used to calculate magnitudes (by \
      taking half of the peak-to-trough amplitude as the peak amplitude).
  
      :type data: numpy.ndarray
      :param data: waveform trace to find the peak-to-trough in.
      :type delta: float
      :param delta: Sampling interval in seconds
  
      :returns: tuple of (amplitude, period, time) with amplitude in the same \
          scale as given in the input data, and period in seconds, and time in \
          seconds from the start of the data window.
      :rtype: tuple