code: def apply_wbc_to_patient(inputs):
      """
      wrapper around prediction box consolidation: weighted cluster scoring (wcs). processes a single patient.
      loops over batch elements in patient results (1 in 3D, slices in 2D) and foreground classes,
      aggregates and stores results in new list.
      :return. patient_results_list: list over batch elements. each element is a list over boxes, where each box is
                                   one dictionary: [[box_0, ...], [box_n,...]]. batch elements are slices for 2D
                                   predictions, and a dummy batch dimension of 1 for 3D predictions.
      :return. pid: string. patient id.
      """
      in_patient_results_list, pid, class_dict, wcs_iou, n_ens = inputs
      out_patient_results_list = [
          [] for _ in range(len(in_patient_results_list))
      ]
  
      for bix, b in enumerate(in_patient_results_list):
          for cl in list(class_dict.keys()):
              boxes = [
                  (ix, box)
                  for ix, box in enumerate(b)
                  if (
                      box["box_type"] == "det"
                      and box["box_pred_class_id"] == cl
                  )
              ]
              box_coords = np.array([b[1]["box_coords"] for b in boxes])
              box_scores = np.array([b[1]["box_score"] for b in boxes])
              box_center_factor = np.array(
                  [b[1]["box_patch_center_factor"] for b in boxes]
              )
              box_n_overlaps = np.array(
                  [b[1]["box_n_overlaps"] for b in boxes]
              )
              box_patch_id = np.array([b[1]["patch_id"] for b in boxes])
  
              if 0 not in box_scores.shape:
                  keep_scores, keep_coords = weighted_box_clustering(
                      np.concatenate(
                          (
                              box_coords,
                              box_scores[:, None],
                              box_center_factor[:, None],
                              box_n_overlaps[:, None],
                          ),
                          axis=1,
                      ),
                      box_patch_id,
                      wcs_iou,
                      n_ens,
                  )
  
                  for boxix in range(len(keep_scores)):
                      out_patient_results_list[bix].append(
                          {
                              "box_type": "det",
                              "box_coords": keep_coords[boxix],
                              "box_score": keep_scores[boxix],
                              "box_pred_class_id": cl,
                          }
                      )
  
          # add gt boxes back to new output list.
          out_patient_results_list[bix].extend(
              [box for box in b if box["box_type"] == "gt"]
          )
  
      return [out_patient_results_list, pid]
  
imports: import os
  import numpy
  import torch
  from scipy.stats import norm
  from collections import OrderedDict
  from multiprocessing import Pool
  import pickle
  import pandas
label_desc: Use image node_id 1 for calling a global function with example usage: apply_wbc_to_patient(inputs) and returns: list