gnuastro-commits
[Top][All Lists]
Advanced

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

[gnuastro-commits] master ca8fc03a 55/69: PSF scripts: getting proper NA


From: Mohammad Akhlaghi
Subject: [gnuastro-commits] master ca8fc03a 55/69: PSF scripts: getting proper NAXIS values when data is compressed as .fz
Date: Wed, 26 Jan 2022 12:39:15 -0500 (EST)

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

    PSF scripts: getting proper NAXIS values when data is compressed as .fz
    
    Until this commit, if some of the input images were compressed as .fz
    files, the computation of the dimension of the images were not properly
    done. This is because it was reading the keywords NAXIS1 and NAXIS2.
    However, when the data is compressed, these keywords are not the original
    image dimensions but the dimensions of the table (data compressed).
    
    With this commit, this bug has been corrected. Now, the scripts read the
    keywords: ZNAXIS1, ZNAXIS2, NAXIS1, and NAXIS2. If ZNAXIS keyword values
    exist, then use them as the original image dimensions. Otherwise, the size
    will be computed from the normal NAXIS and NAXIS2 keywords.
---
 bin/script/psf-create-junction.in       | 47 ++++++++++++++++++++++++++-------
 bin/script/psf-model-scattered-light.in | 46 +++++++++++++++++++++++++-------
 2 files changed, 73 insertions(+), 20 deletions(-)

diff --git a/bin/script/psf-create-junction.in 
b/bin/script/psf-create-junction.in
index 32f189da..9982ae00 100644
--- a/bin/script/psf-create-junction.in
+++ b/bin/script/psf-create-junction.in
@@ -314,11 +314,29 @@ fi
 #
 # The center of the 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).
-xaxis=$(astfits $inputs --hdu=$hdu \
-                | awk '/^NAXIS1/{print $3}')
-yaxis=$(astfits $inputs --hdu=$hdu \
-               | awk '/^NAXIS2/{print $3}')
+# along the two axis (in pixels).  it is necessary to compute the original
+# size of the input image. It is possible that the input image is
+# compressed as '.fz' file. In these situations, the keywords with the
+# original dimesion of the array are ZNAXIS1 and ZNAXIS2, instead of NAXIS1
+# and NAXIS2. The former are the real size of the array (as it were not
+# compressed), the latter are the size after compressing the data (as a
+# table). If there are not ZNAXIS keywords, output values are "n/a". So,
+# they are removed with sed, and then count the number of remaining values.
+# Overall, when there are 4 remaining keywords, the data is compressed,
+# otherwise use the simple NAXIS1 and NAXIS2 keywords (that are always into
+# the header).
+axises=$(astfits $inputs --hdu=$hdu --quiet \
+                 --keyvalue ZNAXIS1,ZNAXIS2,NAXIS1,NAXIS2)
+naxises=$(echo $axises \
+               | sed 's/n\/a//g' \
+               | awk '{print NF}')
+if [ x$naxises = x4 ]; then
+    xaxis=$(echo $axises | awk '{print $1}')
+    yaxis=$(echo $axises | awk '{print $2}')
+else
+    xaxis=$(echo $axises | awk '{print $3}')
+    yaxis=$(echo $axises | awk '{print $4}')
+fi
 
 # To obtain the center of the PSF (in pixels), just divide by 2 the size of
 # the PSF image.
@@ -334,11 +352,20 @@ ycenter=$(astarithmetic $yaxis 2 / --quiet)
 #
 # The center of the core 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).
