gnuastro-commits
[Top][All Lists]
Advanced

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

[gnuastro-commits] master 9ab3dd28 51/69: PSF stamp: new option to set a


From: Mohammad Akhlaghi
Subject: [gnuastro-commits] master 9ab3dd28 51/69: PSF stamp: new option to set a mask sky pixel value: maskskyval
Date: Wed, 26 Jan 2022 12:39:14 -0500 (EST)

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

    PSF stamp: new option to set a mask sky pixel value: maskskyval
    
    Until this commit, when using a mask (labeled image) this script assumed
    that sky background values (pixels that don't have to be masked) were equal
    to 0. The reason is that we used to treat mask images from Gnuastro. For
    Gnuastro (NoiseChisel and Segment outputs) the sky is considered as 0 in
    the detection and segmentation outputs. However, there may be other software
    that don't follow this convention. In that situation it is good to have an
    option to specify what is the sky background pixel value on the mask image.
    
    With this commit, this new option has been added: --maskskyval or -v. Now
    the user is able to specify the sky background value of the mask image. A
    bug has been also corrected. Until now, when the cropped core image (those
    that is used to detect the central object and not mask it) had more sky
    background pixels than the labeled object, the central object was
    considered to be the sky (just because there are more pixels!). This is a
    bug and it has been corrected by changing the sky background pixel values
    to nan values before computing the pixel value of the central object.
    
    This bug was reported by Pablo Manuel Sanchez Alarcon.
---
 bin/script/psf-create-make-stamp.in | 25 +++++++++++++++++++------
 1 file changed, 19 insertions(+), 6 deletions(-)

diff --git a/bin/script/psf-create-make-stamp.in 
b/bin/script/psf-create-make-stamp.in
index 01cd075a..ee3f0212 100644
--- a/bin/script/psf-create-make-stamp.in
+++ b/bin/script/psf-create-make-stamp.in
@@ -48,6 +48,7 @@ maskhdu=1
 output=""
 tmpdir=""
 axisratio=1
+maskskyval=0
 corewidth=""
 saturation=0
 normradii=""
@@ -223,6 +224,9 @@ do
         -M|--maskhdu)        maskhdu="$2";                              
check_v "$1" "$maskhdu";  shift;shift;;
         -M=*|--maskhdu=*)    maskhdu="${1#*=}";                         
check_v "$1" "$maskhdu";  shift;;
         -M*)                 maskhdu=$(echo "$1"  | sed -e's/-M//');    
check_v "$1" "$maskhdu";  shift;;
+        -v|--maskskyval)     maskskyval="$2";                           
check_v "$1" "$maskskyval";  shift;shift;;
+        -v=*|--maskskyval=*) maskskyval="${1#*=}";                      
check_v "$1" "$maskskyval";  shift;;
+        -v*)                 maskskyval=$(echo "$1"  | sed -e's/-v//'); 
check_v "$1" "$maskskyval";  shift;;
         -O|--mode)           mode="$2";                                 
check_v "$1" "$mode";  shift;shift;;
         -O=*|--mode=*)       mode="${1#*=}";                            
check_v "$1" "$mode";  shift;;
         -O*)                 mode=$(echo "$1"  | sed -e's/-O//');       
check_v "$1" "$mode";  shift;;
@@ -460,8 +464,16 @@ if [ x"$mask" != x ]; then
                 --center=$xcenter,$ycenter \
                 --width=$corewidth --output=$cropped_core $quiet
 
+  # If the cropped core labeled image has sky background values (zero by
+  # default), convert them to nan. This prevent considering the central
+  # object to be the sky if there are a lot of sky background pixels
+  # compared to the labeled region.
+  cropped_core_nonzeros=$tmpdir/cropped_core_nozeros-$objectid.fits
+  astarithmetic $cropped_core set-i $quiet \
+                i i $maskskyval eq nan where --output=$cropped_core_nonzeros
+
   # Compute the label of the central object from the core cropped image.
-  centrallabel=$(aststatistics $cropped_core --median -q)
+  centrallabel=$(aststatistics $cropped_core_nonzeros --median -q)
 
   # Check if the user has determined the --saturation option.
   if [ $saturation = 0 ]; then
@@ -473,12 +485,12 @@ if [ x"$mask" != x ]; then
   # Unlabel the central object and then mask everything else.
   cropped_masked=$tmpdir/cropped_masked-$objectid.fits
   astarithmetic $cropped      --hdu=1 set-i \
-                $cropped_mask --hdu=1  set-m \
+                $cropped_mask --hdu=1 set-m \
                                             \
-                $mask_saturated \
-                m m $centrallabel eq 0 where set-a \
-                a 0 ne set-mask \
-                                \
+                $mask_saturated  \
+                m m $centrallabel eq $maskskyval where set-a \
+                a $maskskyval ne set-mask  \
+                                 \
                 i mask nan where \
                 --output=$cropped_masked $quiet
 else
@@ -547,3 +559,4 @@ astarithmetic $cropped_masked --hdu=1 $normvalue / 
--output=$output $quiet
 if [ $keeptmp = 0 ]; then
     rm -r $tmpdir
 fi
+



reply via email to

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