Commit e4e7a6c5 authored by Mohammad Akhlaghi's avatar Mohammad Akhlaghi

Segmentation maps built, directories reorganized

NoiseChisel is now run on the original HST images and the object
labeled image is then warped to the MUSE resolution and prepared to
derive the segmentation maps. To make the prerequisite management of
the final catalog much more easier, the final cutouts of both MUSE and
HST are now in the same directory, only differing with a `-m.fits' or
`-h.fits' suffix. The segmentation maps also follow the same naming
convention, however, since the segmentation map is identical, the
`-m.fits' file is actually a symbolic link to the `-h.fits' file.
parent 2c31a594
......@@ -70,8 +70,8 @@ $(BDIR)/%: | $(BDIR);
#
# Note that we cannot simply include `reproduce/src/*.mk'. Because the
# order of reading them into Make actually matters in some cases.
include $(foreach m, preparations download degrade-hst input-cutouts \
, reproduce/src/$(m).mk)
include $(foreach m, preparations download degrade-hst input-cutouts \
catalog, reproduce/src/$(m).mk)
......
# Broad-band photometry checks with MUSE generated broad-band images.
#
# Make a segmentation map and generate catalogs for each region.
#
# Original author:
# Mohammad Akhlaghi <mohammad.akhlaghi@univ-lyon1.fr>
# Contributing author(s):
# Copyright (C) 2016, Mohammad Akhlaghi.
#
# This script 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 Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This script is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License for more details.
#
# A copy of the GNU General Public License is available at
# <http://www.gnu.org/licenses/>.
# Create the segmentation map
# ---------------------------
#
# The first thing we need to do is to create a segmentation map that
# will be fed into Gnuastro's MakeCatalog to generate the final
# catalog. Unfortunately as it currently stands, the MUSE-generated
# broad-band image has too many artifacts. So if we want to do
# detection over it, we are going to miss a lot of the fainter
# objects. The convolved and scaled HST image also has practically no
# noise left (becase of the huge kernel it was convolved with).
#
# Thus, the only image we can use is the initial HST image. We will
# run NoiseChisel over it, resample the object labels to the MUSE
# pixel grid, remove all pixels with a floating point (where the
# object did not fully cover a resampled pixel) and use that as the
# object labels to generate a catalog.
#
# Some pixels on the circumference of the resampled labels will still
# remain with the wrong label, but they are fixed both for HST and
# MUSE images and since they are on the circumference, they do not
# have any major flux in them. Ideally these segmentation maps should
# also be convolved with the MUSE PSF, but we aren't doing that here
# since it is mostly irrelevant for this study as discussed below:
#
# In the end, the exact object detection is not a major issue here, we
# want a fixed set of pixels to measure/calibrate the magnitudes, so
# the issues above cause no harm in our analysis. By using a higher
# resolution, we do miss the wings of large objects, but on the other
# hand, we are able to check the calibrarion of fainter objects that
# are completely lost in the lower resolution.
#
# The cutouts and catalogs will end with `-m.fits' or `-h.fits' for
# MUSE and HST data respectively. To make the dependency management
# easier, we will follow the same convention here, but since they are
# identical in the case of segmentation maps, we will use symbolic
# links. The actual segmentation map will be the `-h.fits' file, but
# the `-m.fits' file will be a link to it.
segdir = $(BDIR)/seg-maps
segments-m = $(foreach uid, 1 2 3 4 5 6 7 8 9 10, \
$(foreach f, $(filters), $(segdir)/udf$(uid)-$(f)-m.fits) )
segments-h = $(foreach uid, 1 2 3 4 5 6 7 8 9 10, \
$(foreach f, $(filters), $(segdir)/udf$(uid)-$(f)-h.fits) )
$(segments-m): $(segdir)/%-m.fits: $(segdir)/%-h.fits; ln -s $< $@
$(segments-h): $(segdir)/%-h.fits: $(hdegdir)/%-o.fits \
$(hdegdir)/pix-res-scale.txt $(noisechisel) $(imgwarp) \
$(arithmetic) | $(segdir)
# Generate a segmentation map in the high resolution HST image.
astnoisechisel $< -o$(@D)/$*-nc.fits
# Warp it into the MUSE pixel grid in double type, then
# multiply the pixels by the second power of the scale factor
# so they get the same original values.
sf=$$(cat $(hdegdir)/pix-res-scale.txt); \
astimgwarp $(@D)/$*-nc.fits -h1 --scale=$$sf --doubletype \
-o$(@D)/$*-wdi.fits; \
astarithmetic $(@D)/$*-wdi.fits $$sf $$sf "*" "*" -o$(@D)/$*-wd.fits
rm $(@D)/$*-wdi.fits
# Convert the warped image to long type for easy comparison,
# then remove all pixels that differ between the double and
# long type images.
astarithmetic $(@D)/$*-wd.fits 0 + --type=long -o$(@D)/$*-wl.fits
astarithmetic $(@D)/$*-wl.fits \
$(@D)/$*-wl.fits $(@D)/$*-wd.fits neq \
0 where -o$@
# Clean up.
rm $(@D)/$*-nc.fits $(@D)/$*-wd.fits $(@D)/$*-wl.fits
# Generate the MUSE and HST catalogs
# ----------------------------------
catdir = $(BDIR)/catalogs
catalogs = $(foreach uid, 1 2 3 4 5 6 7 8 9 10, \
$(foreach f, $(filters), \
$(foreach i, m h, $(catdir)/udf$(uid)-$(f)-$(i).fits) ) )
$(catalogs): $(catdir)/%: $(cutdir)/% $(segdir)/% $(mkcatalog) | $(catdir)
file.txt: $(catalogs)
@echo; echo "reached end"; echo;
......@@ -186,66 +186,66 @@ $(muse-psfs): %.fits: $(muse-rawpsfs) \
# ----------------------------------
#
# Cutout the original HST images.
hcutdir = $(BDIR)/hst-cutouts
hdegdir = $(BDIR)/hst-degrade
xdf-prefix = $(XDF)/hlsp_xdf_hst_acswfc-$(hstpixelscale)0mas_hudf_
udf1-hst-cutouts = $(foreach f, $(filters), $(hcutdir)/udf1-$(f)-o.fits)
$(udf1-hst-cutouts): $(hcutdir)/udf1-%-o.fits: $(xdf-prefix)%_v1_sci.fits \
udf1-hst-cutouts = $(foreach f, $(filters), $(hdegdir)/udf1-$(f)-o.fits)
$(udf1-hst-cutouts): $(hdegdir)/udf1-%-o.fits: $(xdf-prefix)%_v1_sci.fits \
$(imgcrop) reproduce/config/internal/vertices-udf1.mk \
| $(hcutdir)
| $(hdegdir)
astimgcrop $(udf1polygon) $< -o$@
udf2-hst-cutouts = $(foreach f, $(filters), $(hcutdir)/udf2-$(f)-o.fits)
$(udf2-hst-cutouts): $(hcutdir)/udf2-%-o.fits: $(xdf-prefix)%_v1_sci.fits \
udf2-hst-cutouts = $(foreach f, $(filters), $(hdegdir)/udf2-$(f)-o.fits)
$(udf2-hst-cutouts): $(hdegdir)/udf2-%-o.fits: $(xdf-prefix)%_v1_sci.fits \
$(imgcrop) reproduce/config/internal/vertices-udf2.mk \
| $(hcutdir)
| $(hdegdir)
astimgcrop $(udf2polygon) $< -o$@
udf3-hst-cutouts = $(foreach f, $(filters), $(hcutdir)/udf3-$(f)-o.fits)
$(udf3-hst-cutouts): $(hcutdir)/udf3-%-o.fits: $(xdf-prefix)%_v1_sci.fits \
udf3-hst-cutouts = $(foreach f, $(filters), $(hdegdir)/udf3-$(f)-o.fits)
$(udf3-hst-cutouts): $(hdegdir)/udf3-%-o.fits: $(xdf-prefix)%_v1_sci.fits \
$(imgcrop) reproduce/config/internal/vertices-udf3.mk \
| $(hcutdir)
| $(hdegdir)
astimgcrop $(udf3polygon) $< -o$@
udf4-hst-cutouts = $(foreach f, $(filters), $(hcutdir)/udf4-$(f)-o.fits)
$(udf4-hst-cutouts): $(hcutdir)/udf4-%-o.fits: $(xdf-prefix)%_v1_sci.fits \
udf4-hst-cutouts = $(foreach f, $(filters), $(hdegdir)/udf4-$(f)-o.fits)
$(udf4-hst-cutouts): $(hdegdir)/udf4-%-o.fits: $(xdf-prefix)%_v1_sci.fits \
$(imgcrop) reproduce/config/internal/vertices-udf4.mk \
| $(hcutdir)
| $(hdegdir)
astimgcrop $(udf4polygon) $< -o$@
udf5-hst-cutouts = $(foreach f, $(filters), $(hcutdir)/udf5-$(f)-o.fits)
$(udf5-hst-cutouts): $(hcutdir)/udf5-%-o.fits: $(xdf-prefix)%_v1_sci.fits \
udf5-hst-cutouts = $(foreach f, $(filters), $(hdegdir)/udf5-$(f)-o.fits)
$(udf5-hst-cutouts): $(hdegdir)/udf5-%-o.fits: $(xdf-prefix)%_v1_sci.fits \
$(imgcrop) reproduce/config/internal/vertices-udf5.mk \
| $(hcutdir)
| $(hdegdir)
astimgcrop $(udf5polygon) $< -o$@
udf6-hst-cutouts = $(foreach f, $(filters), $(hcutdir)/udf6-$(f)-o.fits)
$(udf6-hst-cutouts): $(hcutdir)/udf6-%-o.fits: $(xdf-prefix)%_v1_sci.fits \
udf6-hst-cutouts = $(foreach f, $(filters), $(hdegdir)/udf6-$(f)-o.fits)
$(udf6-hst-cutouts): $(hdegdir)/udf6-%-o.fits: $(xdf-prefix)%_v1_sci.fits \
$(imgcrop) reproduce/config/internal/vertices-udf6.mk \
| $(hcutdir)
| $(hdegdir)
astimgcrop $(udf6polygon) $< -o$@
udf7-hst-cutouts = $(foreach f, $(filters), $(hcutdir)/udf7-$(f)-o.fits)
$(udf7-hst-cutouts): $(hcutdir)/udf7-%-o.fits: $(xdf-prefix)%_v1_sci.fits \
udf7-hst-cutouts = $(foreach f, $(filters), $(hdegdir)/udf7-$(f)-o.fits)
$(udf7-hst-cutouts): $(hdegdir)/udf7-%-o.fits: $(xdf-prefix)%_v1_sci.fits \
$(imgcrop) reproduce/config/internal/vertices-udf7.mk \
| $(hcutdir)
| $(hdegdir)
astimgcrop $(udf7polygon) $< -o$@
udf8-hst-cutouts = $(foreach f, $(filters), $(hcutdir)/udf8-$(f)-o.fits)
$(udf8-hst-cutouts): $(hcutdir)/udf8-%-o.fits: $(xdf-prefix)%_v1_sci.fits \
udf8-hst-cutouts = $(foreach f, $(filters), $(hdegdir)/udf8-$(f)-o.fits)
$(udf8-hst-cutouts): $(hdegdir)/udf8-%-o.fits: $(xdf-prefix)%_v1_sci.fits \
$(imgcrop) reproduce/config/internal/vertices-udf8.mk \
| $(hcutdir)
| $(hdegdir)
astimgcrop $(udf8polygon) $< -o$@
udf9-hst-cutouts = $(foreach f, $(filters), $(hcutdir)/udf9-$(f)-o.fits)
$(udf9-hst-cutouts): $(hcutdir)/udf9-%-o.fits: $(xdf-prefix)%_v1_sci.fits \
udf9-hst-cutouts = $(foreach f, $(filters), $(hdegdir)/udf9-$(f)-o.fits)
$(udf9-hst-cutouts): $(hdegdir)/udf9-%-o.fits: $(xdf-prefix)%_v1_sci.fits \
$(imgcrop) reproduce/config/internal/vertices-udf9.mk \
| $(hcutdir)
| $(hdegdir)
astimgcrop $(udf9polygon) $< -o$@
udf10-hst-cutouts = $(foreach f, $(filters), $(hcutdir)/udf10-$(f)-o.fits)
$(udf10-hst-cutouts): $(hcutdir)/udf10-%-o.fits: $(xdf-prefix)%_v1_sci.fits \
udf10-hst-cutouts = $(foreach f, $(filters), $(hdegdir)/udf10-$(f)-o.fits)
$(udf10-hst-cutouts): $(hdegdir)/udf10-%-o.fits: $(xdf-prefix)%_v1_sci.fits \
$(imgcrop) reproduce/config/internal/vertices-udf10.mk \
| $(hcutdir)
| $(hdegdir)
astimgcrop $(udf10polygon) $< -o$@
......@@ -371,6 +371,6 @@ $(kernels): $(kerneldir)/udf%.fits: $(mpsfdir)/udf%.fits \
# one thread so the multiple running on multiple threads can speed
# things up better.
hst-convolved = $(foreach uid, 1 2 3 4 5 6 7 8 9 10, \
$(foreach f, $(filters), $(hcutdir)/udf$(uid)-$(f)-c.fits) )
$(hst-convolved): $(hcutdir)/%-c.fits: $(hcutdir)/%-o.fits $(mpsfdir)/%.fits
$(foreach f, $(filters), $(hdegdir)/udf$(uid)-$(f)-c.fits) )
$(hst-convolved): $(hdegdir)/%-c.fits: $(hdegdir)/%-o.fits $(kerneldir)/%.fits
astconvolve --spatial $< --kernel=$(kerneldir)/$*.fits -o$@ -N1
......@@ -44,84 +44,84 @@ $(udfaligned): $(audfdir)/muse-udf-%.fits: \
# -------------------------
#
# Cutout the original MUSE images.
mcutdir = $(BDIR)/muse-cutouts
udf1-muse-cutouts = $(foreach f, $(filters), $(mcutdir)/udf1-$(f).fits)
$(udf1-muse-cutouts): $(mcutdir)/udf1-%.fits: $(audfdir)/muse-udf-%.fits \
cutdir = $(BDIR)/cutouts
udf1-muse-cutouts = $(foreach f, $(filters), $(cutdir)/udf1-$(f)-m.fits)
$(udf1-muse-cutouts): $(cutdir)/udf1-%-m.fits: $(audfdir)/muse-udf-%.fits \
$(imgcrop) reproduce/config/internal/vertices-udf1.mk \
| $(mcutdir)
| $(cutdir)
astimgcrop $(udf1polygon) $< -o$@
udf2-muse-cutouts = $(foreach f, $(filters), $(mcutdir)/udf2-$(f).fits)
$(udf2-muse-cutouts): $(mcutdir)/udf2-%.fits: $(audfdir)/muse-udf-%.fits \
udf2-muse-cutouts = $(foreach f, $(filters), $(cutdir)/udf2-$(f)-m.fits)
$(udf2-muse-cutouts): $(cutdir)/udf2-%-m.fits: $(audfdir)/muse-udf-%.fits \
$(imgcrop) reproduce/config/internal/vertices-udf2.mk \
| $(mcutdir)
| $(cutdir)
astimgcrop $(udf2polygon) $< -o$@
udf3-muse-cutouts = $(foreach f, $(filters), $(mcutdir)/udf3-$(f).fits)
$(udf3-muse-cutouts): $(mcutdir)/udf3-%.fits: $(audfdir)/muse-udf-%.fits \
udf3-muse-cutouts = $(foreach f, $(filters), $(cutdir)/udf3-$(f)-m.fits)
$(udf3-muse-cutouts): $(cutdir)/udf3-%-m.fits: $(audfdir)/muse-udf-%.fits \
$(imgcrop) reproduce/config/internal/vertices-udf3.mk \
| $(mcutdir)
| $(cutdir)
astimgcrop $(udf3polygon) $< -o$@
udf4-muse-cutouts = $(foreach f, $(filters), $(mcutdir)/udf4-$(f).fits)
$(udf4-muse-cutouts): $(mcutdir)/udf4-%.fits: $(audfdir)/muse-udf-%.fits \
udf4-muse-cutouts = $(foreach f, $(filters), $(cutdir)/udf4-$(f)-m.fits)
$(udf4-muse-cutouts): $(cutdir)/udf4-%-m.fits: $(audfdir)/muse-udf-%.fits \
$(imgcrop) reproduce/config/internal/vertices-udf4.mk \
| $(mcutdir)
| $(cutdir)
astimgcrop $(udf4polygon) $< -o$@
udf5-muse-cutouts = $(foreach f, $(filters), $(mcutdir)/udf5-$(f).fits)
$(udf5-muse-cutouts): $(mcutdir)/udf5-%.fits: $(audfdir)/muse-udf-%.fits \
udf5-muse-cutouts = $(foreach f, $(filters), $(cutdir)/udf5-$(f)-m.fits)
$(udf5-muse-cutouts): $(cutdir)/udf5-%-m.fits: $(audfdir)/muse-udf-%.fits \
$(imgcrop) reproduce/config/internal/vertices-udf5.mk \
| $(mcutdir)
| $(cutdir)
astimgcrop $(udf5polygon) $< -o$@
udf6-muse-cutouts = $(foreach f, $(filters), $(mcutdir)/udf6-$(f).fits)
$(udf6-muse-cutouts): $(mcutdir)/udf6-%.fits: $(audfdir)/muse-udf-%.fits \
udf6-muse-cutouts = $(foreach f, $(filters), $(cutdir)/udf6-$(f)-m.fits)
$(udf6-muse-cutouts): $(cutdir)/udf6-%-m.fits: $(audfdir)/muse-udf-%.fits \
$(imgcrop) reproduce/config/internal/vertices-udf6.mk \
| $(mcutdir)
| $(cutdir)
astimgcrop $(udf6polygon) $< -o$@
udf7-muse-cutouts = $(foreach f, $(filters), $(mcutdir)/udf7-$(f).fits)
$(udf7-muse-cutouts): $(mcutdir)/udf7-%.fits: $(audfdir)/muse-udf-%.fits \
udf7-muse-cutouts = $(foreach f, $(filters), $(cutdir)/udf7-$(f)-m.fits)
$(udf7-muse-cutouts): $(cutdir)/udf7-%-m.fits: $(audfdir)/muse-udf-%.fits \
$(imgcrop) reproduce/config/internal/vertices-udf7.mk \
| $(mcutdir)
| $(cutdir)
astimgcrop $(udf7polygon) $< -o$@
udf8-muse-cutouts = $(foreach f, $(filters), $(mcutdir)/udf8-$(f).fits)
$(udf8-muse-cutouts): $(mcutdir)/udf8-%.fits: $(audfdir)/muse-udf-%.fits \
udf8-muse-cutouts = $(foreach f, $(filters), $(cutdir)/udf8-$(f)-m.fits)
$(udf8-muse-cutouts): $(cutdir)/udf8-%-m.fits: $(audfdir)/muse-udf-%.fits \
$(imgcrop) reproduce/config/internal/vertices-udf8.mk \
| $(mcutdir)
| $(cutdir)
astimgcrop $(udf8polygon) $< -o$@
udf9-muse-cutouts = $(foreach f, $(filters), $(mcutdir)/udf9-$(f).fits)
$(udf9-muse-cutouts): $(mcutdir)/udf9-%.fits: $(audfdir)/muse-udf-%.fits \
udf9-muse-cutouts = $(foreach f, $(filters), $(cutdir)/udf9-$(f)-m.fits)
$(udf9-muse-cutouts): $(cutdir)/udf9-%-m.fits: $(audfdir)/muse-udf-%.fits \
$(imgcrop) reproduce/config/internal/vertices-udf9.mk \
| $(mcutdir)
| $(cutdir)
astimgcrop $(udf9polygon) $< -o$@
udf10-muse-cutouts = $(foreach f, $(filters), $(mcutdir)/udf10-$(f).fits)
$(udf10-muse-cutouts): $(mcutdir)/udf10-%.fits: \
udf10-muse-cutouts = $(foreach f, $(filters), $(cutdir)/udf10-$(f)-m.fits)
$(udf10-muse-cutouts): $(cutdir)/udf10-%-m.fits: \
$(MUSEINPUTS)/muse-udf10-%.fits $(imgcrop) \
reproduce/config/internal/vertices-udf10.mk | $(mcutdir)
reproduce/config/internal/vertices-udf10.mk | $(cutdir)
astimgcrop $(udf10polygon) -h1 $< -o$@
# MUSE pixel resolution
# ---------------------
# Pixel scale conversion
# ----------------------
#
# For the final degrading of HST images, we also need the MUSE pixel
# resolution, so read the MUSE pixel resolution from one of the
# aligned images, then also read the HST pixel resolution from one of
# the images and find scale factor
$(hcutdir)/pix-res-scale.txt: $(mcutdir)/udf1-f606w.fits \
$(hcutdir)/udf1-f606w-c.fits
mres=$$(astheader $(mcutdir)/udf1-f606w.fits | grep PC2_2 \
| awk '{print $$3*3600}'); \
hres=$$(astheader $(hcutdir)/udf1-f606w-c.fits | grep PC2_2 \
| awk '{print $$3*3600}'); \
# For the final degrading of HST images, we also need the scaling
# factor between the HST and MUSE images, so read the MUSE pixel
# resolution from one of the aligned images, then also read the HST
# pixel resolution from one of the images and find scale factor
$(hdegdir)/pix-res-scale.txt: $(cutdir)/udf1-f606w-m.fits \
$(hdegdir)/udf1-f606w-c.fits
mres=$$(astheader $(cutdir)/udf1-f606w-m.fits | grep PC2_2 \
| awk '{print $$3}'); \
hres=$$(astheader $(hdegdir)/udf1-f606w-c.fits | grep PC2_2 \
| awk '{print $$3}'); \
echo | awk '{print '$$hres'/'$$mres'}' > $@
......@@ -132,16 +132,11 @@ $(hcutdir)/pix-res-scale.txt: $(mcutdir)/udf1-f606w.fits \
# -----------------------------
#
# The HST images were convolved with the MUSE PSF for the same spatial
# resolution, now, we need to warp them to the MUSE pixel grid to get
# be able to easily use one segmentation map over both images.
# resolution, now, we need to warp them to the MUSE pixel grid to
# easily use one segmentation map over both images.
h-to-m-pixres = $(foreach uid, 1 2 3 4 5 6 7 8 9 10, \
$(foreach f, $(filters), $(hcutdir)/udf$(uid)-$(f).fits) )
$(h-to-m-pixres): %.fits: %-c.fits $(hcutdir)/pix-res-scale.txt
scalefactor=$$(cat $(hcutdir)/pix-res-scale.txt); \
astimgwarp $< --scale=$$scalefactor -o $@ --numthreads=1
file.txt: $(hst-convolved)
@echo; echo "reached end"; echo;
$(foreach f, $(filters), $(cutdir)/udf$(uid)-$(f)-h.fits) )
$(h-to-m-pixres): $(cutdir)/%-h.fits: $(hdegdir)/%-c.fits \
$(hdegdir)/pix-res-scale.txt
scalefactor=$$(cat $(hdegdir)/pix-res-scale.txt); \
astimgwarp $< --scale=$$scalefactor -o$@ --numthreads=1
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment