gnuastro-commits
[Top][All Lists]
Advanced

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

[gnuastro-commits] master 6ff43d00 05/39: Zeropoint: script for estimati


From: Mohammad Akhlaghi
Subject: [gnuastro-commits] master 6ff43d00 05/39: Zeropoint: script for estimating the zeropoint of an image
Date: Wed, 19 Apr 2023 12:18:22 -0400 (EDT)

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

    Zeropoint: script for estimating the zeropoint of an image
    
    Until now, the make file for estimating the zeropoint of an image from a
    catalog or image(s) was ready. But if want to bring it in Gnuastro, the
    Makefile should be called inside the script.
    
    With this commit, the configuration file of the Makefile is prepared
    automatically, based on the options of zeropoint's script and finally the
    zeropoint of the image from the catalog or image(s) is estimated.
---
 bin/script/zeropoint.conf |  26 --------
 bin/script/zeropoint.in   | 163 ++++++++++++++++++++++++++++++++++++++--------
 bin/script/zeropoint.mk   |  64 +++++++++---------
 3 files changed, 170 insertions(+), 83 deletions(-)

diff --git a/bin/script/zeropoint.conf b/bin/script/zeropoint.conf
deleted file mode 100644
index 184ea67e..00000000
--- a/bin/script/zeropoint.conf
+++ /dev/null
@@ -1,26 +0,0 @@
-# In the script we should define all the ref* variables from the input
-# options.
-# The rest of the variabels come directly from the options.
-
-
-# Input
-##ref1       = indir/sdss-1.fits
-##ref2       = indir/sdss-2.fits
-##ref1hdu    = 0
-##ref2hdu    = 0
-##ref1zp     = 22.5
-##ref2zp     = 22.5
-ref1       = indir/cat.fits
-ref1hdu    = 1
-refnumber  = 1
-reftype    = img cat
-input      = indir/jplus.fits
-inputhdu   = 1
-
-# Output
-tmpdir = build
-
-# Analysis paramaters For 'aper-arcsec' in the script convet the comma into
-# space (the user should give: --aperarcsec=2,3,3.5,...).
-aper-arcsec = 2 3 3.5 4 4.5 5 6 7 10 20
-magrange =
diff --git a/bin/script/zeropoint.in b/bin/script/zeropoint.in
index fd0c9481..9d172173 100644
--- a/bin/script/zeropoint.in
+++ b/bin/script/zeropoint.in
@@ -46,8 +46,11 @@ refrence=""
 aperarcsec=""
 cataloghdu=""
 refrencezp=""
+racolumn="RA"
 refrencehdu=""
+deccolumn="DEC"
 version=@VERSION@
+magcolumn="MAGNITUDE"
 scriptname=@SCRIPT_NAME@
 
 
@@ -69,25 +72,25 @@ print_help() {
    cat <<EOF
 Usage: $scriptname [OPTIONS] image.fits
 
-Build a catalogue of "good stars" that will be considered for constructing
-an extended and non parametric PSF. Here, "good stars" means that they
-don't have close objects that affect it sourrondings and consequently they
-are not contaminated. The script will construct a catalog of stars from
-reference datasets (Gaia) if the user does not provide another one. In
-addition to this, other parameters like the axis ratio are considered to
-filter the sample and select only proper stars.
+Calculate the Zeropoint of the image based on the refrence images or
+catalog.
 
 $scriptname options:
  Input:
-  -h, --hdu=STR/INT       HDU/Extension name of number of the input file.
-  -c, --catalog           Refrence catalog which based on it zeropoint of
-                          input will be compute.
-  -C, --cataloghdu        HDU/Extension name of number of the catalog.
-  -r, --reference         Rerence images which based on them zeropoint of
-                          input will be compute.
-  -z, --referencezp       Zeropoints of reference images.
-  -R, --referencehdu      HDU/Extension name of number of the refrence files.
-  -a, --aprarcsec         Aperure arcseconds.
+  -h, --hdu=STR/INT            HDU/Extension name of number of the input file.
+  -c, --catalog=STR            Refrence catalog which based on it zeropoint of
+                               input will be compute.
+  -C, --cataloghdu=STR/INT     HDU/Extension name of number of the catalog.
+  -r, --racolumn=STR           Right Ascension (R.A.) column name of the 
reference
+                               catalog.
+  -d, --deccolumn=STR          Declination (Dec) column name of the reference
+                               catalog.
+  -m, --magcolumn=STR          Magnitude column name of the reference catalog.
+  -R, --reference=STR[,STR]    Rerence images which based on them zeropoint of
+                               input will be compute.
+  -z, --referencezp=FLT[,FLT]  Zeropoints of reference images.
+  -H, --referencehdu=STR/INT   HDU/Extension name of number of the refrence 
files.
+  -a, --aperarcsec=FLT[,FLT]   Aperure arcseconds.
 
  Output:
   -o, --output            Output table with the object coordinates.
@@ -250,18 +253,27 @@ do
        -C|--cataloghdu)        cataloghdu="$2";                              
