code: def spike_times(signal, threshold, fs, absval=True):
      
      times = []
      if absval:
          signal = np.abs(signal)
      over, = np.where(signal>threshold)
      segments, = np.where(np.diff(over) > 1)
  
      if len(over) > 1:
          if len(segments) == 0:
              segments = [0, len(over)-1]
          else:
              # add end points to sections for looping
              if segments[0] != 0:
                  segments = np.insert(segments, [0], [0])
              else:
                  #first point in singleton
                  times.append(float(over[0])/fs)
                  if 1 not in segments:
                      # make sure that first point is in there
                      segments[0] = 1
              if segments[-1] != len(over)-1:
                  segments = np.insert(segments, [len(segments)], [len(over)-1])
              else:
                  times.append(float(over[-1])/fs)
  
          for iseg in range(1,len(segments)):
              if segments[iseg] - segments[iseg-1] == 1:
                  # only single point over threshold
                  idx = over[segments[iseg]]
              else:
                  segments[0] = segments[0]-1                
                  # find maximum of continuous set over max
                  idx = over[segments[iseg-1]+1] + np.argmax(signal[over[segments[iseg-1]+1]:over[segments[iseg]]])
              times.append(float(idx)/fs)
      elif len(over) == 1:
          times.append(float(over[0])/fs)
          
      if len(times)>0:
      	return refractory(times)
      else:
      	return times
docs: Detect spikes from a given signal
  
      :param signal: Spike trace recording (vector)
      :type signal: numpy array
      :param threshold: Threshold value to determine spikes
      :type threshold: float
      :param absval: Whether to apply absolute value to signal before thresholding
      :type absval: bool
      :returns: list(float) of spike times in seconds
  
      For every continuous set of points over given threshold, 
      returns the time of the maximum