Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
michitaro
hsc-release-faq
Commits
3e37c6d1
Commit
3e37c6d1
authored
Feb 10, 2017
by
michitaro
Browse files
Add new file
parent
fadc510d
Changes
1
Hide whitespace changes
Inline
Side-by-side
stitch_patches.py
0 → 100644
View file @
3e37c6d1
#!/usr/bin/env python
# encoding: utf-8
# Library about image in AFW (Application FrameWork)
import
lsst.afw.image
as
afwImage
# Library about geometry in AFW
import
lsst.afw.geom
as
afwGeom
import
sys
def
main
():
if
len
(
sys
.
argv
)
<=
1
:
print
"Select more than 1 patch"
return
1
largeImage
=
makeLargeImageFromPatches
(
sys
.
argv
[
1
:])
print
"Saving data (Wait a while...)"
largeImage
.
writeFits
(
"large.fits"
)
def
makeLargeImageFromPatches
(
filenames
):
# Get metric information of image
bboxes
=
[]
for
filename
in
filenames
:
print
"Get bounding box:"
,
filename
,
"..."
bboxes
.
append
(
# Get bounding box of this patch in parent(=tract).
afwImage
.
ExposureF
(
filename
).
getBBox
(
afwImage
.
PARENT
)
)
# Derive a BBox that includes all BBox
# Return value of getMin/Max methods is inclusive
# (Region = [min, max]) cf. getBegin/End (Use below)
x0
=
min
(
bbox
.
getMinX
()
for
bbox
in
bboxes
)
y0
=
min
(
bbox
.
getMinY
()
for
bbox
in
bboxes
)
x1
=
max
(
bbox
.
getMaxX
()
for
bbox
in
bboxes
)
y1
=
max
(
bbox
.
getMaxY
()
for
bbox
in
bboxes
)
width
=
x1
-
x0
+
1
height
=
y1
-
y0
+
1
# Prepare large image
print
"Prepare for image: ({}, {})"
.
format
(
width
,
height
)
exposure
=
afwImage
.
ExposureF
(
width
,
height
)
# Set position of image in the tract
exposure
.
setXY0
(
afwGeom
.
Point2I
(
x0
,
y0
))
# Extract am image part from Exposure
largeImage
=
exposure
.
getMaskedImage
()
# Paste patches to largeImage
for
filename
in
filenames
:
print
"Get patch:"
,
filename
,
"..."
# Load patches again
patch
=
afwImage
.
ExposureF
(
filename
)
bbox
=
patch
.
getBBox
(
afwImage
.
PARENT
)
# Position of this patch in the largeImage
# Return value of getBegin/End methods is one past the end
# (Region = [begin,end) ) cf. getMin/Max (Used above)
xp0
=
bbox
.
getBeginX
()
-
x0
yp0
=
bbox
.
getBeginY
()
-
y0
xp1
=
bbox
.
getEndX
()
-
x0
yp1
=
bbox
.
getEndY
()
-
y0
# Pase patches (Please refer to numpy documets for the syntax of [])
largeImage
[
xp0
:
xp1
,
yp0
:
yp1
]
=
patch
.
getMaskedImage
()[:]
# Assume that all patches have the same information (e.g. WCS),
# Set one of them to large image.
if
not
exposure
.
hasWcs
()
and
patch
.
hasWcs
():
exposure
.
setCalib
(
patch
.
getCalib
())
exposure
.
setFilter
(
patch
.
getFilter
())
exposure
.
setMetadata
(
patch
.
getMetadata
())
exposure
.
setWcs
(
patch
.
getWcs
())
return
exposure
if
__name__
==
"__main__"
:
main
()
\ No newline at end of file
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment