pythonastropyastroquery

Input FITS table to astroquery.xmatch


I need to use xmatch from the astroquery package to cross match a large local catalogue with 2MASS. I load my local FITS table with astropy as usual:

from astropy.io import fits
hdu = fits.open(root+'mycat.fits')

Then try to use xmatch with that table (the table is hdu[2]) following the syntax described in the astroquery docs:

from astroquery.xmatch import XMatch
table = XMatch.query(cat1=hdu[2],
                  cat2='vizier:II/246/out',
                  max_distance=1 * u.arcsec, colRA1='RA',
                  colDec1='Dec')

But get the following error:

AttributeError: 'BinTableHDU' object has no attribute 'read'

The examples on the astroquery docs only shows how to give a local CSV file. But my catalogue has about 7 million entries, so it is not convenient to pass it as an ASCII CSV file.

How should I pass my FITS table as input? Thanks!


Solution

  • While xmatch can accept a file object as input, that file object has to be a Vizier-style .csv table. You need to convert your FITS table to an astropy table first, e.g.

    from astropy.table import Table
    myTable = Table(data=hdu[2].data)