code: def merge_wcs_counts_cubes(filelist):
      
      out_prim = None
      out_ebounds = None
  
      datalist_gti = []
      exposure_sum = 0.
      nfiles = len(filelist)
      ngti = np.zeros(nfiles, int)
  
      for i, filename in enumerate(filelist):
          fin = fits.open(filename)
          sys.stdout.write('.')
          sys.stdout.flush()
          if i == 0:
              out_prim = update_primary(fin[0], out_prim)
              out_ebounds = update_ebounds(fin["EBOUNDS"], out_ebounds)
          (gti_data, exposure, tstop) = extract_gti_data(fin["GTI"])
          datalist_gti.append(gti_data)
          exposure_sum += exposure
          ngti[i] = len(gti_data)
          if i == 0:
              first = fin
          elif i == nfiles - 1:
              date_end = fin[0].header['DATE-END']
          else:
              fin.close()
  
      out_gti = merge_all_gti_data(datalist_gti, ngti, first['GTI'])
      out_gti.header['EXPOSURE'] = exposure_sum
      out_gti.header['TSTOP'] = tstop
  
      hdulist = [out_prim, out_ebounds, out_gti]
      for hdu in hdulist:
          hdu.header['DATE-END'] = date_end
  
      out_prim.update_header()
      sys.stdout.write("!\n")
      return fits.HDUList(hdulist)
docs: Merge all the files in filelist, assuming that they WCS counts cubes