code: def get_number_of_leaves_from_tree(alidir):
      stdout = get_command_stdout(
          "tree-info {0}/tree 2>/dev/null | grep num-pdfs".format(
              alidir
          )
      )
      parts = stdout.split()
      assert parts[0] == "num-pdfs"
      num_leaves = int(parts[1])
      if num_leaves == 0:
          raise Exception("Number of leaves is 0")
      return num_leaves
  
imports: from __future__ import print_function
  from __future__ import division
  import argparse
  import logging
  import math
  import os
  import subprocess
  import sys
  import threading
label_desc: Use image node_id 9 for calling a global function with example usage: get_number_of_leaves_from_tree(alidir) and returns: num_leaves