| tmatch | tables | tmatch |
tmatch -- Find closest match between rows in two tables
tmatch (input1, input2, output, match1, match2, maxnorm)
This task combines rows from two tables into one. Rows are combined by looking at each row in the first table and finding the row in the second table whose match columns are closest to those in the first. The distance between two rows is defined in the usual way to be the square root of the sum of the squares of the difference between the corresponding match columns. Rows are only written to the output table if the distance between them is less than the distance specified by maxnorm. This task converts match column units to degrees for the purpose of computing the distance if the column units are recognized angular units (seconds, minutes, degrees, hours, or radians or any abbreviation of these). If the column units are blank or some unrecognized string, no conversion is done. Thus, if the match column is in some recognized angular units, maxnorm should be specified in degrees.
Columns named by the parameters incol1 and incol2 will be copied to the output table. If these parameters are left blank, all columns will be copied to the output table. Columns will have the same name in the output table as in the input table, except that columns with the same name in both input tables will have the suffix "_1" and "_2" added to indicate which table they were copied from.
This task optionally allows you to supply a set of weighting factors that are multiplied by the difference between corresponding match columns when computing the distance. These factors can be used to supply units conversion when column units information is missing from the input table or as a way to weight information from columns containing distinct information. If factors are supplied, any column units information is ignored. If the factors are left bank, they are ignored and column units information is used to convert to degrees when possible.
If the match columns contain spherical coordinates, parameter sphere should be set to yes so that the distance on a sphere can be computed. If the match columns do contain spherical units, the first column should be the longitude column (such as right ascension) and the second column should be the latitude column (such as declination). Columns should also be in some recognized angular units, or a conversion factor should be supplied explicitly.
The task optionally produces a diagnostic output file if a file name is supplied to parameter diagfile. The diagnostic file contains the rows from the first table that were not matched, the cases where more than one row in the first table matched a single row in the second table, and the ten matched rows in the with the largest distance between them. Rows in the diagnostic output are identfied by their table number and row number and optionally by the contents of the columns specified by the parameters nmcol1 and nmcol2.
This task differs from tjoin in two respects. First tjoin combines tables on the basis of a single column, while this task can combine tables based on multiple columns. Second, tjoin places every combination of rows matching within the specified tolerance in the output table, while this task only puts the closest match in the output table.
1. Two star catalogs are being matched. They both have the following columns:
Name CH*12 %12s "" RA D %10.1h hours Dec D %10.0h degrees V R %7.2f "" B-V R %7.2f "" U-B R %7.2f ""
To find the best match between the catalogs within a ten arcsecond radius one would use the following command:
tt> tmatch catalog1.tab catalog2.tab match.tab \ >>> ra,dec ra,dec 0:00:10 sphere+
The search radius can either be supplied in sexgesimal notation, as above, or in decimal degrees.
2. Suppose the input catalogs did not contain units information, as would be the case if they were text files. The units conversion could then be supplied explicitly through the factor parameter:
tt> tmatch catalog1.tab catalog2.tab match.tab \ >>> ra,dec ra,dec 0:00:10 factor=15,1 sphere+
3. Suppose we want the output table to only contain the name from the first catalog and get the rest of its information from the second catalog. This could be done with the following command:
tt> tmatch catalog1.tab catalog2.tab match.tab \ >>> ra,dec ra,dec 0:00:10 incol1=name sphere+
4. To get diagnostic output from the task, use the following command:
tt> tmatch catalog1.tab catalog2.tab match.tab ra,dec ra,dec \ >>> diag=diag.txt nmcol1=name nmcol2=name 0:00:10 sphere+
The following is a subset of the diagnostic output produced:
The following objects matched the same object: 1:163 6601 GEM 1:164 6601 GEM 2:163 6601 GEM The following objects have the largest norms: Norm = 0.00253 1:371 2319 SCO 2:371 2319 SCO Norm = 0.00247 1:368 2101 SCO 2:368 2101 SCO
The number before the colon is the table number, the number after the colon is the row number, and the rest of the line is from the name column.
Written by Bernie Simon