nodes: 0, module; 1, function_definition; 2, function_name:get_ordered_values; 3, parameters; 4, block; 5, identifier:self; 6, identifier:keypath; 7, identifier:distance_from; 8, default_parameter; 9, expression_statement; 10, expression_statement; 11, if_statement; 12, for_statement; 13, if_statement; 14, expression_statement; 15, expression_statement; 16, expression_statement; 17, if_statement; 18, if_statement; 19, expression_statement; 20, expression_statement; 21, expression_statement; 22, for_statement; 23, return_statement; 24, identifier:open_interval; 25, True; 26, comment:"""
          Retrieves the referents's values sorted by their distance from the
          min, max, or mid value.
          """; 27, assignment; 28, comparison_operator:keypath[0] == 'target'; 29, comment:# instances start with 'target' prefix, but; 30, comment:# don't contain it, so we remove it here.; 31, block; 32, pattern_list; 33, call; 34, block; 35, comparison_operator:len(values) == 0; 36, block; 37, assignment; 38, assignment; 39, assignment; 40, comparison_operator:distance_from == 'max'; 41, block; 42, comparison_operator:distance_from == 'mean'; 43, block; 44, assignment; 45, call; 46, assignment; 47, pattern_list; 48, call; 49, block; 50, identifier:results; 51, identifier:values; 52, list; 53, subscript; 54, string; 55, expression_statement; 56, identifier:_; 57, identifier:instance; 58, attribute; 59, argument_list; 60, expression_statement; 61, if_statement; 62, expression_statement; 63, call; 64, integer:0; 65, return_statement; 66, identifier:values; 67, call; 68, identifier:anchor; 69, call; 70, identifier:diffs; 71, binary_operator:values - anchor; 72, identifier:distance_from; 73, string; 74, expression_statement; 75, expression_statement; 76, identifier:distance_from; 77, string; 78, expression_statement; 79, expression_statement; 80, identifier:sdiffs; 81, call; 82, attribute; 83, argument_list; 84, identifier:results; 85, list; 86, identifier:ix; 87, identifier:el; 88, identifier:enumerate; 89, argument_list; 90, expression_statement; 91, expression_statement; 92, if_statement; 93, identifier:keypath; 94, integer:0; 95, string_content:target; 96, assignment; 97, identifier:self; 98, identifier:iter_singleton_referents; 99, assignment; 100, boolean_operator; 101, block; 102, call; 103, identifier:len; 104, argument_list; 105, list; 106, attribute; 107, argument_list; 108, attribute; 109, argument_list; 110, identifier:values; 111, identifier:anchor; 112, string_content:max; 113, assignment; 114, assignment; 115, string_content:mean; 116, assignment; 117, assignment; 118, attribute; 119, argument_list; 120, identifier:sdiffs; 121, identifier:sort; 122, identifier:sdiffs; 123, assignment; 124, assignment; 125, False; 126, comment:# when vagueness has been made precise through an ordinal; 127, block; 128, elif_clause; 129, elif_clause; 130, elif_clause; 131, identifier:keypath; 132, subscript; 133, identifier:value; 134, call; 135, call; 136, comparison_operator:value.low != value.high; 137, return_statement; 138, attribute; 139, argument_list; 140, identifier:values; 141, identifier:np; 142, identifier:array; 143, identifier:values; 144, identifier:values; 145, identifier:min; 146, identifier:anchor; 147, call; 148, identifier:diffs; 149, binary_operator:anchor - values; 150, identifier:anchor; 151, call; 152, identifier:diffs; 153, call; 154, identifier:np; 155, identifier:unique; 156, identifier:diffs; 157, identifier:mask; 158, comparison_operator:diffs <= el; 159, identifier:vals; 160, subscript; 161, expression_statement; 162, comparison_operator:distance_from == 'max'; 163, block; 164, comparison_operator:distance_from == 'min'; 165, block; 166, comparison_operator:distance_from == 'mean'; 167, block; 168, identifier:keypath; 169, slice; 170, attribute; 171, argument_list; 172, identifier:hasattr; 173, argument_list; 174, attribute; 175, attribute; 176, list; 177, identifier:values; 178, identifier:append; 179, call; 180, attribute; 181, argument_list; 182, identifier:anchor; 183, identifier:values; 184, attribute; 185, argument_list; 186, identifier:abs; 187, argument_list; 188, identifier:diffs; 189, identifier:el; 190, identifier:values; 191, identifier:mask; 192, call; 193, identifier:distance_from; 194, string; 195, if_statement; 196, identifier:distance_from; 197, string; 198, if_statement; 199, identifier:distance_from; 200, string; 201, if_statement; 202, expression_statement; 203, integer:1; 204, identifier:instance; 205, identifier:get_value_from_path; 206, identifier:keypath; 207, identifier:value; 208, string; 209, identifier:value; 210, identifier:low; 211, identifier:value; 212, identifier:high; 213, identifier:float; 214, argument_list; 215, identifier:values; 216, identifier:max; 217, identifier:values; 218, identifier:mean; 219, binary_operator:anchor - values; 220, attribute; 221, argument_list; 222, string_content:max; 223, identifier:open_interval; 224, block; 225, else_clause; 226, string_content:min; 227, identifier:open_interval; 228, block; 229, else_clause; 230, string_content:mean; 231, comparison_operator:ix+1 == len(sdiffs); 232, block; 233, call; 234, string_content:low; 235, identifier:value; 236, identifier:anchor; 237, identifier:values; 238, identifier:results; 239, identifier:append; 240, call; 241, expression_statement; 242, block; 243, expression_statement; 244, block; 245, binary_operator:ix+1; 246, call; 247, continue_statement; 248, comment:# skip last; 249, attribute; 250, argument_list; 251, identifier:IntervalCell; 252, argument_list; 253, call; 254, expression_statement; 255, call; 256, expression_statement; 257, identifier:ix; 258, integer:1; 259, identifier:len; 260, argument_list; 261, identifier:results; 262, identifier:append; 263, call; 264, call; 265, call; 266, attribute; 267, argument_list; 268, call; 269, attribute; 270, argument_list; 271, call; 272, identifier:sdiffs; 273, identifier:IntervalCell; 274, argument_list; 275, attribute; 276, argument_list; 277, attribute; 278, argument_list; 279, identifier:results; 280, identifier:append; 281, call; 282, attribute; 283, argument_list; 284, identifier:results; 285, identifier:append; 286, call; 287, attribute; 288, argument_list; 289, call; 290, call; 291, identifier:vals; 292, identifier:min; 293, identifier:vals; 294, identifier:max; 295, identifier:IntervalCell; 296, argument_list; 297, identifier:results; 298, identifier:append; 299, call; 300, identifier:IntervalCell; 301, argument_list; 302, identifier:results; 303, identifier:append; 304, call; 305, attribute; 306, argument_list; 307, attribute; 308, argument_list; 309, call; 310, attribute; 311, identifier:IntervalCell; 312, argument_list; 313, unary_operator; 314, call; 315, identifier:IntervalCell; 316, argument_list; 317, identifier:vals; 318, identifier:min; 319, identifier:vals; 320, identifier:max; 321, attribute; 322, argument_list; 323, identifier:np; 324, identifier:inf; 325, call; 326, call; 327, attribute; 328, attribute; 329, argument_list; 330, call; 331, call; 332, identifier:vals; 333, identifier:min; 334, attribute; 335, argument_list; 336, attribute; 337, argument_list; 338, identifier:np; 339, identifier:inf; 340, identifier:vals; 341, identifier:max; 342, attribute; 343, argument_list; 344, attribute; 345, argument_list; 346, identifier:vals; 347, identifier:min; 348, identifier:vals; 349, identifier:min; 350, identifier:vals; 351, identifier:max; 352, identifier:vals; 353, identifier:max
