gnuastro-commits
[Top][All Lists]
Advanced

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

[gnuastro-commits] master 03bc1e69 22/69: PSF model: using PSF radial pr


From: Mohammad Akhlaghi
Subject: [gnuastro-commits] master 03bc1e69 22/69: PSF model: using PSF radial profile as input for flux factor computation
Date: Wed, 26 Jan 2022 12:39:11 -0500 (EST)

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

    PSF model: using PSF radial profile as input for flux factor computation
    
    Until this commit, when computing the flux factor, only the PSF image was
    provided. As a consequence, each time this script is executed, two radial
    profiles have to be computed: the PSF and the object radial profiles.
    However, in many situations, the PSF would be the same for many different
    calls to this script. So, it would be good to have the possibility of
    passing the radial profile of the PSf directly to the script to avoid
    computing it. In this case, the radial profile has to be computed outside
    of the script.
    
    With this commit, this new feature has been added. Now the script is able
    to use the radial profile of the PSF directly, without having to compute
    it.
---
 bin/script/psf-model-flux-factor.in | 69 ++++++++++++++++++++++++++++++++-----
 doc/gnuastro.texi                   | 18 ++++++++++
 2 files changed, 79 insertions(+), 8 deletions(-)

diff --git a/bin/script/psf-model-flux-factor.in 
b/bin/script/psf-model-flux-factor.in
index 87a096d5..2db419d8 100644
--- a/bin/script/psf-model-flux-factor.in
+++ b/bin/script/psf-model-flux-factor.in
@@ -46,7 +46,10 @@ corewidth=""
 normradii=""
 sigmaclip=""
 stampwidth=""
+psfprofile=""
+psfprofilehdu=1
 normop="median"
+psfprofilecol=""
 version=@VERSION@
 scriptname=@SCRIPT_NAME@
 
@@ -89,8 +92,11 @@ experienced Gnuastro users and developers. For more 
information, please run:
 $scriptname options:
  Input:
   -h, --hdu=STR           HDU/extension of all input FITS files.
-  -p, --psf=STR           PSF fits file.
-  -P, --psfhdu=STR        HDU/extension of all input FITS files.
+  -p, --psf=STR           PSF image fits file.
+  -P, --psfhdu=STR        HDU/extension of the PSF image.
+  -f, --psfprofile=STR    PSF radial profile fits file.
+  -F, --psfprofilehdu=STR HDU/extension of the PSF radial profile.
+  -C, --psfprofilecol=STR,STR  Column names (radius, flux) for PSF radial 
profile.
   -O, --mode=STR          Coordinates mode ('wcs' or 'img').
   -c, --center=FLT,FLT    Center coordinates of the object.
   -W, --stampwidth=INT    Width of the stamp in pixels.
@@ -204,6 +210,15 @@ do
         -P|--psfhdu)         psfhdu="$2";                               
check_v "$1" "$psfhdu";  shift;shift;;
         -P=*|--psfhdu=*)     psfhdu="${1#*=}";                          
check_v "$1" "$psfhdu";  shift;;
         -P*)                 psfhdu=$(echo "$1"  | sed -e's/-P//');     
check_v "$1" "$psfhdu";  shift;;
+        -f|--psfprofile)     psfprofile="$2";                           
check_v "$1" "$psfprofile";  shift;shift;;
+        -f=*|--psfprofile=*) psfprofile="${1#*=}";                      
check_v "$1" "$psfprofile";  shift;;
+        -f*)                 psfprofile=$(echo "$1"  | sed -e's/-f//'); 
check_v "$1" "$psfprofile";  shift;;
+        -F|--psfprofilehdu)     psfprofilehdu="$2";                           
check_v "$1" "$psfprofilehdu";  shift;shift;;
+        -F=*|--psfprofilehdu=*) psfprofilehdu="${1#*=}";                      
check_v "$1" "$psfprofilehdu";  shift;;
+        -F*)                    psfprofilehdu=$(echo "$1"  | sed -e's/-F//'); 
check_v "$1" "$psfprofilehdu";  shift;;
+        -C|--psfprofilecol)     psfprofilecol="$2";                           
check_v "$1" "$psfprofilecol";  shift;shift;;
+        -C=*|--psfprofilecol=*) psfprofilecol="${1#*=}";                      
check_v "$1" "$psfprofilecol";  shift;;
+        -C*)                    psfprofilecol=$(echo "$1"  | sed -e's/-C//'); 
check_v "$1" "$psfprofilecol";  shift;;
         -n|--normradii)      normradii="$2";                            
check_v "$1" "$normradii";  shift;shift;;
         -n=*|--normradii=*)  normradii="${1#*=}";                       
check_v "$1" "$normradii";  shift;;
         -n*)                 normradii=$(echo "$1"  | sed -e's/-n//');  
check_v "$1" "$normradii";  shift;;
@@ -280,13 +295,35 @@ if [ x"$inputs" = x ]; then
     exit 1
 fi
 
