nodes: 0, module; 1, function_definition; 2, function_name:_remove_duplicate; 3, parameters; 4, block; 5, identifier:old_events; 6, identifier:dat; 7, expression_statement; 8, expression_statement; 9, expression_statement; 10, expression_statement; 11, comment:# more convenient, it copies old_event first and then compares; 12, expression_statement; 13, expression_statement; 14, if_statement; 15, expression_statement; 16, expression_statement; 17, for_statement; 18, return_statement; 19, comment:"""Remove duplicates from the events.
  
      Parameters
      ----------
      old_events : ndarray (dtype='int')
          N x 3 matrix with start, peak, end samples
      dat : ndarray (dtype='float')
          vector with the data after detection-transformation (to compute peak)
  
      Returns
      -------
      ndarray (dtype='int')
          vector of indices of the events to keep
      ndarray (dtype='int')
          N x 3 matrix with start, peak, end samples
  
      Notes
      -----
      old_events is assumed to be sorted. It only checks for the start time and
      end time. When two (or more) events have the same start time and the same
      end time, then it takes the largest peak.
  
      There is no tolerance, indices need to be identical.
      """; 20, assignment; 21, assignment; 22, augmented_assignment; 23, assignment; 24, assignment; 25, call; 26, block; 27, assignment; 28, assignment; 29, pattern_list; 30, call; 31, block; 32, expression_list; 33, identifier:diff_events; 34, call; 35, identifier:dupl; 36, subscript; 37, identifier:dupl; 38, integer:1; 39, identifier:n_nondupl_events; 40, binary_operator:old_events.shape[0] - len(dupl); 41, identifier:new_events; 42, call; 43, identifier:len; 44, argument_list; 45, expression_statement; 46, identifier:i; 47, integer:0; 48, identifier:indices; 49, list; 50, identifier:i_old; 51, identifier:one_old_event; 52, identifier:enumerate; 53, argument_list; 54, if_statement; 55, identifier:indices; 56, identifier:new_events; 57, identifier:diff; 58, argument_list; 59, call; 60, integer:0; 61, subscript; 62, call; 63, identifier:zeros; 64, argument_list; 65, identifier:dupl; 66, call; 67, identifier:old_events; 68, comparison_operator:i_old not in dupl; 69, block; 70, else_clause; 71, identifier:old_events; 72, keyword_argument; 73, identifier:where; 74, argument_list; 75, attribute; 76, integer:0; 77, identifier:len; 78, argument_list; 79, tuple; 80, keyword_argument; 81, attribute; 82, argument_list; 83, identifier:i_old; 84, identifier:dupl; 85, expression_statement; 86, expression_statement; 87, expression_statement; 88, block; 89, identifier:axis; 90, integer:0; 91, binary_operator:(diff_events[:, 0] == 0) & (diff_events[:, 2] == 0); 92, identifier:old_events; 93, identifier:shape; 94, identifier:dupl; 95, identifier:n_nondupl_events; 96, subscript; 97, identifier:dtype; 98, string; 99, identifier:lg; 100, identifier:debug; 101, binary_operator:'Removing ' + str(len(dupl)) + ' duplicate events'; 102, assignment; 103, augmented_assignment; 104, call; 105, expression_statement; 106, expression_statement; 107, if_statement; 108, parenthesized_expression; 109, parenthesized_expression; 110, attribute; 111, integer:1; 112, string_content:int; 113, binary_operator:'Removing ' + str(len(dupl)); 114, string; 115, subscript; 116, identifier:one_old_event; 117, identifier:i; 118, integer:1; 119, attribute; 120, argument_list; 121, assignment; 122, assignment; 123, comparison_operator:dat[peak_0] >= dat[peak_1]; 124, block; 125, else_clause; 126, comparison_operator:diff_events[:, 0] == 0; 127, comparison_operator:diff_events[:, 2] == 0; 128, identifier:old_events; 129, identifier:shape; 130, string; 131, call; 132, string_content:duplicate events; 133, identifier:new_events; 134, identifier:i; 135, slice; 136, identifier:indices; 137, identifier:append; 138, identifier:i_old; 139, identifier:peak_0; 140, subscript; 141, identifier:peak_1; 142, subscript; 143, subscript; 144, subscript; 145, expression_statement; 146, block; 147, subscript; 148, integer:0; 149, subscript; 150, integer:0; 151, string_content:Removing; 152, identifier:str; 153, argument_list; 154, identifier:new_events; 155, binary_operator:i - 1; 156, integer:1; 157, identifier:one_old_event; 158, integer:1; 159, identifier:dat; 160, identifier:peak_0; 161, identifier:dat; 162, identifier:peak_1; 163, assignment; 164, expression_statement; 165, identifier:diff_events; 166, slice; 167, integer:0; 168, identifier:diff_events; 169, slice; 170, integer:2; 171, call; 172, identifier:i; 173, integer:1; 174, subscript; 175, identifier:peak_0; 176, assignment; 177, identifier:len; 178, argument_list; 179, identifier:new_events; 180, binary_operator:i - 1; 181, integer:1; 182, subscript; 183, identifier:peak_1; 184, identifier:dupl; 185, identifier:i; 186, integer:1; 187, identifier:new_events; 188, binary_operator:i - 1; 189, integer:1; 190, identifier:i; 191, integer:1
code: def _remove_duplicate(old_events, dat):
      """Remove duplicates from the events.
  
      Parameters
      ----------
      old_events : ndarray (dtype='int')
          N x 3 matrix with start, peak, end samples
      dat : ndarray (dtype='float')
          vector with the data after detection-transformation (to compute peak)
  
      Returns
      -------
      ndarray (dtype='int')
          vector of indices of the events to keep
      ndarray (dtype='int')
          N x 3 matrix with start, peak, end samples
  
      Notes
      -----
      old_events is assumed to be sorted. It only checks for the start time and
      end time. When two (or more) events have the same start time and the same
      end time, then it takes the largest peak.
  
      There is no tolerance, indices need to be identical.
      """
      diff_events = diff(old_events, axis=0)
      dupl = where((diff_events[:, 0] == 0) & (diff_events[:, 2] == 0))[0]
      dupl += 1  # more convenient, it copies old_event first and then compares
  
      n_nondupl_events = old_events.shape[0] - len(dupl)
      new_events = zeros((n_nondupl_events, old_events.shape[1]), dtype='int')
      if len(dupl):
          lg.debug('Removing ' + str(len(dupl)) + ' duplicate events')
  
      i = 0
      indices = []
      for i_old, one_old_event in enumerate(old_events):
          if i_old not in dupl:
              new_events[i, :] = one_old_event
              i += 1
              indices.append(i_old)
          else:
              peak_0 = new_events[i - 1, 1]
              peak_1 = one_old_event[1]
              if dat[peak_0] >= dat[peak_1]:
                  new_events[i - 1, 1] = peak_0
              else:
                  new_events[i - 1, 1] = peak_1
  
      return indices, new_events