gnuastro-commits
[Top][All Lists]
Advanced

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

[gnuastro-commits] master bc6ab04b: PSF scripts: renamed all scripts, tu


From: Mohammad Akhlaghi
Subject: [gnuastro-commits] master bc6ab04b: PSF scripts: renamed all scripts, tutorial updated until subtraction
Date: Sun, 13 Mar 2022 20:29:59 -0400 (EDT)

branch: master
commit bc6ab04b9445943cccc587cf0710eb5c3945e409
Author: Mohammad Akhlaghi <mohammad@akhlaghi.org>
Commit: Mohammad Akhlaghi <mohammad@akhlaghi.org>

    PSF scripts: renamed all scripts, tutorial updated until subtraction
    
    Until now, the names of the PSF scripts contained a '-model-' or '-create-'
    element within them. Also, some of the names were too long, making them
    hard to use in scripts (that have a certain line length limit).
    
    With this commit, those fixed strings have been removed from their names,
    and generally, I have tried to make their names more compact. Here are the
    "old --> new" names:
    
       astscript-psf-create-junction       --> astscript-psf-unite
       astscript-psf-create-make-stamp     --> astscript-psf-stamp
       astscript-psf-model-scattered-light --> astscript-psf-subtract
       astscript-psf-model-flux-factor     --> astscript-psf-scale-factor
       astscript-psf-create-select-stars   --> astscript-psf-select-stars
    
    The tutorial has also been reviewed and edited until the middle of the
    subtraction phase. Furthermore, the following changes were also made:
    
    astscript-fits-view:
      - New '--ds9extra' option added to allow adding any further DS9
        command-line option to the running command. This was used in the
        tutorial.
    
    astscript-scale-factor:
      - The script now uses a division on the image to find the necessary
        scaling factor from all the used pixels, not the radial profile (which
        forces the scaling factor over a circle). As a result, the following
        options have been removed from this script: '--rmax', '--psfprofile',
        '--psfprofilehdu', '--normop', '--psfprofilecol'.
    
    astscript-psf-subtract:
      - Subtraction is always the logical step to do after scaling the PSF to
        each star and placing it in the image. Furthermore, before scaling the
        PSF to the next brightest star, it is necessary to subtract the brigher
        star (unlike the way the tutorial is currently designed). Since
        subtraction is always necessary to help simplify the usage, the script
        actually subtracts the PSF also. In case the user wants the scaled PSF
        models (scatter-light field), they can simply subtract the original
        image from the PSF subtracted one.
      - '--scale' is the new name for '--fluxfactor'. This follows the new name
        for the 'astscript-psf-scale-factor'.
      - All the error messages now use 'cat <<EOF' instead of 'echo'. This is
        necessay because the error message should be a single line. It can't be
        two lines (when run in parallel, other things will be printed in the
        middle, and its hard to interpret which one is for which). Also, a long
        "echo" is inconvenient in the script.
    
    astscript-psf-unite:
      - '--inner' is the new name for the old '--core'. This change was made
        because "core" usually means center. So, when more the two components
        are necessary for the PSF, '--core' could be confusing. As a result,
        the '--corehdu' option was also renamed to '--innerhdu'.
      - '--scale' is the new name for '--fluxfactor'. This follows the new name
        for the 'astscript-psf-scale-factor'.
      - Error messages now use 'cat <<EOF' (see the last point of
        'astscript-psf-subtract').
      - The last three 'astarithmetic' commands were merged into a single (and
        much more simple) command.
    
    bootstrap:
      - While doing the renamings, I needed to bootstrap Gnuastro and noticed
        that Gnulib has updated this script, so its new version is now in
        Gnuastro also.
    
    Webpage:
      - Working on this commit took a little long, in the meantime, I also
        added a notice for Google Summer of Code in the webpage which is being
        committed here also.
    
    Since the scripts have been renamed, to avoid confusion with the old
    scripts that may remain in your installation directory, before installing
    this version of Gnuastro, first remove all the 'astscript-*' files in your
    install directory (assuming its the default '/usr/local/bin/'):
    
        rm /usr/local/bin/astscript-*
---
 bin/script/Makefile.am                             |  42 +-
 bin/script/fits-view.in                            |  17 +-
 ...sf-model-flux-factor.in => psf-scale-factor.in} | 192 ++-------
 ...-create-select-stars.in => psf-select-stars.in} |   0
 .../{psf-create-make-stamp.in => psf-stamp.in}     |   0
 ...sf-model-scattered-light.in => psf-subtract.in} |  65 +--
 .../{psf-create-junction.in => psf-unite.in}       | 167 ++++----
 bootstrap                                          | 244 +++++------
 doc/gnuastro.en.html                               |  12 +-
 doc/gnuastro.texi                                  | 450 +++++++++++----------
 tests/Makefile.am                                  |  25 +-
 ...sf-model-flux-factor.sh => psf-scale-factor.sh} |   2 +-
 ...-create-select-stars.sh => psf-select-stars.sh} |   2 +-
 .../{psf-create-make-stamp.sh => psf-stamp.sh}     |   2 +-
 ...sf-model-scattered-light.sh => psf-subtract.sh} |   4 +-
 .../{psf-create-junction.sh => psf-unite.sh}       |   6 +-
 16 files changed, 568 insertions(+), 662 deletions(-)

diff --git a/bin/script/Makefile.am b/bin/script/Makefile.am
index 86ff2c61..b46760dc 100644
--- a/bin/script/Makefile.am
+++ b/bin/script/Makefile.am
@@ -37,25 +37,25 @@ astscript-fits-view.desktop: $(srcdir)/fits-view.desktop.in 
Makefile
 ## with the tarball ('EXTRA_DIST') and output files (to be cleaned with
 ## 'make clean').
 bin_SCRIPTS = astscript-fits-view \
+              astscript-psf-unite \
+              astscript-psf-stamp \
               astscript-ds9-region \
+              astscript-psf-subtract \
               astscript-sort-by-night \
               astscript-radial-profile \
-              astscript-psf-create-junction \
-              astscript-psf-create-make-stamp \
-              astscript-psf-model-flux-factor \
-              astscript-psf-create-select-stars \
-              astscript-psf-model-scattered-light
+              astscript-psf-scale-factor \
+              astscript-psf-select-stars
 
 EXTRA_DIST = fits-view.in \
+             psf-unite.in \
+             psf-stamp.in \
              ds9-region.in \
+             psf-subtract.in \
              sort-by-night.in \
              radial-profile.in \
-             fits-view.desktop.in \
-             psf-create-junction.in \
-             psf-create-make-stamp.in \
-             psf-model-flux-factor.in \
-             psf-create-select-stars.in \
-             psf-model-scattered-light.in
+             psf-select-stars.in \
+             psf-scale-factor.in \
+             fits-view.desktop.in
 
 CLEANFILES = $(bin_SCRIPTS) \
              astscript-fits-view.desktop
@@ -89,22 +89,22 @@ astscript-sort-by-night: sort-by-night.in Makefile
        $(do_subst) < $(srcdir)/sort-by-night.in > $@
        chmod +x $@
 
-astscript-psf-create-junction: psf-create-junction.in Makefile
-       $(do_subst) < $(srcdir)/psf-create-junction.in > $@
+astscript-psf-unite: psf-unite.in Makefile
+       $(do_subst) < $(srcdir)/psf-unite.in > $@
        chmod +x $@
 
-astscript-psf-create-make-stamp: psf-create-make-stamp.in Makefile
-       $(do_subst) < $(srcdir)/psf-create-make-stamp.in > $@
+astscript-psf-stamp: psf-stamp.in Makefile
+       $(do_subst) < $(srcdir)/psf-stamp.in > $@
        chmod +x $@
 
-astscript-psf-model-flux-factor: psf-model-flux-factor.in Makefile
-       $(do_subst) < $(srcdir)/psf-model-flux-factor.in > $@
+astscript-psf-scale-factor: psf-scale-factor.in Makefile
+       $(do_subst) < $(srcdir)/psf-scale-factor.in > $@
        chmod +x $@
 
-astscript-psf-create-select-stars: psf-create-select-stars.in Makefile
-       $(do_subst) < $(srcdir)/psf-create-select-stars.in > $@
+astscript-psf-select-stars: psf-select-stars.in Makefile
+       $(do_subst) < $(srcdir)/psf-select-stars.in > $@
        chmod +x $@
 
-astscript-psf-model-scattered-light: psf-model-scattered-light.in Makefile
-       $(do_subst) < $(srcdir)/psf-model-scattered-light.in > $@
+astscript-psf-subtract: psf-subtract.in Makefile
+       $(do_subst) < $(srcdir)/psf-subtract.in > $@
        chmod +x $@
diff --git a/bin/script/fits-view.in b/bin/script/fits-view.in
index 4139d91a..5bf58bab 100755
--- a/bin/script/fits-view.in
+++ b/bin/script/fits-view.in
@@ -41,6 +41,7 @@ hdu=""
 quiet=0
 prefix=""
 ds9scale=""
+ds9extra=""
 ds9geometry=""
 version=@VERSION@
 scriptname=@SCRIPT_NAME@
@@ -89,6 +90,7 @@ $scriptname options:
                           for 4K (1800x3000). If not given, the script will
                           attempt to find your screen resolution and find a
                           good match, otherwise, use the default size.
+  -e, --ds9extra=STR      Extra options to pass to DS9 after default ones.
   -s, --ds9scale=STR      Custom value to '-scale' option in DS9.
   -p, --prefix=STR        Directory containing DS9 or TOPCAT executables.
 
@@ -193,6 +195,9 @@ do
         -s|--ds9scale)        ds9scale="$2";                       check_v 
"$1" "$ds9scale"; shift;shift;;
         -s=*|--ds9scale=*)    ds9scale="${1#*=}";                  check_v 
"$1" "$ds9scale"; shift;;
         -s*)                  ds9scale=$(echo "$1"  | sed -e's/-s//');  
check_v "$1" "$ds9scale"; shift;;
+        -e|--ds9extra)        ds9extratmp="$2";                       check_v 
"$1" "$ds9extratmp"; shift;shift;;
+        -e=*|--ds9extra=*)    ds9extratmp="${1#*=}";                  check_v 
"$1" "$ds9extratmp"; shift;;
+        -e*)                  ds9extratmp=$(echo "$1"  | sed -e's/-s//');  
check_v "$1" "$ds9extratmp"; shift;;
         -p|--prefix)          prefix="$2";                         check_v 
"$1" "$prefix"; shift;shift;;
         -p=*|--prefix=*)      prefix="${1#*=}";                    check_v 
"$1" "$prefix"; shift;;
         -p*)                  prefix=$(echo "$1"  | sed -e's/-p//');  check_v 
"$1" "$prefix"; shift;;
@@ -214,6 +219,13 @@ do
         # file name.
         *) inputs="$inputs $1"; shift;;
     esac
+
+    # In case '--ds9extra' was given, add it to any previous values. The
+    # reason is that this option can often become very long and it may be
+    # easier to break it into multiple calls.
+    if [ x"$ds9extratmp" != x ]; then
+        ds9extra="$ds9extra $ds9extratmp"
+    fi
 done
 
 
@@ -328,7 +340,7 @@ else
                                  -zoom to fit -wcs degrees -cmap sls \
                                 -match frame image -match frame colorbar \
                                 -frame lock image -colorbar lock yes \
-                                 -lock slice image"
+                                 -lock slice image $ds9extra"
             else
 
                # 3D multi-extension file: The "Cube" window will slide
@@ -341,7 +353,8 @@ else
                execom="$ds9exec $ds9scaleopt $ds9geoopt -wcs degrees \
                                  -multiframe $inwithhdu -lock slice image \
                                  -lock frame image -zoom to fit -cmap sls \
-                                 -match frame colorbar -colorbar lock yes"
+                                 -match frame colorbar -colorbar lock yes \
+                                 $ds9extra"
             fi
 
        # When input was table.
diff --git a/bin/script/psf-model-flux-factor.in 
b/bin/script/psf-scale-factor.in
similarity index 71%
rename from bin/script/psf-model-flux-factor.in
rename to bin/script/psf-scale-factor.in
index 0dfe966e..647e8ae1 100644
--- a/bin/script/psf-model-flux-factor.in
+++ b/bin/script/psf-scale-factor.in
@@ -1,13 +1,15 @@
 #!/bin/sh
 
-# Obtain the factor by which it is necessary to multiply a given PSF image
-# in order to match in flux a particular star within a given ring of radii.
-# Run with `--help', or see description under `print_help' (below) for
-# more.
+# Obtain the scale factor by which it is necessary to multiply a given PSF
+# image in order to match it to a particular star within a given ring of
+# radii.  Run with `--help', or see description under `print_help' (below)
+# for more.
 #
 # Original author:
 #   Raul Infante-Sainz <infantesainz@gmail.com>
-# Copyright (C) 2021, Free Software Foundation, Inc.
+# Contributing author(s):
+#   Mohammad Akhlaghi <mohammad@akhlaghi.org>
+# Copyright (C) 2021-2022 Free Software Foundation, Inc.
 #
 # Gnuastro is free software: you can redistribute it and/or modify it under
 # the terms of the GNU General Public License as published by the Free
@@ -36,7 +38,6 @@ export LANG=C
 # Default option values (can be changed with options on the command-line).
 hdu=1
 psf=""
-rmax=""
 quiet=""
 psfhdu=1
 center=""
@@ -44,13 +45,9 @@ keeptmp=0
 tmpdir=""
 segment=""
 normradii=""
-sigmaclip=""
 stampwidth=""
-psfprofile=""
-psfprofilehdu=1
 corewidth="3,3"
-normop="median"
-psfprofilecol=""
+sigmaclip="3,0.1"
 version=@VERSION@
 scriptname=@SCRIPT_NAME@
 
@@ -73,9 +70,9 @@ This script is part of GNU Astronomy Utilities $version.
 
 This script will consider a center position and then compute the factor by
 which it is necessary to multiply the specified PSF image in order to match
-in flux with the object at the center (within a ring radii). The main idea
-is to have the necessary factor that will be used to allocate the PSF with
-the proper flux value for constructing the scattered light field.
+it with the object at the center (within a ring radii). The main idea is to
+have the necessary factor that will be used to allocate the PSF with the
+proper flux value for constructing the scattered light field.
 
 For more information, please run any of the following commands. In
 particular the first contains a very comprehensive explanation of this
