code: def _concat(bundles, cat=(0, 0, 0, 0)):
      chan = sorted(set([x['chan'] for x in bundles]))
      cycle = sorted(set([x['cycle'] for x in bundles]))
      stage = sorted(set([x['stage'] for x in bundles]))
      evt_type = sorted(set([x['name'] for x in bundles]))
      all_cycle = None
      all_stage = None
      all_evt_type = None
      if cycle[0] is not None:
          all_cycle = ', '.join([str(c) for c in cycle])
      if stage[0] is not None:
          all_stage = ', '.join(stage)
      if evt_type[0] is not None:
          all_evt_type = ', '.join(evt_type)
      if cat[0]:
          cycle = [all_cycle]
      if cat[1]:
          stage = [all_stage]
      if cat[3]:
          evt_type = [all_evt_type]
      to_concat = []
      for ch in chan:
          for cyc in cycle:
              for st in stage:
                  for et in evt_type:
                      new_times = []
                      for bund in bundles:
                          chan_cond = ch == bund['chan']
                          cyc_cond = cyc in (bund['cycle'], all_cycle)
                          st_cond = st in (bund['stage'], all_stage)
                          et_cond = et in (bund['name'], all_evt_type)
                          if chan_cond and cyc_cond and st_cond and et_cond:
                              new_times.extend(bund['times'])
                      new_times = sorted(new_times, key=lambda x: x[0])
                      new_bund = {'times': new_times,
                                'chan': ch,
                                'cycle': cyc,
                                'stage': st,
                                'name': et
                                }
                      to_concat.append(new_bund)
      if not cat[2]:
          to_concat_new = []
          for bund in to_concat:
              last = None
              bund['times'].append((inf,inf))
              start = 0
              for i, j in enumerate(bund['times']):
                  if last is not None:
                      if not isclose(j[0], last, abs_tol=0.01):
                          new_times = bund['times'][start:i]
                          new_bund = bund.copy()
                          new_bund['times'] = new_times
                          to_concat_new.append(new_bund)
                          start = i
                  last = j[1]
          to_concat = to_concat_new
      to_concat = [x for x in to_concat if x['times']]
      return to_concat