Commit 2135a3ba authored by Mohammad Akhlaghi's avatar Mohammad Akhlaghi

One pixel rows or columns adjusted in MUSE cutouts

Due to very small WCS differences, we might be having one column or
row difference between the warped HST images and the MUSE images. To
generate the catalog, the two images need to be the same size, so this
was a problem.

To solve it, the MUSE images are now cutout from the input image in a
new directory (`muse-cutouts'). Then, after the HST images are warped,
the MUSE and HST-warped image sizes are compared and if they are
different, the MUSE image corrected (by one row or column of pixels
along the respective dimension). Then it is put into the old `cutouts'
directory. If the sizes are the same, then a copy is just put there.
parent 0654f265
......@@ -68,8 +68,7 @@ $(BDIR)/%: | $(BDIR);
# Enable secondary expansion
# --------------------------
#
# We want secondary expansion to to use functions in the prerequisite
# list.
# Secondary expansion allows usage of functions in the prerequisites.
.SECONDEXPANSION:
......
......@@ -44,65 +44,65 @@ $(udfaligned): $(audfdir)/muse-udf-%.fits: \
# -------------------------
#
# Cutout the original MUSE images.
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 \
mcutdir = $(BDIR)/muse-cutouts
udf1-muse-cutouts = $(foreach f, $(filters), $(mcutdir)/udf1-$(f).fits)
$(udf1-muse-cutouts): $(mcutdir)/udf1-%.fits: $(audfdir)/muse-udf-%.fits \
$(imgcrop) reproduce/config/internal/vertices-udf1.mk \
| $(cutdir)
| $(mcutdir)
astimgcrop $(udf1polygon) $< -o$@
udf2-muse-cutouts = $(foreach f, $(filters), $(cutdir)/udf2-$(f)-m.fits)
$(udf2-muse-cutouts): $(cutdir)/udf2-%-m.fits: $(audfdir)/muse-udf-%.fits \
udf2-muse-cutouts = $(foreach f, $(filters), $(mcutdir)/udf2-$(f).fits)
$(udf2-muse-cutouts): $(mcutdir)/udf2-%.fits: $(audfdir)/muse-udf-%.fits \
$(imgcrop) reproduce/config/internal/vertices-udf2.mk \
| $(cutdir)
| $(mcutdir)
astimgcrop $(udf2polygon) $< -o$@
udf3-muse-cutouts = $(foreach f, $(filters), $(cutdir)/udf3-$(f)-m.fits)
$(udf3-muse-cutouts): $(cutdir)/udf3-%-m.fits: $(audfdir)/muse-udf-%.fits \
udf3-muse-cutouts = $(foreach f, $(filters), $(mcutdir)/udf3-$(f).fits)
$(udf3-muse-cutouts): $(mcutdir)/udf3-%.fits: $(audfdir)/muse-udf-%.fits \
$(imgcrop) reproduce/config/internal/vertices-udf3.mk \
| $(cutdir)
| $(mcutdir)
astimgcrop $(udf3polygon) $< -o$@
udf4-muse-cutouts = $(foreach f, $(filters), $(cutdir)/udf4-$(f)-m.fits)
$(udf4-muse-cutouts): $(cutdir)/udf4-%-m.fits: $(audfdir)/muse-udf-%.fits \
udf4-muse-cutouts = $(foreach f, $(filters), $(mcutdir)/udf4-$(f).fits)
$(udf4-muse-cutouts): $(mcutdir)/udf4-%.fits: $(audfdir)/muse-udf-%.fits \
$(imgcrop) reproduce/config/internal/vertices-udf4.mk \
| $(cutdir)
| $(mcutdir)
astimgcrop $(udf4polygon) $< -o$@
udf5-muse-cutouts = $(foreach f, $(filters), $(cutdir)/udf5-$(f)-m.fits)
$(udf5-muse-cutouts): $(cutdir)/udf5-%-m.fits: $(audfdir)/muse-udf-%.fits \
udf5-muse-cutouts = $(foreach f, $(filters), $(mcutdir)/udf5-$(f).fits)
$(udf5-muse-cutouts): $(mcutdir)/udf5-%.fits: $(audfdir)/muse-udf-%.fits \
$(imgcrop) reproduce/config/internal/vertices-udf5.mk \
| $(cutdir)
| $(mcutdir)
astimgcrop $(udf5polygon) $< -o$@
udf6-muse-cutouts = $(foreach f, $(filters), $(cutdir)/udf6-$(f)-m.fits)
$(udf6-muse-cutouts): $(cutdir)/udf6-%-m.fits: $(audfdir)/muse-udf-%.fits \
udf6-muse-cutouts = $(foreach f, $(filters), $(mcutdir)/udf6-$(f).fits)
$(udf6-muse-cutouts): $(mcutdir)/udf6-%.fits: $(audfdir)/muse-udf-%.fits \
$(imgcrop) reproduce/config/internal/vertices-udf6.mk \
| $(cutdir)
| $(mcutdir)
astimgcrop $(udf6polygon) $< -o$@
udf7-muse-cutouts = $(foreach f, $(filters), $(cutdir)/udf7-$(f)-m.fits)
$(udf7-muse-cutouts): $(cutdir)/udf7-%-m.fits: $(audfdir)/muse-udf-%.fits \
udf7-muse-cutouts = $(foreach f, $(filters), $(mcutdir)/udf7-$(f).fits)
$(udf7-muse-cutouts): $(mcutdir)/udf7-%.fits: $(audfdir)/muse-udf-%.fits \
$(imgcrop) reproduce/config/internal/vertices-udf7.mk \
| $(cutdir)
| $(mcutdir)
astimgcrop $(udf7polygon) $< -o$@
udf8-muse-cutouts = $(foreach f, $(filters), $(cutdir)/udf8-$(f)-m.fits)
$(udf8-muse-cutouts): $(cutdir)/udf8-%-m.fits: $(audfdir)/muse-udf-%.fits \
udf8-muse-cutouts = $(foreach f, $(filters), $(mcutdir)/udf8-$(f).fits)
$(udf8-muse-cutouts): $(mcutdir)/udf8-%.fits: $(audfdir)/muse-udf-%.fits \
$(imgcrop) reproduce/config/internal/vertices-udf8.mk \
| $(cutdir)
| $(mcutdir)
astimgcrop $(udf8polygon) $< -o$@
udf9-muse-cutouts = $(foreach f, $(filters), $(cutdir)/udf9-$(f)-m.fits)
$(udf9-muse-cutouts): $(cutdir)/udf9-%-m.fits: $(audfdir)/muse-udf-%.fits \
udf9-muse-cutouts = $(foreach f, $(filters), $(mcutdir)/udf9-$(f).fits)
$(udf9-muse-cutouts): $(mcutdir)/udf9-%.fits: $(audfdir)/muse-udf-%.fits \
$(imgcrop) reproduce/config/internal/vertices-udf9.mk \
| $(cutdir)
| $(mcutdir)
astimgcrop $(udf9polygon) $< -o$@
udf10-muse-cutouts = $(foreach f, $(filters), $(cutdir)/udf10-$(f)-m.fits)
$(udf10-muse-cutouts): $(cutdir)/udf10-%-m.fits: \
udf10-muse-cutouts = $(foreach f, $(filters), $(mcutdir)/udf10-$(f).fits)
$(udf10-muse-cutouts): $(mcutdir)/udf10-%.fits: \
$(MUSEINPUTS)/muse-udf10-%.fits $(imgcrop) \
reproduce/config/internal/vertices-udf10.mk | $(cutdir)
reproduce/config/internal/vertices-udf10.mk | $(mcutdir)
astimgcrop $(udf10polygon) -h1 $< -o$@
......@@ -116,9 +116,9 @@ $(udf10-muse-cutouts): $(cutdir)/udf10-%-m.fits: \
# 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)/pix-res-scale.txt: $(mcutdir)/udf1-f606w.fits \
$(hdegdir)/udf1-f606w-c.fits
mres=$$(astheader $(cutdir)/udf1-f606w-m.fits | grep PC2_2 \
mres=$$(astheader $(mcutdir)/udf1-f606w.fits | grep PC2_2 \
| awk '{print $$3}'); \
hres=$$(astheader $(hdegdir)/udf1-f606w-c.fits | grep PC2_2 \
| awk '{print $$3}'); \
......@@ -134,26 +134,51 @@ $(hdegdir)/pix-res-scale.txt: $(cutdir)/udf1-f606w-m.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
# easily use one segmentation map over both images.
cutdir = $(BDIR)/cutouts
h-to-m-pixres = $(foreach uid, 1 2 3 4 5 6 7 8 9 10, \
$(foreach f, $(filters), $(cutdir)/udf$(uid)-$(f)-h.fits) )
$(h-to-m-pixres): $(cutdir)/%-h.fits: $(hdegdir)/%-c.fits $(cutdir)/%-m.fits \
$(hdegdir)/pix-res-scale.txt
$(h-to-m-pixres): $(cutdir)/%-h.fits: $(hdegdir)/%-c.fits $(mcutdir)/%.fits \
$(hdegdir)/pix-res-scale.txt $(imgwarp) $(imgcrop) \
| $(cutdir)
# Warp the HST image to the MUSE pixel scale.
scalefactor=$$(cat $(hdegdir)/pix-res-scale.txt); \
# Warp the HST image to the MUSE pixel scale, first find the
# scale factor (sf), then wap the image.
scalefactor=$$(cat $(hdegdir)/pix-res-scale.txt); \
astimgwarp $< --scale=$$scalefactor -o$@ --numthreads=1
# The final segmentation map will also be from the HST image
# and warped with the same scale factor. So if the MUSE cutout
# image is not the same size as this warped image, we need to
# make it the same size.
msize=$$(astheader $(cutdir)/$*-m.fits | awk '$$1=="NAXIS1" {x=$$3} \
# Correct MUSE image size
# -----------------------
#
# To generate the catalog, all the inputs have to have the same
# size. However, due to differences in the WCS, after being warped,
# some fields might give a different size (by one pixel) compared to
# the MUSE cropped image. Since we will be using this warp againon an
# orignal HST image later at segmentation time, the only way would be
# to make the MUSE image the same size as the resampled HST
# image. This will only be the addition or removal of one row or
# column in the image, so it shouldn't be significant.
muse-corr = $(foreach uid, 1 2 3 4 5 6 7 8 9 10, \
$(foreach f, $(filters), $(cutdir)/udf$(uid)-$(f)-m.fits) )
$(muse-corr): $(cutdir)/%-m.fits: $(mcutdir)/%.fits $(cutdir)/%-h.fits
# If the sizes are identical, then just copy the actual
# cropped MUSE image, otherwise, using ImageCrop's `--section'
# option, specify if a road should be added or removed from
# the MUSE image.
msize=$$(astheader $(mcutdir)/$*.fits | awk '$$1=="NAXIS1" {x=$$3} \
$$1=="NAXIS2"{y=$$3} END{print x, y}'); \
hsize=$$(astheader $(cutdir)/$*-h.fits | awk '$$1=="NAXIS1" {x=$$3} \
$$1=="NAXIS2"{y=$$3} END{print x, y}'); \
if [ "$$msize" != "$$hsize" ]; then \
echo "$*: Not equal."; \
exit 1; \
if [ "$$msize" = "$$hsize" ]; then \
cp $< $@; \
else \
echo "$*: Equal."; \
so=$$(echo "$$msize $$hsize" \
| awk '{x = $$1==$$3 ? ":" : sprintf("%d:", 1+$$1-$$3); \
y = $$2==$$4 ? ":" : sprintf("%d:", 1+$$2-$$4); \
printf("--section=%s,%s", x, y)}'); \
astimgcrop $< $$so -o$@; \
fi
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