gnuastro-commits
[Top][All Lists]
Advanced

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

[gnuastro-commits] master db2d55be 37/69: PSF select-stars: changing som


From: Mohammad Akhlaghi
Subject: [gnuastro-commits] master db2d55be 37/69: PSF select-stars: changing some variable names to follow conventions
Date: Wed, 26 Jan 2022 12:39:13 -0500 (EST)

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

    PSF select-stars: changing some variable names to follow conventions
    
    Until this commit, this script had several variable names that come from
    long time ago and they did not follow the conventions we are using in
    Gnuastro (at least, for the scripts developed for the PSF). With this
    commit, I have corrected some of them. Still, the script needs to be
    revised to ensure that it works properly.
---
 bin/script/psf-create-select-stars.in | 143 +++++++++++++++++++---------------
 1 file changed, 80 insertions(+), 63 deletions(-)

diff --git a/bin/script/psf-create-select-stars.in 
b/bin/script/psf-create-select-stars.in
old mode 100755
new mode 100644
index 06e16e9b..abf4c72f
--- a/bin/script/psf-create-select-stars.in
+++ b/bin/script/psf-create-select-stars.in
@@ -1,6 +1,5 @@
 #!/bin/sh
 
-
 # Build a catalogue, with column names "columns", of reference stars from
 # an astquery "dataset", with a $magnitud value between "min" and "max"
 # which satisfies a "criteria" specified as awk code. Additionaly, if a
@@ -12,10 +11,11 @@
 # Run with '--help' for more information.
 #
 # Original author:
-#     Carlos Morales-Socorro <cmorsoc@gmail.com>
-# Contributing author:
 #     Sepideh Eskandarlou <sepideh.eskandarlou@gmail.com>
+# Contributing author:
+#     Raul Infante-Sainz <infantesainz@gmail.com>
 #     Mohammad Akhlaghi <mohammad@akhlaghi.org>
+#     Carlos Morales-Socorro <cmorsoc@gmail.com>
 # Copyright (C) 2020-2021, Free Software Foundation, Inc.
 #
 # Gnuastro is free software: you can redistribute it and/or modify it under
@@ -32,36 +32,30 @@
 # with Gnuastro. If not, see <http://www.gnu.org/licenses/>.
 
 
-
-
-
-
 # Exit the script in the case of failure
 set -e
-# Bash debug mode
-# set -x
 
 
 
 
 
 # Default parameter's values
+hdu=1
 min=19
 max=20
-hdu=""
-bdir=""
 show=""
 quiet=""
+output=""
+tmpdir=""
 catalog=""
 segmented=""
-keepbuild=""
+keeptmp=""
 minaxisratio=0.9
 version=@VERSION@
 mindistdeg=0.015277778
 field="phot_g_mean_mag"
 scriptname=@SCRIPT_NAME@
 matchaperturedeg=3.0/3600
-output="selected-stars.txt"
 dataset="gaia --dataset=edr3"
 
 
@@ -93,9 +87,8 @@ within a given "matchaperturedeg", in pixels, and with an 
AXIS_RATIO >
 
 $scriptname options:
  Input:
-  -S, --segmented=STR     Segmentation file obtained by Segment (astsegment).
-  -in,--input=STR         Input file.
   -h, --hdu=STR/INT       Extension name or number of input data.
+  -S, --segmented=STR     Segmentation file obtained by Segment (astsegment).
   -d, --dataset=STR       astquery format dataset ("gaia --dataset=edr3", 
etc.).
   -f, --field=STR         Catalogue key field to identify the magnitude field
                           ("phot_rp_mean_mag", etc.).
@@ -111,8 +104,8 @@ $scriptname options:
                           parrallax and parrallax_error.
 
  Output:
-  -k, --keepbuild         Keep the build directory.
-  -t, --bdir              Build directory (for intermediate files).
+  -k, --keeptmp         Keep the build directory.
+  -t, --tmpdir            Build directory (for intermediate files).
   -o, --output            Catalogue file.
 
  Operating mode:
@@ -212,9 +205,6 @@ do
        -h|--hdu)               hdu="$2";                                     
check_v "$1" "$hdu";  shift;shift;;
        -h=*|--hdu=*)           hdu="${1#*=}";                                
