gnuastro-commits
[Top][All Lists]
Advanced

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

[gnuastro-commits] master 21153ad4: psf-stamp: ignore segmentation when


From: Mohammad Akhlaghi
Subject: [gnuastro-commits] master 21153ad4: psf-stamp: ignore segmentation when star is out of image
Date: Mon, 27 Jun 2022 12:45:50 -0400 (EDT)

branch: master
commit 21153ad4382f479f166bca0b176f7b3330b3ca67
Author: Sepideh Eskandarlou <sepideh.eskandarlou@gmail.com>
Commit: Sepideh Eskandarlou <sepideh.eskandarlou@gmail.com>

    psf-stamp: ignore segmentation when star is out of image
    
    Until now, when the stars were outside the field of view, the label of
    clump and object were empty and the final stamp would not be
    produced. Because in the mask step 'astarithmetic' was looking for the
    label of clumps and objects, while these label were empty.
    
    With this commit, when the clump and object are empty the segmentation
    image is ingnored.
    
    Also, after pulling the most recent commit, I needed to clean the
    'doc/gnuastro-figures' directory and noticed that the 'clean' rule for
    'doc/plotsrc/Makefile' was deleting the Gnuastro logo and the README file
    of that directory. The 'clean' rule was therefore updated to keep certain
    files before deleting others.
    
    This commit was done with the help of Mohammad Akhlaghi.
---
 bin/script/psf-scale-factor.in | 28 +++++++++-------------------
 bin/script/psf-stamp.in        | 42 +++++++++++++++++++-----------------------
 doc/plotsrc/Makefile           |  9 +++++++--
 3 files changed, 35 insertions(+), 44 deletions(-)

diff --git a/bin/script/psf-scale-factor.in b/bin/script/psf-scale-factor.in
index e6210920..f7c5d6f1 100644
--- a/bin/script/psf-scale-factor.in
+++ b/bin/script/psf-scale-factor.in
@@ -526,37 +526,27 @@ astcrop $inputs --hdu=$hdu --mode=img \
 #     sky.
 #   - Mask all non zero pixels in the mask image as nan values.
 if [ x"$segment" != x ]; then
-    clab="not-initialized"
-    olab="not-initialized"
+
     # Find the object and clump labels of the target. Labels are saved into
     # plain text files just in case they are necessary for debugging tasks.
-    cropped_core_clump=$tmpdir/cropped-core-clump-$objectid.fits
-    cropped_core_object=$tmpdir/cropped-core-object-$objectid.fits
-    clumplab=$(astcrop $segment --hdu=CLUMPS --mode=img --width=1,1 \
-               --widthinpix --oneelemstdout --center=$xcenter,$ycenter \
-               --output=$cropped_core_clump --quiet)
-    objectlab=$(astcrop $segment --hdu=OBJECTS --mode=img --width=1,1 \
-                --widthinpix --oneelemstdout --center=$xcenter,$ycenter \
-                --output=$cropped_core_object --quiet)
-    echo $clumplab > $tmpdir/cropped-core-clump-$objectid.txt
-    echo $objectlab > $tmpdir/cropped-core-object-$objectid.txt
-
-    # Read the labels
-    clab=$(cat $tmpdir/cropped-core-clump-$objectid.txt)
-    olab=$(cat $tmpdir/cropped-core-object-$objectid.txt)
+    clab=$(astcrop $segment --hdu=CLUMPS --mode=img --width=1,1 \
+                   --oneelemstdout --center=$xcenter,$ycenter \
+                   --quiet)
+    olab=$(astcrop $segment --hdu=OBJECTS --mode=img --width=1,1 \
+                   --oneelemstdout --center=$xcenter,$ycenter \
+                   --quiet)
 
     # If for any reason, a clump or object label couldn't be initialized at
     # the given coordiante, simply ignore this step. But print a warning so
     # the user is informed of the situation (and that this is a bug: 'clab'
     # should be initialized!).
-    if [ "$clab" = "not-initialized"   -o   "$olab" = "not-initialized" ]; then
+    if [ x"$clab" = x   -o   x"$olab" = x ]; then
         if [ x"$quiet" = x ]; then
             cat <<EOF
-$scriptname: WARNING: a bug! Please contact us at 'bug-gnuastro@gnu.org' to 
fix the problem. For some reason, no clump or object label could be initialized 
for the given coordinate within the given Segment image.
+$scriptname: WARNING: no clump or object label could be found in '$segment' 
for the coordinate $center
 EOF
         fi
         cropped_masked=$cropped
-
     else
         # Crop the object and clump image to same size as desired stamp.
         cropclp=$tmpdir/cropped-clumps-$objectid.fits
