docstr: :param save_path: This needs to be the full path to the dataset.json you intend to write, default is the raw_data_path
  :param images_dir: path to the images folder of that dataset
  :param labels_dir: path to the label folder of that dataset
  :param modalities: tuple of strings with modality names. must be in the same order as the images (first entry
  corresponds to _0000.nii.gz, etc). Example: ('T1', 'T2', 'FLAIR').
  :param labels: dict with int->str (key->value) mapping the label IDs to label names. Note that 0 is always
  supposed to be background! Example: {0: 'background', 1: 'edema', 2: 'enhancing tumor'}
  :param dataset_name: The name of the dataset. Can be anything you want
  :param license_desc:
  :param dataset_description:
  :param dataset_reference: website of the dataset, if available
  :return: saved dataset.json 
docstr_tok: [":","param","save_path",":","This","needs","to","be","the","full","path","to","the","dataset.json","you","intend","to","write",",","default","is","the","raw_data_path",":","param","images_dir",":","path","to","the","images","folder","of","that","dataset",":","param","labels_dir",":","path","to","the","label","folder","of","that","dataset",":","param","modalities",":","tuple","of","strings","with","modality","names",".","must","be","in","the","same","order","as","the","images","(","first","entry","corresponds","to","_0000.nii.gz",",","etc",")",".","Example",":","(","'T1","'",",","'T2","'",",","'FLAIR","'",")",".",":","param","labels",":","dict","with","int-",">","str","(","key-",">","value",")","mapping","the","label","IDs","to","label","names",".","Note","that","0","is","always","supposed","to","be","background","!","Example",":","{","0",":","'background","'",",","1",":","'edema","'",",","2",":","'enhancing","tumor","'","}",":","param","dataset_name",":","The","name","of","the","dataset",".","Can","be","anything","you","want",":","param","license_desc",":",":","param","dataset_description",":",":","param","dataset_reference",":","website","of","the","dataset",",","if","available",":","return",":","saved","dataset.json"]
code: def generate_dataset_json(
      self,
      modalities,
      labels,
      dataset_name,
      license_desc="hands off!",
      dataset_description="",
      dataset_reference="",
      save_path=None,
  ):
      """
      :param save_path: This needs to be the full path to the dataset.json you intend to write, default is the raw_data_path
      :param images_dir: path to the images folder of that dataset
      :param labels_dir: path to the label folder of that dataset
      :param modalities: tuple of strings with modality names. must be in the same order as the images (first entry
      corresponds to _0000.nii.gz, etc). Example: ('T1', 'T2', 'FLAIR').
      :param labels: dict with int->str (key->value) mapping the label IDs to label names. Note that 0 is always
      supposed to be background! Example: {0: 'background', 1: 'edema', 2: 'enhancing tumor'}
      :param dataset_name: The name of the dataset. Can be anything you want
      :param license_desc:
      :param dataset_description:
      :param dataset_reference: website of the dataset, if available
      :return: saved dataset.json
      """
  
      if save_path is not None:
          self.dataset_json_path = join_paths(
              save_path, "dataset.json"
          )  # save the dataset.json to raw path
  
      if osp.exists(self.dataset_json_path):
          print(
              f"Dataset json exists, skipping. Delete file {self.dataset_json_path} to regenerate."
          )
          return
  
      if not self.dataset_json_path.endswith("dataset.json"):
          print(
              "WARNING: output file name is not dataset.json! This may be intentional or not. You decide. "
              "Proceeding anyways..."
          )
  
      json_dict = {}
      json_dict["name"] = dataset_name
      json_dict["description"] = dataset_description
      json_dict["reference"] = dataset_reference
      json_dict["licence"] = license_desc
      json_dict["modality"] = {
          str(i): modalities[i] for i in range(len(modalities))
      }
      json_dict["labels"] = {str(i): labels[i] for i in labels.keys()}
  
      # set information of training and testing file
      json_dict["training"] = {}
  
      for i, image_name in enumerate(
          tqdm(
              self.image_files,
              total=len(self.image_files),
              desc="Load train file information into dataset.json",
          )
      ):
          infor_dict = {
              "image": image_name,
              "label": self.label_files[i],
          }  # nii.gz filename
          infor_dict = self.set_image_infor(image_name, infor_dict)
          json_dict["training"][
              os.path.split(image_name)[1].split(".")[0]
          ] = infor_dict
  
      json_dict["test"] = {}
      if self.image_files_test:
          for i, image_name in enumerate(
              tqdm(
                  self.image_files_test,
                  total=len(self.image_files_test),
                  desc="Load Test file information",
              )
          ):
              infor_dict = {"image": image_name}
              infor_dict = self.set_image_infor(image_name, infor_dict)
              json_dict["test"][
                  os.path.split(image_name)[1].split(".")[0]
              ] = infor_dict
  
      with open(self.dataset_json_path, "w", encoding="utf-8") as f:
          json.dump(json_dict, f, ensure_ascii=False, indent=4)
          print(
              "save dataset.json to {}".format(self.dataset_json_path)
          )
  
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 11 for calling the Prep obj's underlying member method code with example usage: obj.generate_dataset_json(modalities, labels, dataset_name, license_desc, dataset_description, dataset_reference, save_path) without return types