code: def avg_surface_distance(
      test=None,
      reference=None,
      confusion_matrix=None,
      nan_for_nonexisting=True,
      voxel_spacing=None,
      connectivity=1,
      **kwargs,
  ):
      if confusion_matrix is None:
          confusion_matrix = ConfusionMatrix(test, reference)
      (
          test_empty,
          test_full,
          reference_empty,
          reference_full,
      ) = confusion_matrix.get_existence()
      if test_empty or test_full or reference_empty or reference_full:
          if nan_for_nonexisting:
              return float("NaN")
          else:
              return 0
      test, reference = (
          confusion_matrix.test,
          confusion_matrix.reference,
      )
      return metric.asd(test, reference, voxel_spacing, connectivity)
  
imports: import numpy
  from medpy import metric
label_desc: Use image node_id 22 for calling a global function with example usage: avg_surface_distance(test, reference, confusion_matrix, nan_for_nonexisting, voxel_spacing, connectivity) and returns: metric, float, int