gnuastro-commits
[Top][All Lists]
Advanced

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

[gnuastro-commits] master 57b27b9e 12/69: PSF scripts: correcting severa


From: Mohammad Akhlaghi
Subject: [gnuastro-commits] master 57b27b9e 12/69: PSF scripts: correcting several bugs and homogenizing the notation
Date: Wed, 26 Jan 2022 12:39:09 -0500 (EST)

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

    PSF scripts: correcting several bugs and homogenizing the notation
    
    Until this commit, the basis for the PSF scripts were set. However, there
    were several bugs and they did not follow a robust convention/notation. With
    this commit, I changed several parts of the scripts in order to correct
    some bugs and follow the same notation into all of them. In this sense, the
    most important changes are:
    
    - Same output file names by default. Now the output file of each script has
      the script name as a suffix together with the coordinates of the object.
      For example, if a star stamp is generated by the script
      'psf-create-make-stamp' with the coordinates RA=3.4 and Dec=6.7, from an
      image named 'image.fits', then the default output name is:
      image_psfcreatemakestamp_3.4_6.7.fits
    
    - Same but with the temporary directory of each script, they have the name
      of the image followed by the name of the script as a suffix
    
    - Make sure that the mode has been provided by the user. In that way, the
      scripts do not assume that the coordinates are in 'img' or 'wcs'.
      Assuming that is prone to bugs and problems that are hard to detect. If 
the
      user does not give the mode, the scripts will warn about that.
    
    - In the computation of the flux factor, it is not necessary to have a
      stamp width. It is possible to compute internally a default stampwidth
      (based on the maximum normalization radius). As a consequene, now this
      parameter is not mandatory for the script 'psf-model-flux-factor'.
---
 bin/script/psf-create-junction.in       |  4 +--
 bin/script/psf-create-make-stamp.in     | 16 +++++++-----
 bin/script/psf-model-flux-factor.in     | 46 +++++++++++++++++++++------------
 bin/script/psf-model-scattered-light.in | 18 ++++++++-----
 4 files changed, 52 insertions(+), 32 deletions(-)

diff --git a/bin/script/psf-create-junction.in 
b/bin/script/psf-create-junction.in
index 8dbaf7fb..f4eedef7 100644
--- a/bin/script/psf-create-junction.in
+++ b/bin/script/psf-create-junction.in
@@ -285,7 +285,7 @@ fi
 bname_outer=$(basename $inputs | sed 's/\.fits/ /' | awk '{print $1}')
 bname_core=$(basename $core | sed 's/\.fits/ /' | awk '{print $1}')
 if [ x$tmpdir = x ]; then \
-  tmpdir=$(pwd)/"$bname_outer"_psf-junction
+  tmpdir=$(pwd)/"$bname_outer"_psfcreatejunction
 fi
 
 if [ -d $tmpdir ]; then
@@ -296,7 +296,7 @@ fi
 
 # Output
 if [ x$output = x ]; then
-  output="$bname_outer"_"$bname_core"_junction.fits
+  output="$bname_outer"_"$bname_core"_psfcreatejunction.fits
 fi
 
 
diff --git a/bin/script/psf-create-make-stamp.in 
b/bin/script/psf-create-make-stamp.in
index 32bf0ea3..0645e8ec 100644
--- a/bin/script/psf-create-make-stamp.in
+++ b/bin/script/psf-create-make-stamp.in
@@ -47,7 +47,6 @@ keeptmp=0
 maskhdu=1
 output=""
 tmpdir=""
-mode="img"
 corewidth=""
 normradii=""
 sigmaclip=""
@@ -308,12 +307,17 @@ else
     fi
 fi
 
+# If mode (--mode) is not given at all.
+if [ x"$mode" = x ]; then
+    echo "$scriptname: no mode provided."
+    echo "$scriptname: value to '--mode' ('-O') should be provided."
+    exit 1
 # Make sure the value to '--mode' is either 'wcs' or 'img'.
-if [ $mode = "wcs" ] || [ $mode = "img" ]; then
+elif [ $mode = "wcs" ] || [ $mode = "img" ]; then
     junk=1
 else
