[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[gnuastro-commits] master 7d2633c 2/2: MakeProfiles: automatically gener
From: |
Mohammad Akhlaghi |
Subject: |
[gnuastro-commits] master 7d2633c 2/2: MakeProfiles: automatically generated output name now has suffix |
Date: |
Sat, 31 Jul 2021 21:48:20 -0400 (EDT) |
branch: master
commit 7d2633ce3aad279c41623f2a0c741dc30a6921b0
Author: Mohammad Akhlaghi <mohammad@akhlaghi.org>
Commit: Mohammad Akhlaghi <mohammad@akhlaghi.org>
MakeProfiles: automatically generated output name now has suffix
Until now, when no '--output' option was given to MakeProfiles, it would
simply change the suffix of the given file to '.fits' and use that as the
output name. This would work fine for plain text outputs, so for example
'cat.txt' would produce an image called 'cat.fits'.
However, this would create a big problem when the input was a FITS file:
the input would be automatically deleted before it was completely
processed! As a result, MakeProfiles would crash with an error saying that
the input doesn't exist! And this was very confusing for the users (because
it existed before the program started).
With this commit, like all other Gnuastro programs, the suffix of the
automatically generated output file name of MakeProfiles, a word is
inserted before the format: '_profiles.fits' (not just '.fits'). This fixes
the bug above, but also produces a clearly identified output file, in the
middle of the others.
Until now the 'make check' tests for MakeProfiles assumed the old feature,
so it was necessary to add an '--output' for all the MakeProfiles calls in
those scripts.
This fixes bug #60989.
---
NEWS | 10 ++++++++++
bin/mkprof/ui.c | 11 +++++++----
doc/gnuastro.texi | 43 ++++++++++++++++++++---------------------
tests/mkprof/3d-cat.sh | 3 ++-
tests/mkprof/clearcanvas.sh | 3 +--
tests/mkprof/ellipticalmasks.sh | 2 +-
tests/mkprof/mosaic1.sh | 5 +++--
tests/mkprof/mosaic2.sh | 2 +-
tests/mkprof/mosaic3.sh | 3 ++-
tests/mkprof/mosaic4.sh | 3 ++-
tests/mkprof/radeccat.sh | 2 +-
11 files changed, 51 insertions(+), 36 deletions(-)
diff --git a/NEWS b/NEWS
index 3766433..f2c7873 100644
--- a/NEWS
+++ b/NEWS
@@ -82,6 +82,14 @@ See the end of the file for license conditions.
avoid too many crashes when command before the pipe takes longer (thus
needing a manual change of this value).
+ MakeProfiles:
+ - The default output suffix (when no '--output' is given) is now
+ '_profiles.fits'. Until now, when no output name was given,
+ MakeProfiles just replaced the suffix with '.fits' (effectively
+ assuming the input is a plain-text file). As a result, if the input
+ catalog was a FITS file, it would be automatically written-over
+ (causing an error: bug #60989).
+
Match:
- The two '--notmatched' and '--outcols' can be called together (to
create a single catalog that appends the non-matching rows of second
@@ -116,6 +124,8 @@ See the end of the file for license conditions.
floating point errors, found and fixed by Natáli Anzanello.
bug #60958: Warning on long filename not written in FITS keyword printed
even when '--quiet' is called, found by Raúl Infante-Sainz.
+ bug #60989: MakeProfiles deletes input fits catalog when no output name
+ specified.
diff --git a/bin/mkprof/ui.c b/bin/mkprof/ui.c
index cc4b061..425ac5a 100644
--- a/bin/mkprof/ui.c
+++ b/bin/mkprof/ui.c
@@ -578,7 +578,7 @@ ui_check_options_and_arguments(struct mkprofparams *p)
"catalog ('%s'). The parameters necessary to build a single "
"kernel output should be given to '--kernel', not in a "
"catalog", p->catname);
- p->catname="kernel.option";
+ p->catname="kernel.optional";
}
else
{
@@ -612,15 +612,18 @@ ui_check_options_and_arguments(struct mkprofparams *p)
tmpname=gal_checkset_automatic_output(&p->cp,
( p->catname
? p->catname
- : "makeprofiles" ), ".fits");
+ : "makeprofiles" ),
+ ( p->kernel
+ ? ".fits"
+ : "_profiles.fits" ));
p->mergedimgname=gal_checkset_malloc_cat(p->outdir, tmpname);
free(tmpname);
}
p->basename=gal_checkset_not_dir_part(p->mergedimgname);
- /* If a merged image is requested (or '--kernel' the option is called),
- then delete the final filename if it exists. */
+ /* If a merged image is requested (or '--kernel' is called), then delete
+ the final filename if it exists. */
if(p->nomerged==0 && p->kernel)
gal_checkset_writable_remove(p->mergedimgname, p->cp.keep,
p->cp.dontdelete);
diff --git a/doc/gnuastro.texi b/doc/gnuastro.texi
index d929e4e..0c30746 100644
--- a/doc/gnuastro.texi
+++ b/doc/gnuastro.texi
@@ -1767,20 +1767,20 @@ MakeProfiles started on Sat Oct 6 16:26:56 953
---- ./0_cat.fits created.
---- row 0 complete, 1 left to go
---- row 1 complete, 0 left to go
- - ./cat.fits created. 0.041651 seconds
+ - ./cat_profiles.fits created. 0.041651 seconds
MakeProfiles finished in 0.267234 seconds
$ls
-0_cat.fits cat.fits cat.txt
+0_cat.fits cat_profiles.fits cat.txt
@end example
@cindex Oversample
@noindent
-The file @file{0_cat.fits} is the PSF Sufi had asked for, and @file{cat.fits}
is the image containing the main objects in the catalog.
-The size of @file{cat.fits} was surprising for the student, instead of 499 by
499 (as we had requested), it was 2615 by 2615 pixels (from the command below):
+The file @file{0_cat.fits} is the PSF Sufi had asked for, and
@file{cat_profiles.fits} is the image containing the main objects in the
catalog.
+The size of @file{cat_profiles.fits} was surprising for the student, instead
of 499 by 499 (as we had requested), it was 2615 by 2615 pixels (from the
command below):
@example
-$ astfits cat.fits -h1 | grep NAXIS
+$ astfits cat_profiles.fits -h1 | grep NAXIS
@end example
@noindent
@@ -1788,7 +1788,7 @@ So Sufi explained why oversampling is important in
modeling, especially for part
Recall that when you oversample the model (for example by 5 times), for every
desired pixel, you get 25 pixels (@mymath{5\times5}).
Sufi then explained that after convolving (next step below) we will
down-sample the image to get our originally desired size/resolution.
-Sufi then opened @code{cat.fits} [you can use any FITS viewer, for example,
@command{ds9}].
+Sufi then opened @code{cat_profiles.fits} [you can use any FITS viewer, for
example, @command{ds9}].
After seeing the image, the student complained that only the large elliptical
model for the Andromeda nebula can be seen in the center.
He couldn't see the four stars that we had also requested in the catalog.
So Sufi had to explain that the stars are there in the image, but the reason
that they aren't visible when looking at the whole image at once, is that they
only cover a single pixel!
@@ -1800,10 +1800,11 @@ If we didn't have an atmosphere and we didn't need an
aperture, then stars would
So Sufi convolved the image with this command:
@example
-$ astconvolve --kernel=0_cat.fits cat.fits
+$ astconvolve --kernel=0_cat.fits cat_profiles.fits \
+ --output=cat_convolved.fits
Convolve started on Sat Oct 6 16:35:32 953
- Using 8 CPU threads.
- - Input: cat.fits (hdu: 1)
+ - Input: cat_profiles.fits (hdu: 1)
- Kernel: 0_cat.fits (hdu: 1)
- Input and Kernel images padded. 0.075541 seconds
- Images converted to frequency domain. 6.728407 seconds
@@ -1814,7 +1815,7 @@ Convolve started on Sat Oct 6 16:35:32 953
Convolve finished in: 10.422161 seconds
$ls
-0_cat.fits cat_convolved.fits cat.fits cat.txt
+0_cat.fits cat_convolved.fits cat_profiles.fits cat.txt
@end example
@noindent
@@ -1836,7 +1837,7 @@ Warp started on Sat Oct 6 16:51:59 953
$ ls
0_cat.fits cat_convolved_scaled.fits cat.txt
-cat_convolved.fits cat.fits
+cat_convolved.fits cat_profiles.fits
$ astfits -p cat_convolved_scaled.fits | grep NAXIS
NAXIS = 2 / number of data axes
@@ -1871,7 +1872,7 @@ Crop started on Sat Oct 6 17:03:24 953
Crop finished in: 0.027204 seconds
$ls
-0_cat.fits cat_convolved_scaled_cropped.fits cat.fits
+0_cat.fits cat_convolved_scaled_cropped.fits cat_profiles.fits
cat_convolved.fits cat_convolved_scaled.fits cat.txt
@end example
@@ -1893,14 +1894,15 @@ MakeNoise started on Sat Oct 6 17:05:06 953
MakeNoise finished in: 0.033491 (seconds)
$ls
-0_cat.fits cat_convolved_scaled_cropped.fits cat.fits out.fits
-cat_convolved.fits cat_convolved_scaled.fits cat.txt
+0_cat.fits cat_convolved_scaled_cropped.fits cat_profiles.fits
+cat_convolved.fits cat_convolved_scaled.fits cat.txt out.fits
@end example
@noindent
The @file{out.fits} file now contains the noised image of the mock catalog
Sufi had asked for.
-Seeing how the @option{--output} option allows the user to specify the name of
the output file, the student was confused and wanted to know why Sufi hadn't
used it before? Sufi then explained to him that for intermediate steps it is
best to rely on the automatic output, see @ref{Automatic output}.
-Doing so will give all the intermediate files the same basic name structure,
so in the end you can simply remove them all with the Shell's capabilities.
+Seeing how the @option{--output} option allows the user to specify the name of
the output file, the student was confused and wanted to know why Sufi hadn't
used it more regularly before?
+Sufi then explained to him that for intermediate steps, you can rely on the
automatic output of the programs, see @ref{Automatic output}.
+Doing so will give all the intermediate files a similar basic name structure,
so in the end you can simply remove them all with the Shell's capabilities, and
it will be familiar for other users.
So Sufi decided to show this to the student by making a shell script from the
commands he had used before.
The command-line shell has the capability to read all the separate input
commands from a file.
@@ -1926,7 +1928,8 @@ astmkprof --prepforconv --mergedsize=499,499
--zeropoint=18.0 \
"$base".txt
# Convolve the created image with the kernel.
-astconvolve --kernel=0_"$base".fits "$base".fits
+astconvolve --kernel=0_"$base".fits "$base"_profiles.fits \
+ --output="$base"_convolved.fits
# Scale the image back to the intended resolution.
astwarp --scale=1/5 --centeroncorner "$base"_convolved.fits
@@ -3740,14 +3743,10 @@ See @ref{Invoking astmkprof} for details on the options.
@example
$ astmkprof apertures.txt --background=flat-ir/xdf-f160w.fits \
--clearcanvas --replace --type=int16 --mforflatpix \
- --mode=wcs
+ --mode=wcs --output=apertures.fits
@end example
-The first thing you might notice in the printed information is that the
profiles are not built in order.
-This is because MakeProfiles works in parallel, and parallel CPU operations
are asynchronous.
-You can try running MakeProfiles with one thread (using
@option{--numthreads=1}) to see how order is respected in that case, but slower
(note that the multi-threaded run will be much more faster when more
mathematically-complicated profiles are built, like S@'eric profiles).
-
-Open @file{apertures.fits} with a FITS viewer and look around at the circles
placed over the targets.
+Open @file{apertures.fits} with a FITS image viewer (like SAO DS9) and look
around at the circles placed over the targets.
Also open the input image and Segment's clumps image and compare them with the
positions of these circles.
Where the apertures overlap, you will notice that one label has replaced the
other (because of the @option{--replace} option).
In the future, MakeCatalog will be able to work with overlapping labels, but
currently it doesn't.
diff --git a/tests/mkprof/3d-cat.sh b/tests/mkprof/3d-cat.sh
index 459ce02..bd7f3d3 100755
--- a/tests/mkprof/3d-cat.sh
+++ b/tests/mkprof/3d-cat.sh
@@ -45,4 +45,5 @@ if [ ! -f $cat ]; then echo "$cat does not exist.";
exit 77; fi
# Actual test script
# ==================
-$execname $cat --config=.gnuastro/astmkprof-3d.conf --oversample=1
+$execname $cat --config=.gnuastro/astmkprof-3d.conf --oversample=1 \
+ --output=3d-cat.fits
diff --git a/tests/mkprof/clearcanvas.sh b/tests/mkprof/clearcanvas.sh
index d221eb9..bcb4bfb 100755
--- a/tests/mkprof/clearcanvas.sh
+++ b/tests/mkprof/clearcanvas.sh
@@ -59,5 +59,4 @@ if [ ! -f $cat ]; then echo "$cat does not exist.";
exit 77; fi
# string. Such programs will execute the command if present and help in
# debugging when the developer doesn't have access to the user's system.
$check_with_program $execname $cat --background=$img --mforflatpix \
- --clearcanvas --type=int32 \
- --output="clearcanvas.fits"
+ --clearcanvas --type=int32 --output="clearcanvas.fits"
diff --git a/tests/mkprof/ellipticalmasks.sh b/tests/mkprof/ellipticalmasks.sh
index 10941a8..65638e2 100755
--- a/tests/mkprof/ellipticalmasks.sh
+++ b/tests/mkprof/ellipticalmasks.sh
@@ -59,4 +59,4 @@ if [ ! -f $img ]; then echo "$img does not exist.";
exit 77; fi
# string. Such programs will execute the command if present and help in
# debugging when the developer doesn't have access to the user's system.
$check_with_program $execname $cat --background=$img --mforflatpix --replace \
- --oversample=1 --output="ellipticalmasks.fits"
+ --oversample=1 --output="ellipticalmasks.fits"
diff --git a/tests/mkprof/mosaic1.sh b/tests/mkprof/mosaic1.sh
index 27817df..59a0764 100755
--- a/tests/mkprof/mosaic1.sh
+++ b/tests/mkprof/mosaic1.sh
@@ -55,5 +55,6 @@ if [ ! -f $cat ]; then echo "$cat does not exist.";
exit 77; fi
# 'check_with_program' can be something like Valgrind or an empty
# string. Such programs will execute the command if present and help in
# debugging when the developer doesn't have access to the user's system.
-$check_with_program $execname $cat --mergedsize=100,100 \
- && mv 0_mkprofcat1.fits psf.fits
+$check_with_program $execname $cat --mergedsize=100,100 \
+ --output=mkprofcat1.fits \
+ && mv 0_mkprofcat1.fits psf.fits
diff --git a/tests/mkprof/mosaic2.sh b/tests/mkprof/mosaic2.sh
index 9be5228..b20228c 100755
--- a/tests/mkprof/mosaic2.sh
+++ b/tests/mkprof/mosaic2.sh
@@ -61,4 +61,4 @@ if [ ! -f $cat ]; then echo "$cat does not exist.";
exit 77; fi
# string. Such programs will execute the command if present and help in
# debugging when the developer doesn't have access to the user's system.
$check_with_program $execname $cat --mergedsize=100,100 --crpix=-99,1 \
- --individual
+ --output=mkprofcat2.fits --individual
diff --git a/tests/mkprof/mosaic3.sh b/tests/mkprof/mosaic3.sh
index 9984579..75ce94d 100755
--- a/tests/mkprof/mosaic3.sh
+++ b/tests/mkprof/mosaic3.sh
@@ -57,4 +57,5 @@ if [ ! -f $cat ]; then echo "$cat does not exist.";
exit 77; fi
# 'check_with_program' can be something like Valgrind or an empty
# string. Such programs will execute the command if present and help in
# debugging when the developer doesn't have access to the user's system.
-$check_with_program $execname $cat --mergedsize=100,100 --crpix=1,-99
+$check_with_program $execname $cat --mergedsize=100,100 --crpix=1,-99 \
+ --output=mkprofcat3.fits
diff --git a/tests/mkprof/mosaic4.sh b/tests/mkprof/mosaic4.sh
index 7bf48c9..0cb984c 100755
--- a/tests/mkprof/mosaic4.sh
+++ b/tests/mkprof/mosaic4.sh
@@ -58,4 +58,5 @@ if [ ! -f $cat ]; then echo "$cat does not exist.";
exit 77; fi
# 'check_with_program' can be something like Valgrind or an empty
# string. Such programs will execute the command if present and help in
# debugging when the developer doesn't have access to the user's system.
-$check_with_program $execname $cat --mergedsize=100,100 --crpix=-99,-99
+$check_with_program $execname $cat --mergedsize=100,100 --crpix=-99,-99 \
+ --output=mkprofcat4.fits
diff --git a/tests/mkprof/radeccat.sh b/tests/mkprof/radeccat.sh
index cc8b701..3a31a4d 100755
--- a/tests/mkprof/radeccat.sh
+++ b/tests/mkprof/radeccat.sh
@@ -54,4 +54,4 @@ if [ ! -f $cat ]; then echo "$cat does not exist.";
exit 77; fi
# string. Such programs will execute the command if present and help in
# debugging when the developer doesn't have access to the user's system.
$check_with_program $execname $cat --ccol=RA --ccol=Dec --mode=wcs \
- --mergedsize=100,100
+ --mergedsize=100,100 --output=radeccat.fits