code: def level_thickness(p, p_top=0., p_bot=1.01325e5):
      
      p_vals = to_pascal(p.values.copy())
      dp_vals = np.empty_like(p_vals)
      # Bottom level extends from p[0] to halfway betwen p[0] and p[1].
      dp_vals[0] = p_bot - 0.5*(p_vals[0] + p_vals[1])
      # Middle levels extend from halfway between [k-1], [k] and [k], [k+1].
      dp_vals[1:-1] = 0.5*(p_vals[0:-2] - p_vals[2:])
      # Top level extends from halfway between top two levels to 0 hPa.
      dp_vals[-1] = 0.5*(p_vals[-2] + p_vals[-1]) - p_top
      dp = p.copy()
      dp.values = dp_vals
      return dp
docs: Calculates the thickness, in Pa, of each pressure level.
  
      Assumes that the pressure values given are at the center of that model
      level, except for the lowest value (typically 1000 hPa), which is the
      bottom boundary. The uppermost level extends to 0 hPa.
  
      Unlike `dp_from_p`, this does not incorporate the surface pressure.