docstr: preprocess files, transfer to the correct type, and save it to the directory.
docstr_tok: ["preprocess","files",",","transfer","to","the","correct","type",",","and","save","it","to","the","directory","."]
code: def load_save(self):
      """
      preprocess files, transfer to the correct type, and save it to the directory.
      """
      print(
          "Start convert images to numpy array using {}, please wait patiently".format(
              self.gpu_tag
          )
      )
  
      tic = time.time()
      with open(self.dataset_json_path, "r", encoding="utf-8") as f:
          dataset_json_dict = json.load(f)
  
      if self.image_files_test:
          process_files = (
              self.image_files,
              self.label_files,
              self.image_files_test,
          )
          process_tuple = ("images", "labels", "images_test")
          save_tuple = (
              self.image_path,
              self.label_path,
              self.image_path_test,
          )
      else:
          process_files = (self.image_files, self.label_files)
          process_tuple = ("images", "labels")
          save_tuple = (self.image_path, self.label_path)
  
      for i, files in enumerate(process_files):
          pre = self.preprocess[process_tuple[i]]
          savepath = save_tuple[i]
  
          for f in tqdm(
              files,
              total=len(files),
              desc="preprocessing the {}".format(
                  ["images", "labels", "images_test"][i]
              ),
          ):
              # load data will transpose the image from "zyx" to "xyz"
              spacing = (
                  dataset_json_dict["training"][
                      osp.basename(f).split(".")[0]
                  ]["spacing"]
                  if i == 0
                  else None
              )
              f_nps = Prep.load_medical_data(f)
  
              for volume_idx, f_np in enumerate(f_nps):
                  for op in pre:
                      if op.__name__ == "resample":
                          f_np, new_spacing = op(
                              f_np, spacing=spacing
                          )  # (960, 15, 960) if transpose
                      else:
                          f_np = op(f_np)
  
                  f_np = (
                      f_np.astype("float32")
                      if i == 0
                      else f_np.astype("int32")
                  )
                  volume_idx = (
                      "" if len(f_nps) == 1 else f"-{volume_idx}"
                  )
                  np.save(
                      join_paths(
                          savepath,
                          osp.basename(f).split(".")[0] + volume_idx,
                      ),
                      f_np,
                  )
  
              if i == 0:
                  dataset_json_dict["training"][
                      osp.basename(f).split(".")[0]
                  ]["spacing_resample"] = new_spacing
  
      with open(self.dataset_json_path, "w", encoding="utf-8") as f:
          json.dump(dataset_json_dict, f, ensure_ascii=False, indent=4)
  
      print(
          "The preprocess time on {} is {}".format(
              self.gpu_tag, time.time() - tic
          )
      )
  
imports: import os
  import os.path
  import sys
  import time
  import glob
  import numpy
  import nibabel
  import SimpleITK
  from tqdm import tqdm
  import json
  from medicalseg.utils import get_image_list
  from tools.preprocess_utils import uncompressor, global_var, add_qform_sform, join_paths
label_desc: Use image node_id 4 for calling the Prep obj's underlying member method code with example usage: obj.load_save() without return types