code: def check_constraint(data, constraint):
      unique, count = np.unique(np.round(data), return_counts=True)
      list_labels = []
      data = np.round(data)
      if constraint.list_labels is not None:
          list_labels = constraint.list_labels
          for label in constraint.list_labels:
              if label not in unique:
                  print("Label %d is not there" % label)
                  return False
      num_labels_add = 0
      if constraint.num_labels > 0:
          num_labels_add = constraint.num_labels - len(list_labels)
          if num_labels_add <= 0:
              num_labels_add = 0
          if len(unique) < constraint.num_labels:
              print("Missing labels")
              return False
      to_add = num_labels_add
      if constraint.min_ratio > 0:
          num_min = constraint.min_number_from_ratio(data.shape)
          print("unique in test is ", unique)
          for value, c in zip(unique, count):
              if value in list_labels:
                  if c < num_min:
                      print("Not enough in label %d", value)
                      return False
              else:
                  if c > num_min:
                      to_add -= 1
          if to_add > 0:
              print("to add initial is ", num_labels_add)
              print("Not enough in additional labels")
              return False
      return True
  
file_path: NiftyNet/niftynet/contrib/segmentation_selective_sampler/test_sampler_selective.py
imports: from __future__ import absolute_import, division, print_function
  import os
  import numpy
  import tensorflow
  from niftynet.contrib.segmentation_selective_sampler.sampler_selective import SelectiveSampler, Constraint
  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 1 for calling a global function with example usage: check_constraint(data, constraint) and returns: True, False, False, False, False