docstr: Think about how one could to this, say, with 3D and 4D volumes at the same time.
  Also, patching across the modality dimension..? Interesting..
docstr_tok: ["Think","about","how","one","could","to","this",",","say",",","with","3D","and","4D","volumes","at","the","same","time",".","Also",",","patching","across","the","modality","dimension","..","?","Interesting",".."]
code: def generate_patch_corner(self, augmentation_num=0):
      """Think about how one could to this, say, with 3D and 4D volumes at the same time.
      Also, patching across the modality dimension..? Interesting..
      """
  
      # TODO: Escape clause in case acceptable patches cannot be found.
  
      if self.patch_region_conditions is None:
          corner_idx = None
      else:
          region = self.patch_regions[self.region_list[self.iteration]]
          # print(self.region_list[self.iteration])
          # TODO: Make errors like these more ubiquitous.
          if len(region[0]) == 0:
              # raise ValueError('The region ' + str(self.patch_region_conditions[self.region_list[self.iteration]][0]) + ' has no voxels to select patches from. Please modify your patch-sampling region')
              # Tempfix -- Eek
              region = self.patch_regions[self.region_list[1]]
          if len(region[0]) == 0:
              print(
                  "Provided patch extraction region has selected 0 voxels. Selecting non-zero patch."
              )
              region = np.where(
                  self.data_groups["input_data"].augmentation_cases[
                      augmentation_num
                  ]
                  != 0
              )
              self.patch_regions[self.region_list[0]] = region
  
          corner_idx = np.random.randint(len(region[0]))
  
      self.patches = {}
  
      # Pad edge patches.
      for label, data_group in list(self.data_groups.items()):
          input_data = self.data_groups[label].augmentation_cases[
              augmentation_num
          ]
  
          # TODO: Some redundancy here
          if corner_idx is None:
              corner = np.array(
                  [
                      np.random.randint(0, self.input_shape[label][i])
                      for i in range(len(self.input_shape[label]))
                  ]
              )[self.patch_dimensions[label]]
          else:
              corner = np.array([d[corner_idx] for d in region])[
                  self.patch_dimensions[label]
              ]
  
          patch_slice = [slice(None)] * (
              len(self.input_shape[label]) + 1
          )
          # Will run into problems with odd-shaped patches.
          for idx, patch_dim in enumerate(self.patch_dimensions[label]):
              patch_slice[patch_dim] = slice(
                  max(0, corner[idx] - self.patch_shape[idx] // 2),
                  corner[idx] + self.patch_shape[idx] // 2,
                  1,
              )
  
          input_shape = input_data.shape
  
          self.patches[label] = input_data[tuple(patch_slice)]
  
          # More complicated padding needed for center-voxel based patches.
          pad_dims = [(0, 0)] * len(self.patches[label].shape)
          for idx, patch_dim in enumerate(self.patch_dimensions[label]):
              pad = [0, 0]
              if (
                  corner[idx]
                  > input_shape[patch_dim] - self.patch_shape[idx] // 2
              ):
                  pad[1] = self.patch_shape[idx] // 2 - (
                      input_shape[patch_dim] - corner[idx]
                  )
              if corner[idx] < self.patch_shape[idx] // 2:
                  pad[0] = self.patch_shape[idx] // 2 - corner[idx]
              pad_dims[patch_dim] = tuple(pad)
  
          self.patches[label] = np.lib.pad(
              self.patches[label], tuple(pad_dims), "edge"
          )
  
          # print(self.patches[label].shape)
          # if label == 'ground_truth':
          #     for i in range(4):
          #         print(np.sum(self.patches[label][..., i]))
          # print(label, np.sum(self.patches[label]))
  
      return
  
imports: import numpy
  from random import shuffle
  from scipy.sparse import csr_matrix
  from deepneuro.utilities.util import add_parameter
  from deepneuro.augmentation.augment import Augmentation
label_desc: Use image node_id 6 for calling the ExtractPatches obj's underlying member method code with example usage: obj.generate_patch_corner(augmentation_num) without return types