gnuastro-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[gnuastro-commits] master 19a69ef4 1/6: psf-stamp: assuming a centered p


From: Mohammad Akhlaghi
Subject: [gnuastro-commits] master 19a69ef4 1/6: psf-stamp: assuming a centered position by default
Date: Mon, 13 Jun 2022 11:18:49 -0400 (EDT)

branch: master
commit 19a69ef4960a1f6f632ba1274d4e4df1f040de7f
Author: Raul Infante-Sainz <infantesainz@gmail.com>
Commit: Mohammad Akhlaghi <mohammad@akhlaghi.org>

    psf-stamp: assuming a centered position by default
    
    Until this commit, when the user didn't specify the coordinates to generate
    the stamp, the script complained about not having the coordinates of the
    desired position. However, this forced to the user to provide the position
    of the object even when it was already centered on the image.
    
    With this commit, the script has changed and now it assumes that the object
    of interest is in the center of the image (if no coordinates are provided
    with --center). As a consequence, when the object is aready centered on the
    image, it is not necessary to explicitly provide the coordinates.
---
 bin/script/psf-stamp.in | 58 ++++++++++++++++++++-----------------------------
 doc/gnuastro.texi       |  6 ++---
 2 files changed, 27 insertions(+), 37 deletions(-)

diff --git a/bin/script/psf-stamp.in b/bin/script/psf-stamp.in
index 2c4bd6c6..80d479b6 100644
--- a/bin/script/psf-stamp.in
+++ b/bin/script/psf-stamp.in
@@ -367,17 +367,26 @@ fi
 # If a stamp width (--stampwidth) is not given at all.
 if [ x"$stampwidth" = x ]; then
     cat <<EOF
-$scriptname: no stamp width provided. A stamp size (width) has to be specified 
with '--stampwidth' (or '-w')
+$scriptname: no stamp width provided. A stamp size (width) has to be specified 
with '--stampwidth' (or '-W')
 EOF
     exit 1
 fi
 
-# If center coordinates (--center) is not given at all.
+# If center coordinates (--center) is not given, assume it is centered.
 if [ x"$center" = x ]; then
+    # Find the size of the image
+    xsize=$(astfits $inputs --hdu=$hdu --keyvalue=NAXIS1 --quiet)
+    ysize=$(astfits $inputs --hdu=$hdu --keyvalue=NAXIS2 --quiet)
+
+    # Find the center of the image
+    xcoord=$(echo $xsize | awk '{if($1%2) print int($1/2); else print 
int($1/2)+1}')
+    ycoord=$(echo $ysize | awk '{if($1%2) print int($1/2); else print 
int($1/2)+1}')
+
+    # The center has been computed in pixels, assume pixel coordinates mode
+    mode=img
     cat <<EOF
-$scriptname: no center coordinates provided. Please use '--center' ('-c') to 
give the central coordinates
+$scriptname: warning: no center provided (--center). Considering that the 
center of the image is: (x,y)=($xcoord,$ycoord)
 EOF
-    exit 1
 else
     ncenter=$(echo $center | awk 'BEGIN{FS=","}END{print NF}')
     if [ x$ncenter != x2 ]; then
@@ -386,12 +395,15 @@ $scriptname: '--center' (or '-c') only take two values, 
but $ncenter were given
 EOF
         exit 1
     fi
+    # Obtain the coordinates of the center.
+    xcoord=$(echo "$center" | awk 'BEGIN{FS=","} {print $1}')
+    ycoord=$(echo "$center" | awk 'BEGIN{FS=","} {print $2}')
 fi
 
 # If a normalization range is not given at all.
 if [ x"$normradii" = x ]; then
     cat <<EOF
-$scriptname: warning: no ring of normalization provided. the stamp won't be 
normalized
+$scriptname: warning: no ring of normalization provided (--normradii). The 
stamp won't be normalized
 EOF
 else
     nnormradii=$(echo $normradii | awk 'BEGIN{FS=","}END{print NF}')
@@ -401,19 +413,15 @@ $scriptname: '--normradii' (or '-n') only take two 
values, but $nnormradii were
 EOF
         exit 1
     fi
