Coverage for tests/test_assemble.py : 29%

Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
# This file is part of obs_lsst. # # Developed for the LSST Data Management System. # This product includes software developed by the LSST Project # (http://www.lsst.org). # See the COPYRIGHT file at the top-level directory of this distribution # for details of code ownership. # # This program 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 program 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. # # You should have received a copy of the GNU General Public License # along with this program. If not, see <http://www.gnu.org/licenses/>.
# A snapshot of LATISS that has incorrect overscan regions for this # data ID self.cameraBroken = Camera.readFits(os.path.join(LOCAL_DATA_ROOT, "camera-bad-overscan.fits")) # A snapshot of the Detector for this file after we've read it in with # code that fixes the overscans. self.detectorFixed = Detector.readFits(os.path.join(LOCAL_DATA_ROOT, "detector-fixed-assembled.fits")) self.assertEqual(self.cameraBroken[0].getName(), self.detectorFixed.getName())
"""Check that Raw bounding boxes match between amps.
Parameters ---------- amp1 : `~lsst.afw.cameraGeom.Amplifier` First amplifier. amp2 : `~lsst.afw.cameraGeom.Amplifier` Second amplifier. """ self.assertEqual(amp1.getRawBBox(), amp2.getRawBBox()) self.assertEqual(amp1.getRawHorizontalOverscanBBox(), amp2.getRawHorizontalOverscanBBox()) self.assertEqual(amp1.getRawVerticalOverscanBBox(), amp2.getRawVerticalOverscanBBox())
"""Check that amp1 can be self-consistently transformed to match amp2.
This method compares amplifier bounding boxes by confirming that they represent the same segment of the detector image. If the offsets or amplifier flips differ between the amplifiers, this method will pass even if the raw bounding boxes returned by the amplifier accessors are not equal.
Parameters ---------- amp1 : `~lsst.afw.cameraGeom.Amplifier` Amplifier to transform. amp2 : `~lsst.afw.cameraGeom.Amplifier` Reference amplifier.
""" xFlip = amp1.getRawFlipX() ^ amp2.getRawFlipX() yFlip = amp1.getRawFlipY() ^ amp2.getRawFlipY() XYOffset = amp1.getRawXYOffset() - amp2.getRawXYOffset()
testRawBox = amp1.getRawBBox() testHOSBox = amp1.getRawHorizontalOverscanBBox() testVOSBox = amp1.getRawVerticalOverscanBBox()
if xFlip: size = amp1.getRawBBox().getWidth() testRawBox.flipLR(size) testHOSBox.flipLR(size) testVOSBox.flipLR(size) if yFlip: size = amp1.getRawBBox().getHeight() testRawBox.flipTB(size) testHOSBox.flipTB(size) testVOSBox.flipTB(size)
testRawBox.shift(XYOffset) testHOSBox.shift(XYOffset) testVOSBox.shift(XYOffset)
self.assertEqual(testRawBox, amp2.getRawBBox()) self.assertEqual(testHOSBox, amp2.getRawHorizontalOverscanBBox()) self.assertEqual(testVOSBox, amp2.getRawVerticalOverscanBBox())
"""Test that we can use the Gen2 Butler to read a file with overscan regions that disagree with cameraGeom, and that the detector attached to it has its overscan regions corrected.
This is essentially just a regression test, and an incomplete one at that: the fixed Detector snapshot that we're comparing to was generated by the same code we're calling here. And because the LATISS associated by the Butler we use in this test may in the future be corrected to have the right overscan regions, we may end up just testing a simpler case than we intended. We'll use a snapshot of the incorrect Camera in other tests to get coverage of that case. """ butler = Butler(LATISS_DATA_ROOT) raw = butler.get("raw", dataId=BAD_OVERSCAN_GEN2_DATA_ID) for amp1, amp2 in zip(self.detectorFixed, raw.getDetector()): with self.subTest(amp=amp1.getName()): self.assertEqual(amp1.getName(), amp2.getName()) self.assertAmpRawBBoxesEqual(amp1, amp2)
"""Test the low-level code for repairing cameraGeom overscan regions that disagree with raw files. """ testFile = os.path.join(LATISS_DATA_ROOT, BAD_OVERSCAN_FILENAME)
for i, (ampBad, ampGood) in enumerate(zip(self.cameraBroken[0], self.detectorFixed)): with self.subTest(amp=ampBad.getName()): self.assertEqual(ampBad.getName(), ampGood.getName()) hdu = i + 1 reader = ImageFitsReader(testFile, hdu=hdu) metadata = reader.readMetadata() image = reader.read() self.assertEqual(ampGood.getRawBBox().getDimensions(), image.getBBox().getDimensions()) self.assertNotEqual(ampBad.getRawBBox().getDimensions(), image.getBBox().getDimensions()) newAmp, modified = fixAmpGeometry(ampBad, image.getBBox(), metadata) self.assertTrue(modified) self.assertNotEqual(newAmp.getRawBBox().getDimensions(), ampBad.getRawBBox().getDimensions()) self.assertAmpRawBBoxesFlippablyEqual(newAmp, ampGood)
fileName = os.path.join(LATISS_DATA_ROOT, BAD_OVERSCAN_FILENAME) policy = os.path.join(PACKAGE_DIR, "policy", "latiss.yaml") camera = yamlCamera.makeCamera(policy) exposure = readRawFile(fileName, camera[0], dataId={"file": fileName}) self.assertIsInstance(exposure, lsst.afw.image.Exposure) md = exposure.getMetadata() self.assertIn("INSTRUME", md)
lsst.utils.tests.init()
setup_module(sys.modules[__name__]) unittest.main() |