In the example above, we had the luxury to generate the catalogs ourselves, and where thus able to generate them in a way that the rows match. But this is not generally the case. In many situations, you need to use catalogs from many different telescopes, or catalogs with high-level calculations that you cannot simply regenerate with the same pixels without spending a lot of time or using heavy computation. In such cases, when each catalog has the coordinates of its own objects, you can use the coordinates to match the rows with Gnuastro’s Match program (see Match).
As the name suggests, Gnuastro’s Match program will match rows based on distance (or aperture in 2D) in one, two, or three columns. For this tutorial, let’s try matching the two catalogs that were not created from the same labeled images, recall how each has a different number of rows:
$ asttable cat/xdf-f105w.fits -hCLUMPS -i $ asttable cat/xdf-f160w.fits -hCLUMPS -i
You give Match two catalogs (from the two different filters we derived above) as argument, and the HDUs containing them (if they are FITS files) with the --hdu and --hdu2 options. The --ccol1 and --ccol2 options specify the coordinate-columns which should be matched with which in the two catalogs. With --aperture you specify the acceptable error (radius in 2D), in the same units as the columns.
$ astmatch cat/xdf-f160w.fits cat/xdf-f105w.fits \ --hdu=CLUMPS --hdu2=CLUMPS \ --ccol1=RA,DEC --ccol2=RA,DEC \ --aperture=0.5/3600 \ --output=matched.fits $ astfits matched.fits
From the second command, you see that the output has two extensions and that both have the same number of rows. The rows in each extension are the matched rows of the respective input table: those in the first HDU come from the first input and those in the second HDU come from the second. However, their order may be different from the input tables because the rows match: the first row in the first HDU matches with the first row in the second HDU, etc. You can also see which objects did not match with the --notmatched, like below. Note how each extension of now has a different number of rows.
$ astmatch cat/xdf-f160w.fits cat/xdf-f105w.fits \ --hdu=CLUMPS --hdu2=CLUMPS \ --ccol1=RA,DEC --ccol2=RA,DEC \ --aperture=0.5/3600 \ --output=not-matched.fits --notmatched $ astfits not-matched.fits
The --outcols of Match is a very convenient feature: you can use it to specify which columns from the two catalogs you want in the output (merge two input catalogs into one).
If the first character is an ‘a’, the respective matched column (number or name, similar to Table above) in the first catalog will be written in the output table.
When the first character is a ‘b’, the respective column from the second catalog will be written in the output.
Also, if the first character is followed by
_all, then all the columns from the respective catalog will be put in the output.
$ astmatch cat/xdf-f160w.fits cat/xdf-f105w.fits \ --hdu=CLUMPS --hdu2=CLUMPS \ --ccol1=RA,DEC --ccol2=RA,DEC \ --aperture=0.35/3600 \ --outcols=a_all,bMAGNITUDE,bSN \ --output=matched.fits $ astfits matched.fits