+    # Obtain the minimum/maximum normalization radii.
+    normradiusmin=$(echo "$normradii" | awk 'BEGIN{FS=","} {print $1}')
+    normradiusmax=$(echo "$normradii" | awk 'BEGIN{FS=","} {print $2}')
 fi
 
-# If mode (--mode) is not given at all.
-if [ x"$mode" = x ]; then
-    cat <<EOF
-$scriptname: no coordinate mode provided. The '--mode' ('-O') takes one of the 
following two values: 'img' (for pixel coordinates) or 'wcs' (for celestial 
coordinates)
-EOF
-    exit 1
-
 # Make sure the value to '--mode' is either 'wcs' or 'img'. Note: '-o'
 # means "or" and is preferred to '[ ] || [ ]' because only a single
 # invocation of 'test' is done. Run 'man test' for more.
-elif [ "$mode" = wcs     -o      $mode = "img" ]; then
+if [ "$mode" = wcs     -o      $mode = "img" ]; then
     junk=1
 else
     cat <<EOF
@@ -426,25 +434,6 @@ fi
 
 
 
-# Basic parameters: coordinates and normalization radii
-# -----------------------------------------------------
-#
-# Obtain the coordinates of the center as well as the normalization radii
-# ring from the command line arguments.
-xcoord=$(echo "$center" | awk 'BEGIN{FS=","} {print $1}')
-ycoord=$(echo "$center" | awk 'BEGIN{FS=","} {print $2}')
-
-normradiusmin=$(echo "$normradii" | awk 'BEGIN{FS=","} {print $1}')
-normradiusmax=$(echo "$normradii" | awk 'BEGIN{FS=","} {print $2}')
-
-# With the center coordinates, generate a specific label for the object
-# consisting in its coordinates.
-objectid="$xcoord"_"$ycoord"
-
-
-
-
-
 # Define a temporal directory and thefinal output file
 # ----------------------------------------------------
 #
@@ -457,8 +446,9 @@ objectid="$xcoord"_"$ycoord"
 # The final output stamp is also defined here if the user does not provide
 # an explicit name. If the user has defined a specific path/name for the
 # output, it will be used for saving the output file. If the user does not
-# specify a output name, then a default value containing the center and
-# mode will be generated.
+# specify a output name, then a default value containing the center will be
+# generated.
+objectid="$xcoord"_"$ycoord"
 bname_prefix=$(basename "$inputs" | sed 's/\.fits/ /' | awk '{print $1}')
 if [ x"$tmpdir" = x ]; then \
   tmpdir=$(pwd)/"$bname_prefix"_stamp
diff --git a/doc/gnuastro.texi b/doc/gnuastro.texi
index 903b11cc..fcbfd1e2 100644
--- a/doc/gnuastro.texi
+++ b/doc/gnuastro.texi
@@ -25789,9 +25789,9 @@ $ asttable catalog.fits | while read -r ra dec mag; do \
 @end example
 
 The input is an image from which the stamp of the stars are constructed.
-There are mandatory options that the user has to specify: @option{--mode}, 
@option{--center}, @option{--stampwidth} and @option{--normradii}.
-The output will be an image with a size specified by @option{--stampwidth}, 
centered at the position specified by the option @option{--center}.
-The output will be ``normalized'' by the value computed within the ring around 
the center (at a radial distance between the two radii specified by the option 
@option{--normradii}).
+The output will be an image with a size specified by @option{--stampwidth}, 
centered at the position specified by the option @option{--center}, and 
normalized ``normalized'' by the value computed within the ring around the 
center (at a radial distance between the two radii specified by the option 
@option{--normradii}).
+If no center is specified, then it is assumed that the object of interest is 
already in the center of the image.
+In the same way, if no normalization ring is considered, the output will not 
be normalized.
 
 If the given coordinate is not within the image at all (such that the full 
requested stamp is outside the input image), then this script will abort with a 
message and a non-zero return value.
 If all the pixels within the normalization radii are NaN, the output stamp 
will be fully NaN.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]