code: def test_classes_balances(self):
      # Set the random state to prevent false positive
      np.random.seed(0)
  
      # Setting these too high inflats the run time
      number_of_repetitions = 1000
      samples_per_repetition = 10
      num_classes = 3
  
      # Create a map with almost all background, one pixel of each
      # other label
      img_size = (50, 25, 10, 1, 1)
      win_size = (8, 7, 2, 1, 1)
      sampling_map = np.zeros(img_size)
      sampling_map[6, 5, 2:, 0, 0] = 1
      sampling_map[11, 13:, 3, 0, 0] = 2
  
      # Accumulate the number of times each class is sampled
      accum = np.zeros((num_classes))
      for _ in range(number_of_repetitions):
          coords = balanced_spatial_coordinates(
              samples_per_repetition, img_size, win_size, sampling_map
          )
  
          # Be sure to sample the correct number
          self.assertAllEqual(
              coords.shape, (samples_per_repetition, N_SPATIAL)
          )
  
          # Convert to np.ndarry indexable
          for coord in coords.astype(int):
              x, y, z = coord
              label = int(sampling_map[x, y, z])
              accum[label] = accum[label] + 1
  
      # Each class should be within 2 decimal places of 1.0/num_classes
      accum = np.divide(accum, accum.sum())
      self.assertAllClose(
          accum,
          np.ones((num_classes)) * 1.0 / num_classes,
          rtol=1e-2,
          atol=1e-2,
      )
  
imports: from __future__ import absolute_import, division, print_function
  import os
  import unittest
  import numpy
  import tensorflow
  from niftynet.engine.image_window import N_SPATIAL
  from niftynet.engine.sampler_balanced_v2 import BalancedSampler, balanced_spatial_coordinates
  from niftynet.io.image_reader import ImageReader
  from niftynet.io.image_sets_partitioner import ImageSetsPartitioner
  from niftynet.utilities.util_common import ParserNamespace
  from tests.niftynet_testcase import NiftyNetTestCase
label_desc: Use image node_id 5 for calling the BalancedCoordinatesTest obj's underlying member method code with example usage: obj.test_classes_balances() without return types