docs: def mean_velocity(self, tol=0.05, Lx=None):
          '''
          Calculate the mean velocity for a step (mm/ms which is equivalent to
          m/s). Fit a line to the capacitance data and get the slope.
          '''
          dx = None
          dt = None
          p = None
          ind = None
          t_end = None
  
          if self.area == 0:
              return dict(dx=dx, dt=dt, p=p, ind=ind, t_end=t_end)
  
          x = self.x_position(Lx=Lx)
  
          # find the first and last valid indices
          ind_start = mlab.find(x.mask==False)[0]
          ind_last = mlab.find(x.mask==False)[-1]
  
          # if the original x value is within tol % of the final x value, include
          # all samples
          if x[ind_start] > (1 - tol) * x[ind_last] or x[ind_last] < 0:
              ind_stop = ind_last
          else: # otherwise, stop when x reaches (1 - tol) % of it's final value
              ind_stop = mlab.find(x > (1 - tol) * x[ind_last])[0]
  
          ind = [ind_start, ind_stop]
  
          # if we have at least 2 valid samples
          if len(ind) >=2:
              dx = np.diff(x[ind])[0]
              dt = np.diff(self.time[ind])[0] # ms
  
              # suppress polyfit warnings
              with warnings.catch_warnings():
                  warnings.simplefilter("ignore")
                  # fit a line to the data
                  p = np.polyfit(self.time[ind[0]:ind[1]], x[ind[0]:ind[1]], 1)
  
              # find time when the the line intercepts x[ind_last]
              ind_stop = mlab.find(self.time > \
                                   (x[ind_last] - p[1]) / p[0])
              if len(ind_stop):
                  t_end = self.time[ind_stop[0]]
              else:
                  t_end = self.time[-1]
          return dict(dx=dx, dt=dt, p=p, ind=ind, t_end=t_end)