code: def infer_ndims_from_file(file_path, loader=None):
      """
      Get spatial rank of the image file.
  
      :param file_path:
      :param loader:
      :return:
      """
      image_header = load_image_obj(file_path, loader).header
      try:
          return int(image_header["dim"][0])
      except (TypeError, KeyError, IndexError):
          pass
      try:
          return int(len(image_header.get_data_shape()))
      except (TypeError, AttributeError):
          pass
  
      tf.logging.fatal(
          "unsupported file header in: {}".format(file_path)
      )
      raise IOError(
          "could not get ndims from file header, please "
          "consider convert image files to NifTI format."
      )
  
imports: from __future__ import absolute_import, print_function, unicode_literals
  import errno
  import importlib
  import logging
  import os
  import re
  import sys
  import warnings
  import nibabel
  import numpy
  import pandas
  import scipy.ndimage
  import tensorflow
  from tensorflow.core.framework import summary_pb2
  from niftynet.io.image_loader import load_image_obj
  from niftynet.utilities.niftynet_global_config import NiftyNetGlobalConfig
  from niftynet.utilities.util_import import require_module
label_desc: Use image node_id 1 for calling a global function with example usage: infer_ndims_from_file(file_path, loader) and returns: int, int