gnuastro-commits
[Top][All Lists]
Advanced

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

[gnuastro-commits] master 6901ec82 49/69: PSF select-stars: check the im


From: Mohammad Akhlaghi
Subject: [gnuastro-commits] master 6901ec82 49/69: PSF select-stars: check the image and catalog have a overlap area or not
Date: Wed, 26 Jan 2022 12:39:14 -0500 (EST)

branch: master
commit 6901ec823d3a03d1c42e84585b72ca9caf2aed2a
Author: Sepideh Eskandarlou <sepideh.eskandarlou@gmail.com>
Commit: Mohammad Akhlaghi <mohammad@akhlaghi.org>

    PSF select-stars: check the image and catalog have a overlap area or not
    
    Until now, if the user provides a catalog of stars and want based on that
    and input image, select the stars in the specific range of the magnitude,
    just check the image are smaller than the catalog or larger than it. But
    did not check that image and catalog have an overlap area together or not.
    
    With this commit, before selecting the stars in the specific range of
    magnitude, at first by using the 'astfits' and '--skycoverage' option we
    find the four coordinate of the iamge, then based on these coordinate and
    by using the '--polygon' option in 'asttable' the overlap area between the
    image and the catalog has been found and if they have not to overlap area
    (if the number of rows in table to be zero) the script will be stopped and
    print an error, otherwise, if the number of rows in this table not to be
    zero the script will be run and select the stars in the range of magnitude
    between minimum and maximum.
---
 bin/script/psf-create-select-stars.in | 52 +++++++++++++++++++----------------
 1 file changed, 29 insertions(+), 23 deletions(-)

diff --git a/bin/script/psf-create-select-stars.in 
b/bin/script/psf-create-select-stars.in
index cc9f42e7..9ab27c54 100755
--- a/bin/script/psf-create-select-stars.in
+++ b/bin/script/psf-create-select-stars.in
@@ -414,39 +414,49 @@ fi
 # filter the objects to have only the ones with proper brightness. If the
 # user does not provide a catalogue, obtain it using the program
 # 'astquery'.
+#
+# The output name of the catalog of stars in the range of the
+# magnitude.
 catalog_magfiltered=$tmpdir/catalog-mag-$minmag-$maxmag.fits
+
+# The output name of the sky coverage.
+skycoverage=$tmpdir/skycoverage.fits
+
+# If the catalog and the image have an overlap area, then select the stars
+# in the range of magnitude between minimum and maximum.
 if [ x"$catalog" != x ]; then
 
     # Find minimum and maximum RA/Dec values of the input image.
     minraimg=$(astfits $inputs --hdu=$hdu --skycoverage \
-               | grep 'RA' | awk '{print $2}')
+                   | grep 'RA' | awk '{print $2}')
     maxraimg=$(astfits $inputs --hdu=$hdu --skycoverage \
-               | grep 'RA' | awk '{print $3}')
+                   | grep 'RA' | awk '{print $3}')
 
     mindecimg=$(astfits $inputs --hdu=$hdu --skycoverage \
-                | grep 'DEC' | awk '{print $2}')
+                    | grep 'DEC' | awk '{print $2}')
     maxdecimg=$(astfits $inputs --hdu=$hdu --skycoverage \
-                | grep 'DEC' | awk '{print $3}')
+                    | grep 'DEC' | awk '{print $3}')
 
-    # Find minimum and maximum RA/Dec values of the input catalog.
-    minracatalog=$(asttable $catalog -c$racolumn \
-                   | aststatistics --minimum)
-    maxracatalog=$(asttable $catalog -c$racolumn \
-                   | aststatistics --maximum)
+    # Find the overlap area between catalog and image.
+    asttable $catalog --inpolygon=$racolumn,$deccolumn \
+             --polygon="$minraimg,$mindecimg \
+                        : $minraimg,$maxdecimg \
+                        : $maxraimg,$mindecimg \
+                        : $maxraimg,$maxdecimg" \
+             --output=$skycoverage
 
-    mindeccatalog=$(asttable $catalog -c$deccolumn \
-                    | aststatistics --minimum)
-    maxdeccatalog=$(asttable $catalog -c$deccolumn \
-                    | aststatistics --maximum)
-
-    # Check if the catalog overlap the image or not.
-    checkoverlap=$(echo $minraimg $minracatalog $mindecimg $mindeccatalog \
-                 $maxraimg $maxracatalog $maxdecimg $maxdeccatalog \
-                 | awk '{print ($1 <= $2 && $3 <= $4 && $5 >= $6 && $7 >= 
$8)}')
+    # The number of stars in the overlap area.
+    number=$(asttable $skycoverage | wc -l)
 
     # If catalog overlap the image, select stars with magnitudes between
     # the minimum and maximum values.
-    if [ "$checkoverlap" = 1 ]; then
+    if [ "$number" = 0 ]; then
+
+        # Stop if the catalog doesn't overlap with the image.
+        echo "Image and catalog do not overlap."
+        echo "Please provide an iamge and a catalog which overlap together."
+        exit 1
+    else
 
         # Make a file for output of 'asttable'.
         if [ -f $catalog_magfiltered ]; then
@@ -467,10 +477,6 @@ if [ x"$catalog" != x ]; then
                 exit 2
             fi
         fi
-    else
-        # Stop if the catalog doesn't overlap with the image.
-        echo "The catalog is smaller than the image and doesn't overlap with 
the image."
-        exit 1
     fi
 
 # If the user doesn't provide a catalog, use 'astquery' to obtain it.



reply via email to

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