@@ -95,19 +92,13 @@ $scriptname options:
   -h, --hdu=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.
   -n, --normradii=INT,INT Minimum and maximum radii (in pixels)
-                          for computing the flux factor value.
+                          for computing the scaling factor value.
   -w, --corewidth=INT     Area width of the central object in pixels for 
unmasking.
   -S, --segment=STR       Output of Segment (with OBJECTS and CLUMPS).
-  -R, --rmax=FLT          Maximum radius for the radial profile (in pixels).
-  -N, --normop=STR        Operator for computing the normalization value
-                          (mean, sigclip-mean, etc.).
   -s, --sigmaclip=FLT,FLT Sigma-clip multiple and tolerance.
 
  Output:
@@ -210,15 +201,6 @@ 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;;
@@ -237,17 +219,10 @@ do
         -c|--center)         center="$2";                               
check_v "$1" "$center";  shift;shift;;
         -c=*|--center=*)     center="${1#*=}";                          
check_v "$1" "$center";  shift;;
         -c*)                 center=$(echo "$1"  | sed -e's/-c//');     
check_v "$1" "$center";  shift;;
-        -N|--normop)         normop="$2";                               
check_v "$1" "$normop";  shift;shift;;
-        -N=*|--normop=*)     normop="${1#*=}";                          
check_v "$1" "$normop";  shift;;
-        -N*)                 normop=$(echo "$1"  | sed -e's/-N//');     
check_v "$1" "$normop";  shift;;
-        -R|--rmax)           rmax="$2";                                 
check_v "$1" "$rmax";  shift;shift;;
-        -R=*|--rmax=*)       rmax="${1#*=}";                            
check_v "$1" "$rmax";  shift;;
-        -R*)                 rmax=$(echo "$1"  | sed -e's/-R//');       
check_v "$1" "$rmax";  shift;;
         -s|--sigmaclip)      sigmaclip="$2";                            
check_v "$1" "$sigmaclip";  shift;shift;;
         -s=*|--sigmaclip=*)  sigmaclip="${1#*=}";                       
check_v "$1" "$sigmaclip";  shift;;
         -s*)                 sigmaclip=$(echo "$1"  | sed -e's/-s//');  
check_v "$1" "$sigmaclip";  shift;;
 
-
         # Output parameters
         -k|--keeptmp)     keeptmp=1; shift;;
         -k*|--keeptmp=*)  on_off_option_error --keeptmp -k;;
@@ -296,41 +271,14 @@ elif [ ! -f $inputs ]; then
     exit 1
 fi
 
-# If a PSF image (--psf) and profile (--psfprofile) are not given at all.
-if [ x"$psf" = x ] && [ x"$psfprofile" = x ]; then
-    cat <<EOF
-$scriptname: no PSF image or profile provided. A PSF image (profile) has to be 
specified with --psf or -p (--psfprofile or -f).
-EOF
-    exit 1
-fi
-
-# If a PSF image (--psf) and profile (--psfprofile) are given.
-if [ x"$psf" != x ] && [ x"$psfprofile" != x ]; then
+# If a PSF image (--psf) is not given.
+if [ x"$psf" = x ]; then
     cat <<EOF
-$scriptname: both PSF image and profile provided. Only one PSF input (image or 
profile) has to be provided. Image (--psf, -p), profile (--psfprofile, -f).
+$scriptname: no PSF image or profile provided. A PSF image (profile) has to be 
specified with '--psf' (or '-p').
 EOF
     exit 1
 fi
 
-# If PSF profile provided, ensure also column names are provided.
-if [ x"$psfprofile" != x ]; then
-    if [ x"$psfprofilecol" = x ]; then
-        cat <<EOF
-$scriptname: no PSF profile column names provided. Values to '--psfprofilecol' 
('-C') should be provided.
-EOF
-        exit 1
-    else
-        npsfprofilecols=$(echo $psfprofilecol \
-                              | awk 'BEGIN{FS=","}END{print NF}')
-        if [ x$npsfprofilecols != x2 ]; then
-            cat <<EOF
-$scriptname: '--psfprofilecol' (or '-C') only take two values, but 
$npsfprofilecols were given
-EOF
-            exit 1
-        fi
-    fi
-fi
-
 # If center coordinates (--center) is not given at all.
 if [ x"$center" = x ]; then
     cat <<EOF
@@ -394,13 +342,6 @@ 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"
@@ -409,8 +350,8 @@ objectid="$xcoord"_"$ycoord"
 
 
 
-# Define a temporary directory and thefinal output file
-# -----------------------------------------------------
+# 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
@@ -425,7 +366,7 @@ objectid="$xcoord"_"$ycoord"
 # mode will be generated.
 bname_prefix=$(basename $inputs | sed 's/\.fits/ /' | awk '{print $1}')
 if [ x$tmpdir = x ]; then \
-    tmpdir=$(pwd)/"$bname_prefix"_psfmodelfluxfactor
+    tmpdir=$(pwd)/"$bname_prefix"_psfmodelscalefactor
 fi
 
 if [ -d $tmpdir ]; then
@@ -570,7 +511,7 @@ if [ x"$segment" != x ]; then
                                        \
                 c o $olab ne 0 where c $clab eq -1 where 0 gt set-cmask \
                 o o $olab eq 0 where set-omask \
-                i omask cmask or nan where
+                i omask cmask or nan where $quiet
 else
   cropped_masked=$cropped
 fi
@@ -579,86 +520,41 @@ fi
 
 
 
-# Compute the radial profiles
-# ---------------------------
-#
-# Generate the radial profile of the stamp and the PSF, since it has been
-# already centered on the center of the object, it is not necessary to give
-# the center coordinates. If the user specifies a maximum radius, use it.
-# Otherwise, compute the radial profile up to the outer part of the ring
-# for the normalization (to not wast CPU time).
-radialprofile=$tmpdir/rprofile-$objectid.fits
-psfradialprofile=$tmpdir/rprofile-psf-$objectid.fits
-if [ x"$rmax" != x ]; then maximumradius="--rmax=$rmax"
-else                       maximumradius="--rmax=$normradiusmax";
-fi
-astscript-radial-profile $cropped_masked --hdu=1 \
-                         $maximumradius --measure=$normop \
-                         --tmpdir $tmpdir --keeptmp \
-                         --output=$radialprofile $quiet
-
-# If the user provide a PSF image, compute the radial profile of that PSF.
-# Otherwise, consider the PSF radial profile provided.
-if [ x"$psfprofile" = x ]; then
-    astscript-radial-profile $psf --hdu=$psfhdu $maximumradius \
-                             --measure=$normop \
-                             --tmpdir $tmpdir --keeptmp \
-                             --output=$psfradialprofile $quiet
-else
-    asttable $psfprofile \
-             --output=$psfradialprofile $quiet \
-             --column=$psfprofilecolradius,$psfprofilecolflux \
-             --range=$psfprofilecolradius,$normradiusmin,$normradiusmax
-fi
-
-
-
-
-
-# Select the same rows in the matching radii
-# ------------------------------------------
-#
-# To compute the flux factor, it is necessary to consider the same radii
-# values. Here, the radii values are extracted from the radial profiles of
-# the input object and the provided PSF image. After that, the two
-# different tables are concatenated into a single one.
-radialprofile_ring=$tmpdir/rprofile-ring-$objectid.fits
-asttable $radialprofile --range=1,$normradiusmin,$normradiusmax \
-         --output=$radialprofile_ring $quiet
+# Crop the PSF image with the same size.
+psfcropped=$tmpdir/cropped-psf-$objectid.fits
+psfxcenter=$(astfits $psf -h$psfhdu --keyvalue=NAXIS1 -q \
+                 | awk '{print $1/2+0.5}')
+psfycenter=$(astfits $psf -h$psfhdu --keyvalue=NAXIS2 -q \
+                 | awk '{print $1/2+0.5}')
+astcrop $psf --hdu=$psfhdu --mode=img \
+        --center=$psfxcenter,$psfycenter \
+        --width=$stampwidth --output=$psfcropped $quiet
 
-psfradialprofile_ring=$tmpdir/rprofile-psf-ring-$objectid.fits
-asttable $psfradialprofile --range=1,$normradiusmin,$normradiusmax \
-         --output=$psfradialprofile_ring $quiet
 
-# Concatenated table. This table has the rows corresponding to the ring
-# over which the flux radius is computed, and 3 columns: radius, STAR
-# radial profile, PSF radial profile.
-radialprofile_ring_both=$tmpdir/rprofile-ring-both-$objectid.fits
-asttable $radialprofile_ring --output=$radialprofile_ring_both $quiet \
-         --catcolumnfile=$psfradialprofile_ring --catcolumns=2
 
 
 
+# Build a radial profile image. It will be used to only select pixels
+# within the requested radial range.
+radcenter=$(echo $stampwidth | awk '{print $1/2+0.5}')
+radradius=$(echo $stampwidth | awk '{print $1+2}')
+radcropped=$tmpdir/cropped-radial-$objectid.fits
+echo "1 $radcenter $radcenter 7 $radradius 0 0 1 1 1" \
+    | astmkprof --background=$psfcropped --clearcanvas \
+                --oversample=1 --output=$radcropped $quiet
 
 
-# Compute the flux factor
-# -----------------------
-#
-# Once a table with the 3 columns has been generated, it is possible to
-# make the ratio of the two radial profiles (STAR and PSF) columns.
-radialprofile_ratio=$tmpdir/rprofile-ratio-$objectid.fits
-asttable $radialprofile_ring_both $quiet \
-         --column=1,2,3 \
-         --column='arith $2 $3 /' \
-         --output=$radialprofile_ratio
 
-# Obtain the flux factor by computing the averaged value of the ratio.
-# Print the flux factor on the screen and save it into the output file.
-fluxfactor=$(aststatistics $radialprofile_ratio --column=4 --$normop --quiet)
 
-# Print the flux factor.
-echo $fluxfactor
 
+# Find the multiplication factor
+multipimg=$tmpdir/for-factor-$objectid.fits
+astarithmetic $cropped -h1 set-i \
+              $psfcropped -h1 set-p \
+              $radcropped -h1 set-r \
+              r $normradiusmin lt r $normradiusmax ge or set-m \
+              i p / m nan where -o$multipimg $quiet
+aststatistics $multipimg --sclipparams=$sigmaclip  --sigclip-median
 
 
 
diff --git a/bin/script/psf-create-select-stars.in 
b/bin/script/psf-select-stars.in
similarity index 100%
rename from bin/script/psf-create-select-stars.in
rename to bin/script/psf-select-stars.in
diff --git a/bin/script/psf-create-make-stamp.in b/bin/script/psf-stamp.in
similarity index 100%
rename from bin/script/psf-create-make-stamp.in
rename to bin/script/psf-stamp.in
diff --git a/bin/script/psf-model-scattered-light.in 
b/bin/script/psf-subtract.in
similarity index 89%
rename from bin/script/psf-model-scattered-light.in
rename to bin/script/psf-subtract.in
index 31d22beb..48e545b0 100644
--- a/bin/script/psf-model-scattered-light.in
+++ b/bin/script/psf-subtract.in
@@ -1,9 +1,7 @@
 #!/bin/sh
 
 # Situate a PSF stamp into a given position with the same output image size
-# than the original image. This script is useful to generate a scattered
-# light field image. Run with `--help', or see description under
-# `print_help' (below) for more.
+# than the original image and subtract it.
 #
 # Original author:
 #   Raul Infante-Sainz <infantesainz@gmail.com>
@@ -41,11 +39,11 @@ hdu=1
 psf=""
 psfhdu=1
 quiet=""
+scale=""
 center=""
 keeptmp=0
 output=""
 tmpdir=""
-fluxfactor=""
 version=@VERSION@
 scriptname=@SCRIPT_NAME@
 
@@ -66,9 +64,8 @@ Usage: $scriptname [OPTION] FITS-files
 
 This script is part of GNU Astronomy Utilities $version.
 
-This script will consider a center position to situate the PSF image into a
-new empty image. It is intendeed to generate several images that can be
-added to construct the scattered light field.
+This script will place the given PSF image into a certain central position
+with the image and subtract it.
 
 For more information, please run any of the following commands. In
 particular the first contains a very comprehensive explanation of this
@@ -90,7 +87,7 @@ $scriptname options:
   -P, --psfhdu=STR        HDU/extension of the PSF image.
   -O, --mode=STR          Coordinates mode ('wcs' or 'img').
   -c, --center=FLT,FLT    Center coordinates of the object.
-  -f, --fluxfactor=FLT    Factor by which the PSF is multiplied.
+  -s, --scale=FLT         Factor by which the PSF is multiplied.
 
  Output:
   -o, --output            Output table with the radial profile.
@@ -199,9 +196,9 @@ do
         -c|--center)         center="$2";                               
check_v "$1" "$center";  shift;shift;;
         -c=*|--center=*)     center="${1#*=}";                          
check_v "$1" "$center";  shift;;
         -c*)                 center=$(echo "$1"  | sed -e's/-c//');     
check_v "$1" "$center";  shift;;
-        -f|--fluxfactor)     fluxfactor="$2";                           
check_v "$1" "$fluxfactor";  shift;shift;;
-        -f=*|--fluxfactor=*) fluxfactor="${1#*=}";                      
check_v "$1" "$fluxfactor";  shift;;
-        -f*)                 fluxfactor=$(echo "$1"  | sed -e's/-f//'); 
check_v "$1" "$fluxfactor";  shift;;
+        -s|--scale)          scale="$2";                                
check_v "$1" "$scale";  shift;shift;;
+        -s=*|--scale=*)      scale="${1#*=}";                           
check_v "$1" "$scale";  shift;;
+        -s*)                 scale=$(echo "$1"  | sed -e's/-f//');      
check_v "$1" "$scale";  shift;;
 
         # Output parameters
         -k|--keeptmp)     keeptmp=1; shift;;
@@ -242,8 +239,9 @@ done
 
 # If an input image is not given at all.
 if [ x"$inputs" = x ]; then
-    echo "$scriptname: no input FITS image files."
-    echo "Run with '--help' for more information on how to run."
+    cat <<EOF
+$scriptname: no input FITS image files. Run with '--help' for more information 
on how to run
+EOF
     exit 1
 elif [ ! -f $inputs ]; then
     echo "$scriptname: $inputs: No such file or directory."
@@ -252,25 +250,28 @@ fi
 
 # If a PSF image (--psf) is not given at all.
 if [ x"$psf" = x ]; then
