original_docstring:  Compute labels from background and seizure intervals
  
      Args:
          intvs: list of list of intervals
          labels: list of labels of background and seizure. Must be same len as INTVS
          len_pre: length of pre-seizure stage in seconds
          len_post: length of post-seizure stage in seconds
          sec_gap: gap between pre-seizure and seizure in seconds
  
      Returns:
          tuple: (Array of intervals, Array of labels).
      
docstring: Compute labels from background and seizure intervals
docstring_tokens: Compute labels from background and seizure intervals
code: def relabel_tse_bi(intvs, labels, len_pre=100, len_post=300, sec_gap=0):
      """ Compute labels from background and seizure intervals
  
      Args:
          intvs: list of list of intervals
          labels: list of labels of background and seizure. Must be same len as INTVS
          len_pre: length of pre-seizure stage in seconds
          len_post: length of post-seizure stage in seconds
          sec_gap: gap between pre-seizure and seizure in seconds
  
      Returns:
          tuple: (Array of intervals, Array of labels).
      """
      _intvs, _labls = [], []
      # Find LABEL_SEZ
      # locate pre, gap and pos
      # assign others to LABEL_BKG
      for i, lbl in enumerate(labels):
          beg, end = intvs[i]
          pos = beg + len_post
          pre = end - sec_gap - len_pre
          gap = end - sec_gap
          if lbl == LABEL_BKG:
              if i == 0 and i == len(labels)-1:
                  _intvs.append([beg, end])
                  _labls.append(LABEL_BKG)
              elif i == 0:
                  _intvs.extend([[beg, max(beg, pre)],
                                 [max(beg, pre), max(beg, gap)],
                                 [max(beg, gap), end]])
                  _labls.extend([LABEL_BKG, LABEL_PRE, LABEL_NAN])
              elif i == len(labels)-1:
                  _intvs.extend([[beg, min(pos, end)],
                                 [min(pos, end), end]])
                  _labls.extend([LABEL_POS, LABEL_BKG])
              else:
                  pos_end = min(pos, end)
                  pre_beg = max(pos_end, pre)
                  gap_beg = max(pos_end, gap)
                  _intvs.extend([[beg, pos_end],[pos_end, pre_beg],
                                 [pre_beg, gap_beg],[gap_beg, end]])
                  _labls.extend([LABEL_POS, LABEL_BKG, LABEL_PRE, LABEL_NAN])
          elif lbl == LABEL_SEZ:
              _intvs.append([beg, end])
              _labls.append(LABEL_SEZ)
          else:
              raise ValueError("Illegal LABELS")
  
      _labls = [_labls[i] for i, intv in enumerate(_intvs) if intv[0] < intv[1]]
      _intvs = [_intvs[i] for i, intv in enumerate(_intvs) if intv[0] < intv[1]]
  
      return _intvs, _labls
code_tokens: def relabel_tse_bi ( intvs , labels , len_pre = 100 , len_post = 300 , sec_gap = 0 ) : _intvs , _labls = [ ] , [ ] for i , lbl in enumerate ( labels ) : beg , end = intvs [ i ] pos = beg + len_post pre = end - sec_gap - len_pre gap = end - sec_gap if lbl == LABEL_BKG : if i == 0 and i == len ( labels ) - 1 : _intvs . append ( [ beg , end ] ) _labls . append ( LABEL_BKG ) elif i == 0 : _intvs . extend ( [ [ beg , max ( beg , pre ) ] , [ max ( beg , pre ) , max ( beg , gap ) ] , [ max ( beg , gap ) , end ] ] ) _labls . extend ( [ LABEL_BKG , LABEL_PRE , LABEL_NAN ] ) elif i == len ( labels ) - 1 : _intvs . extend ( [ [ beg , min ( pos , end ) ] , [ min ( pos , end ) , end ] ] ) _labls . extend ( [ LABEL_POS , LABEL_BKG ] ) else : pos_end = min ( pos , end ) pre_beg = max ( pos_end , pre ) gap_beg = max ( pos_end , gap ) _intvs . extend ( [ [ beg , pos_end ] , [ pos_end , pre_beg ] , [ pre_beg , gap_beg ] , [ gap_beg , end ] ] ) _labls . extend ( [ LABEL_POS , LABEL_BKG , LABEL_PRE , LABEL_NAN ] ) elif lbl == LABEL_SEZ : _intvs . append ( [ beg , end ] ) _labls . append ( LABEL_SEZ ) else : raise ValueError ( "Illegal LABELS" ) _labls = [ _labls [ i ] for i , intv in enumerate ( _intvs ) if intv [ 0 ] < intv [ 1 ] ] _intvs = [ _intvs [ i ] for i , intv in enumerate ( _intvs ) if intv [ 0 ] < intv [ 1 ] ] return _intvs , _labls
short_docstring: Compute labels from background and seizure intervals
short_docstring_tokens: Compute labels from background and seizure intervals
comment: """ Compute labels from background and seizure intervals
  
      Args:
          intvs: list of list of intervals
          labels: list of labels of background and seizure. Must be same len as INTVS
          len_pre: length of pre-seizure stage in seconds
          len_post: length of post-seizure stage in seconds
          sec_gap: gap between pre-seizure and seizure in seconds
  
      Returns:
          tuple: (Array of intervals, Array of labels).
      """$SEP$# Find LABEL_SEZ$SEP$# locate pre, gap and pos$SEP$# assign others to LABEL_BKG