-xpsfaxis=$(astfits $core --hdu=$corehdu \
-                   | awk '/^NAXIS1/{print $3}')
-ypsfaxis=$(astfits $core --hdu=$corehdu \
-                  | awk '/^NAXIS2/{print $3}')
+# PSF image along the two axis (in pixels). Dimension values are computed
+# as described above.
+psfaxises=$(astfits $psf --hdu=$psfhdu --quiet \
+                    --keyvalue ZNAXIS1,ZNAXIS2,NAXIS1,NAXIS2)
+psfnaxises=$(echo $psfaxises \
+                  | sed 's/n\/a//g' \
+                  | awk '{print NF}')
+if [ x$psfnaxises = x4 ]; then
+    xpsfaxis=$(echo $psfaxises | awk '{print $1}')
+    ypsfaxis=$(echo $psfaxises | awk '{print $2}')
+else
+    xpsfaxis=$(echo $psfaxises | awk '{print $3}')
+    ypsfaxis=$(echo $psfaxises | awk '{print $4}')
+fi
 
 # To obtain the center of the PSF (in pixels), just divide by 2 the size of
 # the PSF image.
diff --git a/bin/script/psf-model-scattered-light.in 
b/bin/script/psf-model-scattered-light.in
index d2ef5db1..4d73609f 100644
--- a/bin/script/psf-model-scattered-light.in
+++ b/bin/script/psf-model-scattered-light.in
@@ -384,11 +384,28 @@ astarithmetic $psf --hdu=$psfhdu $fluxfactor x \
 # ----------------------------
 #
 # In order to have the final PSF with the same size than the input image,
-# it is necessary to compute the original size of the input image.
-xaxis=$(astfits $inputs --hdu=$hdu \
-                | awk '/^NAXIS1/{print $3}')
-yaxis=$(astfits $inputs --hdu=$hdu \
-               | awk '/^NAXIS2/{print $3}')
+# it is necessary to compute the original size of the input image. It is
+# possible that the input image is compressed as '.fz' file. In these
+# situations, the keywords with the original dimesion of the array are
+# ZNAXIS1 and ZNAXIS2, instead of NAXIS1 and NAXIS2. The former are the
+# real size of the array (as it were not compressed), the latter are the
+# size after compressing the data (as a table). If there are not ZNAXIS
+# keywords, output values are "n/a". So, they are removed with sed, and
+# then count the number of remaining values. Overall, when there are 4
+# remaining keywords, the data is compressed, otherwise use the simple
+# NAXIS1 and NAXIS2 keywords (that are always into the header).
+axises=$(astfits $inputs --hdu=$hdu --quiet \
+                 --keyvalue ZNAXIS1,ZNAXIS2,NAXIS1,NAXIS2)
+naxises=$(echo $axises \
+               | sed 's/n\/a//g' \
+               | awk '{print NF}')
+if [ x$naxises = x4 ]; then
+    xaxis=$(echo $axises | awk '{print $1}')
+    yaxis=$(echo $axises | awk '{print $2}')
+else
+    xaxis=$(echo $axises | awk '{print $3}')
+    yaxis=$(echo $axises | awk '{print $4}')
+fi
 
 
 
@@ -399,11 +416,20 @@ yaxis=$(astfits $inputs --hdu=$hdu \
 #
 # The center of the 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).
-xpsfaxis=$(astfits $psf --hdu=$psfhdu \
-                   | awk '/^NAXIS1/{print $3}')
-ypsfaxis=$(astfits $psf --hdu=$psfhdu \
-                  | awk '/^NAXIS2/{print $3}')
+# along the two axis (in pixels). Dimension values are computed as
+# described above.
+psfaxises=$(astfits $psf --hdu=$psfhdu --quiet \
+                    --keyvalue ZNAXIS1,ZNAXIS2,NAXIS1,NAXIS2)
+psfnaxises=$(echo $psfaxises \
+                  | sed 's/n\/a//g' \
+                  | awk '{print NF}')
+if [ x$psfnaxises = x4 ]; then
+    xpsfaxis=$(echo $psfaxises | awk '{print $1}')
+    ypsfaxis=$(echo $psfaxises | awk '{print $2}')
+else
+    xpsfaxis=$(echo $psfaxises | awk '{print $3}')
+    ypsfaxis=$(echo $psfaxises | awk '{print $4}')
+fi
 
 # To obtain the center of the PSF (in pixels), just divide by 2 the size of
 # the PSF image.



reply via email to

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