-    echo "$scriptname: no PSF image provided."
-    echo "$scriptname: a PSF image '--psf' ('-p') should be provided."
+    cat <<EOF
+$scriptname: no PSF image provided. The PSF image should be provided with 
'--psf' ('-p').
+EOF
     exit 1
 elif [ ! -f $psf ]; then
     echo "$scriptname: $psf: No such file or directory."
     exit 1
 fi
 
-# If a flux factor (--fluxfactor) is not given at all.
-if [ x"$fluxfactor" = x ]; then
-    echo "$scriptname: no flux factor provided."
-    echo "$scriptname: value to '--fluxfactor' ('-f') should be provided."
+# If a scale factor (--scale) is not given at all.
+if [ x"$scale" = x ]; then
+    cat <<EOF
+$scriptname: no scale factor provided. It can be given with '--scale' (or 
'-s'). You can derive this value with the 'astscript-psf-model-scale-factor'
+EOF
     exit 1
 fi
 
 # If center coordinates (--center) is not given at all.
 if [ x"$center" = x ]; then
-    echo "$scriptname: no center coordinates provided."
-    echo "$scriptname: values to '--center' ('-c') should be provided."
+    cat <<EOF
+$scriptname: no center coordinates provided (for the star that should be 
subtracted). You can use '--center' ('-c').
+EOF
     exit 1
 else
     ncenter=$(echo $center | awk 'BEGIN{FS=","}END{print NF}')
@@ -281,16 +282,17 @@ else
 fi
 
 # If mode (--mode) is not given at all.
+modeerrorinfo="Depending on the nature of the star's coordinates, please give 
either 'img' (for pixel coordinates) or 'wcs' (for RA,Dec) to the '--mode' (or 
'-O') option."
 if [ x"$mode" = x ]; then
-    echo "$scriptname: no mode provided."
-    echo "$scriptname: value to '--mode' ('-O') should be provided."
+    echo "$scriptname: no coordinate mode provided! $modeerrorinfo"
     exit 1
 # Make sure the value to '--mode' is either 'wcs' or 'img'.
 elif [ $mode = "wcs" ] || [ $mode = "img" ]; then
     junk=1
 else
-    echo "$scriptname: wrong value to --mode (-O) provided."
-    echo "$scriptname: value to '--mode' ('-O') should be 'wcs' or 'img'"
+    cat <<EOF
+$scriptname: '$mode' not acceptable for '--mode' (or '-O'). $modeerrorinfo
+EOF
     exit 1
 fi
 
@@ -369,16 +371,16 @@ fi
 
 
 
-# Scale the PSF in flux
-# ---------------------
+# Scale the PSF with the given factor
+# -----------------------------------
 #
 # The PSF absolute pixel values are not relevant since they are used to be
 # normalized somehow. Here, the input PSF is scaled (multiplied) by the
 # specified factor (--fluxfactor) in order to appropiately obtain the PSF
 # brightness.
 psffluxscaled=$tmpdir/psf-flux-scaled-$objectid.fits
-astarithmetic $psf --hdu=$psfhdu $fluxfactor float32 x \
-                   --output=$psffluxscaled $quiet
+astarithmetic $psf --hdu=$psfhdu $scale float32 x \
+              --output=$psffluxscaled $quiet
 
 
 
@@ -494,7 +496,7 @@ yrange=$(echo "$ydiff $yaxis $ycenter" \
 # situated where the user has specified.
 psfcropped=$tmpdir/psf-cropped-$objectid.fits
 astcrop $psftranslated --mode=img --section=$xrange,$yrange \
-                       --output=$psfcropped $quiet
+        --output=$psfcropped $quiet
 
 
 
@@ -511,7 +513,8 @@ astcrop $psftranslated --mode=img --section=$xrange,$yrange 
\
 # stars (using the PSF) or the subtraction without having nan values in the
 # final subtracted image.
 astarithmetic $psfcropped --hdu=1 set-i \
-              i i isblank 0 where --output=$output $quiet
+              i i isblank 0 where set-psf \
+              $inputs --hdu=$hdu psf - --output=$output $quiet
 
 
 
diff --git a/bin/script/psf-create-junction.in b/bin/script/psf-unite.in
similarity index 76%
rename from bin/script/psf-create-junction.in
rename to bin/script/psf-unite.in
index d050fcaa..ceabf4c4 100644
--- a/bin/script/psf-create-junction.in
+++ b/bin/script/psf-unite.in
@@ -35,15 +35,15 @@ export LANG=C
 
 # Default option values (can be changed with options on the command-line).
 hdu=1
-core=""
-corehdu=1
-radius=""
+inner=""
 quiet=""
+scale=""
+radius=""
 keeptmp=0
 output=""
 tmpdir=""
+innerhdu=1
 axisratio=1
-fluxfactor=""
 positionangle=0
 version=@VERSION@
 scriptname=@SCRIPT_NAME@
@@ -67,7 +67,7 @@ This script is part of GNU Astronomy Utilities $version.
 
 This script will consider two different PSF images to join them into a
 single one. It is intendeed to generate a single PSF by combining different
-PSF regions (core and wings).
+PSF regions (inner and outer).
 
 For more information, please run any of the following commands. In
 particular the first contains a very comprehensive explanation of this
@@ -85,10 +85,10 @@ experienced Gnuastro users and developers. For more 
information, please run:
 $scriptname options:
  Input:
   -h, --hdu=STR           HDU/extension of all input FITS files.
-  -c, --core=STR          Core PSF FITS image.
-  -C, --corehdu=STR       HDU/extension of the PSF image.
+  -i, --inner=STR         Inner PSF FITS image.
+  -I, --innerhdu=STR      HDU/extension of the inner PSF image.
   -r, --radius=FLT        Radius at which the junction is done (in pixels).
-  -f, --fluxfactor=FLT    Factor by which the inner PSF is multiplied.
+  -s, --scale=FLT         Factor by which the inner PSF is multiplied.
   -Q, --axisratio=FLT     Axis ratio for ellipse maskprofile (A/B).
   -p, --positionangle=FLT Position angle for ellipse mask profile.
 
@@ -187,18 +187,18 @@ 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;;
-        -c|--core)           core="$2";                                 
check_v "$1" "$core";  shift;shift;;
-        -c=*|--core=*)       core="${1#*=}";                            
check_v "$1" "$core";  shift;;
-        -c*)                 core=$(echo "$1"  | sed -e's/-c//');       
check_v "$1" "$core";  shift;;
-        -C|--corehdu)        corehdu="$2";                              
check_v "$1" "$corehdu";  shift;shift;;
-        -C=*|--corehdu=*)    corehdu="${1#*=}";                         
check_v "$1" "$corehdu";  shift;;
-        -C*)                 corehdu=$(echo "$1"  | sed -e's/-C//');    
check_v "$1" "$corehdu";  shift;;
+        -i|--inner)          inner="$2";                                
check_v "$1" "$inner";  shift;shift;;
+        -i=*|--inner=*)      inner="${1#*=}";                           
check_v "$1" "$inner";  shift;;
+        -i*)                 inner=$(echo "$1"  | sed -e's/-c//');      
check_v "$1" "$inner";  shift;;
+        -I|--innerhdu)       innerhdu="$2";                             
check_v "$1" "$innerhdu";  shift;shift;;
+        -I=*|--innerhdu=*)   innerhdu="${1#*=}";                        
check_v "$1" "$innerhdu";  shift;;
+        -I*)                 innerhdu=$(echo "$1"  | sed -e's/-C//');   
check_v "$1" "$innerhdu";  shift;;
         -r|--radius)         radius="$2";                               
check_v "$1" "$radius";  shift;shift;;
         -r=*|--radius=*)     radius="${1#*=}";                          
check_v "$1" "$radius";  shift;;
         -r*)                 radius=$(echo "$1"  | sed -e's/-r//');     
check_v "$1" "$radius";  shift;;
-        -f|--fluxfactor)     fluxfactor="$2";                           
check_v "$1" "$fluxfactor";  shift;shift;;
-        -f=*|--fluxfactor=*) fluxfactor="${1#*=}";                      
check_v "$1" "$fluxfactor";  shift;;
-        -f*)                 fluxfactor=$(echo "$1"  | sed -e's/-f//'); 
check_v "$1" "$fluxfactor";  shift;;
+        -s|--scale)          scale="$2";                                
check_v "$1" "$scale";  shift;shift;;
+        -s=*|--scale=*)      scale="${1#*=}";                           
check_v "$1" "$scale";  shift;;
+        -s*)                 scale=$(echo "$1"  | sed -e's/-f//');      
check_v "$1" "$scale";  shift;;
         -Q|--axisratio)      axisratio="$2";                            
check_v "$1" "$axisratio";  shift;shift;;
         -Q=*|--axisratio=*)  axisratio="${1#*=}";                       
check_v "$1" "$axisratio";  shift;;
         -Q*)                 axisratio=$(echo "$1"  | sed -e's/-Q//');  
check_v "$1" "$axisratio";  shift;;
@@ -245,43 +245,47 @@ done
 
 # If an input image is not given at all.
 if [ x"$inputs" = x ]; then
-    echo "$scriptname: no input FITS image files."
-    echo "Run with '--help' for more information on how to run."
+    cat <<EOF
+$scriptname: 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
+EOF
     exit 1
 elif [ ! -f $inputs ]; then
     echo "$scriptname: $inputs: No such file or directory."
     exit 1
 fi
 
-# If a core image (--core) is not given at all.
-if [ x"$core" = x ]; then
-    echo "$scriptname: no core image provided."
-    echo "A core image of the PSF to be specified with --stampwidth or -w."
+# If an inner image (--inner) is not given at all.
+if [ x"$inner" = x ]; then
+    cat <<EOF
+$scriptname: no inner FITS image provided. The inner part of the PSF (to unite 
with the outer part, which is the main argument) can be specified with the 
'--inner' (or '-i') option as a FITS image
+EOF
     exit 1
-elif [ ! -f $core ]; then
-    echo "$scriptname: $core: No such file or directory."
+elif [ ! -f $inner ]; then
+    echo "$scriptname: $inner: No such file or directory."
     exit 1
 fi
 
 # If a radius (--radius) is not given at all.
 if [ x"$radius" = x ]; then
-    echo "$scriptname: no radius (in pixels) provided."
-    echo "A radius value (in pixels) has to be specified with --radius or -r."
+    cat <<EOF
+$scriptname: no radius (in pixels) provided. All pixels below this radius will 
be filled with the inner PSf image. You can use '--radius' (or '-r') to specify 
it
+EOF
     exit 1
 fi
 
-# If a fluxfactor (--fluxfactor) is not given at all.
-if [ x"$fluxfactor" = x ]; then
-    echo "$scriptname: no flux factor provided."
-    echo "A flux factor has to be specified with --fluxfactor or -f."
+# If a scale (--scale) is not given at all.
+if [ x"$scale" = x ]; then
+    cat <<EOF
+$scriptname: no scale factor provided ('--scale' or '-s'). This is necessary 
to scale the inner region to the outer and is usually determined with the 
'astscript-psf-model-scale-factor'. See the Gnuastro tutorial on "Building the 
extended PSF" for more
+EOF
     exit 1
 fi
 
 
 
 
-# Define a temporal directory and the final output file
-# -----------------------------------------------------
+# 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
@@ -293,7 +297,7 @@ fi
 # 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.
 bname_outer=$(basename $inputs | sed 's/\.fits/ /' | awk '{print $1}')
-bname_core=$(basename $core | sed 's/\.fits/ /' | awk '{print $1}')
+bname_inner=$(basename $inner  | sed 's/\.fits/ /' | awk '{print $1}')
 if [ x$tmpdir = x ]; then \
   tmpdir=$(pwd)/"$bname_outer"_psfcreatejunction
 fi
@@ -306,7 +310,7 @@ fi
 
 # Output
 if [ x$output = x ]; then
-  output="$bname_outer"_"$bname_core"_psfcreatejunction.fits
+  output="$bname_outer"_"$bname_inner"_psfcreatejunction.fits
 fi
 
 
@@ -351,14 +355,14 @@ ycenter=$(astarithmetic $yaxis float32 2.0 / --quiet)
 
 
 
-# Get the center of the core PSF
-# ------------------------------
+# Get the center of the inner PSF
+# -------------------------------
 #
-# The center of the core PSF is assumed to be at the center of the PSF
+# The center of the inner PSF is assumed to be at the center of the PSF
 # image.  So, the center of the PSF is computed here from the size of the
 # PSF image along the two axis (in pixels). Dimension values are computed
 # as described above.
