Commit 3e37c6d1 authored by michitaro's avatar michitaro
Browse files

Add new file

parent fadc510d
#!/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...)"
def makeLargeImageFromPatches(filenames):
# Get metric information of image
bboxes = []
for filename in filenames:
print "Get bounding box:", filename, "..."
# Get bounding box of this patch in parent(=tract).
# 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.setWcs (patch.getWcs ())
return exposure
if __name__ == "__main__":
\ No newline at end of file
Supports Markdown
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