check_v "$1" "$cataloghdu";  shift;shift;;
        -C=*|--cataloghdu=*)    cataloghdu="${1#*=}";                         
check_v "$1" "$cataloghdu";  shift;;
        -C*)                    cataloghdu=$(echo "$1" | sed -e's/-C//');     
check_v "$1" "$cataloghdu";  shift;;
-       -r|--reference)         reference="$2";                               
check_v "$1" "$reference";  shift;shift;;
-       -r=*|--reference=*)     reference="${1#*=}";                          
check_v "$1" "$reference";  shift;;
-       -r*)                    reference=$(echo "$1" | sed -e's/-r//');      
check_v "$1" "$reference";  shift;;
+       -r|--racolumn)          racolumn="$2";                                
check_v "$1" "$racolumn";  shift;shift;;
+       -r=*|--racolumn=*)      racolumn="${1#*=}";                           
check_v "$1" "$racolumn";  shift;;
+       -r*)                    racolumn=$(echo "$1" | sed -e's/-r//');       
check_v "$1" "$racolumn";  shift;;
+       -d|--deccolumn)         deccolumn="$2";                               
check_v "$1" "$deccolumn";  shift;shift;;
+       -d=*|--deccolumn=*)     deccolumn="${1#*=}";                          
check_v "$1" "$deccolumn";  shift;;
+       -d*)                    deccolumn=$(echo "$1" | sed -e's/-d//');      
check_v "$1" "$deccolumn";  shift;;
+       -m|--magcolumn)         magcolumn="$2";                               
check_v "$1" "$magcolumn";  shift;shift;;
+       -m=*|--magcolumn=*)     magcolumn="${1#*=}";                          
check_v "$1" "$magcolumn";  shift;;
+       -m*)                    magcolumn=$(echo "$1" | sed -e's/-m//');      
check_v "$1" "$magcolumn";  shift;;
+       -R|--reference)         reference="$2";                               
check_v "$1" "$reference";  shift;shift;;
+       -R=*|--reference=*)     reference="${1#*=}";                          
check_v "$1" "$reference";  shift;;
+       -R*)                    reference=$(echo "$1" | sed -e's/-R//');      
check_v "$1" "$reference";  shift;;
        -z|--referencezp)       referencezp="$2";                             
check_v "$1" "$referencezp";  shift;shift;;
        -z=*|--referencezp=*)   referencezp="${1#*=}";                        
check_v "$1" "$referencezp";  shift;;
        -z*)                    referencezp=$(echo "$1" | sed -e's/-z//');    
check_v "$1" "$referencezp";  shift;;
-       -R|--referencehdu)      referencehdu="$2";                            
check_v "$1" "$referencehdu";  shift;shift;;
-       -R=*|--referencehdu=*)   referencehdu="${1#*=}";                       
check_v "$1" "$referencehdu";  shift;;
-       -R*)                    referencehdu=$(echo "$1" | sed -e's/-R//');    
check_v "$1" "$referencehdu";  shift;;
-       -a|--aperarcsec)         aperarcsec="$2";                             
check_v "$1" "$aperarcsec";  shift;shift;;
-       -a=*|--referencehdu=*)   aperarcsec="${1#*=}";                        
check_v "$1" "$aperarcsec";  shift;;
-       -a*)                     aperarcsec=$(echo "$1" | sed -e's/-a//');    
check_v "$1" "$aperarcsec";  shift;;
+       -H|--referencehdu)      referencehdu="$2";                            
check_v "$1" "$referencehdu";  shift;shift;;
+       -H=*|--referencehdu=*)  referencehdu="${1#*=}";                       
check_v "$1" "$referencehdu";  shift;;
+       -H*)                    referencehdu=$(echo "$1" | sed -e's/-H//');   
check_v "$1" "$referencehdu";  shift;;
+       -a|--aperarcsec)        aperarcsec="$2";                              
check_v "$1" "$aperarcsec";  shift;shift;;
+       -a=*|--aperarcsec=*)    aperarcsec="${1#*=}";                         
check_v "$1" "$aperarcsec";  shift;;
+       -a*)                    aperarcsec=$(echo "$1" | sed -e's/-a//');     
check_v "$1" "$aperarcsec";  shift;;
 
 
 # Output parameters