-psfaxises=$(astfits $core --hdu=$corehdu --quiet \
+psfaxises=$(astfits $inner --hdu=$innerhdu --quiet \
                     --keyvalue ZNAXIS1,ZNAXIS2,NAXIS1,NAXIS2)
 psfnaxises=$(echo $psfaxises \
                   | sed 's/n\/a//g' \
@@ -389,9 +393,9 @@ ypsfcenter=$(astarithmetic $ypsfaxis float32 2.0 / --quiet)
 xdiff=$(astarithmetic $xcenter float32 $xpsfcenter float32 - --quiet)
 ydiff=$(astarithmetic $ycenter float32 $ypsfcenter float32 - --quiet)
 
-coretranslated=$tmpdir/"$bname_core"_translated.fits
-astwarp $core --translate=$xdiff,$ydiff \
-             --output=$coretranslated $quiet
+innertranslated=$tmpdir/"$bname_inner"_translated.fits
+astwarp $inner --translate=$xdiff,$ydiff \
+        --output=$innertranslated $quiet
 
 
 
@@ -430,9 +434,9 @@ yrange=$(echo "$ydiff $yaxis $ycenter" \
 # Once the necessary crop parameters have been computed, use the option
 # '--section' to get the PSF image with the correct size and the center
 # situated where the user has specified.
-corecropped=$tmpdir/"$bname_core"_cropped.fits
-astcrop $coretranslated --mode=img --section=$xrange,$yrange \
-                        --output=$corecropped $quiet
+innercropped=$tmpdir/"$bname_inner"_cropped.fits
+astcrop $innertranslated --mode=img --section=$xrange,$yrange \
+        --output=$innercropped $quiet
 
 
 
@@ -441,16 +445,16 @@ astcrop $coretranslated --mode=img 
--section=$xrange,$yrange \
 # Flux scaling, zero in the outer part
 # ------------------------------------
 #
-# In order to put the core at the desired level of flux than the outer
-# part, it is necessary to multiply this core by the factor specified by
-# the user with the option --fluxfactor. Here, the cropped image of the
-# core is scaled by using that factor. In addition to that, the nan pixels
-# that came from the cropping are set to zero. This is necessary for the
-# final addition of the two different PSF images.
-corefluxscaled=$tmpdir/"$bname_core"_fluxscaled.fits
-astarithmetic $corecropped --hdu=1 set-i \
+# In order to put the inner image at the desired level of flux than the
+# outer part, it is necessary to multiply the inner part by the factor
+# specified by the user with the option --scale. Here, the cropped image of
+# the inner is scaled by using that factor. In addition to that, the nan
+# pixels that came from the cropping are set to zero. This is necessary for
+# the final addition of the two different PSF images.
+innerfluxscaled=$tmpdir/"$bname_inner"_fluxscaled.fits
+astarithmetic $innercropped --hdu=1 set-i \
               i i isblank 0 where set-z \
-              z $fluxfactor x --output=$corefluxscaled $quiet
+              z $scale x --output=$innerfluxscaled $quiet
 
 
 
@@ -461,65 +465,32 @@ astarithmetic $corecropped --hdu=1 set-i \
 # In order to join the two images properly, it is necessary to consider a
 # general mask. The mask is a circular flat (5) profile with the ones in
 # the center and the zeros in the outer part. It will be used for masking
-# the outer part of the core image, and the core part of the outer image.
+# the outer part of the inner image, and the inner part of the outer image.
 # As a consequence, the final image will be the sum of these two masked
 # images.
 maskimage=$tmpdir/mask-image.fits
 xcentmask=$(astarithmetic $xcenter float32 1.0 + --quiet)
 ycentmask=$(astarithmetic $ycenter float32 1.0 + --quiet)
 echo "1 $xcentmask $ycentmask 5 $radius 1 $positionangle $axisratio 1 1" \
-      | astmkprof --background=$corefluxscaled \
+      | astmkprof --background=$innerfluxscaled \
                  --mode=img \
                   --clearcanvas \
-                  --mforflatpix \
+                  --mforflatpix --type=uint8 \
                   --output=$maskimage $quiet
 
 
 
 
 
-# Masking both images
-# -------------------
-#
-# Once both images are centered, flux scaled, and have the same dimensions,
-# it is necessary to mask them properly.  The masking process consist in
-# putting to zero the core of the outer image, and to put zeros in the
-# outer part of the core image: 0=zeros, W = Wings, C = Core.
-
-# - Outer image:
-#   W W W W W W
-#   W W 0 0 W W
-#   W W 0 0 W W
-#   W W W W W W
-#
-# - Core image:
-#   0 0 0 0 0 0
-#   0 0 C C 0 0
-#   0 0 C C 0 0
-#   0 0 0 0 0 0
-
-outer_masked=$tmpdir/"$bname_outer"_outermasked.fits
-astarithmetic $inputs --hdu=1 set-psfouter \
-              $maskimage --hdu=1 set-mask \
-              psfouter mask 1 eq 0 where --output=$outer_masked $quiet
-
-
-core_masked=$tmpdir/"$bname_core"_coremasked.fits
-astarithmetic $corefluxscaled --hdu=1 set-psfinner \
-              $maskimage --hdu=1 set-mask \
-              psfinner mask 1 ne 0 where --output=$core_masked $quiet
-
-
-
-
-
-# Masking both images
-# -------------------
+# Fill inner pixels with inner image
+# ----------------------------------
 #
-# Sum the two images to obtain the final output
-astarithmetic $outer_masked --hdu=1 \
-              $core_masked --hdu=1 \
-              2 sum --output=$output $quiet
+# Having the mask from above, we simply replace those pixels in the outer
+# image with the same pixels of the inner image.
+astarithmetic $inputs --hdu=$hdu       set-outer \
+              $innerfluxscaled --hdu=1 set-inner \
+              $maskimage --hdu=1       set-mask \
+              outer mask inner where -o$output $quiet --wcsfile=none
 
 
 
diff --git a/bootstrap b/bootstrap
index 2161c696..dc2238f4 100755
--- a/bootstrap
+++ b/bootstrap
@@ -1,6 +1,6 @@
 #! /bin/sh
 # Print a version string.
-scriptversion=2021-04-11.09; # UTC
+scriptversion=2022-01-26.05; # UTC
 
 # Bootstrap this package from checked-out sources.
 
@@ -313,6 +313,116 @@ find_tool ()
   eval "export $find_tool_envvar"
 }
 
+# Strip blank and comment lines to leave significant entries.
+gitignore_entries() {
+  sed '/^#/d; /^$/d' "$@"
+}
+
+# If $STR is not already on a line by itself in $FILE, insert it at the start.
+# Entries are inserted at the start of the ignore list to ensure existing
+# entries starting with ! are not overridden.  Such entries support
+# whitelisting exceptions after a more generic blacklist pattern.
+insert_if_absent() {
+  file=$1
+  str=$2
+  test -f $file || touch $file
+  test -r $file || die "Error: failed to read ignore file: $file"
+  duplicate_entries=$(gitignore_entries $file | sort | uniq -d)
+  if [ "$duplicate_entries" ] ; then
+    die "Error: Duplicate entries in $file: " $duplicate_entries
+  fi
+  linesold=$(gitignore_entries $file | wc -l)
+  linesnew=$( { echo "$str"; cat $file; } | gitignore_entries | sort -u | wc 
-l)
+  if [ $linesold != $linesnew ] ; then
+    { echo "$str" | cat - $file > $file.bak && mv $file.bak $file; } \
+      || die "insert_if_absent $file $str: failed"
+  fi
+}
+
+# Adjust $PATTERN for $VC_IGNORE_FILE and insert it with
+# insert_if_absent.
+insert_vc_ignore() {
+  vc_ignore_file="$1"
+  pattern="$2"
+  case $vc_ignore_file in
+  *.gitignore)
+    # A .gitignore entry that does not start with '/' applies
+    # recursively to subdirectories, so prepend '/' to every
+    # .gitignore entry.
+    pattern=$(echo "$pattern" | sed s,^,/,);;
+  esac
+  insert_if_absent "$vc_ignore_file" "$pattern"
+}
+
+symlink_to_dir()
+{
+  src=$1/$2
+  dst=${3-$2}
+
+  test -f "$src" && {
+
+    # If the destination directory doesn't exist, create it.
+    # This is required at least for "lib/uniwidth/cjk.h".
+    dst_dir=$(dirname "$dst")
+    if ! test -d "$dst_dir"; then
+      mkdir -p "$dst_dir"
+
+      # If we've just created a directory like lib/uniwidth,
+      # tell version control system(s) it's ignorable.
+      # FIXME: for now, this does only one level
+      parent=$(dirname "$dst_dir")
+      for dot_ig in x $vc_ignore; do
+        test $dot_ig = x && continue
+        ig=$parent/$dot_ig
+        insert_vc_ignore $ig "${dst_dir##*/}"
+      done
+    fi
+
+    if $copy; then
+      {
+        test ! -h "$dst" || {
+          echo "$me: rm -f $dst" &&
+          rm -f "$dst"
+        }
+      } &&
+      test -f "$dst" &&
+      cmp -s "$src" "$dst" || {
+        echo "$me: cp -fp $src $dst" &&
+        cp -fp "$src" "$dst"
+      }
+    else
+      # Leave any existing symlink alone, if it already points to the source,
+      # so that broken build tools that care about symlink times
+      # aren't confused into doing unnecessary builds.  Conversely, if the
+      # existing symlink's timestamp is older than the source, make it afresh,
+      # so that broken tools aren't confused into skipping needed builds.  See
+      # <https://lists.gnu.org/r/bug-gnulib/2011-05/msg00326.html>.
+      test -h "$dst" &&
+      src_ls=$(ls -diL "$src" 2>/dev/null) && set $src_ls && src_i=$1 &&
+      dst_ls=$(ls -diL "$dst" 2>/dev/null) && set $dst_ls && dst_i=$1 &&
+      test "$src_i" = "$dst_i" &&
+      both_ls=$(ls -dt "$src" "$dst") &&
+      test "X$both_ls" = "X$dst$nl$src" || {
+        dot_dots=
+        case $src in
+        /*) ;;
+        *)
+          case /$dst/ in
+          *//* | */../* | */./* | /*/*/*/*/*/)
+             die "invalid symlink calculation: $src -> $dst";;
+          /*/*/*/*/)    dot_dots=../../../;;
+          /*/*/*/)      dot_dots=../../;;
+          /*/*/)        dot_dots=../;;
+          esac;;
+        esac
+
+        echo "$me: ln -fs $dot_dots$src $dst" &&
+        ln -fs "$dot_dots$src" "$dst"
+      }
+    fi
+  }
+}
+
 # Override the default configuration, if necessary.
 # Make sure that bootstrap.conf is sourced from the current directory
 # if we were invoked as "sh bootstrap".
@@ -375,47 +485,6 @@ if test -n "$checkout_only_file" && test ! -r 
"$checkout_only_file"; then
   die "Bootstrapping from a non-checked-out distribution is risky."
 fi
 
-# Strip blank and comment lines to leave significant entries.
-gitignore_entries() {
-  sed '/^#/d; /^$/d' "$@"
-}
-
-# If $STR is not already on a line by itself in $FILE, insert it at the start.
-# Entries are inserted at the start of the ignore list to ensure existing
-# entries starting with ! are not overridden.  Such entries support
-# whitelisting exceptions after a more generic blacklist pattern.
-insert_if_absent() {
-  file=$1
-  str=$2
-  test -f $file || touch $file
-  test -r $file || die "Error: failed to read ignore file: $file"
-  duplicate_entries=$(gitignore_entries $file | sort | uniq -d)
-  if [ "$duplicate_entries" ] ; then
-    die "Error: Duplicate entries in $file: " $duplicate_entries
-  fi
-  linesold=$(gitignore_entries $file | wc -l)
-  linesnew=$( { echo "$str"; cat $file; } | gitignore_entries | sort -u | wc 
-l)
-  if [ $linesold != $linesnew ] ; then
-    { echo "$str" | cat - $file > $file.bak && mv $file.bak $file; } \
-      || die "insert_if_absent $file $str: failed"
-  fi
-}
-
-# Adjust $PATTERN for $VC_IGNORE_FILE and insert it with
-# insert_if_absent.
-insert_vc_ignore() {
-  vc_ignore_file="$1"
-  pattern="$2"
-  case $vc_ignore_file in
-  *.gitignore)
-    # A .gitignore entry that does not start with '/' applies
-    # recursively to subdirectories, so prepend '/' to every
-    # .gitignore entry.
-    pattern=$(echo "$pattern" | sed s,^,/,);;
-  esac
-  insert_if_absent "$vc_ignore_file" "$pattern"
-}
-
 # Die if there is no AC_CONFIG_AUX_DIR($build_aux) line in configure.ac.
 found_aux_dir=no
 grep '^[        ]*AC_CONFIG_AUX_DIR(\['"$build_aux"'\])' configure.ac \
@@ -694,9 +763,25 @@ if $use_gnulib; then
       shallow=
       if test -z "$GNULIB_REVISION"; then
         git clone -h 2>&1 | grep -- --depth > /dev/null && shallow='--depth 2'
+        git clone $shallow ${GNULIB_URL:-$default_gnulib_url} "$gnulib_path" \
+          || cleanup_gnulib
+      else
+        git fetch -h 2>&1 | grep -- --depth > /dev/null && shallow='--depth 2'
+        mkdir -p "$gnulib_path"
+        # Only want a shallow checkout of $GNULIB_REVISION, but git does not
+        # support cloning by commit hash. So attempt a shallow fetch by commit
+        # hash to minimize the amount of data downloaded and changes needed to
+        # be processed, which can drastically reduce download and processing
+        # time for checkout. If the fetch by commit fails, a shallow fetch can
+        # not be performed because we do not know what the depth of the commit
+        # is without fetching all commits. So fallback to fetching all commits.
+        git -C "$gnulib_path" init
+        git -C "$gnulib_path" remote add origin 
${GNULIB_URL:-$default_gnulib_url}
+        git -C "$gnulib_path" fetch $shallow origin "$GNULIB_REVISION" \
+          || git -C "$gnulib_path" fetch origin \
+          || cleanup_gnulib
+        git -C "$gnulib_path" reset --hard FETCH_HEAD
       fi
-      git clone $shallow ${GNULIB_URL:-$default_gnulib_url} "$gnulib_path" \
-        || cleanup_gnulib
 
       trap - 1 2 13 15
     fi
@@ -813,75 +898,6 @@ case $SKIP_PO in
   fi;;
 esac
 