diff --git a/bin/script/psf-stamp.in b/bin/script/psf-stamp.in
index 0fe86ecb..ded12594 100644
--- a/bin/script/psf-stamp.in
+++ b/bin/script/psf-stamp.in
@@ -583,32 +583,23 @@ fi
 #     sky.
 #   - Mask all non zero pixels in the mask image as nan values.
 if [ x"$segment" != x ]; then
-    clab="not-initialized"
-    olab="not-initialized"
+
     # Find the object and clump labels of the target. Labels are saved into
     # plain text files just in case they are necessary for debugging tasks.
-    cropped_core_clump=$tmpdir/cropped-core-clump-$objectid.fits
-    cropped_core_object=$tmpdir/cropped-core-object-$objectid.fits
-    clumplab=$(astcrop $segment --hdu=CLUMPS --mode=img --width=1,1 \
-               --widthinpix --oneelemstdout --center=$xcenter,$ycenter \
-               --output=$cropped_core_clump --quiet)
-    objectlab=$(astcrop $segment --hdu=OBJECTS --mode=img --width=1,1 \
-                --widthinpix --oneelemstdout --center=$xcenter,$ycenter \
-                --output=$cropped_core_object --quiet)
-    echo $clumplab > $tmpdir/cropped-core-clump-$objectid.txt
-    echo $objectlab > $tmpdir/cropped-core-object-$objectid.txt
-
-    # Read the labels
-    clab=$(cat $tmpdir/cropped-core-clump-$objectid.txt)
-    olab=$(cat $tmpdir/cropped-core-object-$objectid.txt)
+    clab=$(astcrop $segment --hdu=CLUMPS --mode=img --width=1,1 \
+                   --oneelemstdout --center=$xcenter,$ycenter \
+                   --quiet)
+    olab=$(astcrop $segment --hdu=OBJECTS --mode=img --width=1,1 \
+                   --oneelemstdout --center=$xcenter,$ycenter \
+                   --quiet)
 
     # If for any reason, a clump or object label couldn't be initialized at
     # the given coordiante, simply ignore this step. But print a warning so
     # the user is informed of the situation (and that this is a bug: 'clab'
     # should be initialized!).
-    if [ "$clab" = "not-initialized"   -o   "$olab" = "not-initialized" ]; then
+    if [ x"$clab" = x   -o   x"$olab" = x ]; then
         cat <<EOF
-$scriptname: WARNING: a bug! Please contact us at 'bug-gnuastro@gnu.org' to 
fix the problem. For some reason, no clump or object label could be initialized 
for the given coordinate within the given Segment image.
+$scriptname: WARNING: no clump or object label could be found in '$segment' 
for the coordinate $center
 EOF
         cropped_masked=$cropped
 
@@ -712,11 +703,16 @@ astarithmetic $cropped_masked --hdu=1 $normvalue float32 
/ \
 # are kept into the header of the output file. The data kept are: object
 # and clump that were not masked and the normalization value. If not masks
 # were applied, then set the clump and object labels to 'none'.
-if [ x"$clab" = x ]; then clab="none"; fi
-if [ x"$olab" = x ]; then olab="none"; fi
-astfits $output --write=NORMVAL,$normvalue,"Normalization value" \
-                --write=CLABEL,$clab,"CLUMP label that was not masked" \
-                --write=OLABEL,$olab,"OBJECT label that was not masked"
+if [ x"$clab" = x ]; then
+    if ! [ x"$normvalue" = xnan ]; then
+        astfits $output --write=NORMVAL,$normvalue,"Normalization value"
+    fi
+else
+    astfits $output --write=NORMVAL,$normvalue,"Normalization value" \
+            --write=CLABEL,$clab,"CLUMP label that was not masked" \
+            --write=OLABEL,$olab,"OBJECT label that was not masked"
+fi
+
 
 
 
diff --git a/doc/plotsrc/Makefile b/doc/plotsrc/Makefile
index 8ee2a3e4..950a2876 100644
--- a/doc/plotsrc/Makefile
+++ b/doc/plotsrc/Makefile
@@ -68,8 +68,13 @@ $(finaltarget): all.tex ./tex/*.tex ./conversions.sh | tikz
 #        NOTE II: All non-plot PNG figures should be listed here.
 #   2. Remove everything in the gnuastro-figures directory
 #   3. Put the actual images back in that directory.
+tokeep = epicycles.png gnuastro.svg README
 clean:
        rm -rf all.pdf tikz \
-       && cp ../gnuastro-figures/epicycles.png ./ \
+       && for f in $(tokeep); do \
+            cp ../gnuastro-figures/$$f ./$$f-tmp; \
+          done \
        && rm ../gnuastro-figures/* \
-       && mv epicycles.png ../gnuastro-figures/
+       && for f in $(tokeep); do \
+            mv ./$$f-tmp ../gnuastro-figures/$$f; \
+          done



reply via email to

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