gnuastro-commits
[Top][All Lists]
Advanced

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

[gnuastro-commits] master 7769e279 07/39: zeropoint: new options for mag


From: Mohammad Akhlaghi
Subject: [gnuastro-commits] master 7769e279 07/39: zeropoint: new options for magnitude and keeping the results are added
Date: Wed, 19 Apr 2023 12:18:22 -0400 (EDT)

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

    zeropoint: new options for magnitude and keeping the results are added
    
    Until now, we did not have any option for considering the magnitude range
    and keeping the zeropoint obtained from the different aperture.
    
    With this commit, a new option for considering the magnitude range is
    added. However, new option for keeping the magnitude versus apperture in
    different extension.
---
 bin/script/zeropoint.in | 83 +++++++++++++++++++++++++++++++++++++------------
 bin/script/zeropoint.mk | 28 ++++++++++++++---
 2 files changed, 86 insertions(+), 25 deletions(-)

diff --git a/bin/script/zeropoint.in b/bin/script/zeropoint.in
index 425fb396..f52b76ac 100644
--- a/bin/script/zeropoint.in
+++ b/bin/script/zeropoint.in
@@ -42,6 +42,7 @@ output=""
 tmpdir=""
 catalog=""
 keeptmp=""
+keepzpap=""
 refrence=""
 aperarcsec=""
 cataloghdu=""
@@ -49,7 +50,8 @@ refrencezp=""
 racolumn="RA"
 refrencehdu=""
 deccolumn="DEC"
-version=@VERSION@
+version=@VERSION@magmg
+magnituderange=""
 magcolumn="MAGNITUDE"
 scriptname=@SCRIPT_NAME@
 
@@ -86,11 +88,13 @@ $scriptname options:
   -d, --deccolumn=STR          Declination (Dec) column name of the reference
                                catalog.
   -m, --magcolumn=STR          Magnitude column name of the reference catalog.
+  -M, --magnituderange=FLT,FLT Range of the magnitude.
   -R, --reference=STR[,STR]    Rerence image(s) 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.
+  -K, --keepzpap               Keep zeropoint of each aperture in different 
extension.
 
  Output:
   -o, --output            Output with zeropoint estimation and best aperture.
@@ -244,24 +248,28 @@ while [ $# -gt 0 ]
 do
    case "$1" in
    # Input parameters.
-       -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;;
-       -c|--catalog)           catalog="$2";                                 
check_v "$1" "$catalog";  shift;shift;;
-       -c=*|--catalog=*)       catalog="${1#*=}";                            
check_v "$1" "$catalog";  shift;;
-       -c*)                    catalog=$(echo "$1" | sed -e's/-c//');        
check_v "$1" "$catalog";  shift;;
-       -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|--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;;
+       -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;;
+       -c|--catalog)            catalog="$2";                                 
check_v "$1" "$catalog";  shift;shift;;
+       -c=*|--catalog=*)        catalog="${1#*=}";                            
check_v "$1" "$catalog";  shift;;
+       -c*)                     catalog=$(echo "$1" | sed -e's/-c//');        
check_v "$1" "$catalog";  shift;;
+       -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|--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;;
+
+       -M|--magnituderange)     magnituderange="$2";                          
check_v "$1" "$magnituderange";  shift;shift;;
+       -M=*|--magnituderange=*) magnituderange="${1#*=}";                     
check_v "$1" "$magnituderange";  shift;;
+       -M*)                     magnituderange=$(echo "$1" | sed -e's/-M//'); 
check_v "$1" "$magnituderange";  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;;
@@ -274,7 +282,8 @@ do
        -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;;
-
+       -K|--keepzpap)          keepzpap=1; shift;;
+       -K*|--keepzpap=*)       on_off_option_error --keepzpap -K;;
 
 # Output parameters
        -k|--keeptmp)           keeptmp=1; shift;;
@@ -325,6 +334,17 @@ EOF
     exit 1
 fi
 