check_v "$1" "$hdu";  shift;;
        -h*)                    hdu=$(echo "$1" | sed -e's/-h//');            
check_v "$1" "$hdu";  shift;;
-       -in|--input)            input="$2";                                   
check_v "$1" "$input";  shift;shift;;
-       -in=*|--input=*)        input="${1#*=}";                              
check_v "$1" "$input";  shift;;
-       -in*)                   input=$(echo "$1" | sed -e's/-in//');         
check_v "$1" "$input";  shift;;
        -e|--extscript)         extscript="$2";                               
check_v "$1" "$extscript";  shift;shift;;
        -e=*|--extscript=*)     extscript="${1#*=}";                          
check_v "$1" "$extscript";  shift;;
        -e*)                    extscript=$(echo "$1" | sed -e's/-e//');      
check_v "$1" "$extscript";  shift;;
@@ -244,11 +234,11 @@ do
        -D*)                    mindistdeg=$(echo "$1" | sed -e's/-D//');     
check_v "$1" "$mindistdeg";  shift;;
 
 # Output parameters
-       -k|--keepbuild)         keepbuild=1; shift;;
-       -k*|--keepbuild=*)      on_off_option_error --keepbuild -k;;
-       -t|--bdir)              bdir="$2";                                    
check_v "$1" "$bdir";  shift;shift;;
-       -t=*|--bdir=*)          bdir="${1#*=}";                               
check_v "$1" "$bdir";  shift;;
-       -t*)                    bdir=$(echo "$1" | sed -e's/-t//');           
check_v "$1" "$bdir";  shift;;
+       -k|--keeptmp)         keeptmp=1; shift;;
+       -k*|--keeptmp=*)      on_off_option_error --keeptmp -k;;
+       -t|--tmpdir)            tmpdir="$2";                                    
check_v "$1" "$tmpdir";  shift;shift;;
+       -t=*|--tmpdir=*)        tmpdir="${1#*=}";                               
check_v "$1" "$tmpdir";  shift;;
+       -t*)                    tmpdir=$(echo "$1" | sed -e's/-t//');           
check_v "$1" "$tmpdir";  shift;;
        -o|--output)            output="$2";                                  
check_v "$1" "$output"; shift;shift;;
        -o=*|--output=*)        output="${1#*=}";                             
check_v "$1" "$output"; shift;;
        -o*)                    output=$(echo "$1" | sed -e's/-o//');         
check_v "$1" "$output"; shift;;
@@ -267,9 +257,9 @@ do
    # Unrecognized option:
        -*) echo "$scriptname: unknown option '$1'"; exit 1;;
 
-       # Not an option (not starting with a '-'):
-       # it's assumed to be detected.fits or segmented.fits
-       *) input="$1 $input"; shift;;
+       # Not an option (not starting with a `-'): assumed to be input FITS
+       # file name.
+       *) inputs="$1 $input"; shift;;
    esac
 done
 
@@ -281,7 +271,7 @@ done
 # ===================
 #
 # If the input image has not been given at all.
-if [ x"$input" = x ]; then
+if [ x"$inputs" = x ]; then
     echo " $scriptname: no input image file specified."
     echo "Run with '--help' for more information on how to run."
        exit 1
@@ -289,7 +279,7 @@ fi
 
 # Check that if 'matchaperturedeg' is not specified as input,
 # Set its value to'3.0/3600'