-    echo "$scriptname: wrong value to --mode (-m) provided."
-    echo "$scriptname: value to '--mode' ('-m') should be 'wcs' or 'img'"
+    echo "$scriptname: wrong value to --mode (-O) provided."
+    echo "$scriptname: value to '--mode' ('-O') should be 'wcs' or 'img'"
     exit 1
 fi
 
@@ -356,7 +360,7 @@ objectid="$xcoord"_"$ycoord"
 # mode will be generated.
 bname_prefix=$(basename $inputs | sed 's/\.fits/ /' | awk '{print $1}')
 if [ x$tmpdir = x ]; then \
-  tmpdir=$(pwd)/"$bname_prefix"_stamps
+  tmpdir=$(pwd)/"$bname_prefix"_psfcreatemakestamp
 fi
 
 if [ -d $tmpdir ]; then
@@ -367,7 +371,7 @@ fi
 
 # Output
 if [ x$output = x ]; then
-  output=$tmpdir/stamp-$objectid.fits
+  output="$bname_prefix"_psfcreatemakestamp_$objectid.fits
 fi
 
 
diff --git a/bin/script/psf-model-flux-factor.in 
b/bin/script/psf-model-flux-factor.in
index 73907cc9..fe361267 100644
--- a/bin/script/psf-model-flux-factor.in
+++ b/bin/script/psf-model-flux-factor.in
@@ -42,7 +42,6 @@ keeptmp=0
 maskhdu=1
 output=""
 tmpdir=""
-mode="img"
 corewidth=""
 normradii=""
 sigmaclip=""
@@ -93,7 +92,7 @@ $scriptname options:
   -h, --hdu=STR           HDU/extension of all input FITS files.
   -p, --psf=STR           PSF fits file.
   -P, --psfhdu=STR        HDU/extension of all input FITS files.
-  -m, --mode=STR          Coordinates mode ('wcs' or 'img').
+  -O, --mode=STR          Coordinates mode ('wcs' or 'img').
   -c, --center=FLT,FLT    Center coordinates of the object.
   -W, --stampwidth=INT    Width of the stamp in pixels.
   -w, --corewidth=INT     Area width of the central object in pixels for 
unmasking.
@@ -293,13 +292,6 @@ if [ x"$psf" = x ]; then
     exit 1
 fi
 
-# If a stamp width (--stampwidth) is not given at all.
-if [ x"$stampwidth" = x ]; then
-    echo "$scriptname: no stamp width provided."
-    echo "A stamp size (width) has to be specified with --stampwidth or -w."
-    exit 1
-fi
-
 # If center coordinates (--center) is not given at all.
 if [ x"$center" = x ]; then
     echo "$scriptname: no center coordinates provided."
@@ -326,12 +318,17 @@ else
     fi
 fi
 
+# If mode (--mode) is not given at all.
+if [ x"$mode" = x ]; then
+    echo "$scriptname: no mode provided."
+    echo "$scriptname: value to '--mode' ('-O') should be provided."
+    exit 1
 # Make sure the value to '--mode' is either 'wcs' or 'img'.
-if [ $mode = "wcs" ] || [ $mode = "img" ]; then
+elif [ $mode = "wcs" ] || [ $mode = "img" ]; then
     junk=1
 else
-    echo "$scriptname: wrong value to --mode (-m) provided."
-    echo "$scriptname: value to '--mode' ('-m') should be 'wcs' or 'img'"
+    echo "$scriptname: wrong value to --mode (-O) provided."
+    echo "$scriptname: value to '--mode' ('-O') should be 'wcs' or 'img'"
     exit 1
 fi
 
@@ -374,7 +371,7 @@ objectid="$xcoord"_"$ycoord"
 # mode will be generated.
 bname_prefix=$(basename $inputs | sed 's/\.fits/ /' | awk '{print $1}')
 if [ x$tmpdir = x ]; then \
-  tmpdir=$(pwd)/"$bname_prefix"_fluxfactors
+  tmpdir=$(pwd)/"$bname_prefix"_psfmodelfluxfactor
 fi
 
 if [ -d $tmpdir ]; then
@@ -385,7 +382,7 @@ fi
 
 # Output
 if [ x$output = x ]; then
