class_docstr: This class generates samples using the coordinates of the centre as
  extracted from a csv file
  
  This layer can be considered as a "guided cropping" layer of the
  input image based on preselected input.
class_docstr_tok: ["This","class","generates","samples","using","the","coordinates","of","the","centre","as","extracted","from","a","csv","file","This","layer","can","be","considered","as","a","``","guided","cropping","''","layer","of","the","input","image","based","on","preselected","input","."]
docstr: Generate spatial coordinates for sampling.
  
  Values in ``win_sizes`` could be different --
  for example in a segmentation network ``win_sizes`` could be
  ``{'training_image_spatial_window': (32, 32, 10),
     'Manual_label_spatial_window': (16, 16, 10)}``
  (the network reduces x-y plane spatial resolution).
  
  This function handles this situation by first find the largest
  window across these window definitions, and generate the coordinates.
  These coordinates are then adjusted for each of the
  smaller window sizes (the output windows are almost concentric)
  This function provide the appropriate sampled coordinates modified
  according to knowledge of the reader constraints on resolution and
  orientation.
docstr_tok: ["Generate","spatial","coordinates","for","sampling",".","Values","in","``","win_sizes","``","could","be","different","--","for","example","in","a","segmentation","network","``","win_sizes","``","could","be","``","{","'training_image_spatial_window","'",":","(","32",",","32",",","10",")",",","'Manual_label_spatial_window","'",":","(","16",",","16",",","10",")","}","``","(","the","network","reduces","x-y","plane","spatial","resolution",")",".","This","function","handles","this","situation","by","first","find","the","largest","window","across","these","window","definitions",",","and","generate","the","coordinates",".","These","coordinates","are","then","adjusted","for","each","of","the","smaller","window","sizes","(","the","output","windows","are","almost","concentric",")","This","function","provide","the","appropriate","sampled","coordinates","modified","according","to","knowledge","of","the","reader","constraints","on","resolution","and","orientation","."]
code: def csvcenter_spatial_coordinates(
      self,
      subject_id,
      data,
      img_sizes,
      win_sizes,
      mode_correction="pad",
      n_samples=1,
  ):
      """
      Generate spatial coordinates for sampling.
  
      Values in ``win_sizes`` could be different --
      for example in a segmentation network ``win_sizes`` could be
      ``{'training_image_spatial_window': (32, 32, 10),
         'Manual_label_spatial_window': (16, 16, 10)}``
      (the network reduces x-y plane spatial resolution).
  
      This function handles this situation by first find the largest
      window across these window definitions, and generate the coordinates.
      These coordinates are then adjusted for each of the
      smaller window sizes (the output windows are almost concentric)
      This function provide the appropriate sampled coordinates modified
      according to knowledge of the reader constraints on resolution and
      orientation.
      """
  
      assert data is not None, (
          "No input from image reader. Please check"
          "the configuration file."
      )
  
      # infer the largest spatial window size and check image spatial shapes
      img_spatial_size, win_spatial_size = _infer_spatial_size(
          img_sizes, win_sizes
      )
  
      window_centres = []
      reject = False
      if mode_correction == "remove":
          reject = True
  
      # try:
      #     window_centres = csv_data.get('sampler', None)
      # except AttributeError:
      #     pass
  
      n_samples = max(n_samples, 1)
      all_coordinates = {}
  
      # If there is no csv reader for the sampler, we fall back to a uniform sampling
      if "sampler" not in self.csv_reader.task_param.keys():
          window_centres = rand_spatial_coordinates(
              n_samples, img_spatial_size, win_spatial_size, None
          )
          list_idx = np.arange(0, n_samples)
  
      else:
          window_centres_list = []
          list_idx = []
          _, _ = self.check_csv_sampler_valid(
              subject_id, img_sizes, win_sizes
          )
          idx_check, _, _ = self.csv_reader(
              subject_id=subject_id, mode="multi", reject=False
          )
          idx_multi = idx_check["sampler"]
          for mod in self.csv_reader.task_param:
              all_coordinates[mod] = []
          for n in range(0, n_samples):
              # print("reject value is ", reject)
              idx, data_csv, _ = self.csv_reader(
                  subject_id=subject_id, mode="single", reject=reject
              )
              # print(data_csv['sampler'].shape[0], 'data_sampler')
              if data_csv["sampler"].shape[0] > 0:
                  centre_transform = self.transform_centres(
                      subject_id,
                      img_sizes,
                      np.expand_dims(
                          np.squeeze(data_csv["sampler"]), 0
                      ),
                  )
                  # centre_tmp = np.expand_dims(centre_transform,0)
                  # for mod in idx.keys():
                  #     all_coordinates[mod].append(np.expand_dims(
                  #         np.squeeze(data_csv[mod]), 0))
                  list_idx.append(idx["sampler"])
                  print(centre_transform.shape)
                  window_centres_list.append(centre_transform)
                  window_centres = np.concatenate(
                      window_centres_list, 0
                  )
          # If nothing is valid and the mode of correction is rand, then we
          #  default back to a uniform sampling
          if (
              np.sum(
                  self.csv_reader.valid_by_task["sampler"][idx_multi]
              )
              == 0
              and np.asarray(window_centres).shape[0] == 0
              and mode_correction == "rand"
          ):
              tf.logging.warning(
                  "Nothing is valid, taking random centres"
              )
              window_centres = rand_spatial_coordinates(
                  n_samples, img_spatial_size, win_spatial_size, None
              )
              list_idx = np.arange(0, n_samples)
      print("all prepared and added ")
  
      assert window_centres.shape == (n_samples, N_SPATIAL), (
          "the coordinates generator should return "
          "{} samples of rank {} locations".format(n_samples, N_SPATIAL)
      )
  
      # adjust spatial coordinates based on each mod spatial window size
  
      for mod in list(win_sizes):
          win_size = np.asarray(win_sizes[mod][:N_SPATIAL])
          half_win = np.floor(win_size / 2.0).astype(int)
  
          # Make starting coordinates of the window
          spatial_coords = np.zeros((1, N_SPATIAL * 2), dtype=np.int32)
          if mode_correction != "pad":
              spatial_coords[:, :N_SPATIAL] = np.maximum(
                  window_centres[0, :N_SPATIAL] - half_win[:N_SPATIAL],
                  0,
              )
          else:
              spatial_coords[:, :N_SPATIAL] = (
                  window_centres[0, :N_SPATIAL] - half_win[:N_SPATIAL]
              )
  
          # Make the opposite corner of the window is
          # just adding the mod specific window size
          spatial_coords[:, N_SPATIAL:] = (
              spatial_coords[:, :N_SPATIAL] + win_size[:N_SPATIAL]
          )
  
          # assert np.all(spatial_coords[:, N_SPATIAL:] <= img_spatial_size),
          #     'spatial coords: out of bounds.'
  
          # include subject id as the 1st column of all_coordinates values
          idx_subject_id = np.where(
              self.reader._file_list.subject_id == subject_id
          )[0][0]
          idx_subject_id = (
              np.ones((n_samples,), dtype=np.int32) * idx_subject_id
          )
          spatial_coords = np.append(
              idx_subject_id[:, None], spatial_coords, axis=1
          )
          all_coordinates[mod] = spatial_coords
  
      return all_coordinates, list_idx
  
file_path: NiftyNet/niftynet/contrib/csv_reader/sampler_csvpatch.py
imports: from __future__ import absolute_import, division, print_function
  import numpy
  import tensorflow
  from niftynet.contrib.csv_reader.sampler_csv_rows import ImageWindowDatasetCSV
  from niftynet.engine.image_window import N_SPATIAL, LOCATION_FORMAT
  from niftynet.io.misc_io import do_reorientation_idx, do_resampling_idx
label_desc: Use image node_id 3 for calling the CSVPatchSampler obj's underlying member method code with example usage: obj.csvcenter_spatial_coordinates(subject_id, data, img_sizes, win_sizes, mode_correction, n_samples) and returns: all_coordinates,  list_idx