[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[gnuastro-commits] master 6ff43d00 05/39: Zeropoint: script for estimati
From: |
Mohammad Akhlaghi |
Subject: |
[gnuastro-commits] master 6ff43d00 05/39: Zeropoint: script for estimating the zeropoint of an image |
Date: |
Wed, 19 Apr 2023 12:18:22 -0400 (EDT) |
branch: master
commit 6ff43d00dd0b23fe32a20590aff64cda594f6f9b
Author: Sepideh Eskandarlou <sepideh.eskandarlou@gmail.com>
Commit: Mohammad Akhlaghi <mohammad@akhlaghi.org>
Zeropoint: script for estimating the zeropoint of an image
Until now, the make file for estimating the zeropoint of an image from a
catalog or image(s) was ready. But if want to bring it in Gnuastro, the
Makefile should be called inside the script.
With this commit, the configuration file of the Makefile is prepared
automatically, based on the options of zeropoint's script and finally the
zeropoint of the image from the catalog or image(s) is estimated.
---
bin/script/zeropoint.conf | 26 --------
bin/script/zeropoint.in | 163 ++++++++++++++++++++++++++++++++++++++--------
bin/script/zeropoint.mk | 64 +++++++++---------
3 files changed, 170 insertions(+), 83 deletions(-)
diff --git a/bin/script/zeropoint.conf b/bin/script/zeropoint.conf
deleted file mode 100644
index 184ea67e..00000000
--- a/bin/script/zeropoint.conf
+++ /dev/null
@@ -1,26 +0,0 @@
-# In the script we should define all the ref* variables from the input
-# options.
-# The rest of the variabels come directly from the options.
-
-
-# Input
-##ref1 = indir/sdss-1.fits
-##ref2 = indir/sdss-2.fits
-##ref1hdu = 0
-##ref2hdu = 0
-##ref1zp = 22.5
-##ref2zp = 22.5
-ref1 = indir/cat.fits
-ref1hdu = 1
-refnumber = 1
-reftype = img cat
-input = indir/jplus.fits
-inputhdu = 1
-
-# Output
-tmpdir = build
-
-# Analysis paramaters For 'aper-arcsec' in the script convet the comma into
-# space (the user should give: --aperarcsec=2,3,3.5,...).
-aper-arcsec = 2 3 3.5 4 4.5 5 6 7 10 20
-magrange =
diff --git a/bin/script/zeropoint.in b/bin/script/zeropoint.in
index fd0c9481..9d172173 100644
--- a/bin/script/zeropoint.in
+++ b/bin/script/zeropoint.in
@@ -46,8 +46,11 @@ refrence=""
aperarcsec=""
cataloghdu=""
refrencezp=""
+racolumn="RA"
refrencehdu=""
+deccolumn="DEC"
version=@VERSION@
+magcolumn="MAGNITUDE"
scriptname=@SCRIPT_NAME@
@@ -69,25 +72,25 @@ print_help() {
cat <<EOF
Usage: $scriptname [OPTIONS] image.fits
-Build a catalogue of "good stars" that will be considered for constructing
-an extended and non parametric PSF. Here, "good stars" means that they
-don't have close objects that affect it sourrondings and consequently they
-are not contaminated. The script will construct a catalog of stars from
-reference datasets (Gaia) if the user does not provide another one. In
-addition to this, other parameters like the axis ratio are considered to
-filter the sample and select only proper stars.
+Calculate the Zeropoint of the image based on the refrence images or
+catalog.
$scriptname options:
Input:
- -h, --hdu=STR/INT HDU/Extension name of number of the input file.
- -c, --catalog Refrence catalog which based on it zeropoint of
- input will be compute.
- -C, --cataloghdu HDU/Extension name of number of the catalog.
- -r, --reference Rerence images which based on them zeropoint of
- input will be compute.
- -z, --referencezp Zeropoints of reference images.
- -R, --referencehdu HDU/Extension name of number of the refrence files.
- -a, --aprarcsec Aperure arcseconds.
+ -h, --hdu=STR/INT HDU/Extension name of number of the input file.
+ -c, --catalog=STR Refrence catalog which based on it zeropoint of
+ input will be compute.
+ -C, --cataloghdu=STR/INT HDU/Extension name of number of the catalog.
+ -r, --racolumn=STR Right Ascension (R.A.) column name of the
reference
+ catalog.
+ -d, --deccolumn=STR Declination (Dec) column name of the reference
+ catalog.
+ -m, --magcolumn=STR Magnitude column name of the reference catalog.
+ -R, --reference=STR[,STR] Rerence images which based on them zeropoint of
+ input will be compute.
+ -z, --referencezp=FLT[,FLT] Zeropoints of reference images.
+ -H, --referencehdu=STR/INT HDU/Extension name of number of the refrence
files.
+ -a, --aperarcsec=FLT[,FLT] Aperure arcseconds.
Output:
-o, --output Output table with the object coordinates.
@@ -250,18 +253,27 @@ do
-C|--cataloghdu) cataloghdu="$2";
check_v "$1" "$cataloghdu"; shift;shift;;
-C=*|--cataloghdu=*) cataloghdu="${1#*=}";
check_v "$1" "$cataloghdu"; shift;;
-C*) cataloghdu=$(echo "$1" | sed -e's/-C//');
check_v "$1" "$cataloghdu"; shift;;
- -r|--reference) reference="$2";
check_v "$1" "$reference"; shift;shift;;
- -r=*|--reference=*) reference="${1#*=}";
check_v "$1" "$reference"; shift;;
- -r*) reference=$(echo "$1" | sed -e's/-r//');
check_v "$1" "$reference"; shift;;
+ -r|--racolumn) racolumn="$2";
check_v "$1" "$racolumn"; shift;shift;;
+ -r=*|--racolumn=*) racolumn="${1#*=}";
check_v "$1" "$racolumn"; shift;;
+ -r*) racolumn=$(echo "$1" | sed -e's/-r//');
check_v "$1" "$racolumn"; shift;;
+ -d|--deccolumn) deccolumn="$2";
check_v "$1" "$deccolumn"; shift;shift;;
+ -d=*|--deccolumn=*) deccolumn="${1#*=}";
check_v "$1" "$deccolumn"; shift;;
+ -d*) deccolumn=$(echo "$1" | sed -e's/-d//');
check_v "$1" "$deccolumn"; shift;;
+ -m|--magcolumn) magcolumn="$2";
check_v "$1" "$magcolumn"; shift;shift;;
+ -m=*|--magcolumn=*) magcolumn="${1#*=}";
check_v "$1" "$magcolumn"; shift;;
+ -m*) magcolumn=$(echo "$1" | sed -e's/-m//');
check_v "$1" "$magcolumn"; shift;;
+ -R|--reference) reference="$2";
check_v "$1" "$reference"; shift;shift;;
+ -R=*|--reference=*) reference="${1#*=}";
check_v "$1" "$reference"; shift;;
+ -R*) reference=$(echo "$1" | sed -e's/-R//');
check_v "$1" "$reference"; shift;;
-z|--referencezp) referencezp="$2";
check_v "$1" "$referencezp"; shift;shift;;
-z=*|--referencezp=*) referencezp="${1#*=}";
check_v "$1" "$referencezp"; shift;;
-z*) referencezp=$(echo "$1" | sed -e's/-z//');
check_v "$1" "$referencezp"; shift;;
- -R|--referencehdu) referencehdu="$2";
check_v "$1" "$referencehdu"; shift;shift;;
- -R=*|--referencehdu=*) referencehdu="${1#*=}";
check_v "$1" "$referencehdu"; shift;;
- -R*) referencehdu=$(echo "$1" | sed -e's/-R//');
check_v "$1" "$referencehdu"; shift;;
- -a|--aperarcsec) aperarcsec="$2";
check_v "$1" "$aperarcsec"; shift;shift;;
- -a=*|--referencehdu=*) aperarcsec="${1#*=}";
check_v "$1" "$aperarcsec"; shift;;
- -a*) aperarcsec=$(echo "$1" | sed -e's/-a//');
check_v "$1" "$aperarcsec"; shift;;
+ -H|--referencehdu) referencehdu="$2";
check_v "$1" "$referencehdu"; shift;shift;;
+ -H=*|--referencehdu=*) referencehdu="${1#*=}";
check_v "$1" "$referencehdu"; shift;;
+ -H*) referencehdu=$(echo "$1" | sed -e's/-H//');
check_v "$1" "$referencehdu"; shift;;
+ -a|--aperarcsec) aperarcsec="$2";
check_v "$1" "$aperarcsec"; shift;shift;;
+ -a=*|--aperarcsec=*) aperarcsec="${1#*=}";
check_v "$1" "$aperarcsec"; shift;;
+ -a*) aperarcsec=$(echo "$1" | sed -e's/-a//');
check_v "$1" "$aperarcsec"; shift;;
# Output parameters
@@ -303,7 +315,7 @@ done
# If an input image is not given at all.
if [ x"$inputs" = x ]; then
cat <<EOF
-$scriptname: ERROR: no input FITS image files (outer part of the PSF to unite
with an inner part). Run with '--help' for more information on how to run
+$scriptname: ERROR: no input FITS image files. Run with '--help' for more
information on how to run
EOF
exit 1
elif [ ! -f $inputs ]; then
@@ -312,3 +324,102 @@ $scriptname: ERROR: $inputs, no such file or directory
EOF
exit 1
fi
+
+
+
+
+# Define a temporary directory and the final output file
+# ------------------------------------------------------
+#
+# Construct the temporary directory. If the user does not specify any
+# directory, then a default one with the base name of the input image will
+# be constructed. If the user set the directory, then make it. This
+# directory will be deleted at the end of the script if the user does not
+# want to keep it (with the `--keeptmp' option).
+
+# The final catalog is also defined here if the user does not provide an
+# explicit name. If the user has defined a specific path/name for the
+# output, it will be used for saving the output file. If the user does not
+# specify an output name, then a default value containing the field, min,
+# and max magnitudes will will be generated.
+basename=$(basename $inputs | sed 's/\.fits/ /' | awk '{print $1}')
+if [ x"$tmpdir" = x ]; then \
+ tmpdir=$(pwd)/"$basename"_zeropoint
+fi
+
+if [ -d "$tmpdir" ]; then
+ junk=1
+else
+ mkdir -p "$tmpdir"
+fi
+
+# Default output catalog file
+if [ x"$output" = x ]; then
+ output="$basename"_zeropoint.fits
+fi
+
+
+
+
+
+# Prepare a configuration file for running the make file
+#-------------------------------------------------------
+#
+# At first the user wants to compute the Zeropoint for input image based on
+# the images or catalog.
+config=$tmpdir/zeropoint.conf
+echo "input = $inputs" > $config
+echo "output =$output" >> $config
+echo "hduinput = $hdu" >> $config
+echo "tmpdir = $tmpdir" >> $config
+# Put the size of the apertures in a variables. The comma should be
+# change with a space.
+aper=$(echo $aperarcsec | sed 's|,| |g')
+echo "aper-arcsec = $aper" >> $config
+if [ x"$catalog" != x ]; then
+
+ # Determine the type of the refence. In this case, if the user give the
+ # catalog the type of the reference is "img cat", because based on the
+ # catlog we want to compute the zeropoint.
+ echo "reftype = cat" >> $config
+ echo "ref1 = $catalog" >> $config
+ echo "hduref1 = $cataloghdu" >> $config
+ echo "refnumber = 1" >> $config
+ echo "ra = $racolumn" >> $config
+ echo "dec = $deccolumn" >> $config
+ echo "mag = $magcolumn" >> $config
+else
+ # Basic configuration
+ echo "reftype = img" >> $config
+
+ # Compute how many references images is used.
+ num=$(echo $reference \
+ | awk 'BEGIN{FS=","}{for(i=1;i<=NF;++i) printf "%s ", i}')
+ echo "refnumber = $num" >> $config
+ for n in $num; do
+ img=$(echo $reference | awk 'BEGIN{FS=","}{printf "%s", $'$n'}')
+ hdu=$(echo $referencehdu | awk 'BEGIN{FS=","}{printf "%s", $'$n'}')
+ zp=$(echo $referencezp | awk 'BEGIN{FS=","}{printf "%s", $'$n'}')
+ echo "ref$n = $img" >> $config
+ echo "hduref$n = $hdu" >> $config
+ echo "zpref$n = $zp" >> $config
+ done
+fi
+
+
+
+
+# Call the Makefile
+make -f zeropoint.mk tmpdir=$tmpdir
+
+
+
+
+# Remove temporary directory
+# --------------------------
+#
+# If user does not specify to keep build file with the option of
+# --keeptmp', then the directory will be removed.
+if [ x"$keeptmp" = x ]; then
+ rm -rf $tmpdir
+fi
diff --git a/bin/script/zeropoint.mk b/bin/script/zeropoint.mk
index 6a32ce68..b882d706 100644
--- a/bin/script/zeropoint.mk
+++ b/bin/script/zeropoint.mk
@@ -1,4 +1,4 @@
-# Creat final PSF for all tiles and all filters.
+#Creat final PSF for all tiles and all filters.
#
# Original authors:
# Copyright (C) 2019-2022 Samane Raji <samaneraji@gmail.com>
@@ -40,7 +40,7 @@ all: final
.SHELLFLAGS = -ec
# Include configure files.
-include zeropoint.conf
+include $(tmpdir)/zeropoint.conf
@@ -58,12 +58,12 @@ $(tmpdir):; mkdir $@
# Use Gaia catalog and only keep the objects with good parallax (to
# confirm that they are stars).
stars=$(tmpdir)/gaia.fits
-$(stars): $(indir)/$(input) | $(tmpdir)
+$(stars): $(input) | $(tmpdir)
# Download from Gaia.
raw=$(subst .fits,-raw.fits,$@)
astquery gaia --dataset=dr3 \
- --overlapwith=$(indir)/$(input) \
+ --overlapwith=$(input) \
-csource_id -cra -cdec -cparallax \
-cphot_g_mean_mag -cparallax_error \
-cpmra -cpmdec --output=$$raw
@@ -85,6 +85,32 @@ $(stars): $(indir)/$(input) | $(tmpdir)
+# Conditional for image or catalog reference
+ifeq ($(reftype),img)
+gencat=$(foreach i, $(refnumber), ref$(i))
+
+else
+
+# Initialize 'gencat' to an empty string
+gencat=
+
+# Prepare the catalog for comparing in different apperture.
+cataper=$(foreach a,$(aper-arcsec), \
+ $(tmpdir)/ref1-$(a)-cat.fits)
+$(cataper): $(tmpdir)/ref1-%-cat.fits:
+
+ asttable $(ref1) -c$(ra),$(dec) -c$(mag) \
+ | cat -n \
+ | asttable --output=$@ \
+ --colmetadata=1,OBJ_ID,int32,"Id of object." \
+ --colmetadata=2,RA,float64,"Right Assencion." \
+ --colmetadata=3,DEC,float64,"Declination." \
+ --colmetadata=4,MAGNITUDE,float32,"Magnitude."
+endif
+
+
+
+
# Apertures photometry
# --------------------
#
@@ -93,12 +119,7 @@ $(stars): $(indir)/$(input) | $(tmpdir)
# to set the other parameters of each profile to be a fixed circle of
# radius 5.1 pixels. To calculate the pixel size I have to use the big
# origin image before cropping
-inputzp=0
-ifeq ($(reftype),img)
-gencat=$(foreach i, $(refnumber), ref$(i))
-else
-gencat=
-endif
+zpinput=0
aperture=$(foreach i,input $(gencat), \
$(foreach a,$(aper-arcsec), \
$(tmpdir)/$(i)-$(a)-cat.fits))
@@ -106,9 +127,9 @@ $(aperture): $(tmpdir)/%-cat.fits: $(stars)
# Extract the names.
img=$($(word 1, $(subst -, ,$*)))
- zp=$($(word 1, $(subst -, ,$*))zp)
+ zp=$(zp$(word 1, $(subst -, ,$*)))
aperarcsec=$(word 2, $(subst -, ,$*))
- hdu=$($(word 1, $(subst -, ,$*))hdu)
+ hdu=$(hdu$(word 1, $(subst -, ,$*)))
# Convert the aperture size (arcsec) to pixels.
aperpix=$$(astfits $$img --hdu=$$hdu --pixelscale --quiet \
@@ -139,25 +160,6 @@ $(aperture): $(tmpdir)/%-cat.fits: $(stars)
-# Prepare the catalog for comparing in different apperture.
-cataper=$(foreach a,$(aper-arcsec), \
- $(tmpdir)/ref1-$(a)-cat.fits)
-$(cataper): $(tmpdir)/ref1-%-cat.fits: $(tmpdir)/input-%-cat.fits
-
- asttable $(ref1) -cRA,DEC -cMAGNITUDE \
- | cat -n \
- | asttable --output=$@ \
- --colmetadata=1,OBJ_ID,int32,"Id of object." \
- --colmetadata=2,RA,float64,"Right Assencion." \
- --colmetadata=3,DEC,float64,"Declination." \
- --colmetadata=4,MAGNITUDE,float32,"Magnitude."
-
-
-
-
-
-
-
# Calculate magnitude differences
# -------------------------------
- [gnuastro-commits] master 46d328cd 12/39: Book: writing a tutorial for the zero-point script; preface, (continued)
- [gnuastro-commits] master 46d328cd 12/39: Book: writing a tutorial for the zero-point script; preface, Mohammad Akhlaghi, 2023/04/19
- [gnuastro-commits] master 01dcbeed 15/39: Book: tutorial of zero point; magnitude range and aperture size, Mohammad Akhlaghi, 2023/04/19
- [gnuastro-commits] master b3077f0d 27/39: Book: revision of the first part of the zeropoint tutorial, Mohammad Akhlaghi, 2023/04/19
- [gnuastro-commits] master 17b5fa81 36/39: Book: simplifying and polishing the zero point script tutorial, Mohammad Akhlaghi, 2023/04/19
- [gnuastro-commits] master 7769e279 07/39: zeropoint: new options for magnitude and keeping the results are added, Mohammad Akhlaghi, 2023/04/19
- [gnuastro-commits] master a1c7a277 16/39: Book: tutorial of zero point; select the best aperture, Mohammad Akhlaghi, 2023/04/19
- [gnuastro-commits] master 1a987e04 19/39: Book: tutorial of zero point; using keepzpap and completion of results, Mohammad Akhlaghi, 2023/04/19
- [gnuastro-commits] master a3c0f0e2 31/39: Zeropoint: optimize the script for overlaping check, Mohammad Akhlaghi, 2023/04/19
- [gnuastro-commits] master 156da6c7 28/39: Book: Increase readability and correction, Mohammad Akhlaghi, 2023/04/19
- [gnuastro-commits] master d8402f1a 32/39: Book: some command and some tips is added to better recognition, Mohammad Akhlaghi, 2023/04/19
- [gnuastro-commits] master 6ff43d00 05/39: Zeropoint: script for estimating the zeropoint of an image,
Mohammad Akhlaghi <=
- [gnuastro-commits] master 76c8a482 03/39: Zeropoint: add a script for bing it on Gnuastro, Mohammad Akhlaghi, 2023/04/19
- [gnuastro-commits] master dddb483f 01/39: zeropoint: First make file for obtainaing the zeropoint photometry, Mohammad Akhlaghi, 2023/04/19
- [gnuastro-commits] master a841d3f2 02/39: zeropoint: catalogs can be used as reference, Mohammad Akhlaghi, 2023/04/19
- [gnuastro-commits] master 2c027224 08/39: Zeropoint: change the output file, Mohammad Akhlaghi, 2023/04/19
- [gnuastro-commits] master ea79c2ba 14/39: Book: tutorial of zero point; removing the sky and running the script, Mohammad Akhlaghi, 2023/04/19
- [gnuastro-commits] master 48edcd91 13/39: Book: tutorial of zero point; preparing images for using the script, Mohammad Akhlaghi, 2023/04/19
- [gnuastro-commits] master 88b4c298 23/39: Book: tutorial of zero point; subsection catalog reference, Mohammad Akhlaghi, 2023/04/19
- [gnuastro-commits] master aeb507b8 22/39: Book: correct the info format menus, Mohammad Akhlaghi, 2023/04/19
- [gnuastro-commits] master 069e12f4 24/39: Zeropoint: a bug about the matching of reference and main catalog, Mohammad Akhlaghi, 2023/04/19
- [gnuastro-commits] master c4af3dfc 25/39: Book: tutorial of zero point; completing the catalog reference, Mohammad Akhlaghi, 2023/04/19