code: def sortframe(frame):
      '''
      sorts particles for a frame
      '''
      d = frame['data'];
      sortedargs = np.lexsort([d['xi'],d['yi'],d['zi']])
      d = d[sortedargs];
      frame['data']=d;
      return frame;