-  output=$tmpdir/fluxfactor-$objectid.txt
+  output="$bname_prefix"_psfmodelfluxfactor_$objectid.txt
 fi
 
 
@@ -414,6 +411,21 @@ fi
 
 
 
+# Compute the width of the stamp
+# ------------------------------
+#
+# If the width of the stamp is specified by the user, use that size.
+# Otherwise, make the stamp width of the same size than two times the
+# maximum radius for computing the flux factor. This is the maximum radius
+# that is needed for computing the flux value.
+if [ x"$stampwidth" = x ]; then
+    stampwidth=$(astarithmetic $normradiusmax 2 x 1 + --quiet)
+fi
+
+
+
+
+
 # Crop the original image around the object
 # -----------------------------------------
 #
@@ -484,9 +496,9 @@ fi
 # Compute the radial profiles
 # ---------------------------
 #
-# Generate the radial profile of the stamp, since it has been already
-# centered on the center of the object, it is not necessary to give the
-# center coordinates. If the user specifies a maximum radius, use it.
+# Generate the radial profile of the stamp and the PSF, since it has been
+# already centered on the center of the object, it is not necessary to give
+# the center coordinates. If the user specifies a maximum radius, use it.
 radialprofile=$tmpdir/rprofile-$objectid.fits
 psfradialprofile=$tmpdir/rprofile-psf-$objectid.fits
 if [ x"$rmax" != x ]; then
diff --git a/bin/script/psf-model-scattered-light.in 
b/bin/script/psf-model-scattered-light.in
index 90234612..d1c74103 100644
--- a/bin/script/psf-model-scattered-light.in
+++ b/bin/script/psf-model-scattered-light.in
@@ -42,7 +42,6 @@ center=""
 keeptmp=0
 output=""
 tmpdir=""
-mode="img"
 fluxfactor=""
 version=@VERSION@
 scriptname=@SCRIPT_NAME@
@@ -86,7 +85,7 @@ $scriptname options:
   -h, --hdu=STR           HDU/extension of all input FITS files.
   -p, --psf=STR           PSF FITS image.
   -P, --psfhdu=STR        HDU/extension of the PSF image.
-  -m, --mode=STR          Coordinates mode ('wcs' or 'img').
+  -O, --mode=STR          Coordinates mode ('wcs' or 'img').
   -c, --center=FLT,FLT    Center coordinates of the object.
   -f, --fluxfactor=FLT    Factor by which the PSF is multiplied.
 
@@ -271,12 +270,17 @@ else
     fi
 fi
 
+# If mode (--mode) is not given at all.
+if [ x"$mode" = x ]; then
+    echo "$scriptname: no mode provided."
+    echo "$scriptname: value to '--mode' ('-O') should be provided."
+    exit 1
 # Make sure the value to '--mode' is either 'wcs' or 'img'.
-if [ $mode = "wcs" ] || [ $mode = "img" ]; then
+elif [ $mode = "wcs" ] || [ $mode = "img" ]; then
     junk=1
 else
-    echo "$scriptname: wrong value to --mode (-m) provided."
-    echo "$scriptname: value to '--mode' ('-m') should be 'wcs' or 'img'"
+    echo "$scriptname: wrong value to --mode (-O) provided."
+    echo "$scriptname: value to '--mode' ('-O') should be 'wcs' or 'img'"
     exit 1
 fi
 
@@ -315,7 +319,7 @@ objectid="$xcoord"_"$ycoord"
 # mode will be generated.
 bname_prefix=$(basename $inputs | sed 's/\.fits/ /' | awk '{print $1}')
 if [ x$tmpdir = x ]; then \
-  tmpdir=$(pwd)/"$bname_prefix"_psf_stamps
+  tmpdir=$(pwd)/"$bname_prefix"_psfmodelscatteredlight
 fi
 
 if [ -d $tmpdir ]; then
@@ -326,7 +330,7 @@ fi
 
 # Output
 if [ x$output = x ]; then
-  output=$tmpdir/psf-stamp-$objectid.fits
+  output="$bname_prefix"_psfmodelscatteredlight_$objectid.fits
 fi
 
 



reply via email to

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