@@ -303,7 +315,7 @@ done
 # If an input image is not given at all.
 if [ x"$inputs" = x ]; then
     cat <<EOF
-$scriptname: ERROR: no input FITS image files (outer part of the PSF to unite 
with an inner part). Run with '--help' for more information on how to run
+$scriptname: ERROR: no input FITS image files. Run with '--help' for more 
information on how to run
 EOF
     exit 1
 elif [ ! -f $inputs ]; then
@@ -312,3 +324,102 @@ $scriptname: ERROR: $inputs, no such file or directory
 EOF
     exit 1
 fi
+
+
+
+
+# Define a temporary directory and the final output file
+# ------------------------------------------------------
+#
+# 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.
+basename=$(basename $inputs | sed 's/\.fits/ /' | awk '{print $1}')
+if [ x"$tmpdir" = x ]; then \
+  tmpdir=$(pwd)/"$basename"_zeropoint
+fi
+
+if [ -d "$tmpdir" ]; then
+  junk=1
+else
+  mkdir -p "$tmpdir"
+fi
+
+# Default output catalog file
+if [ x"$output" = x ]; then
+  output="$basename"_zeropoint.fits
+fi
+
+
+
+
+
+# Prepare a configuration file for running the make file
+#-------------------------------------------------------
+#
+# At first the user wants to compute the Zeropoint for input image based on
+# the images or catalog.
+config=$tmpdir/zeropoint.conf
+echo "input = $inputs" > $config
+echo "output =$output" >> $config
+echo "hduinput = $hdu" >> $config
+echo "tmpdir = $tmpdir" >> $config
+# Put the size of the apertures in a variables. The comma should be
+# change with a space.
+aper=$(echo $aperarcsec | sed 's|,| |g')
+echo "aper-arcsec = $aper" >> $config
+if [ x"$catalog" != x ]; then
+
+    # Determine the type of the refence. In this case, if the user give the
+    # catalog the type of the reference is "img cat", because based on the
+    # catlog we want to compute the zeropoint.
+    echo "reftype = cat" >> $config
+    echo "ref1 = $catalog" >> $config
+    echo "hduref1 = $cataloghdu" >> $config
+    echo "refnumber = 1" >> $config
+    echo "ra = $racolumn" >> $config
+    echo "dec = $deccolumn" >> $config
+    echo "mag = $magcolumn" >> $config
+else
+    # Basic configuration
+    echo "reftype = img" >> $config
+
+    # Compute how many references images is used.
+    num=$(echo $reference \
+              | awk 'BEGIN{FS=","}{for(i=1;i<=NF;++i) printf "%s ", i}')
+    echo "refnumber = $num" >> $config
+    for n in $num; do
+        img=$(echo $reference | awk 'BEGIN{FS=","}{printf "%s", $'$n'}')
+        hdu=$(echo $referencehdu | awk 'BEGIN{FS=","}{printf "%s", $'$n'}')
+        zp=$(echo $referencezp | awk 'BEGIN{FS=","}{printf "%s", $'$n'}')
+        echo "ref$n = $img" >> $config
+        echo "hduref$n = $hdu" >> $config
+        echo "zpref$n = $zp" >> $config
+    done
+fi
+
+
+
+
+# Call the Makefile
+make -f zeropoint.mk tmpdir=$tmpdir
+
+
+
+
+# Remove temporary directory
+# --------------------------
+#
+# If user does not specify to keep build file with the option of
+# --keeptmp', then the directory will be removed.
+if [ x"$keeptmp" = x ]; then
+   rm -rf $tmpdir
+fi
diff --git a/bin/script/zeropoint.mk b/bin/script/zeropoint.mk
index 6a32ce68..b882d706 100644
--- a/bin/script/zeropoint.mk
+++ b/bin/script/zeropoint.mk
@@ -1,4 +1,4 @@
-# Creat final PSF for all tiles and all filters.
+#Creat final PSF for all tiles and all filters.
 #
 # Original authors:
 # Copyright (C) 2019-2022 Samane Raji <samaneraji@gmail.com>
