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:
              if segments[0] != 0:
                  segments = np.insert(segments, [0], [0])
              else:
                  times.append(float(over[0])/fs)
                  if 1 not in segments:
                      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:
                  idx = over[segments[iseg]]
              else:
                  segments[0] = segments[0]-1                
                  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