              self.rename_faces(map_faces)
              self.alignments.data[key] = sorted_alignments
              reindexed += 1
          logger.info("%s Frames had their faces reindexed", reindexed)
  
      def map_face_names(self, alignments, sorted_alignments, frame):
          """ Map the old and new indexes for face renaming """
          map_faces = list()
          if not self.faces:
              return map_faces
          for idx, alignment in enumerate(alignments):
              idx_new = sorted_alignments.index(alignment)
              mapping = [{"old_name": face["face_fullname"],
                          "new_name": "{}_{}{}".format(frame,
                                                       idx_new,
                                                       face["face_extension"])}
                         for face in self.faces.file_list_sorted
                         if face["frame_name"] == frame
                         and face["face_index"] == idx]
              if not mapping:
                  logger.warning("No face image found for frame '%s' at index %s", frame, idx)
              map_faces.extend(mapping)
          return map_faces
  
      def rename_faces(self, map_faces):
          """ Rename faces
              Done in 2 iterations as two files cannot share the same name """
          temp_ext = ".temp_move"
          for action in ("temp", "final"):
              for face in map_faces:
                  old = face["old_name"]
                  new = face["new_name"]
                  if old == new:
                      continue
                  old_file = old if action == "temp" else old + temp_ext
                  new_file = old + temp_ext if action == "temp" else new
                  src = os.path.join(self.faces.folder, old_file)
                  dst = os.path.join(self.faces.folder, new_file)
                  os.rename(src, dst)
                  if action == "final":
                      logger.verbose("Renamed '%s' to '%s'", old, new)
  
  
  class Spatial():
      """ Apply spatial temporal filtering to landmarks
          Adapted from:
 
</s> remove             map_faces = self.map_face_names(alignments,
                                            sorted_alignments,
                                            frame)
            self.rename_faces(map_faces)
 </s> add             logger.trace("Sorting alignments for frame: '%s'", frame) </s> remove     def rename_faces(self):
        """ Rename the aligned faces to match their "
            new index in alignments file """
        current_frame = ""
        current_index = 0
        rename_count = 0
        for face in tqdm(self.items.file_list_sorted,
                         desc="Renaming aligned faces",
                         total=self.items.count):

            if face["frame_name"] not in self.removed:
                continue
            current_index, current_frame = self.set_image_index(
                current_index,
                current_frame,
                face["frame_name"])
            if current_index != face["face_index"]:
                rename_count += self.rename_file(face,
                                                 current_frame,
                                                 current_index)

            current_index += 1
        if rename_count == 0:
            logger.info("No files were renamed. Exiting")
            return
        logger.info("%s face(s) were renamed to match with alignments file", rename_count)

    @staticmethod
    def set_image_index(index, current, original):
        """ Set the current processing image and index """
        idx = 0 if current != original else index
        return idx, original

    def rename_file(self, face, frame_name, index):
        """ Rename the selected file """
        old_file = face["face_name"] + face["face_extension"]
        new_file = "{}_{}{}".format(frame_name,
                                    str(index),
                                    face["face_extension"])
        src = os.path.join(self.items.folder, old_file)
        dst = os.path.join(self.items.folder, new_file)
        os.rename(src, dst)
        logger.verbose("Renamed '%s' to '%s'", src, dst)
        return 1

 </s> add  </s> remove             sorted_alignments = sorted([item for item in alignments],
                                       key=lambda x: (x[self.axis]))
 </s> add             sorted_alignments = sorted([item for item in alignments], key=lambda x: (x[self.axis])) </s> remove             logger.debug("No face to delete")
 </s> add             logger.debug("No face to delete: (frame: '%s', idx %s)", frame, idx)
        return reindexed
              self.rename_faces(map_faces)
              self.alignments.data[key] = sorted_alignments
              reindexed += 1
          logger.info("%s Frames had their faces reindexed", reindexed)
        return reindexed
        return reindexed
        return reindexed
        return reindexed
        return reindexed
        return reindexed
        return reindexed
        return reindexed
        return reindexed
        return reindexed
        return reindexed
        return reindexed
        return reindexed
        return reindexed
        return reindexed
        return reindexed
        return reindexed
        return reindexed
        return reindexed
        return reindexed
        return reindexed
        return reindexed
        return reindexed
        return reindexed
        return reindexed
        return reindexed
        return reindexed
        return reindexed
        return reindexed
        return reindexed
        return reindexed
        return reindexed
        return reindexed
        return reindexed
        return reindexed
        return reindexed
        return reindexed
  
  
  class Spatial():
      """ Apply spatial temporal filtering to landmarks
          Adapted from:
keep keep keep keep replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace keep keep keep keep keep
 Add Face Hashes to Alignments (#550)

* Convert main scripts to use face hashes

* Alignment tool: Use hashes, add logging, add face rename function

* More logging. Update Manual tool to work with hashing 
tools/lib_alignments/jobs.py