@@ -40,7 +40,7 @@ all: final
 .SHELLFLAGS = -ec
 
 # Include configure files.
-include zeropoint.conf
+include $(tmpdir)/zeropoint.conf
 
 
 
@@ -58,12 +58,12 @@ $(tmpdir):; mkdir $@
 # Use Gaia catalog and only keep the objects with good parallax (to
 # confirm that they are stars).
 stars=$(tmpdir)/gaia.fits
-$(stars): $(indir)/$(input) | $(tmpdir)
+$(stars): $(input) | $(tmpdir)
 
 #      Download from Gaia.
        raw=$(subst .fits,-raw.fits,$@)
        astquery gaia --dataset=dr3 \
-                --overlapwith=$(indir)/$(input) \
+                --overlapwith=$(input) \
                 -csource_id -cra -cdec -cparallax \
                 -cphot_g_mean_mag -cparallax_error \
                 -cpmra -cpmdec --output=$$raw
@@ -85,6 +85,32 @@ $(stars): $(indir)/$(input) | $(tmpdir)
 
 
 
+# Conditional for image or catalog reference
+ifeq ($(reftype),img)
+gencat=$(foreach i, $(refnumber), ref$(i))
+
+else
+
+# Initialize 'gencat' to an empty string
+gencat=
+
+# Prepare the catalog for comparing in different apperture.
+cataper=$(foreach a,$(aper-arcsec), \
+          $(tmpdir)/ref1-$(a)-cat.fits)
+$(cataper): $(tmpdir)/ref1-%-cat.fits:
+
+       asttable $(ref1) -c$(ra),$(dec) -c$(mag) \
+                | cat -n \
+                | asttable --output=$@ \
+                      --colmetadata=1,OBJ_ID,int32,"Id of object." \
+                      --colmetadata=2,RA,float64,"Right Assencion." \
+                      --colmetadata=3,DEC,float64,"Declination." \
+                      --colmetadata=4,MAGNITUDE,float32,"Magnitude."
+endif
+
+
+
+
 # Apertures photometry
 # --------------------
 #
@@ -93,12 +119,7 @@ $(stars): $(indir)/$(input) | $(tmpdir)
 # to set the other parameters of each profile to be a fixed circle of
 # radius 5.1 pixels. To calculate the pixel size I have to use the big
 # origin image before cropping
-inputzp=0
-ifeq ($(reftype),img)
-gencat=$(foreach i, $(refnumber), ref$(i))
-else
-gencat=
-endif
+zpinput=0
 aperture=$(foreach i,input $(gencat), \
           $(foreach a,$(aper-arcsec), \
            $(tmpdir)/$(i)-$(a)-cat.fits))
@@ -106,9 +127,9 @@ $(aperture): $(tmpdir)/%-cat.fits: $(stars)
 
 #      Extract the names.
        img=$($(word 1, $(subst -, ,$*)))
-       zp=$($(word 1, $(subst -, ,$*))zp)
+       zp=$(zp$(word 1, $(subst -, ,$*)))
        aperarcsec=$(word 2, $(subst -, ,$*))
-       hdu=$($(word 1, $(subst -, ,$*))hdu)
+       hdu=$(hdu$(word 1, $(subst -, ,$*)))
 
 #      Convert the aperture size (arcsec) to pixels.
        aperpix=$$(astfits $$img --hdu=$$hdu --pixelscale --quiet \
@@ -139,25 +160,6 @@ $(aperture): $(tmpdir)/%-cat.fits: $(stars)
 
 
 
-# Prepare the catalog for comparing in different apperture.
-cataper=$(foreach a,$(aper-arcsec), \
-          $(tmpdir)/ref1-$(a)-cat.fits)
-$(cataper): $(tmpdir)/ref1-%-cat.fits: $(tmpdir)/input-%-cat.fits
-
-       asttable $(ref1) -cRA,DEC -cMAGNITUDE \
-                | cat -n \
-                | asttable --output=$@ \
-                      --colmetadata=1,OBJ_ID,int32,"Id of object." \
-                      --colmetadata=2,RA,float64,"Right Assencion." \
-                      --colmetadata=3,DEC,float64,"Declination." \
-                      --colmetadata=4,MAGNITUDE,float32,"Magnitude."
-
-
-
-
-
-
-
 
 # Calculate magnitude differences
 # -------------------------------



reply via email to

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