-arcsec_per_pixel=$(astfits $input --hdu=$hdu --pixelscale -q \
+arcsec_per_pixel=$(astfits $inputs--hdu=$hdu --pixelscale -q \
                       | awk '{print $1*3600}')
 if [ x"$matchaperturedeg" = x ]; then
    matchaperturedeg=$(echo $matchaperturedeg $arcsec_per_pixel \
@@ -314,16 +304,36 @@ fi
 
 
 
-# Make a directory for output files.
-#-----------------------------------
+
+
+# Define a temporal directory and thefinal output file
+# ----------------------------------------------------
 #
-# If user dos not specify build directory make directory
-# in pwd
-if [ x"$bdir" = x ]; then
-   bdir="$imgfile"_cat_"$field"_"$min"_"$max"
+# Construct the temporary directory. If the user does not specify any
+# directory, then a default one with the base name of the input image will
+# be constructed.  If the user set the directory, then make it. This
+# directory will be deleted at the end of the script if the user does not
+# want to keep it (with the `--keeptmp' option).
+
+# The final catalog is also defined here if the user does not provide an
+# explicit name. If the user has defined a specific path/name for the
+# output, it will be used for saving the output file. If the user does not
+# specify an output name, then a default value containing the field, min,
+# and max magnitudes will will be generated.
+bname_prefix=$(basename $inputs | sed 's/\.fits/ /' | awk '{print $1}')
+if [ x$tmpdir = x ]; then \
+  tmpdir=$(pwd)/"$bname_prefix"_psfcreateselectstar_"$field"_"$min"_"$max"
 fi
-if [ ! -d $bdir ]; then
-   mkdir $bdir
+
+if [ -d $tmpdir ]; then
+  junk=1
+else
+  mkdir -p $tmpdir
+fi
+
+# Output
+if [ x$output = x ]; then
+  output="$bname_prefix"_psfcreateselectstar_"$field"_"$min"_"$max".fits
 fi
 
 
@@ -331,7 +341,7 @@ fi
 
 
 # Catalog of stars
-#-----------------
+# ----------------
 #
 # At first check that user have catalog of stars or no. If the user geive a
 # catalog to script at first with help of "--skycoverage" check the
@@ -340,30 +350,38 @@ fi
 # magnitude between 0 to maximum of magitude. If it isn't stop script. If
 # user don't provide catalog with help of "--astquery" download the
 # catalog.
-if [ -f $catalog ]; then
+if [ x"$catalog" != x ]; then
     # Find minimum value of image's ra.
-    minraimg=$(astfits $input --skycoverage | grep 'RA' | awk '{print $2}')
+    minraimg=$(astfits $inputs --hdu=$hdu --skycoverage \
+               | grep 'RA' | awk '{print $2}')
 
     # Find minimum value of image's dec.
-    mindecimg=$(astfits $input --skycoverage | grep 'DEC' | awk '{print $2}')
+    mindecimg=$(astfits $inputs --hdu=$hdu --skycoverage \
+                | grep 'DEC' | awk '{print $2}')
 
     # Find maximum value of image's ra.
-    maxraimg=$(astfits $input --skycoverage | grep 'RA' | awk '{print $3}')
+    maxraimg=$(astfits $inputs --hdu=$hdu --skycoverage \
+               | grep 'RA' | awk '{print $3}')
 
     # Find maximum value of image's dec.
-    maxdecimg=$(astfits $input --skycoverage | grep 'DEC' | awk '{print $3}')
+    maxdecimg=$(astfits $inputs --hdu=$hdu --skycoverage \
+                | grep 'DEC' | awk '{print $3}')
 
     # Find minimum value of catalog's ra.
-    minracatalog=$(asttable $catalog -cRA | aststatistics --minimum)
+    minracatalog=$(asttable $catalog -cRA \
+                   | aststatistics --minimum)
 
     # Find minimum value of catalog's dec.
-    mindeccatalog=$(asttable $catalog -cDEC | aststatistics --minimum)
+    mindeccatalog=$(asttable $catalog -cDEC \
+                    | aststatistics --minimum)
 
     # Find maximum value of catalog's ra.
-    maxracatalog=$(asttable $catalog -cRA | aststatistics --maximum)
+    maxracatalog=$(asttable $catalog -cRA \
+                   | aststatistics --maximum)
 
     # Find maximum value of catalog's dec.
-    maxdeccatalog=$(asttable $catalog -cDEC | aststatistics --maximum)
+    maxdeccatalog=$(asttable $catalog -cDEC \
+                    | aststatistics --maximum)
 
     # Check that catalog overlap the image or not.
     check=$(echo $minraimg $minracatalog $mindecimg $mindeccatalog \
@@ -375,7 +393,7 @@ if [ -f $catalog ]; then
     if [ "$check" = 1 ]; then
 
         # Make a file for output of 'asttable'.
-        query=$bdir/query.fits
+        query=$tmpdir/query.fits
         if [ -f $query ]; then
             echo "External Cataloge already exists "
         else
@@ -387,7 +405,7 @@ if [ -f $catalog ]; then
 
             numstars=$(asttable $query -i | grep 'Number of rows' | awk 
'{print $4}')
             if [ "$numstars" = 0 ]; then
-                rm -rf $bdir
+                rm -rf $tmpdir
                 echo "There were no stars in magnitude range $min to $max"
                 exit 2
             fi
@@ -401,13 +419,13 @@ if [ -f $catalog ]; then
 # with magnitude between 0 to max from gaia has been downloaded.
 else
     # Make a 'query.fits' for output of 'astquery'.
-    query=$bdir/query.fits
+    query=$tmpdir/query.fits
     if [ -f $query ]; then
         echo "External Cataloge already exists "
     else
         # Download catalog of stars with magnitude between 0 to max from
         # Gaia with '--astquery'.
-        astquery $dataset --output=$query --overlapwith=$input \
+        astquery $dataset --output=$query --overlapwith=$inputs \
                 --hdu=$hdu --column=ra,dec,$field,parallax,parallax_error \
                 --range=$field,0:$max --sort=$field $quiet
     fi
@@ -416,14 +434,13 @@ fi
 
 
 
-
 # Select stars with good parallax.
 #---------------------------------
 #
 # With some options of 'asttable' such as '--noblank'
 # remove all stras have parallax larger than three
 # times of parallax-error.
-goodparallax=$bdir/parallax-good.fits
+goodparallax=$tmpdir/parallax-good.fits
 asttable $query -cra,dec -c$field \
          --range=$field,$min:$max --colinfoinstdout --noblank=4 \
         -c'arith parallax parallax abs \
@@ -443,7 +460,7 @@ asttable $query -cra,dec -c$field \
 # catalogue of stars from Gaia data sets with clump
 # catalogue. Finally apply the mimimumm axis atio
 # criteria.
-circular=$bdir/circular-objects.fits
+circular=$tmpdir/circular-objects.fits
 if [ -f $circular ]; then
     echo "Catalog of circular objects already exists "
 else
@@ -451,8 +468,8 @@ else
        cp $goodparallax $circular
     else
        # Intermediate files.
-       qraw=$bdir/axisratio-raw.fits
-       qmatch=$bdir/axisratio-match.fits
+       qraw=$tmpdir/axisratio-raw.fits
+       qmatch=$tmpdir/axisratio-match.fits
 
        # Measure axisratios
        astmkcatalog $segmented --ids --ra --dec --axisratio \
@@ -484,8 +501,8 @@ fi
 # minimumm distance and based on '--noblank' and 'where' remove
 # stars tha have distance larger than minimumm distance. Then
 # remove each circular stars that have more than 9 neighbors.
-lessneighbor=$bdir/less-than-9-stars.txt
-moreneighbor=$bdir/more-than-9-stars.txt
+lessneighbor=$tmpdir/less-than-9-stars.txt
+moreneighbor=$tmpdir/more-than-9-stars.txt
 echo "# Column 1: ra [deg,f64] Right ascension" >> $lessneighbor
 echo "# Column 2: dec [deg,f64] Declination" >> $lessneighbor
 echo "# Column 3: photo-g-mean-mag [mag,f64] Magnitude" >> $lessneighbor
@@ -494,7 +511,7 @@ echo "# Column 3: photo-g-mean-mag [mag,f64] Magnitude" >> 
$lessneighbor
 asttable $circular -cra,dec -c$field | while read r d mag; do
 
    # Make a file for number of neighbourhood.
-   numberneighbor=$bdir/"$r"th-star-neighbor.fits
+   numberneighbor=$tmpdir/"$r"th-star-neighbor.fits
 
    # Find number of neighborhod for each star.
    asttable $query -cra,dec -c$field \
@@ -552,8 +569,8 @@ fi
 #---------------------------
 #
 # If user dos not specify to keep build file
-# with the option of --keepbuild', then the
+# with the option of --keeptmp', then the
 # directory will be removed.
-if [ x"$keepbuild" = x ]; then
-   rm -rf $bdir
+if [ x"$keeptmp" = x ]; then
+   rm -rf $tmpdir
 fi



reply via email to

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