-symlink_to_dir()
-{
-  src=$1/$2
-  dst=${3-$2}
-
-  test -f "$src" && {
-
-    # If the destination directory doesn't exist, create it.
-    # This is required at least for "lib/uniwidth/cjk.h".
-    dst_dir=$(dirname "$dst")
-    if ! test -d "$dst_dir"; then
-      mkdir -p "$dst_dir"
-
-      # If we've just created a directory like lib/uniwidth,
-      # tell version control system(s) it's ignorable.
-      # FIXME: for now, this does only one level
-      parent=$(dirname "$dst_dir")
-      for dot_ig in x $vc_ignore; do
-        test $dot_ig = x && continue
-        ig=$parent/$dot_ig
-        insert_vc_ignore $ig "${dst_dir##*/}"
-      done
-    fi
-
-    if $copy; then
-      {
-        test ! -h "$dst" || {
-          echo "$me: rm -f $dst" &&
-          rm -f "$dst"
-        }
-      } &&
-      test -f "$dst" &&
-      cmp -s "$src" "$dst" || {
-        echo "$me: cp -fp $src $dst" &&
-        cp -fp "$src" "$dst"
-      }
-    else
-      # Leave any existing symlink alone, if it already points to the source,
-      # so that broken build tools that care about symlink times
-      # aren't confused into doing unnecessary builds.  Conversely, if the
-      # existing symlink's timestamp is older than the source, make it afresh,
-      # so that broken tools aren't confused into skipping needed builds.  See
-      # <https://lists.gnu.org/r/bug-gnulib/2011-05/msg00326.html>.
-      test -h "$dst" &&
-      src_ls=$(ls -diL "$src" 2>/dev/null) && set $src_ls && src_i=$1 &&
-      dst_ls=$(ls -diL "$dst" 2>/dev/null) && set $dst_ls && dst_i=$1 &&
-      test "$src_i" = "$dst_i" &&
-      both_ls=$(ls -dt "$src" "$dst") &&
-      test "X$both_ls" = "X$dst$nl$src" || {
-        dot_dots=
-        case $src in
-        /*) ;;
-        *)
-          case /$dst/ in
-          *//* | */../* | */./* | /*/*/*/*/*/)
-             die "invalid symlink calculation: $src -> $dst";;
-          /*/*/*/*/)    dot_dots=../../../;;
-          /*/*/*/)      dot_dots=../../;;
-          /*/*/)        dot_dots=../;;
-          esac;;
-        esac
-
-        echo "$me: ln -fs $dot_dots$src $dst" &&
-        ln -fs "$dot_dots$src" "$dst"
-      }
-    fi
-  }
-}
-
 version_controlled_file() {
   parent=$1
   file=$2
@@ -1093,7 +1109,7 @@ bootstrap_epilogue
 
 echo "$0: done.  Now you can run './configure'."
 
-# Local variables:
+# Local Variables:
 # eval: (add-hook 'before-save-hook 'time-stamp)
 # time-stamp-start: "scriptversion="
 # time-stamp-format: "%:y-%02m-%02d.%02H"
diff --git a/doc/gnuastro.en.html b/doc/gnuastro.en.html
index 537e33b5..4116805e 100644
--- a/doc/gnuastro.en.html
+++ b/doc/gnuastro.en.html
@@ -294,12 +294,14 @@ mailing list for advice.</p>
 
 <dl>
 
-<!--
-<dt>Google Summer of Code 2020</dt>
-<dd>Gnuastro has some <a 
href="/software/soc-projects/ideas-2020.html#gnuastro">suggested projects</a> 
for Google Summer of Code (GSoC) 2020.
+
+<dt>Google Summer of Code 2022</dt>
+<dd>Gnuastro has some two suggested projects (one medium and one large) for 
Google Summer of Code (GSoC) 2022 as part of <a 
href="https://openastronomy.org/gsoc/gsoc2022/#/projects";>OpenAstronomy</a>.
+  The medium project is for estimating <a 
href="https://openastronomy.org/gsoc/gsoc2022/#/projects?project=distortion_coefficients_in_astrometry";>Distortion
 coefficients in astrometry</a>, and the larger one is for <a 
href="https://openastronomy.org/gsoc/gsoc2022/#/projects?project=gnuastro_library_in_python";>Python
 wrappers to Gnuastro's library</a>.
+  A checklist of steps to get you started in developing Gnuastro is <a 
href="https://savannah.gnu.org/support/index.php?110613#comment0";>available 
here</a>.
   Generally, if you are interested in any of the Gnuastro <a 
href="https://savannah.gnu.org/task/?group=gnuastro";>open tasks</a> for the 
GSoC please get in touch.
-  We are also open to any new suggestion to contribute to Gnuastro through 
GSoC 2020.</dd>
--->
+  We are also open to any new suggestion to contribute to Gnuastro through 
GSoC 2022.</dd>
+
 
 <dt>Test releases</dt>
 
diff --git a/doc/gnuastro.texi b/doc/gnuastro.texi
index bf843ec2..d30108a2 100644
--- a/doc/gnuastro.texi
+++ b/doc/gnuastro.texi
@@ -113,11 +113,11 @@ A copy of the license is included in the section entitled 
``GNU Free Documentati
 * astscript-radial-profile: (gnuastro)Invoking astscript-radial-profile. 
Options to this script
 * astscript-ds9-region: (gnuastro)Invoking astscript-ds9-region. Options to 
this script
 * astscript-fits-view: (gnuastro)Invoking astscript-fits-view. Options to this 
script
-* astscript-psf-create-select-stars: (gnuastro)Invoking 
astscript-psf-create-select-stars. Options to this script
-* astscript-psf-create-make-stamp: (gnuastro)Invoking 
astscript-psf-create-make-stamp. Options to this script
-* astscript-psf-create-junction: (gnuastro)Invoking 
astscript-psf-create-junction. Options to this script
-* astscript-psf-model-flux-factor: (gnuastro)Invoking 
astscript-psf-model-flux-factor. Options to this script
-* astscript-psf-model-scattered-light: (gnuastro)Invoking 
astscript-psf-model-scattered-light. Options to this script
+* astscript-psf-select-stars: (gnuastro)Invoking astscript-psf-select-stars. 
Options to this script
+* astscript-psf-stamp: (gnuastro)Invoking astscript-psf-stamp. Options to this 
script
+* astscript-psf-unite: (gnuastro)Invoking astscript-psf-unite. Options to this 
script
+* astscript-psf-scale-factor: (gnuastro)Invoking astscript-psf-scale-factor. 
Options to this script
+* astscript-psf-subtract: (gnuastro)Invoking astscript-psf-subtract. Options 
to this script
 @end direntry
 
 
@@ -683,11 +683,11 @@ Viewing FITS file contents with DS9 or TOPCAT
 PSF construction and subtraction
 
 * Overview of the PSF scripts::  Summary of concepts and methods
-* Invoking astscript-psf-create-select-stars::  Select good starts within an 
image.
-* Invoking astscript-psf-create-make-stamp::  Make a stamp of each star to 
stack.
-* Invoking astscript-psf-create-junction::  Merge stacks of different regions 
of PSF.
-* Invoking astscript-psf-model-flux-factor::  Calculate factor to scale PSF to 
star.
-* Invoking astscript-psf-model-scattered-light::  Put the PSF in the image to 
subtract.
+* Invoking astscript-psf-select-stars::  Select good starts within an image.
+* Invoking astscript-psf-stamp::  Make a stamp of each star to stack.
+* Invoking astscript-psf-unite::  Merge stacks of different regions of PSF.
+* Invoking astscript-psf-scale-factor::  Calculate factor to scale PSF to star.
+* Invoking astscript-psf-subtract::  Put the PSF in the image to subtract.
 
 Library
 
@@ -5816,27 +5816,27 @@ For more on Query, see @ref{Query}.
 
 @example
 $ astquery gaia --dataset=edr3 --overlapwith=flat/67510.fits \
-           --range=phot_g_mean_mag,-inf,10 --output=gaia.fits
+           --range=phot_g_mean_mag,-inf,10 \
+           --output=flat/67510-bright.fits
 @end example
 
 Now, we can easily visualize the magnitude and positions of these stars using 
@command{astscript-ds9-region} and the command below (for more on this script, 
see @ref{SAO DS9 region files from table})
 
 @example
-$ astscript-ds9-region gaia.fits -cra,dec \
+$ astscript-ds9-region flat/67510-bright.fits -cra,dec \
            --namecol=phot_g_mean_mag \
            --command="ds9 flat/67510.fits -zoom to fit -zscale"
-$ rm gaia.fits
 @end example
 
 You can see that we have several stars between magnitudes 6 to 10.
-Let's use @file{astscript-psf-create-select-stars} in the command below to 
select the relevant stars in the image (the brightest; with a magnitude between 
6 to 10).
+Let's use @file{astscript-psf-select-stars} in the command below to select the 
relevant stars in the image (the brightest; with a magnitude between 6 to 10).
 The advantage of using this script (instead of a simple @option{--range} in 
Table), is that it will also check distances to nearby stars and reject those 
that are too close (and not good for constructing the PSF).
 Since we have very bright stars in this very wide-field image, we will also 
increase the distance to nearby neighbors with brighter or similar magnitudes 
(the default value is 1 arcmin).
 To do this, we will set @option{--mindistdeg=0.02}, which corresponds to 1.2 
arcmin.
 
 @example
 $ mkdir outer
-$ astscript-psf-create-select-stars flat/67510.fits \
+$ astscript-psf-select-stars flat/67510.fits \
            --magnituderange=6,10 --mindistdeg=0.02 \
            --output=outer/67510-6-10.fits
 @end example
@@ -5851,7 +5851,7 @@ $ astscript-ds9-region outer/67510-6-10.fits -cra,dec \
 @end example
 
 Now that the catalog of good stars is ready, it is time to construct the 
individual stamps from the catalog above.
-To do that, we'll use @file{astscript-psf-create-make-stamp}.
+To do that, we'll use @file{astscript-psf-stamp}.
 One of the most important parameters for this script is the normalization 
radii @code{--normradii}.
 This parameter defines a ring for the flux normalization of each star stamp.
 The normalization of the flux is necessary because each star has a different 
brightness, and consequently, it is crucial for having all the stamps with the 
same flux level in the same region.
@@ -5880,7 +5880,7 @@ $ counter=1
 $ mkdir finding-normradii
 $ asttable outer/67510-6-10.fits \
            | while read -r ra dec mag; do
-               astscript-psf-create-make-stamp label/67510-seg.fits \
+               astscript-psf-stamp label/67510-seg.fits \
                     --mode=wcs \
                     --stampwidth=1000 \
                     --center=$ra,$dec \
@@ -5920,7 +5920,7 @@ $ counter=1
 $ mkdir outer/stamps
 $ asttable outer/67510-6-10.fits \
            | while read -r ra dec mag; do
-               astscript-psf-create-make-stamp label/67510-seg.fits \
+               astscript-psf-stamp label/67510-seg.fits \
                     --mode=wcs \
                     --stampwidth=1000 \
                     --center=$ra,$dec \
@@ -5939,12 +5939,15 @@ Just recall that we need to specify the number of 
inputs into the stacking opera
 $ imgs=outer/stamps/*.fits
 $ numimgs=$(echo $imgs | wc -w)
 $ astarithmetic $imgs $numimgs 3 0.2 sigclip-mean -g1 \
-                --output=outer/stack.fits
-$ astarithmetic $imgs $numimgs median -g1 --output=outer/stack.fits
+                --output=outer/stack.fits  --wcsfile=none
 @end example
 
 @noindent
-With the command below, we'll compare this stacked PSF with the images of the 
individual stars that were used to create it.
+Did you notice the @option{--wcsfile=none} option above?
+With it, the stacked image no longer has any WCS information.
+This is natural, because the stacked image doesn't correspond to any specific 
region of the sky any more.
+
+Let's compare this stacked PSF with the images of the individual stars that 
were used to create it.
 You clearly see that the number of masked pixels is significantly decreased 
and the PSF is much more ``cleaner'').
 
 @example
@@ -5985,7 +5988,7 @@ So let's have a look and see how many stars we have in 
the magnitude range of 12
 
 @example
 $ mkdir inner
-$ astscript-psf-create-select-stars flat/67510.fits \
+$ astscript-psf-select-stars flat/67510.fits \
            --magnituderange=12,13 --mindistdeg=0.01 \
            --output=inner/67510-12-13.fits
 
@@ -6006,7 +6009,7 @@ $ counter=1
 $ mkdir inner/stamps
 $ asttable inner/67510-12-13.fits \
            | while read -r ra dec mag; do
-               astscript-psf-create-make-stamp label/67510-seg.fits \
+               astscript-psf-stamp label/67510-seg.fits \
                     --mode=wcs \
                     --stampwidth=500 \
                     --center=$ra,$dec \
@@ -6019,12 +6022,12 @@ $ asttable inner/67510-12-13.fits \
 $ imgs=inner/stamps/*.fits
 $ numimgs=$(echo $imgs | wc -w)
 $ astarithmetic $imgs $numimgs 3 0.2 sigclip-mean -g1 \
-                --output=inner/stack.fits
+                --output=inner/stack.fits --wcsfile=none
 $ astscript-fits-view inner/stack.fits inner/stamps/*.fits
 @end example
 
 @noindent
-We are ready now to unite the two stacks we have constructed: the outer and 
the inner parts.
+We are now ready to unite the two stacks we have constructed: the outer and 
the inner parts.
 
 @node Uniting the different PSF components, Subtracting the PSF, Inner part of 
the PSF, Building the extended PSF
 @subsection Uniting the different PSF components
@@ -6115,124 +6118,147 @@ We had masked all saturated pixels before, so this 
divergance for radii smaller
 This is present in all CCDs and pixels beyond this level should not be used in 
measurements (or properly corrected).
 @end enumerate
 
-The items above were only listed so you get a good mental/visual understanding 
of the logic behind the operation of the next script (and to learn how to tune 
its parameters where necessary): @file{astscript-psf-model-flux-factor}.
+The items above were only listed so you get a good mental/visual understanding 
of the logic behind the operation of the next script (and to learn how to tune 
its parameters where necessary): @file{astscript-psf-scale-factor}.
 This script is more general than this particular problem, but can be used for 
this special case also.
-Its job is to take a model of an object and a larger image.
-It will calculate the radial profile of the model, and the profile of the 
object at a certain point within the larger image.
-It will divide the centered object profile by the model profile and will use 
the range of radii you specify to find the flux factor.
-You can multiply its retured value by the model to scale it to your object's 
flux (for more on this script, see @ref{Invoking 
astscript-psf-model-flux-factor}).
-
-The basic parameters are the normalization radii (i.e., the radius ring at 
which the ratio betwen the radial profiles of the outer and inner part is 
done), and the center of the outer part of the PSF.
-You can also provide a segmentation image with a CLUMPS and OBJECTS extensions 
in order to mask contaminant sources as explained above.
-The center of the inner PSF is asumed to be in the center of the image.
-Let's obtain that flux factor with the following command:
+Its job is to take a model of an object (PSF, or inner stack in this case) and 
the position of an instance of that model (a star, or the outer stack in this 
case) in a larger image.
 
-@c The radial profiles in this script appear to be different from the
-@c radial profiles of the last section.
+Instead of dealing with radial profiles (that enforce a certain shape), this 
script will put the centers of the inner and outer PSFs over each other and 
divide the outer by the inner.
+Let's have a look with the command below.
+Just note that we are running it with @option{--keeptmp} so the temporary 
directory with all the intermediate files remain for further clarification:
 
 @example
-$ astscript-psf-model-flux-factor outer/stack.fits \
-           --psf=inner/stack.fits --center=500,500 \
-           --mode=img --normradii=15,16
+$ astscript-psf-scale-factor outer/stack.fits \
+           --psf=inner/stack.fits --center=501,501 \
+           --mode=img --normradii=10,15 --keeptmp
+$ astscript-fits-view stack_psfmodelscalefactor/cropped-*.fits \
+                      stack_psfmodelscalefactor/for-factor-*.fits
 @end example
 
-The output of this script is a value (98.9177), and the interpretation of the 
value is the following: it is the number by which you have to multiply the 
inner stack to have the same pixel values (on average) than the outer stack in 
the ring of pixels defined by @option{--normradii=15,16}.
-Basically, the script has computed the mean of the ratio of the radial 
profiles of the two images at the specified normalization radii ring.
+With the second command, you see the four steps of the process: the first two 
images show the cropped outer and inner stacks (to same width image).
+The third shows the radial position of each pixel (which is used to only keep 
the pixels within the desired radial range).
+The fourth shows the per-pixel division of the outer by the inner within the 
requested radii.
+The sigma-clipped median of these pixels is finally reported.
+Unlike the radial profile method (which averages over a circular/elliptical 
annulus for each radius), this method imposes no a-priori shape on the PSF.
+This makes it very useful for complex PSFs (like the case here).
 
-Once we have obtained the flux factor, we are ready to unite the outer and the 
inner part of the PSF.
-To do that, we will use the script @file{astscript-psf-create-junction} (for 
more on this script, see @ref{Invoking astscript-psf-create-junction}).
-The basic parameters are the core part of the PSF @option{--core}, the 
junction radius @option{--radius}, and the flux factor @option{--fluxfactor}.
-With these parameters provided, the script will consider the input image as 
reference outer part of the PSF.
-Then, it will scale the inner part by the flux factor, and replace the inner 
part (radius less than the @option{--radius}) by this image.
-Since the flux factor was computed for a ring of 1 pixel between 15 and 16 
pixels, let's make the junction at R=15 pixel and check the result with the 
following commands:
+To continue, let's remove the temporary directory and re-run the script but 
with @option{--quiet} mode so we can put the output in a shell variable.
 
 @example
-$ astscript-psf-create-junction outer/stack.fits \
-           --core=inner/stack.fits --radius=15 \
-           --fluxfactor=98.9177 --output=psf-complete.fits
-$ ds9 psf-complete.fits
+$ rm -r stack_psfmodelscalefactor
+$ scale=$(astscript-psf-scale-factor outer/stack.fits \
+                   --psf=inner/stack.fits --center=501,501 \
+                   --mode=img --normradii=10,15 --quiet)
+$ echo $scale
 @end example
 
-The selection of the @option{--normradii} is something that has to be explored 
from the visual inspection of the radial profiles as well as the images.
-Our best advice is that the final selection of this normalization and junction 
radius is something that has to be explored.
-So, take your time to play with different values to check how the junction 
changes.
-A good junction radius is that let no saturation in the central part, high 
signal to noise ratio in the outer part, and creates a smooth transition in 
between the two parts.
-For example, check that the values used above @option{--normradii=15,16} and 
@option{--radius=15} makes a good junction (it is almost impossible to see the 
transition in the final PSF).
-With the goal of make the search of the junction radius easier, you can use 
the commands below.
-Check for example that the junction at different radius (R=50) is not a good 
option (compared with the result we have obtained above).
+Now that we know the scaling factor, we are ready to unite the outer and the 
inner part of the PSF.
+To do that, we will use the script @file{astscript-psf-unite} with the command 
below (for more on this script, see @ref{Invoking astscript-psf-unite}).
+The basic parameters are the inner part of the PSF (given to 
@option{--inner}), the inner part's scale factor (@option{--scale}), and the 
junction radius (@option{--radius}).
+The inner profile is first scaled, and all the pixels of the outer image 
within the given radius are replaced with the pixels of the inner image.
+Since the flux factor was computed for a ring of pixels between 10 and 15 
pixels, let's set the junction radius to be 12 pixels (roughly in between 10 
and 15):
 
 @example
-$ RI=50
-$ RO=51
-$ mkdir junction-radius-test
+$ astscript-psf-unite outer/stack.fits \
+           --inner=inner/stack.fits --radius=12 \
+           --scale=$scale --output=psf.fits
+@end example
 
-$ astscript-psf-model-flux-factor outer/stack.fits \
-           --psf=inner/stack.fits --center=250,250 \
-           --mode=img --normradii=$RI,$RO \
-           --segment=label/67510-seg.fits \
-           --output=junction-radius-test/ffactor-$RI-$RO.txt
+@noindent
+Let's have a look at the outer stack and the final PSF with the command below.
+Since we want several other DS9 settings to help you directly see the main 
point, we are using @option{--ds9extra}.
+After DS9 is opened, you can see that the center of the PSF has now been 
nicely filled.
+You can click on the ``Edit'' button and then the ``Colorbar'' and hold your 
cursor over the image and move it.
+You can see that besides filling the inner regions nicely, there is also no 
major discontinuity in the 2D image around the union radius of 12 pixels around 
the center.
 
-$ ffactor=$(cat junction-radius-test/ffactor-$RI-$RO.txt)
-$ astscript-psf-create-junction outer/stack.fits \
-           --core=inner/stack.fits --radius=$RI --fluxfactor=$ffactor \
-           --output=junction-radius-test/joined-$RI-$RO.fits
+@example
+$ astscript-fits-view outer/stack.fits psf.fits --ds9scale=minmax \
+           --ds9extra="-scale limits 0 22000 -match scale" \
+           --ds9extra="-lock scale yes -zoom 4 -scale log"
+@end example
 
-$ ds9 psf-complete.fits junction-radius-test/joined-$RI-$RO.fits
+Noting demonstrates the effect of a bad analysis, then actually seeing a bad 
result!
+So let's choose a bad normalization radial range (50 to 60 pixels) and unite 
the inner and outer parts based on that.
+The last command will open the two PSFs together in DS9, you should be able to 
immediately see the discontinuity in the union radius.
+
+@example
+$ scale=$(astscript-psf-scale-factor outer/stack.fits \
+                   --psf=inner/stack.fits --center=501,501 \
+                   --mode=img --normradii=50,60 --quiet)
+
+$ astscript-psf-unite outer/stack.fits \
+           --inner=inner/stack.fits --radius=55 \
+           --scale=$scale --output=psf-bad.fits
+
+$ astscript-fits-view psf-bad.fits psf.fits --ds9scale=minmax \
+           --ds9extra="-scale limits 0 50 -match scale" \
+           --ds9extra="-lock scale yes -zoom 4 -scale log"
 @end example
 
-Now that the complete PSF has been obtained, let's remove non necessary files 
and continue with the modeling and the subtraction of the stars.
+As you see, the selection of the normalization radii is very important.
+The first time you are trying to build the PSF of a new dataset, it has to be 
explored with a visual inspection of the images and radial profiles.
+Once you have found a good normalization radius for a certain part of the PSF 
in a survey, you can generally use it comfortably without change.
+But for a new survey, or a different part of the PSF, be sure to repeat the 
visual checks above to choose the best radii.
+As a summary, a good junction radius is one that:
+
+@itemize
+@item
+Is large enough to not let saturation and non-linearity (from the outer 
profile) into the inner region.
+@item
+Is small enough to have a sufficiently high signal to noise ratio (from the 
inner profile)to avoid adding noise in the union radius.
+@end itemize
+
+Now that the complete PSF has been obtained, let's remove that bad-looking 
PSF, and stick with the nice and clean PSF for the next step in 
@ref{Subtracting the PSF}.
 
 @example
-$ rm -rf junction-radius-test
+$ rm -rf psf-bad.fits
 @end example
 
 @node Subtracting the PSF,  , Uniting the different PSF components, Building 
the extended PSF
 @subsection Subtracting the PSF
-In the previous sections we have constructed a complete PSF.
-Now we are going to use it for modeling and subtracting each individual star.
-By construction, the pixel values of the PSF came from the normalization of 
the individual stamps.
-As a consequence, when modeling each individual star, it is necessary to 
compute what is the factor by which the PSF has to be scaled.
-This is done with the script @file{astscript-psf-model-flux-factor} (for more 
on this script, see @ref{Invoking astscript-psf-model-flux-factor}).
-Essentially, this step is the same than the calculation of the flux factor 
described above in @ref{Uniting the different PSF components}.
-The difference is that now we are not aiming to join two different PSF parts 
but looking for the flux factor that match the star with the PSF.
-Then, we will use the script @file{astscript-psf-model-scattered-light} for 
allocating the PSF image at the desired coordinates within the appropriate grid.
-Finally, once the star have been modeled by the PSF, we will subtract it.
-
-Let's make the model and subtraction for one single star first.
+Previously (in @ref{Uniting the different PSF components}) we constructed a 
full PSF, from the central pixel to a radius of 500 pixels.
+Now, let's use the PSF to subtract the scattered light from each individual 
star in the image.
+
+By construction, the pixel values of the PSF came from the normalization of 
the individual stamps (that were created for stars of different magnitudes).
+As a consequence, it is necessary to compute a scale factor to fit that PSF 
image to each star.
+This is done with the same @file{astscript-psf-scale-factor} command that we 
used previously in @ref{Uniting the different PSF components}.
+The difference is that now we are not aiming to join two different PSF parts 
but looking for the necessary scale factor to match the star with the PSF.
+Afterwards, we will use @file{astscript-psf-subtract} for placing the PSF 
image at the desired coordinates within the same pixel grid as the image.
+Finally, once the stars have been modeled by the PSF, we will subtract it.
+
+First, let's start with a single star.
 Later, when the basic idea has been explained, we will generalize the method 
for any number of stars.
-With the following command we obtain the coordinates (RA and DEC) and 
magnitude of the second brightnest star in the catalog we obtained previously 
(the first one is just at the border of the image).
+With the following command we obtain the coordinates (RA and DEC) and 
magnitude of the brightest star in the image (which is on the top edge of the 
image):
 
 @example
-$ asttable gaia.fits --sort phot_g_mean_mag \
-           --column=ra,dec,phot_g_mean_mag --head 2
+$ mkdir single-star
+$ center=$(asttable flat/67510-bright.fits --sort phot_g_mean_mag \
+                    --column=ra,dec --head 1 \
+                    | awk '@{printf "%s,%s", $1, $2@}')
+$ echo $center
 @end example
 
 With the center position of that star, let's obtain the flux factor using the 
same normalization ring we used for the creation of the outer part of the PSF:
 
 @example
-$ mkdir single-star
-$ astscript-psf-model-flux-factor label/67510-seg.fits \
-           --mode=wcs \
-           --normradii=20,30 \
-           --psf=psf-complete.fits \
-           --segment=label/67510-seg.fits \
-           --center=202.98395469814,47.234397688023 \
-           --output=single-star/fluxfactor.txt
+$ scale=$(astscript-psf-scale-factor label/67510-seg.fits \
+                   --mode=wcs --quiet\
+                   --psf=psf.fits \
+                   --center=$center \
+                   --normradii=10,15 \
+                   --segment=label/67510-seg.fits)
 @end example
 
 Now we have all the information necessary to model the star using the PSF: the 
position on the sky and the flux factor.
-Let's use this data with the script @file{astscript-psf-model-scattered-light} 
for modeling this star and have a look with DS9.
+Let's use this data with the script @file{astscript-psf-subtract} for modeling 
this star and have a look with DS9.
 
 @example
-$ fluxfactor=$(cat single-star/fluxfactor.txt)
-$ astscript-psf-model-scattered-light label/67510-seg.fits \
-          --mode=wcs \
-          --psf=psf-complete.fits \
-          --fluxfactor=$fluxfactor \
-          --center=202.98395469814,47.234397688023 \
-          --output=single-star/star-2.fits
-
-$ ds9 label/67510-seg.fits single-star/star-2.fits
+$ astscript-psf-subtract label/67510-seg.fits \
+           --mode=wcs \
+           --psf=psf.fits \
+           --scale=$scale \
+           --center=$center \
+           --output=single-star/subtracted.fits
+$ astscript-fits-view label/67510-seg.fits single-star/subtracted.fits
 @end example
 
 The result is the complete PSF situated in the sky position we have provided 
(RA, DEC) with the flux specified by the flux factor value.
@@ -6270,7 +6296,7 @@ $ mkdir models/stars
 $ mkdir models/fluxes
 $ asttable outer/67510-6-10.fits \
            | while read -r ra dec mag; do
-              astscript-psf-model-flux-factor label/67510-seg.fits \
+              astscript-psf-scale-factor label/67510-seg.fits \
                    --mode=wcs \
                    --center=$ra,$dec \
                    --normradii=20,30 \
@@ -6280,7 +6306,7 @@ $ asttable outer/67510-6-10.fits \
 
               fluxfactor=$(cat models/fluxes/flux-$counter.txt)
 
-              astscript-psf-model-scattered-light label/67510-seg.fits \
+              astscript-psf-subtract label/67510-seg.fits \
                    --mode=wcs \
                    --center=$ra,$dec \
                    --psf=psf-complete.fits \
@@ -24651,9 +24677,9 @@ The initial DS9 window geometry (value to DS9's 
@option{-geometry} option).
 @section PSF construction and subtraction
 
 @c Alternative names
-@c astscript-psf-create-select-stars  --> astscript-psf-select
-@c astscript-psf-create-make-stamp    --> astscript-psf-stamp
-@c astscript-psf-create-junction      --> astscript-psf-unite
+@c astscript-psf-select-stars  --> astscript-psf-select
+@c astscript-psf-stamp    --> astscript-psf-stamp
+@c astscript-psf-unite      --> astscript-psf-unite
 
 The point spread function (PSF) describes how the light of a point-like source 
is affected by several optical scattering effects (atmosphere, telescope, 
instrument, etc.).
 The role of the PSF is key in astronomical analysis (for small and large 
objects), and consequently, having a good characterization of the PSF is 
fundamental.
@@ -24667,14 +24693,14 @@ Furthermore, before going into the technical details 
of each script, in a specif
 
 @menu
 * Overview of the PSF scripts::  Summary of concepts and methods
-* Invoking astscript-psf-create-select-stars::  Select good starts within an 
image.
-* Invoking astscript-psf-create-make-stamp::  Make a stamp of each star to 
stack.
-* Invoking astscript-psf-create-junction::  Merge stacks of different regions 
of PSF.
-* Invoking astscript-psf-model-flux-factor::  Calculate factor to scale PSF to 
star.
-* Invoking astscript-psf-model-scattered-light::  Put the PSF in the image to 
subtract.
+* Invoking astscript-psf-select-stars::  Select good starts within an image.
+* Invoking astscript-psf-stamp::  Make a stamp of each star to stack.
+* Invoking astscript-psf-unite::  Merge stacks of different regions of PSF.
+* Invoking astscript-psf-scale-factor::  Calculate factor to scale PSF to star.
+* Invoking astscript-psf-subtract::  Put the PSF in the image to subtract.
 @end menu
 
-@node Overview of the PSF scripts, Invoking astscript-psf-create-select-stars, 
PSF construction and subtraction, PSF construction and subtraction
+@node Overview of the PSF scripts, Invoking astscript-psf-select-stars, PSF 
construction and subtraction, PSF construction and subtraction
 @subsection Overview of the PSF scripts
 The fundamental ideas of the following methodology are thoroughly described in 
Infante-Sainz et al. (2020, @url{https://arxiv.org/abs/1911.01430}).
 Once the PSF has been obtained, it can be scaled to the magnitude of the 
point-like sources to subtract.
@@ -24688,11 +24714,11 @@ In general, not all stars are good to construct a PSF.
 For example we don't want contamination from other bright, and nearby objects.
 The first script below is therefore designed for selecting only good candidate 
stars in your image.
 It will use different criteria, for example good parallax (where available, to 
avoid confusion with galaxies), not near bright stars, axis ratio, etc.
-For more on this script, see @ref{Invoking astscript-psf-create-select-stars}.
+For more on this script, see @ref{Invoking astscript-psf-select-stars}.
 
 Once the catalog of stars is constructed, another script is in charge of 
making appropiate stamps of the stars.
 Each stamp is a cropped image of the star with the desired size, normalization 
of the flux, and mask of the contaminant objects.
-For more on this script, see @ref{Invoking astscript-psf-create-make-stamp}
+For more on this script, see @ref{Invoking astscript-psf-stamp}
 After obtaining a set of star stamps, they can be stacked for obtaining the 
combined PSF from many stars (for example with @ref{Stacking operators}).
 
 In the combined PSF, the masked background objects of each star's image will 
be covered and the signal-to-noise ratio will increase, giving a very nice view 
of the ``clean'' PSF.
@@ -24706,15 +24732,15 @@ For example, in Infante-Sainz et al. (2020, 
@url{https://arxiv.org/abs/1911.0143
 In other cases, we even needed four groups of stars!
 Once clean stacks of different parts of the PSF have been constructed through 
the steps above, it is therefore necessary to blend them all into one.
 This is done by finding a common radial region in both, and scaling the inner 
region by a factor to add with the outer region.
-This is not trivial, therefore, a third script is in charge of it, see 
@ref{Invoking astscript-psf-create-junction}.
+This is not trivial, therefore, a third script is in charge of it, see 
@ref{Invoking astscript-psf-unite}.
 
 Having constructed the PSF as described above (or by any other procedure), it 
can be scaled to the brightness of the various stars in the image to get 
subtracted (and thus remove the extended/bright wings; better showing the 
background objects of interest).
 Note that the absolute flux of a PSF is meaningless (and in fact, it is 
usually normalized to have a total sum of unity!), so it should be scaled.
 We therefore have another script that will calculate the scale 
(multiplication) factor of the PSF for each star.
-For more on the scaling script, see @ref{Invoking 
astscript-psf-model-flux-factor}.
+For more on the scaling script, see @ref{Invoking astscript-psf-scale-factor}.
 
 Once the flux factor has been computed, a final script is in charge of placing 
the scaled PSF over the proper location in the image and subtract it.
-For more on the scaling and positioning script, see @ref{Invoking 
astscript-psf-model-scattered-light}.
+For more on the scaling and positioning script, see @ref{Invoking 
astscript-psf-subtract}.
 
 As mentioned above, in the following sections, each script has its own 
documentation and list of options for very detailed customization (if 
necessary).
 But before going into them, we continue with a practical tutorial to show the 
usage of scripts in practice; see the tutorial @ref{Building the extended PSF}.
@@ -24723,8 +24749,8 @@ But before going into them, we continue with a 
practical tutorial to show the us
 
 
 
-@node Invoking astscript-psf-create-select-stars, Invoking 
astscript-psf-create-make-stamp, Overview of the PSF scripts, PSF construction 
and subtraction
-@subsection Invoking astscript-psf-create-select-stars
+@node Invoking astscript-psf-select-stars, Invoking astscript-psf-stamp, 
Overview of the PSF scripts, PSF construction and subtraction
+@subsection Invoking astscript-psf-select-stars
 This installed script will select good star candidates for constructing a PSF.
 It will consider stars within a given range of brightness without nearby 
contaminant objects.
 To do that, it allows to the user to specify different options.
@@ -24732,7 +24758,7 @@ To do that, it allows to the user to specify different 
options.
 This script can be used with the following general template:
 
 @example
-$ astscript-psf-create-select-stars [OPTION...] FITS-file
+$ astscript-psf-select-stars [OPTION...] FITS-file
 @end example
 
 @noindent
@@ -24741,7 +24767,7 @@ Examples:
 @example
 ## From the Gaia select the stars in the range of magnitude
 ## between '7' and '9', which overlap with input image.
-$ astscript-psf-create-select-stars image.fits --hdu=1 \
+$ astscript-psf-select-stars image.fits --hdu=1 \
       --magnituderange=7,9 \
       --minaxisratio=0.9 \
       --mindistdeg=0.1 \
@@ -24752,7 +24778,7 @@ $ astscript-psf-create-select-stars image.fits --hdu=1 \
 
 ## Select the stars in the range of magnitude between
 ## 7 and 9 magnitudes from the input catalog.
-$ astscript-psf-create-select-stars image.fits --hdu=1 \
+$ astscript-psf-select-stars image.fits --hdu=1 \
     --catalog=starscatalog.fits \
     --magnituderange=7,9 \
     --minaxisratio=0.9 \
@@ -24865,15 +24891,15 @@ This option is useful for debugging and checking the 
steps of selecting stars.
 The output name of the final catalog containing good stars.
 @end table
 
-@node Invoking astscript-psf-create-make-stamp, Invoking 
astscript-psf-create-junction, Invoking astscript-psf-create-select-stars, PSF 
construction and subtraction
-@subsection Invoking astscript-psf-create-make-stamp
+@node Invoking astscript-psf-stamp, Invoking astscript-psf-unite, Invoking 
astscript-psf-select-stars, PSF construction and subtraction
+@subsection Invoking astscript-psf-stamp
 This installed script will read an image, the center of an object 
@option{--center}, the type of the center coordinates @option{--mode} (img or 
wcs), the normalization radii @option{--normradii}, and the size of the output 
stamp @option{--stampwidth}.
 With that input, it will generate a stamp centered at the coordinates 
provided, and normalized by the flux computed in the normalization radius.
 
 This script can be used with the following general template:
 
 @example
-$ astscript-psf-create-make-stamp [OPTION...] FITS-file
+$ astscript-psf-stamp [OPTION...] FITS-file
 @end example
 
 @noindent
@@ -24882,14 +24908,14 @@ Examples:
 @example
 ## Make a stamp around (x,y)=(53,69) of width=151 pixels.
 ## Normalize the stamp within the radii 20 and 30 pixels.
-$ astscript-psf-create-make-stamp image.fits --mode=img \
+$ astscript-psf-stamp image.fits --mode=img \
       --center=53,69 --stampwidth=151 --normradii=20,30 \
       --output=stamp.fits
 
 ## Iterate over a catalog with positions of stars that are
 ## in the the input image. Use WCS coordinates.
 $ asttable catalog.fits | while read -r ra dec mag; do \
-    astscript-psf-create-make-stamp image.fits \
+    astscript-psf-stamp image.fits \
         --mode=wcs \
         --stampwidth=150 \
         --center=$ra,$dec \
@@ -25012,8 +25038,8 @@ The main reason of setting this name is to have an 
unique name for each stamp by
 
 
 
-@node Invoking astscript-psf-create-junction, Invoking 
astscript-psf-model-flux-factor, Invoking astscript-psf-create-make-stamp, PSF 
construction and subtraction
-@subsection Invoking astscript-psf-create-junction
+@node Invoking astscript-psf-unite, Invoking astscript-psf-scale-factor, 
Invoking astscript-psf-stamp, PSF construction and subtraction
+@subsection Invoking astscript-psf-unite
 This installed script will join two PSF images at a given radius.
 This operation is commonly used when the outer part of the PSF has been 
computed from very bright stars, and consequently, they are saturated in most 
central part (core).
 In order to have an extended but not saturated PSF in the core, it is 
necessary to put in the central part the PSF constructed from fainter stars.
@@ -25022,7 +25048,7 @@ This is the main goal of the current script.
 This script can be used with the following general template:
 
 @example
-$ astscript-psf-create-junction [OPTION...] FITS-file
+$ astscript-psf-unite [OPTION...] FITS-file
 @end example
 
 @noindent
@@ -25031,13 +25057,13 @@ Examples:
 @example
 ## Multiply inner.fits by 3 and put it in the center of
 ## outer.fits. The core goes up to a radius of 25 pixels.
-$ astscript-psf-create-junction outer.fits \
+$ astscript-psf-unite outer.fits \
       --core=inner.fits --fluxfactor=3 \
       --radius=25 --output=joined.fits
 
 ## Same example than the above, but considering an
 ## ellipse (instead of a circle).
-$ astscript-psf-create-junction outer.fits \
+$ astscript-psf-unite outer.fits \
       --core=inner.fits --fluxfactor=3 \
       --radius=25 --axisratio=0.5 \
       --positionangle=40 --output=joined.fits
@@ -25077,7 +25103,7 @@ Radius (in pixels) at which the junction of the images 
is done.
 @itemx --fluxfactor=FLT
 Factor by which the core (@option{--core}) is multiplied.
 This factor is necessary to put the two different parts of the PSF at the same 
flux level.
-A convenient way of obtaining this value is by using the script 
@file{astscript-model-flux-factor}, see @ref{Invoking 
astscript-psf-model-flux-factor}.
+A convenient way of obtaining this value is by using the script 
@file{astscript-model-scale-factor}, see @ref{Invoking 
astscript-psf-scale-factor}.
 
 @item -Q FLT
 @itemx --axisratio=FLT
@@ -25108,19 +25134,14 @@ This option is useful for debugging.
 
 
 
-@node Invoking astscript-psf-model-flux-factor, Invoking 
astscript-psf-model-scattered-light, Invoking astscript-psf-create-junction, 
PSF construction and subtraction
-@subsection Invoking astscript-psf-model-flux-factor
-This installed script will consider an object within the input image and it 
will obtain the radial profile of that object.
-In the same way, it will compute the radial profile of a given PSF image.
-Then, by comparing the two radial profiles in the same region, it will 
calculate the factor by which it is necessary to multiply the PSF image in 
order to scale it at the same level of flux than the object.
-
-The computation of this flux factor is commonly used when joining two 
different parts of the same PSF, see @ref{Invoking 
astscript-psf-create-junction}.
-Also when modeling a star in order to subtract it using the PSF, see 
@ref{Invoking astscript-psf-model-scattered-light}.
+@node Invoking astscript-psf-scale-factor, Invoking astscript-psf-subtract, 
Invoking astscript-psf-unite, PSF construction and subtraction
+@subsection Invoking astscript-psf-scale-factor
+This installed script will find the multiplication (scale) factor to multiply 
with a PSF image in order to scale it to a star within another image (the 
coordinates of the star in the different image should be given).
 
 This script can be used with the following general template:
 
 @example
-$ astscript-psf-model-flux-factor [OPTION...] FITS-file
+$ astscript-psf-scale-factor [OPTION...] FITS-file
 @end example
 
 @noindent
@@ -25129,13 +25150,13 @@ Examples:
 @example
 ## Compute the flux factor for the object at (x,y)=(53,69) for
 ## the PSF (psf.fits). Compute it in the ring 20-30 pixels.
-$ astscript-psf-model-flux-factor image.fits --mode=img \
+$ astscript-psf-scale-factor image.fits --mode=img \
       --center=53,69 --normradii=20,30 --psf=psf.fits
 
 ## Iterate over a catalog with positions of stars that are
 ## in the the input image to compute their flux factors.
 $ asttable catalog.fits | while read -r ra dec mag; do \
-    astscript-psf-model-flux-factor image.fits \
+    astscript-psf-scale-factor image.fits \
         --mode=wcs \
         --psf=psf.fits \
         --center=$ra,$dec \
@@ -25143,10 +25164,28 @@ $ asttable catalog.fits | while read -r ra dec mag; 
do \
 
 @end example
 
-The input is an image from which the star is considered.
-The output will be the flux factor: the value by which the PSF image 
(@option{--psf}) has to be multiplied to put it at the same level than the 
object specified (@option{--center}), within the ring of pixels specified by 
the option @option{--normradii}.
-More options are available with the goal of obtaining a good flux factor value.
-A full description of each option is given below.
+The input should be an image containing the star that you want to scale with 
the PSF.
+The output will be a single number that is printed on the command-line.
+That number is the multiplication factor to multiply with the PSF image 
(@option{--psf}) to scale it with the given star (which is located in 
@option{--center} of the input image).
+The scale factor will be calculated within the ring of pixels specified by the 
option @option{--normradii}.
+
+All the pixels within this ring will be separated from both the PSF and input 
images.
+For the input image, around the selected coordinate; while masking all other 
sources (see @option{--segment}).
+The finally selected pixels of the input image will then be divided by those 
of the PSF image.
+This gives us an image containing one scale factor per pixel.
+The finally reported value is the sigma-clipped median of all the scale 
factors in the finally-used pixels.
+To fully understand the process, we recommend running this script once with 
@option{--keeptmp} and inspect the files inside of it.
+
+The most common use-cases of this scale factor are:
+@enumerate
+@item
+To find the factor for joining two different parts of the same PSF, see 
@ref{Invoking astscript-psf-unite}.
+@item
+When modeling a star in order to subtract it using the PSF, see @ref{Invoking 
astscript-psf-subtract}.
+@end enumerate
+
+For a full tutorial on how to use this script along with the other 
@command{astscript-psf-*} scripts in Gnuastro, please see @ref{Building the 
extended PSF}.
+To allow full customizability, the following options are available with this 
script.
 
 @table @option
 
@@ -25163,97 +25202,64 @@ 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 -c FLT[,FLT[,...]]
+@itemx --center=FLT[,FLT[,...]]
+The central position of the object to scale with the PSF.
+This parameter is used in @ref{Crop} to center and crop the image.
+The positions along each dimension must be separated by a comma (@key{,}).
+The units of the coordinates are read based on the value to the 
@option{--mode} option (see below).
 
 @item -O STR
 @itemx --mode=STR
 Interpret the center position of the object (values given to 
@option{--center}) in image or WCS coordinates.
 This option thus accepts only two values: @option{img} or @option{wcs}.
 
-@item -c FLT[,FLT[,...]]
-@itemx --center=FLT[,FLT[,...]]
-The central position of the object.
-This parameter is used in @ref{Crop} to center and crop the image.
-The positions along each dimension must be separated by a comma (@key{,}).
-The units of the coordinates are read based on the value to the 
@option{--mode} option, see above.
+@item -n INT,INT
+@itemx --normradii=INT,INT
+Inner and outer radii (in units of pixels) around the central position in 
which the flux factor is computed.
+The option takes two values separated by a comma (@key{,}).
+The first value is the inner radius, the second is the outer radius.
+These two radius define a ring of pixels around the center that is used for 
obtaining the flux factor value.
 
 @item -W INT
 @itemx --stampwidth=INT
 Size (width) of the image stamp in pixels.
 This is an intermediate product computed internally by the script.
-By default, the size of the stamp is automatically set to be as small as 
possible (i.e., two times the external radius of the ring specified by 
@option{--rnorm}) to make the computation fast.
-As a consequence, this option is only relevant for checking and testing that 
everything is fine.
-
-@item -n INT[,INT[,...]]
-@itemx --normradii=INT[,INT[,...]]
-Region around the central position in which the flux factor is computed.
-The option takes two values separated by a comma (@key{,}).
-The first value is the inner radius, the second is the outer radius.
-These two radius define a ring of pixels around the center that is used for 
obtaining the flux factor value.
+By default, the size of the stamp is automatically set to be as small as 
possible (i.e., two times the external radius of the ring specified by 
@option{--normradii}) to make the computation fast.
+As a consequence, this option is only relevant for checking and testing that 
everything is fine (debugging).
 
 @item -S STR
 @itemx --segment=STR
-Filename of a segmentation image from Segment's output.
+Filename of a segmentation image from Segment's output (see @ref{Segment}).
 This image is used to mask all objects that are not the central clump/object.
-The script computes an internal mask that combine the objects and clumps to 
mask all objects that do not correspond to the central one.
-All clumps of the central object that are not the central clump are also 
masked.
-The result is that all objects and clumps that contaminate the central source 
are masked.
-The size of the region that is used for identifying the central clump/object 
can be specified by the option @option{--corewidth}, see below.
+To obtain an accurate scale factor, it is important to mask all such sources.
+All ``clumps'' of the central object that are not the central clump are also 
masked.
+Similarly, all ``objects'' that are not the central object will be masked.
+As a result, all objects and clumps that contaminate the central source are 
masked.
+The size of the region that is used for identifying the central clump/object 
can be specified by the option @option{--corewidth} (see below).
 
 @item -w INT
 @itemx --corewidth=INT
-Width of the region that is used to compute the central clump/object over the 
segmentation image @option{--segment}, with the goal of not masking them.
-If a segmentation image is provided, then it is necessary to not mask the 
central object.
-To do that, a central region is considered in order to compute the values of 
the central object on the segmentation image.
-Once it has been identified, that pixels are not masked.
-With this option, it is possible to control the size of the central region for 
computing the central object label (on the segmentation image).
-
-@item -R FLT
-@itemx --rmax=FLT
-By default, the radial profile will be computed up to a radial distance equal 
to the outer radius of the normalization region (@option{--normradii}).
-If the user wants to compute larger radial profile it is possible with this 
option.
-Situations in which this option is necessary are those in which the user wants 
to check individual radial profiles to ensure everything is fine.
-To be able to check the radial profile use the option @option{--keeptmp} to 
not delete temporary files, see below.
-
-@item -N STR
-@itemx --normop=STR
-The operator for measuring the values within the ring defined by the option 
@option{--normradii}.
-The operator given to this option will be directly passed to the radial 
profile script @file{astscript-radial-profile}, see @ref{Generate radial 
profile}.
-As a consequence, all MakeCatalog measurements (median, mean, sigclip-mean, 
sigclip-number, etc.) can be used here.
-For a full list of MakeCatalog's measurements, please run 
@command{astmkcatalog --help}.
-In the same way, this operator is used to compute the final flux factor value.
-This calculation is done by dividing the two radial profiles (object and PSF) 
and then taking the averaged value using this operator.
+Width of the region that is used to find the central clump/object label over 
the segmentation image given to @option{--segment} (with the goal of not 
masking them).
+The default size is @code{3}, which should generally be sufficient.
+It is rarely necessary to change this value.
 
 @item -s FLT,FLT
 @itemx --sigmaclip=FLT,FLT
-Sigma clipping parameters: only relevant if sigma-clipping operators are 
requested by @option{--normop}.
+Sigma clipping parameters used in the end to find the final scale factor from 
the distribution of all pixels used.
 For more on sigma-clipping, see @ref{Sigma clipping}.
 
 @item -t STR
 @itemx --tmpdir=STR
 Several intermediate files are necessary to obtain the flux factor value.
-All of these temporal files are saved into a temporal directory.
-With this option, you can directly specify this directory.
+All of these temporary files are saved into a temporary directory.
+With this option, you can directly specify the name of this directory.
 By default (when this option isn't called), it will be built in the running 
directory and given an input-based name.
+Therefore, within a larger project, it is recommended to manually set this in 
your desired location with your desired name (to avoid conflicting with other 
instances of this script that may be run together in parallel).
+
 If the directory doesn't exist at run-time, this script will create it.
-Once all temporal files are not necessary, this directory is removed.
-You can disable the deletion of the temporary directory with the 
@option{--keeptmp} option, see below.
+Once the script finishes, this directory is removed.
+To help debugging/understanding the output value, you can disable the deletion 
of the temporary directory with the @option{--keeptmp} option and inspect all 
the temporary files (see below).
 
 @item -k
 @itemx --keeptmp
@@ -25265,15 +25271,15 @@ For example, to check that the intermediate images 
have the desired center, they
 
 
 
-@node Invoking astscript-psf-model-scattered-light,  , Invoking 
astscript-psf-model-flux-factor, PSF construction and subtraction
-@subsection Invoking astscript-psf-model-scattered-light
+@node Invoking astscript-psf-subtract,  , Invoking astscript-psf-scale-factor, 
PSF construction and subtraction
+@subsection Invoking astscript-psf-subtract
 This installed script will put the PSF provided into a given position of the 
sky within the input image.
 It is aimed to model the scattered light field of an input image.
 
 This script can be used with the following general template:
 
 @example
-$ astscript-psf-model-scattered-light [OPTION...] FITS-file
+$ astscript-psf-subtract [OPTION...] FITS-file
 @end example
 
 @noindent
@@ -25282,7 +25288,7 @@ Examples:
 @example
 ## Multiply the the PSF (psf.fits) by 3 and put it into the the
 ## pixel position (x,y)=(53,69) of the input image (image.fits).
-$ astscript-psf-model-scattered-light image.fits \
+$ astscript-psf-subtract image.fits \
     --psf=psf.fits \
     --mode=img \
     --fluxfactor=3 \
@@ -25293,7 +25299,7 @@ $ astscript-psf-model-scattered-light image.fits \
 ## in the the input image. Use WCS coordinates.
 $ asttable catalog.fits | while read -r ra dec mag; do
          fluxfactor=$(cat fluxfactor-"$ra"_"$dec".txt)
-         astscript-psf-model-scattered-light image.fits \
+         astscript-psf-subtract image.fits \
              --mode=wcs \
              --psf=psf.fits \
              --fluxfactor=$fluxfactor \
@@ -25341,7 +25347,7 @@ The units of the coordinates are read based on the 
value to the @option{--mode}
 @itemx --fluxfactor=FLT
 Factor by which the PSF (@option{--psf}) is multiplied.
 This factor is necessary to put the PSF with the desired flux level.
-A convenient way of obtaining this value is by using the script 
@file{astscript-model-flux-factor}, see @ref{Invoking 
astscript-psf-model-flux-factor}.
+A convenient way of obtaining this value is by using the script 
@file{astscript-model-scale-factor}, see @ref{Invoking 
astscript-psf-scale-factor}.
 
 @item -t STR
 @itemx --tmpdir=STR
diff --git a/tests/Makefile.am b/tests/Makefile.am
index c4b74b3e..b4de5606 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -206,23 +206,22 @@ if COND_WARP
 endif
 
 # Script tests.
-SCRIPT_TESTS = script/sort-by-night.sh \
+SCRIPT_TESTS = script/psf-unite.sh \
+               script/psf-stamp.sh \
+               script/psf-subtract.sh \
+               script/sort-by-night.sh \
                script/radial-profile.sh \
-               script/psf-create-junction.sh \
-               script/psf-create-make-stamp.sh \
-               script/psf-model-flux-factor.sh \
-               script/psf-create-select-stars.sh \
-               script/psf-model-scattered-light.sh
+               script/psf-scale-factor.sh \
+               script/psf-select-stars.sh
 
 # We want to have several FITS files as input for this script.
-script/sort-by-night.sh: mkcatalog/aperturephot.sh.log
+script/psf-unite.sh: mkprof/mosaic2.sh.log
+script/psf-stamp.sh: mkprof/mosaic2.sh.log
+script/psf-subtract.sh: mkprof/mosaic2.sh.log
 script/radial-profile.sh: mkprof/mosaic2.sh.log
-script/psf-create-junction.sh: mkprof/mosaic2.sh.log
-script/psf-create-make-stamp.sh: mkprof/mosaic2.sh.log
-script/psf-model-flux-factor.sh: mkprof/mosaic2.sh.log
-script/psf-create-select-stars.sh: segment/segment.sh.log
-script/psf-model-scattered-light.sh: mkprof/mosaic2.sh.log
-
+script/psf-scale-factor.sh: mkprof/mosaic2.sh.log
+script/psf-select-stars.sh: segment/segment.sh.log
+script/sort-by-night.sh: mkcatalog/aperturephot.sh.log
 
 
 # Environment variables for the test scripts.
diff --git a/tests/script/psf-model-flux-factor.sh 
b/tests/script/psf-scale-factor.sh
similarity index 98%
rename from tests/script/psf-model-flux-factor.sh
rename to tests/script/psf-scale-factor.sh
index d83ace2c..413c1ec0 100755
--- a/tests/script/psf-model-flux-factor.sh
+++ b/tests/script/psf-scale-factor.sh
@@ -24,7 +24,7 @@
 # Set the variables (the executable is in the build tree). Do the
 # basic checks to see if the executable is made or if the defaults
 # file exists (basicchecks.sh is in the source tree).
-prog=psf-model-flux-factor
+prog=psf-scale-factor
 execname=../bin/script/astscript-$prog
 
 fits1name=mkprofcat1.fits
diff --git a/tests/script/psf-create-select-stars.sh 
b/tests/script/psf-select-stars.sh
similarity index 98%
rename from tests/script/psf-create-select-stars.sh
rename to tests/script/psf-select-stars.sh
index bdfb1163..039b9ad4 100755
--- a/tests/script/psf-create-select-stars.sh
+++ b/tests/script/psf-select-stars.sh
@@ -24,7 +24,7 @@
 # Set the variables (the executable is in the build tree). Do the
 # basic checks to see if the executable is made or if the defaults
 # file exists (basicchecks.sh is in the source tree).
-prog=psf-create-select-stars
+prog=psf-select-stars
 execname=../bin/script/astscript-$prog
 
 dep1name=$progbdir/astmatch
diff --git a/tests/script/psf-create-make-stamp.sh b/tests/script/psf-stamp.sh
similarity index 98%
rename from tests/script/psf-create-make-stamp.sh
rename to tests/script/psf-stamp.sh
index a46deff2..dac978a6 100755
--- a/tests/script/psf-create-make-stamp.sh
+++ b/tests/script/psf-stamp.sh
@@ -24,7 +24,7 @@
 # Set the variables (the executable is in the build tree). Do the
 # basic checks to see if the executable is made or if the defaults
 # file exists (basicchecks.sh is in the source tree).
-prog=psf-create-make-stamp
+prog=psf-stamp
 execname=../bin/script/astscript-$prog
 
 fits1name=0_mkprofcat2.fits
diff --git a/tests/script/psf-model-scattered-light.sh 
b/tests/script/psf-subtract.sh
similarity index 96%
rename from tests/script/psf-model-scattered-light.sh
rename to tests/script/psf-subtract.sh
index 34d7b4e8..ea16fadc 100755
--- a/tests/script/psf-model-scattered-light.sh
+++ b/tests/script/psf-subtract.sh
@@ -24,7 +24,7 @@
 # Set the variables (the executable is in the build tree). Do the
 # basic checks to see if the executable is made or if the defaults
 # file exists (basicchecks.sh is in the source tree).
-prog=psf-model-scattered-light
+prog=psf-subtract
 execname=../bin/script/astscript-$prog
 
 fits1name=mkprofcat1.fits
@@ -74,4 +74,4 @@ export PATH="$progbdir:$PATH"
 x=$($dep1name $fits1name -h1 | awk '/^NAXIS1/{print $3/2}')
 y=$($dep1name $fits1name -h1 | awk '/^NAXIS2/{print $3/2}')
 $check_with_program $execname $fits1name --center=$x,$y --mode=img \
-                                         --psf=$fits1name --fluxfactor=3.3
+                                         --psf=$fits1name --scale=3.3
diff --git a/tests/script/psf-create-junction.sh b/tests/script/psf-unite.sh
similarity index 93%
rename from tests/script/psf-create-junction.sh
rename to tests/script/psf-unite.sh
index ebcab291..cb4fe4b5 100755
--- a/tests/script/psf-create-junction.sh
+++ b/tests/script/psf-unite.sh
@@ -24,7 +24,7 @@
 # Set the variables (the executable is in the build tree). Do the
 # basic checks to see if the executable is made or if the defaults
 # file exists (basicchecks.sh is in the source tree).
-prog=psf-create-junction
+prog=psf-unite
 execname=../bin/script/astscript-$prog
 
 fits1name=0_mkprofcat2.fits
@@ -69,5 +69,5 @@ if [ ! -f $fits1name ]; then echo "$fits1name doesn't 
exist."; exit 77; fi
 # Since we want the script to recognize the programs that it will use from
 # this same build of Gnuastro, we'll add the current directory to PATH.
 export PATH="$progbdir:$PATH"
-$check_with_program $execname $fits1name --core=$fits1name \
-                              --fluxfactor=3.3 --radius=5
+$check_with_program $execname $fits1name --inner=$fits1name \
+                              --scale=3.3 --radius=5



reply via email to

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