[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[gnuastro-commits] master ea59208: make-ds9-reg: Added option to give ea
From: |
Mohammad Akhlaghi |
Subject: |
[gnuastro-commits] master ea59208: make-ds9-reg: Added option to give each region a name |
Date: |
Wed, 24 Feb 2021 14:53:35 -0500 (EST) |
branch: master
commit ea592084bc1185d1448cde439cd2ac59bb493d52
Author: Samane Raji <samaneraji@protonmail.com>
Commit: Mohammad Akhlaghi <mohammad@akhlaghi.org>
make-ds9-reg: Added option to give each region a name
Until now, we made a region for each object with a defined coordinate and
radius but each region doesn't have any name. However, in some cases we
need to know the name of objects to recognize them
With this commit, a new and optional '--namecol' option has been added to
this installed script. When given, it will print the given column's value
over each region.
---
bin/script/make-ds9-reg.in | 68 ++++++++++++++++++++++++++++++++++------------
doc/gnuastro.texi | 6 ++++
2 files changed, 57 insertions(+), 17 deletions(-)
diff --git a/bin/script/make-ds9-reg.in b/bin/script/make-ds9-reg.in
index 15d115e..3c55243 100644
--- a/bin/script/make-ds9-reg.in
+++ b/bin/script/make-ds9-reg.in
@@ -5,6 +5,7 @@
# Original author:
# Mohammad Akhlaghi <mohammad@akhlaghi.org>
# Contributing author(s):
+# Samane Raji <samaneraji@protonmail.com>
# Copyright (C) 2021 Free Software Foundation, Inc.
#
# Gnuastro is free software: you can redistribute it and/or modify it under
@@ -32,11 +33,11 @@ set -e
# command-line).
hdu=1
col=""
-name=""
width=1
mode=wcs
radius=""
command=""
+namecol=""
out=ds9.reg
color=green
dontdelete=0
@@ -82,6 +83,7 @@ $scriptname options:
-h, --hdu=STR HDU/extension of all input FITS files.
-c, --column=STR,STR Columns to use as coordinates (name or number).
-m, --mode=wcs|img Coordinates in WCS or image (default: $mode)
+ -n, --namecol=STR ID of each region (name or number of a column)
Output:
-C, --color Color for the regions (read by DS9).
@@ -189,6 +191,9 @@ do
-m|--mode) mode="$2"; check_v "$1"
"$mode"; shift;shift;;
-m=*|--mode=*) mode="${1#*=}"; check_v "$1"
"$mode"; shift;;
-m*) mode=$(echo "$1" | sed -e's/-m//'); check_v "$1"
"$mode"; shift;;
+ -n|--namecol) namecol="$2"; check_v "$1"
"$namecol"; shift;shift;;
+ -n=*|--namecol=*) namecol="${1#*=}"; check_v "$1"
"$namecol"; shift;;
+ -n*) namecol=$(echo "$1" | sed -e's/-n//'); check_v
"$1" "$namecol"; shift;;
# Output parameters
-C|--color) color="$2"; check_v
"$1" "$color"; shift;shift;;
@@ -244,7 +249,7 @@ if [ x$col = x ]; then
else
ncols=$(echo $col | awk 'BEGIN{FS=","}END{print NF}')
if [ x$ncols != x2 ]; then
- echo "$scriptname: only two columns should be given, but $ncols were
given"
+ echo "$scriptname: only two columns should be given with '--column'
(or '-c'), but $ncols were given"
exit 1
fi
fi
@@ -266,6 +271,15 @@ if [ -f $out ]; then
fi
fi
+# Make sure a single column is given to '--namecol':
+if [ x"$namecol" != x ]; then
+ ncols=$(echo $namecol | awk 'BEGIN{FS=","}END{print NF}')
+ if [ x$ncols != x1 ]; then
+ echo "$scriptname: only one column should be given to '--namecol'"
+ exit 1
+ fi
+fi
+
@@ -288,8 +302,11 @@ if [ x$mode = x"wcs" ]; then unit="\""; else unit=""; fi
# Write the metadata in the output.
printf "# Region file format: DS9 version 4.1\n" > $out
printf "# Created by $scriptname (GNU Astronomy Utilities) $version\n" >> $out
-printf "# Input: $input (hdu $hdu)\n" >> $out
+printf "# Input file: $input (hdu $hdu)\n" >> $out
printf "# Columns: $col\n" >> $out
+if [ x"$namecol" != x ]; then
+ printf "# Region name (or label) column: $namecol\n" >> $out
+fi
printf "global color=%s width=%d\n" $color $width >> $out
if [ $mode = "wcs" ]; then printf "fk5\n" >> $out
else printf "image\n" >> $out; fi
@@ -300,27 +317,44 @@ else printf "image\n" >> $out; fi
# Write each region's results (when no input file is given, read from the
# standard input).
-if [ x"$input" = x ]; then
- cat /dev/stdin \
- | asttable $input --column=$col \
- | while read a b; do \
- printf "circle(%g,%g,%g%s)\n" $a $b $radius $unit >> $out; \
- done
+if [ x"$namecol" = x ]; then
+ if [ x"$input" = x ]; then
+ cat /dev/stdin \
+ | asttable $input --column=$col \
+ | while read a b; do \
+ printf "circle(%g,%g,%g%s)\n" \
+ $a $b $radius $unit >> $out; \
+ done
+ else
+ asttable $input --column=$col \
+ | while read a b; do \
+ printf "circle(%g,%g,%g%s)\n" \
+ $a $b $radius $unit >> $out; \
+ done
+ fi
else
- asttable $input --column=$col \
- | while read a b; do \
- printf "circle(%g,%g,%g%s)\n" $a $b $radius $unit >> $out; \
- done
+ if [ x"$input" = x ]; then
+ cat /dev/stdin \
+ | asttable $input --column=$col --column=$namecol \
+ | while read a b c; do \
+ printf "circle(%g,%g,%g%s) # text={%g}\n" \
+ $a $b $radius $unit $c >> $out; \
+ done
+ else
+ asttable $input --column=$col --column=$namecol \
+ | while read a b c; do \
+ printf "circle(%g,%g,%g%s) # text={%g}\n" \
+ $a $b $radius $unit $c >> $out; \
+ done
+ fi
fi
-# Run ds9 with the desired region over-plotted.
-if [ x"$command" = x ]; then
- junk=1
-else
+# Run the user's command (while appending the region).
+if [ x"$command" != x ]; then
$command -regions $out
if [ $dontdelete = 0 ]; then rm $out; fi
fi
diff --git a/doc/gnuastro.texi b/doc/gnuastro.texi
index 0e98715..0fc804c 100644
--- a/doc/gnuastro.texi
+++ b/doc/gnuastro.texi
@@ -18307,6 +18307,12 @@ Identifiers of the two positional columns to use in
the DS9 region file from the
They can either be in WCS (RA and Dec) or image (pixel) coordiantes.
The mode can be specified with the @option{--mode} option, described below.
+@item -n STR
+@itemx --namecol=STR
+The column containing the name (or label) of each region.
+The type of the column (numeric or a character-based string) is irrelevant:
you can use both types of columns as a name or label for the region.
+This feature is useful when you need to recognize each region with a certain
ID or property (for example magnitude or redshift).
+
@item -m wcs|img
@itemx --mode=wcs|org
The coordinate system of the positional columns (can be either
@option{--mode=wcs} and @option{--mode=img}).
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [gnuastro-commits] master ea59208: make-ds9-reg: Added option to give each region a name,
Mohammad Akhlaghi <=