Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DM-28717: Allow for Stamps formatter to handle bbox #573

Merged
merged 3 commits into from
Mar 10, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
35 changes: 20 additions & 15 deletions python/lsst/afw/image/image/fitsIoWithOptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def imageReadFitsWithOptions(cls, source, options):
source : `str`
Fits file path from which to read image, mask, masked image
or exposure.
options : `lsst.daf.base.PropertySet`
options : `lsst.daf.base.PropertySet` or `dict`
Read options:

- llcX: bbox minimum x (int)
Expand All @@ -52,6 +52,9 @@ def imageReadFitsWithOptions(cls, source, options):
- imageOrigin: one of "LOCAL" or "PARENT" (has no effect unless
a bbox is specified by llcX, etc.)

Alternatively, a bounding box () can be passed on with the
``"bbox"'' (`lsst.geom.Box2I`) key.

Raises
------
RuntimeError
Expand All @@ -60,22 +63,24 @@ def imageReadFitsWithOptions(cls, source, options):
If options contains "llcX" and is missing any of
"llcY", "width", or "height".
"""
origin = ImageOrigin.PARENT
bbox = lsst.geom.Box2I()
if options.exists("llcX"):
llcX = options.getInt("llcX")
llcY = options.getInt("llcY")
width = options.getInt("width")
height = options.getInt("height")
if "bbox" in options:
bbox = options["bbox"]
elif "llcX" in options:
llcX = int(options["llcX"])
llcY = int(options["llcY"])
width = int(options["width"])
height = int(options["height"])
bbox = lsst.geom.Box2I(lsst.geom.Point2I(llcX, llcY), lsst.geom.Extent2I(width, height))
origin = ImageOrigin.PARENT
if options.exists("imageOrigin"):
originStr = options.getString("imageOrigin")
if (originStr == "LOCAL"):
origin = ImageOrigin.LOCAL
elif (originStr == "PARENT"):
origin = ImageOrigin.PARENT
else:
raise RuntimeError("Unknown ImageOrigin type {}".format(originStr))
if "imageOrigin" in options:
originStr = str(options["imageOrigin"])
if (originStr == "LOCAL"):
origin = ImageOrigin.LOCAL
elif (originStr == "PARENT"):
origin = ImageOrigin.PARENT
else:
raise RuntimeError("Unknown ImageOrigin type {}".format(originStr))

return cls(source, bbox=bbox, origin=origin)

Expand Down
8 changes: 4 additions & 4 deletions tests/test_ellipse.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def setUp(self):

def testRadii(self):
for core, det, trace in zip(self.cores, [144, 14], [25, 8]):
with self.subTest(core=core):
with self.subTest(core=str(core)):
detRadius = det**0.25
traceRadius = (0.5 * trace)**0.5
area = np.pi * det**0.5
Expand All @@ -78,7 +78,7 @@ def testRadii(self):

def testAccessors(self):
for core in self.cores:
with self.subTest(core=core):
with self.subTest(core=str(core)):
vec = np.random.randn(3) * 1E-3 + core.getParameterVector()
core.setParameterVector(vec)
self.assertImagesEqual(core.getParameterVector(), vec)
Expand All @@ -103,7 +103,7 @@ def testAccessors(self):

def testTransform(self):
for core in self.cores:
with self.subTest(core=core):
with self.subTest(core=str(core)):
transform = lsst.geom.LinearTransform(np.random.randn(2, 2))
t1 = core.transform(transform)
core.transformInPlace(transform)
Expand All @@ -113,7 +113,7 @@ def testTransform(self):

def testPixelRegion(self):
for core in self.cores:
with self.subTest(core=core):
with self.subTest(core=str(core)):
e = lsst.afw.geom.ellipses.Ellipse(
core, lsst.geom.Point2D(*np.random.randn(2)))
region = lsst.afw.geom.ellipses.PixelRegion(e)
Expand Down
2 changes: 1 addition & 1 deletion tests/test_image.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ def testImagesOverlap(self):
imageClasses = (afwImage.ImageF, afwImage.ImageD, afwImage.ImageI, afwImage.Mask)

for ImageClass1, ImageClass2 in itertools.product(imageClasses, imageClasses):
with self.subTest(ImageClass1=ImageClass1, ImageClass2=ImageClass2):
with self.subTest(ImageClass1=str(ImageClass1), ImageClass2=str(ImageClass2)):
image1 = ImageClass1(dim)
self.assertTrue(afwImage.imagesOverlap(image1, image1))

Expand Down
4 changes: 2 additions & 2 deletions tests/test_imageIo1.py
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ def testReadFitsWithOptions(self):
(afwImage.ImageF, afwImage.ImageD),
(None, "LOCAL", "PARENT"),
):
with self.subTest(ImageClass=ImageClass, imageOrigin=imageOrigin):
with self.subTest(ImageClass=str(ImageClass), imageOrigin=imageOrigin):
fullImage = ImageClass(filepath)
options = dafBase.PropertySet()
options.set("llcX", bbox.getMinX())
Expand All @@ -242,7 +242,7 @@ def testReadFitsWithOptions(self):
for name in ("llcY", "width", "height"):
badOptions = options.deepCopy()
badOptions.remove(name)
with self.assertRaises(pexExcept.NotFoundError):
with self.assertRaises(LookupError):
ImageClass.readFitsWithOptions(filepath, badOptions)

badOptions = options.deepCopy()
Expand Down
2 changes: 1 addition & 1 deletion tests/test_maskedImage.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ def testImagesOverlap(self):
images = [ImageClass1(dim), ImageClass2(dim)]
for image1, mask1, variance1, image2, mask2, variance2 in itertools.product(
images, masks, variances, images, masks, variances):
with self.subTest(ImageClass1=ImageClass1, ImageClass2=ImageClass2,
with self.subTest(ImageClass1=str(ImageClass1), ImageClass2=str(ImageClass2),
image1=image1, mask1=mask1, variance1=variance1,
image2=image2, mask2=mask2, variance2=variance2):
shouldOverlap = (image1 is image2) or (mask1 is mask2) or (variance1 is variance2)
Expand Down
4 changes: 2 additions & 2 deletions tests/test_maskedImageIO.py
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ def testReadFitsWithOptions(self):
(afwImage.MaskedImageF, afwImage.MaskedImageD),
(None, "LOCAL", "PARENT"),
):
with self.subTest(ImageClass=ImageClass, imageOrigin=imageOrigin):
with self.subTest(ImageClass=str(ImageClass), imageOrigin=imageOrigin):
fullImage = ImageClass(filepath)
options = dafBase.PropertySet()
options.set("llcX", bbox.getMinX())
Expand All @@ -232,7 +232,7 @@ def testReadFitsWithOptions(self):
for name in ("llcY", "width", "height"):
badOptions = options.deepCopy()
badOptions.remove(name)
with self.assertRaises(pexEx.NotFoundError):
with self.assertRaises(LookupError):
ImageClass.readFitsWithOptions(filepath, badOptions)

badOptions = options.deepCopy()
Expand Down