nodes: 0, module; 1, function_definition; 2, function_name:sort_labeled_intervals; 3, parameters; 4, block; 5, identifier:intervals; 6, default_parameter; 7, expression_statement; 8, expression_statement; 9, expression_statement; 10, if_statement; 11, identifier:labels; 12, None; 13, string; 14, assignment; 15, assignment; 16, comparison_operator:labels is None; 17, block; 18, else_clause; 19, string_content:Sort intervals, and optionally, their corresponding labels
      according to start time.
  
      Parameters
      ----------
      intervals : np.ndarray, shape=(n, 2)
          The input intervals
  
      labels : list, optional
          Labels for each interval
  
      Returns
      -------
      intervals_sorted or (intervals_sorted, labels_sorted)
          Labels are only returned if provided as input; 20, identifier:idx; 21, call; 22, identifier:intervals_sorted; 23, subscript; 24, identifier:labels; 25, None; 26, return_statement; 27, block; 28, attribute; 29, argument_list; 30, identifier:intervals; 31, identifier:idx; 32, identifier:intervals_sorted; 33, return_statement; 34, identifier:np; 35, identifier:argsort; 36, subscript; 37, expression_list; 38, identifier:intervals; 39, slice; 40, integer:0; 41, identifier:intervals_sorted; 42, list_comprehension; 43, subscript; 44, for_in_clause; 45, identifier:labels; 46, identifier:_; 47, identifier:_; 48, identifier:idx
code: def sort_labeled_intervals(intervals, labels=None):
      '''Sort intervals, and optionally, their corresponding labels
      according to start time.
  
      Parameters
      ----------
      intervals : np.ndarray, shape=(n, 2)
          The input intervals
  
      labels : list, optional
          Labels for each interval
  
      Returns
      -------
      intervals_sorted or (intervals_sorted, labels_sorted)
          Labels are only returned if provided as input
      '''
  
      idx = np.argsort(intervals[:, 0])
  
      intervals_sorted = intervals[idx]
  
      if labels is None:
          return intervals_sorted
      else:
          return intervals_sorted, [labels[_] for _ in idx]