code: def create_new_data_copy(
      test_key: str,
      datalist_json: dict,
      data_dir: str,
      num_input_channels: int,
      output_datafolder: str,
  ) -> None:
      """
      Create and organize a new copy of data to meet the requirements of nnU-Net V2
  
      Args:
          test_key: key for test data in the data list .json.
          datalist_json: original data list .json (required by most monai tutorials).
          data_dir: raw data directory.
          num_input_channels: number of input (image) channels.
          output_datafolder: output folder.
      """
      _index = 0
      new_datalist_json: dict = {"training": [], test_key: []}
  
      for _key, _folder, _label_folder in list(
          zip(
              ["training", test_key],
              ["imagesTr", "imagesTs"],
              ["labelsTr", "labelsTs"],
          )
      ):
          if _key is None:
              continue
  
          logger.info(f"converting data section: {_key}...")
          for _k in (
              tqdm(range(len(datalist_json[_key])))
              if has_tqdm
              else range(len(datalist_json[_key]))
          ):
              orig_img_name = (
                  datalist_json[_key][_k]["image"]
                  if isinstance(datalist_json[_key][_k], dict)
                  else datalist_json[_key][_k]
              )
              img_name = f"case_{_index}"
              _index += 1
  
              # copy image
              nda = monai.transforms.LoadImage(
                  image_only=True,
                  ensure_channel_first=True,
                  simple_keys=True,
              )(os.path.join(data_dir, orig_img_name))
              affine = nda.meta["original_affine"]
              nda = nda.numpy()
              for _l in range(num_input_channels):
                  outimg = nib.Nifti1Image(nda[_l, ...], affine)
                  index = "_" + str(_l + 10000)[-4:]
                  nib.save(
                      outimg,
                      os.path.join(
                          output_datafolder,
                          _folder,
                          img_name + index + ".nii.gz",
                      ),
                  )
  
              # copy label
              if (
                  isinstance(datalist_json[_key][_k], dict)
                  and "label" in datalist_json[_key][_k]
              ):
                  nda = monai.transforms.LoadImage(
                      image_only=True,
                      ensure_channel_first=True,
                      simple_keys=True,
                  )(
                      os.path.join(
                          data_dir, datalist_json[_key][_k]["label"]
                      )
                  )
                  affine = nda.meta["original_affine"]
                  nda = nda.numpy().astype(np.uint8)
                  nda = (
                      nda[0, ...]
                      if nda.ndim == 4 and nda.shape[0] == 1
                      else nda
                  )
                  nib.save(
                      nib.Nifti1Image(nda, affine),
                      os.path.join(
                          output_datafolder,
                          _label_folder,
                          img_name + ".nii.gz",
                      ),
                  )
  
              if isinstance(datalist_json[_key][_k], dict):
                  _val = copy.deepcopy(datalist_json[_key][_k])
                  _val["new_name"] = img_name
                  new_datalist_json[_key].append(_val)
              else:
                  new_datalist_json[_key].append(
                      {
                          "image": datalist_json[_key][_k],
                          "new_name": img_name,
                      }
                  )
  
              ConfigParser.export_config_file(
                  config=new_datalist_json,
                  filepath=os.path.join(
                      output_datafolder, "datalist.json"
                  ),
                  fmt="json",
                  sort_keys=True,
                  indent=4,
                  ensure_ascii=False,
              )
  
      return
  
file_path: MONAI/monai/apps/nnunet/utils.py
imports: from __future__ import annotations
  import copy
  import os
  import numpy
  import monai
  from monai.bundle import ConfigParser
  from monai.utils import StrEnum, ensure_tuple, optional_import
label_desc: Use image node_id 2 for calling a global function with example usage: create_new_data_copy(test_key, datalist_json, data_dir, num_input_channels, output_datafolder) without return types