code: def peaks_in_time(dat, troughs=False):
      
      diff_dat = diff(dat)
      increasing = zeros(len(diff_dat))
      increasing[diff_dat > 0] = 1 # mask for all points where dat is increasing
      flipping = diff(increasing) # peaks are -1, troughs are 1, the rest is zero
      
      target = -1 if not troughs else 1
          
      return where(flipping == target)[0]
docs: Find indices of peaks or troughs in data.
      
      Parameters
      ----------
      dat : ndarray (dtype='float')
          vector with the data
      troughs : bool
          if True, will return indices of troughs instead of peaks
          
      Returns
      -------
      nadarray of int
          indices of peaks (or troughs) in dat
          
      Note
      ----
      This function does not deal well with flat signal; when the signal is not 
      increasing, it is assumed to be descreasing. As a result, this function
      finds troughs where the signal begins to increase after either decreasing 
      or remaining constant