code: def get_ordered_values(self, keypath, distance_from, open_interval=True):
          """
          Retrieves the referents's values sorted by their distance from the
          min, max, or mid value.
          """
  
          values = []
          if keypath[0] == 'target':
              # instances start with 'target' prefix, but 
              # don't contain it, so we remove it here.
              keypath = keypath[1:]
          for _, instance in self.iter_singleton_referents():
              value = instance.get_value_from_path(keypath)
              if hasattr(value, 'low') and value.low != value.high:
                  return []
              values.append(float(value))
  
          if len(values) == 0:
              return []
          values = np.array(values)
          anchor = values.min()
          diffs = values - anchor
          if distance_from == 'max':
              anchor = values.max()
              diffs = anchor - values
          if distance_from == 'mean':
              anchor = values.mean()
              diffs = abs(anchor - values)
  
          sdiffs = np.unique(diffs)
          sdiffs.sort()
          results = []
        
          for ix, el in enumerate(sdiffs):
              mask = diffs <= el
              vals = values[mask]
              if False:
                  # when vagueness has been made precise through an ordinal
                  results.append(IntervalCell(vals.min(), vals.max()))
              elif distance_from == 'max':
                  if open_interval:
                      results.append(IntervalCell(vals.min(), np.inf))
                  else:
                      results.append(IntervalCell(vals.min(), vals.min()))
              elif distance_from == 'min':
                  if open_interval:
                      results.append(IntervalCell(-np.inf, vals.max()))
                  else:
                      results.append(IntervalCell(vals.max(), vals.max()))
              elif distance_from == 'mean':
                  if ix+1 == len(sdiffs): continue  # skip last
                  results.append(IntervalCell(vals.min(), vals.max()))
          return results