class_docstr: This class maintains a pandas.dataframe of filenames for all input sections.
  The list of filenames are obtained by searching the specified folders
  or loading from an existing csv file.
  
  Users can query a subset of the dataframe by train/valid/infer partition
  label and input section names.
docstr: list all files by a given input data section::
      if the ``csv_file`` property of ``data_param[modality_name]``
      corresponds to a file, read the list from the file;
      otherwise
          write the list to ``csv_file``.
  
  :return: a table with two columns,
           the column names are ``(COLUMN_UNIQ_ID, modality_name)``.
docstr_tok: ["list","all","files","by","a","given","input","data","section",":",":","if","the","``","csv_file","``","property","of","``","data_param","[","modality_name","]","``","corresponds","to","a","file",",","read","the","list","from","the","file",";","otherwise","write","the","list","to","``","csv_file","``",".",":","return",":","a","table","with","two","columns",",","the","column","names","are","``","(","COLUMN_UNIQ_ID",",","modality_name",")","``","."]
code: def grep_files_by_data_section(self, modality_name):
      """
      list all files by a given input data section::
          if the ``csv_file`` property of ``data_param[modality_name]``
          corresponds to a file, read the list from the file;
          otherwise
              write the list to ``csv_file``.
  
      :return: a table with two columns,
               the column names are ``(COLUMN_UNIQ_ID, modality_name)``.
      """
      if modality_name not in self.data_param:
          tf.logging.fatal(
              "unknown section name [%s], "
              "current input section names: %s.",
              modality_name,
              list(self.data_param),
          )
          raise ValueError
  
      # input data section must have a ``csv_file`` section for loading
      # or writing filename lists
      if isinstance(self.data_param[modality_name], dict):
          mod_spec = self.data_param[modality_name]
      else:
          mod_spec = vars(self.data_param[modality_name])
  
      #########################
      # guess the csv_file path
      #########################
      temp_csv_file = None
      try:
          csv_file = os.path.expanduser(mod_spec.get("csv_file", None))
          if not os.path.isfile(csv_file):
              # writing to the same folder as data_split_file
              default_csv_file = os.path.join(
                  os.path.dirname(self.data_split_file),
                  "{}.csv".format(modality_name),
              )
              tf.logging.info(
                  "`csv_file = %s` not found, "
                  'writing to "%s" instead.',
                  csv_file,
                  default_csv_file,
              )
              csv_file = default_csv_file
              if os.path.isfile(csv_file):
                  tf.logging.info(
                      'Overwriting existing: "%s".', csv_file
                  )
          csv_file = os.path.abspath(csv_file)
      except (AttributeError, KeyError, TypeError):
          tf.logging.debug(
              "`csv_file` not specified, writing the list of "
              "filenames to a temporary file."
          )
          import tempfile
  
          temp_csv_file = os.path.join(
              tempfile.mkdtemp(), "{}.csv".format(modality_name)
          )
          csv_file = temp_csv_file
  
      #############################################
      # writing csv file if path_to_search specified
      ##############################################
      if mod_spec.get("path_to_search", None):
          if not temp_csv_file:
              tf.logging.info(
                  "[%s] search file folders, writing csv file %s",
                  modality_name,
                  csv_file,
              )
          # grep files by section properties and write csv
          try:
              matcher = KeywordsMatching.from_dict(
                  input_dict=mod_spec,
                  default_folder=self.default_image_file_location,
              )
              match_and_write_filenames_to_csv([matcher], csv_file)
          except (IOError, ValueError) as reading_error:
              tf.logging.warning(
                  "Ignoring input section: [%s], "
                  "due to the following error:",
                  modality_name,
              )
              tf.logging.warning(repr(reading_error))
              return pandas.DataFrame(
                  columns=[COLUMN_UNIQ_ID, modality_name]
              )
      else:
          tf.logging.info(
              "[%s] using existing csv file %s, skipped filenames search",
              modality_name,
              csv_file,
          )
  
      if not os.path.isfile(csv_file):
          tf.logging.fatal(
              "[%s] csv file %s not found.", modality_name, csv_file
          )
          raise IOError
      ###############################
      # loading the file as dataframe
      ###############################
      try:
          csv_list = pandas.read_csv(
              csv_file,
              header=None,
              dtype=(str, str),
              names=[COLUMN_UNIQ_ID, modality_name],
              skipinitialspace=True,
          )
      except Exception as csv_error:
          tf.logging.fatal(repr(csv_error))
          raise
  
      if temp_csv_file:
          shutil.rmtree(
              os.path.dirname(temp_csv_file), ignore_errors=True
          )
  
      return csv_list
  
imports: from __future__ import absolute_import
  from __future__ import division
  from __future__ import print_function
  import math
  import os
  import random
  import shutil
  import pandas
  import tensorflow
  from niftynet.engine.signal import TRAIN, VALID, INFER, ALL
  from niftynet.utilities.decorators import singleton
  from niftynet.utilities.filename_matching import KeywordsMatching
  from niftynet.utilities.niftynet_global_config import NiftyNetGlobalConfig
  from niftynet.utilities.util_common import look_up_operations
  from niftynet.utilities.util_csv import match_and_write_filenames_to_csv
  from niftynet.utilities.util_csv import write_csv
label_desc: Use image node_id 5 for calling the ImageSetsPartitioner obj's underlying member method code with example usage: obj.grep_files_by_data_section(modality_name) and returns: csv_list, pandas