+# If the brighter and fainter range of magnitude are not given at all.
+if [ x$magnituderange != x ]; then
+    nmagrange=$(echo $magnituderange | awk 'BEGIN{FS=","}END{print NF}')
+    if [ x$nmagrange != x2 ]; then
+        cat<<EOF
+$scriptname: ERROR: '--magnituderange' (or '-m') only take two values, but 
$nmagrange were given
+EOF
+        exit 1
+    fi
+fi
+
 
 
 
@@ -372,6 +392,14 @@ echo "input = $inputs" > $config
 echo "output =$output" >> $config
 echo "hduinput = $hdu" >> $config
 echo "tmpdir = $tmpdir" >> $config
+
+# Obtain the magnitude range from the command line arguments.
+if [ x$magnituderange = x ]; then
+    echo "magrange = " >> $config
+else
+    echo "magrange = $magnituderange" >> $config
+fi
+
 # Put the size of the apertures in a variables. The comma should be
 # change with a space.
 aper=$(echo $aperarcsec | sed 's|,| |g')
@@ -409,6 +437,21 @@ fi
 
 
 
+# Keep the zeropoint of different appertures in different extension.
+# ------------------------------------------------------------------
+#
+# If user specify to keep the zeropoint of the different appeertures it
+# will be saved in the different extension of the output.
+if [ x"$keepzpap" = x ]; then
+    echo "zeropointap =    " >> $config
+else
+    echo "zeropointap = keep" >> $config
+fi
+
+
+
+
+
 # Call the Makefile
 make -f zeropoint.mk tmpdir=$tmpdir
 
diff --git a/bin/script/zeropoint.mk b/bin/script/zeropoint.mk
index b882d706..0fda8d4f 100644
--- a/bin/script/zeropoint.mk
+++ b/bin/script/zeropoint.mk
@@ -5,7 +5,7 @@
 #
 # Contributers:
 # Copyright (C) 2019-2022 Mohammad Akhlaghi <mohammad@akhlaghi.org>
-# Copyright (C) 2019-2022 Zahra sharbaf <ahra.sharbaf2@gmail.com>
+# Copyright (C) 2019-2022 Zahra sharbaf <zahra.sharbaf2@gmail.com>
 # Copyright (C) 2022 Sepideh Eskandarlou <sepideh.eskandarlou@gmail.com>
 #
 # This Makefile is free software: you can redistribute it and/or modify
@@ -241,17 +241,35 @@ $(aperzeropoint): $(tmpdir)/zeropoint-%.txt: \
 #
 # Using the standard deviation of the zeropoints for each aperture,
 # select the one with the least scatter.
-zeropoint=$(tmpdir)/zeropoint.txt
+zeropoint=$(tmpdir)/zeropoint.fits
 $(zeropoint): $(aperzeropoint)
-       zp=$(subst .txt,-tmp.txt,$@)
+       zp=$(subst .fits,-tmp.txt,$@)
        echo "# Column 1: APERTURE  [arcsec,f32,]" > $$zp
        echo "# Column 2: ZEROPOINT [mag,f32,]"  >> $$zp
        echo "# Column 3: ZPSTD     [mag,f32,]"  >> $$zp
        for a in $(aper-arcsec); do
          cat $(tmpdir)/zeropoint-$$a.txt        >> $$zp
        done
-       asttable $$zp --sort=ZPSTD --head=1 \
-                --column=APERTURE,ZEROPOINT >$@
+       asttable $$zp --output=$@.fits
+       bestzpaper=$$(asttable $$zp --sort=ZPSTD --head=1 \
+                              --column=APERTURE,ZEROPOINT)
+
+       astfits $@.fits --write=BESTAPZE,"$$bestzpaper","Beat aperture and 
zeropoitn."
+
+       if [ x"$(zeropointap)" = x ]; then
+          mv $@.fits $@
+       else
+         counter=1
+         for i in $(aper-arcsec); do
+           counter=$$((counter+1))
+           astfits $(tmpdir)/zeropoint-$$i-merged.fits --copy=1 -o$@.fits
+           astfits $@.fits -h$$counter --update=EXTNAME,APER-$$i
+         done
+         mv $@.fits $@
+       fi
+
+#      Clean up.
+       rm $$zp
 
 
 



reply via email to

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