# Creating a header of matched catalogs

**URL:** <https://community.openastronomy.org/t/creating-a-header-of-matched-catalogs/1015>\
**Category:** Astropy\
**Created:** [June 17, 2024, 11:27am UTC](https://community.openastronomy.org/t/creating-a-header-of-matched-catalogs/1015 "2024-06-17T11:27:10Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![lifemannequin](https://dub1.discourse-cdn.com/flex005/user_avatar/community.openastronomy.org/lifemannequin/32/546_2.png) [@lifemannequin](https://community.openastronomy.org/u/lifemannequin)\
**Post date:** [June 17, 2024, 11:27am UTC](https://community.openastronomy.org/t/creating-a-header-of-matched-catalogs/1015/1 "2024-06-17T11:27:10Z")

</div>

I used the function match\_to\_catalog\_sky to match two catalogs. I want to save the new matched catalog with the headers of the 2 catalogs plus the match\_id and match\_d2d columns. The matching is done :

```auto
#Finds the closest DR12 source for each Fermi source
idx, d2d, d3d = fermi_choord.match_to_catalog_sky(dr12_choord)
print('done matching')

# Convert to pandas first
fermi_table = QTable(fermi_data)
fermi_source_pd = fermi_table.to_pandas()
dr12_table = QTable(DR12_data)
sdss_source_pd = dr12_table.to_pandas()

fermi_sdss = fermi_source_pd.copy()

# Append the id and distance 
fermi_sdss['match_id'] = sdss_source_pd.iloc[idx].index.values
fermi_sdss['match_d2d_deg'] = d2d.deg

# Join the result
fermi_sdss= fermi_sdss.merge(sdss_source_pd, how='left',
                         left_on='match_id', right_index=True, 
                         suffixes=("_fermi", "_sdss"))

fermi_sdss_2 = fermi_sdss[fermi_sdss['match_d2d_deg'] <=2]

```

If I save this, I lose all information on the columns. ChatGPT says to do:

```auto
combined_header = fits.Header()
combined_header.extend(fermi_header.cards, useblanks=False, update=True)
combined_header.extend(DR12_header.cards, useblanks=False, update=True)

# Save the result as a FITS file with the combined header
combined_fits_file = filepath + "fermi_sdss_matches_possacc.fits"
hdu = fits.BinTableHDU(data=fermi_sdss_table, header=combined_header)
hdu.writeto(combined_fits_file, overwrite=True)

```

but when i open it with topcat i only have the dr12 header starting from column 1 instead of 169… is there a way to do this? thanks
