batsurvey-catmux is a convenience tool which will split a FITS binary table into different files based the value of a "key" column within the table.
This task may be used for BAT catalog files, to split one file with many different sources, into many files with one source each. However, this task will work with any generic FITS file where multiple selections are desired.
The "key" column is the column which is used to decide which output file a row will be assigned. The output file name can be constructed using the "key" value if necessary. For BAT catalogs, the best "key" column is the catalog ID number, or CATNUM. However, it is also possible to use the NAME column. The output file name can be a single file name, or a template constructed using C-style "printf" syntax. The "key" column value will be substitued into the template for each row.
For example, consider a catalog file of the following structure:
== myrun.cat == CATNUM NAME RATE .... 1 XYZ 123.4 1 XYZ 120.5 2 ABC 21.2 3 WWW -1.9If keycolumn=CATNUM and outfile="myrun%03d.cat", then the output of the task would be three files. The files would be:
== myrun001.cat == CATNUM NAME RATE .... 1 XYZ 123.4 1 XYZ 120.5and
== myrun002.cat == CATNUM NAME RATE .... 2 ABC 21.2and
== myrun003.cat == CATNUM NAME RATE .... 3 WWW -1.9The file myrun001.cat has two entries because there were two entries in the original file which matched '1'. The other files only have one entry because '2' and '3' matched only one row each.
IMPORTANT NOTE: the default is clobber=NO, which will cause data to be APPENDED to named files, if they already exist.
batsurvey-catmux has some filtering and transformation capabilities. It is possible to exclude certain from the process using the 'exclude' parameter. If a "key" value is listed in the 'exclude' list, then columns which match that value will not be written to an output file. For example, if exclude=3 in the above example, then myrun003.cat would not be created.
It is also possible redirect one or more key values to a different file using the translate map. The translate_map is a list of transformations of "a" to "b" where "a" and "b" are "key" values. If any column values match "a" then the rows are actually written to an output file given by substituting "b" into the template. For example, if translate_map="3->2", then the fourth row of the table would be written to myrun002.dat, and myrun003.dat would not be created. The user can specify the transformations either as a comma separated list, such as "a->b,c->d,e->f", or as a text file with one transformation per line. In this example, if "key" values of a, c, or e are found in the input table, then they are transformed to b, d, and f respectively.
batsurvey-catmux will attempt to protect against special characters in the "key" column. If a key has a character that matches any of these special characters: ][!$%^&*;(){}<>?|/\ or a white space, then that character will be replaced by an underscore. Note that this also means that the 'outfile' parameter may not contain spaces.
1. Split a BAT catalog apart by catalog number. Output files will be named myrun001.cat, myrun002.cat and so on. Catalog values of -1 are ignored, and values are 500 are stored in a file myrun999.cat.
batsurvey-catmux myrun.cat myrun%03d.cat CATNUM exclude=-1 translate_map="500->999"