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: Label each subject as one of the ``TRAIN``, ``VALID``, ``INFER``,
  use ``self.ratios`` to compute the size of each set.
  
  The results will be written to ``self.data_split_file`` if overwrite
  otherwise it tries to read partition labels from it.
  
  This function sets ``self._partition_ids``.
docstr_tok: ["Label","each","subject","as","one","of","the","``","TRAIN","``",",","``","VALID","``",",","``","INFER","``",",","use","``","self.ratios","``","to","compute","the","size","of","each","set",".","The","results","will","be","written","to","``","self.data_split_file","``","if","overwrite","otherwise","it","tries","to","read","partition","labels","from","it",".","This","function","sets","``","self._partition_ids","``","."]
code: def randomly_split_dataset(self, overwrite=False):
      """
      Label each subject as one of the ``TRAIN``, ``VALID``, ``INFER``,
      use ``self.ratios`` to compute the size of each set.
  
      The results will be written to ``self.data_split_file`` if overwrite
      otherwise it tries to read partition labels from it.
  
      This function sets ``self._partition_ids``.
      """
      if overwrite:
          try:
              valid_fraction, infer_fraction = self.ratios
              valid_fraction = max(min(1.0, float(valid_fraction)), 0.0)
              infer_fraction = max(min(1.0, float(infer_fraction)), 0.0)
          except (TypeError, ValueError):
              tf.logging.fatal(
                  "Unknown format of faction values %s", self.ratios
              )
              raise
  
          if (valid_fraction + infer_fraction) <= 0:
              tf.logging.warning(
                  "To split dataset into training/validation, "
                  "please make sure "
                  '"exclude_fraction_for_validation" parameter is set to '
                  "a float in between 0 and 1. Current value: %s.",
                  valid_fraction,
              )
              # raise ValueError
  
          n_total = self.number_of_subjects()
          n_valid = int(math.ceil(n_total * valid_fraction))
          n_infer = int(math.ceil(n_total * infer_fraction))
          n_train = int(n_total - n_infer - n_valid)
          phases = (
              [TRAIN] * n_train + [VALID] * n_valid + [INFER] * n_infer
          )
          if len(phases) > n_total:
              phases = phases[:n_total]
          random.shuffle(phases)
          write_csv(
              self.data_split_file,
              zip(self._file_list[COLUMN_UNIQ_ID], phases),
          )
      elif os.path.isfile(self.data_split_file):
          tf.logging.warning(
              "Loading from existing partitioning file %s, "
              "ignoring partitioning ratios.",
              self.data_split_file,
          )
  
      if os.path.isfile(self.data_split_file):
          try:
              self._partition_ids = pandas.read_csv(
                  self.data_split_file,
                  header=None,
                  dtype=(str, str),
                  names=[COLUMN_UNIQ_ID, COLUMN_PHASE],
                  skipinitialspace=True,
              )
              assert (
                  not self._partition_ids.empty
              ), "partition file is empty."
          except Exception as csv_error:
              tf.logging.warning(
                  "Unable to load the existing partition file %s, %s",
                  self.data_split_file,
                  repr(csv_error),
              )
              self._partition_ids = None
  
          try:
              phase_strings = self._partition_ids[COLUMN_PHASE]
              phase_strings = phase_strings.astype(str).str.lower()
              is_valid_phase = phase_strings.isin(SUPPORTED_PHASES)
              assert (
                  is_valid_phase.all()
              ), "Partition file contains unknown phase id."
              self._partition_ids[COLUMN_PHASE] = phase_strings
          except (TypeError, AssertionError):
              tf.logging.warning(
                  "Please make sure the values of the second column "
                  "of data splitting file %s, in the set of phases: %s.\n"
                  "Remove %s to generate random data partition file.",
                  self.data_split_file,
                  SUPPORTED_PHASES,
                  self.data_split_file,
              )
              raise ValueError
  
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 6 for calling the ImageSetsPartitioner obj's underlying member method code with example usage: obj.randomly_split_dataset(overwrite) without return types