Build a region file from a cdfp-style catalog that can be used to overplot line numbers on a ds9 display. This script has a longish name and a seemingly simple task, but the tools I use to implement this task summarize a lot of fairly useful things. Hence, after the brief usage description below, I show the script source code (as of Feb02,2018) and provide some links to some of the scripts employed by cdfp_ds9_text_reg.
% cdfp_ds9_text_reg --help Usage: cdfp_ds9_text_reg file.cdfp a.FITS cyan 9 text.reg arg1 - name of cdfp file arg2 - name of (wcs-calibrated) FITS image to be displayed arg3 - color for text labeles arg4 - fontsize for text labeles arg5 - name of regions file to be built % cdfp_ds9_text_reg file.cdfp a.FITS cyan 9 text.reg
Recall that cdfp stands for "CoorDinate Floating Point" file. The Ra,Dec are always the first two column of such a file, and the values are always stored as floating point numbers in units of HOURS and DEGREES respectively. This script is designed to identify the Ra,Dec positions of the file memnbers, in this case using text markers. Each position is labeled with the line number in the cdfp file (sans the first line, line number = 0, where the header is placed. Here is the source code:
#!/bin/bash # build a ds9 text regions file from a cdfp file debug="N" # Check command line arguments if [ -z "$1" ] then printf "Usage: cdfp_ds9_text_reg file.cdfp a.FITS cyan 9 text.reg \n" printf "arg1 - name of cdfp file \n" printf "arg2 - name of (wcs-calibrated) FITS image to be displayed \n" printf "arg3 - color for text labeles \n" printf "arg4 - fontsize for text labeles \n" printf "arg5 - name of regions file to be built \n" exit fi if [ $1 = "--help" ] then show_help cdfp_ds9_text_reg exit fi if [ -z "$2" ] then printf "Usage: cdfp_ds9_text_reg file.cdfp a.FITS cyan 9 text.reg \n" printf "arg2 - name of (wcs-calibrated) FITS image to be displayed \n" exit fi if [ -z "$3" ] then printf "Usage: cdfp_ds9_text_reg file.cdfp a.FITS cyan 9 text.reg \n" printf "arg3 - color for text labeles \n" exit fi if [ -z "$3" ] then printf "Usage: cdfp_ds9_text_reg file.cdfp a.FITS cyan 9 text.reg \n" printf "arg4 - fontsize for text labeles \n" exit fi if [ -z "$5" ] then printf "arg5 - name of regions file to be built \n" exit fi fcdfp="$1" fim="$2" color="$3" fontsize="$4" fout="$5" # make the file of Ra,Dec cdfp_rdxy.sh $fcdfp none none # get the X,Y via image wcs sky2xy $fim @list.rd > A0 # build the file number_lines A0 > A1 awk < A1 '{ print $6 " " $7 " " $1}' > MyObjects # build the regions file text_file_ds9.py MyObjects $color $fontsize > $foutIt is useful to describe a few of the scripts used here. The script cdfp_rdxy read the Ra,Dec from a cdfp file and writem out in a simple ASCII format where the Ra,Dec are bothe written in units of degrees. There is not "# data" header or other header information. The next call involves the wcstools routine sky2xy. We want to convert the RA,DEC of list.rd, via the WCS of our input FITS images (arg2), into X,Y pixel positions. Here is what the top part of the temporay working file "A0" looks like:
93.74087524414 39.69704055786 J2000 -> 1124.813 286.871 93.76224517822 39.69044876099 J2000 -> 1066.207 265.032 93.76840209961 39.69412231445 J2000 -> 1049.805 278.415Next we want to add a column of line numbers to the A1 file. We'll use these line numbers as names for overplotting the target positions on our ds9 display. For this I use the simple, but useful, bash script number_lines. Here is the top of the file "A1" from this step:
1 93.74087524414 39.69704055786 J2000 -> 1124.813 286.871 2 93.76224517822 39.69044876099 J2000 -> 1066.207 265.032 3 93.76840209961 39.69412231445 J2000 -> 1049.805 278.415Next, we use a simple awk call to extract the values we need for out input file to the python code text_file_ds9.py. The file we build is named "MyObjects". Notice that text_file_ds9.py doesn't care what is in that third column. We do not have to have intgers tehre. Our script might use some other sets of strings for names, etc... Once we have our file "MyObjects" constructed we simply pass it to text_file_ds9.py and derive our ds9 regions file.