-# If a PSF image (--psf) is not given at all.
-if [ x"$psf" = x ]; then
-    echo "$scriptname: no PSF image provided."
-    echo "A PSF image has to be specified with --psf or -p."
+# If a PSF image (--psf) and profile (--psfprofile) are not given at all.
+if [ x"$psf" = x ] && [ x"$psfprofile" = x ]; then
+    echo "$scriptname: no PSF image or profile provided."
+    echo "A PSF image (profile) has to be specified with --psf or -p 
(--psfprofile or -f)."
     exit 1
 fi
 
+# If a PSF image (--psf) and profile (--psfprofile) are given.
+if [ x"$psf" != x ] && [ x"$psfprofile" != x ]; then
+    echo "$scriptname: both PSF image and profile provided."
+    echo "Only one PSF input (image or profile) has to be provided. Image 
(--psf, -p), profile (--psfprofile, -f)."
+    exit 1
+fi
+
+# If PSF profile provided, ensure also column names are provided.
+if [ x"$psfprofile" != x ]; then
+    if [ x"$psfprofilecol" = x ]; then
+        echo "$scriptname: no PSF profile column names provided."
+        echo "Values to '--psfprofilecol' ('-C') should be provided."
+        exit 1
+    else
+        npsfprofilecols=$(echo $psfprofilecol | awk 'BEGIN{FS=","}END{print 
NF}')
+        if [ x$npsfprofilecols != x2 ]; then
+            echo "$scriptname: '--psfprofilecol' (or '-C') only take two 
values, but $npsfprofilecols were given."
+            exit 1
+        fi
+    fi
+fi
+
 # If center coordinates (--center) is not given at all.
 if [ x"$center" = x ]; then
     echo "$scriptname: no center coordinates provided."
@@ -342,6 +379,13 @@ ycoord=$(echo "$center" | awk 'BEGIN{FS=","} {print $2}')
 normradiusmin=$(echo "$normradii" | awk 'BEGIN{FS=","} {print $1}')
 normradiusmax=$(echo "$normradii" | awk 'BEGIN{FS=","} {print $2}')
 
+# If PSF radial profile provided
+if [ x"$psfprofile" != x ]; then
+    psfprofilecolradius=$(echo "$psfprofilecol" | awk 'BEGIN{FS=","} {print 
$1}')
+    psfprofilecolflux=$(echo "$psfprofilecol" | awk 'BEGIN{FS=","} {print $2}')
+fi
+
+
 # With the center coordinates, generate a specific label for the object
 # consisting in its coordinates.
 objectid="$xcoord"_"$ycoord"
@@ -504,8 +548,17 @@ fi
 astscript-radial-profile $cropped_masked --hdu=1 $maximumradius \
                          --measure=$normop --output=$radialprofile $quiet
 
-astscript-radial-profile $psf --hdu=$psfhdu $maximumradius \
-                         --measure=$normop --output=$psfradialprofile $quiet
+# If the user provide a PSF image, compute the radial profile of that PSF.
+# Else, consider the PSF radial profile provided.
+if [ x"$psfprofile" = x ]; then
+    astscript-radial-profile $psf --hdu=$psfhdu $maximumradius $quiet \
+                             --measure=$normop --output=$psfradialprofile
+else
+    asttable $psfprofile \
+             --output=$psfradialprofile $quiet \
+             --column=$psfprofilecolradius,$psfprofilecolflux \
+             --range=$psfprofilecolradius,$normradiusmin,$normradiusmax
+fi
 
 
 
diff --git a/doc/gnuastro.texi b/doc/gnuastro.texi
index b4118a5a..905b903a 100644
--- a/doc/gnuastro.texi
+++ b/doc/gnuastro.texi
@@ -23861,6 +23861,24 @@ The PSF is assumed to be centered in this image.
 @itemx --psfhdu=STR
 The HDU/extension of the PSF image.
 
+@item -f STR
+@itemx --psfprofile=STR
+Filename of the PSF radial profile.
+Instead of using @option{--psf} to provide the PSF image, it is possible to 
provide the radial profile of the PSF directly.
+By doing this, the script does not calculate the radial profile internally and 
the execution is faster.
+This is convenient when the same PSF image is used for many stars.
+In this situation, it is necessary to compute the radial profile only once, 
and then feed the radial profile to this script.
+
+@item -F STR
+@itemx --psfprofilehdu=STR
+The HDU/extension of the PSF radial profile.
+
+@item -C STR,STR
+@itemx --psfprofilecol=STR,STR
+The column names for the radial profile of the PSF.
+It takes two values separated by a comma (@key{,}).
+The values are the column names for the radius and the flux of the radial 
profile.
+
 @item -O STR
 @itemx --mode=STR
 Interpret the center position of the object (values given to 
@option{--center}) in image or WCS coordinates.



reply via email to

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