gnuastro-commits
[Top][All Lists]
Advanced

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

[gnuastro-commits] master c92ed4bb 3/3: psf-scale-factor: providing a na


From: Mohammad Akhlaghi
Subject: [gnuastro-commits] master c92ed4bb 3/3: psf-scale-factor: providing a nan value as output instead of crashing
Date: Tue, 21 Mar 2023 12:16:45 -0400 (EDT)

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

    psf-scale-factor: providing a nan value as output instead of crashing
    
    Until this commit, this script crashes when the scaling factor could not be
    computed. But in some scenarios it is good to not crash but continue by
    providing a nan value as output.
    
    With this commit, this has been done. Now the script provides a nan value
    when the scaling factor is not computed. This situation happens when there
    is not overlap with the input image and the center coordinates provided.
    
    This fixes task #16353: https://savannah.gnu.org/task/?16353
---
 bin/script/psf-scale-factor.in | 32 ++++++++++++++++++++++++++++++++
 1 file changed, 32 insertions(+)

diff --git a/bin/script/psf-scale-factor.in b/bin/script/psf-scale-factor.in
index 36b13126..f2e40b66 100644
--- a/bin/script/psf-scale-factor.in
+++ b/bin/script/psf-scale-factor.in
@@ -240,6 +240,13 @@ EOF
 }
 
 
+all_nan_warning() {
+    cat <<EOF
+$scriptname: WARNING: the cropped image could not be generated. Probably 
because it is out of the input image coverage. Therefore the output stamp will 
be all NaN. If you later use this stamp (among others) with any stack operator 
of 'astarithmetic' this image will effectively be ignored, so you can safely 
continue with stacking all the files
+EOF
+}
+
+
 
 
 
@@ -510,6 +517,31 @@ astcrop $inputs --hdu=$hdu --mode=img \
         --width=$xwidthinpix,$ywidthinpix\
         --output=$cropped $quiet
 
+# If the cropped image is not generated, it may happen that it does not
+# overlap with the input image. Save a nan value as the output and
+# continue.
+if ! [ -f $cropped ]; then
+
+    multifactor=nan
+
+    # Let the user know what happened.
+    if [ x"$quiet" = x ]; then all_nan_warning; fi
+
+    # Print the multiplication factor in standard output or in a given file
+    if [ x"$output" = x ]; then echo $multifactor
+    else                        echo $multifactor > $output
+    fi
+
+    # If the user does not specify to keep the temporal files with the option
+    # `--keeptmp', then remove the whole directory.
+    if [ $keeptmp = 0 ]; then
+        rm -r $tmpdir
+    fi
+
+    exit 0
+
+fi
+
 
 
 



reply via email to

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