From d07892e45e7e4187cdaacf6fc504e3a0c2b198dd Mon Sep 17 00:00:00 2001 From: Erfan Nourbakhsh Date: Fri, 23 Jun 2023 02:56:32 -0400 Subject: [PATCH 1/2] Add unit test for ReinterpolatePixelsTask in meas_algorithms --- tests/test_reinterpolate_pixels.py | 65 ++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100644 tests/test_reinterpolate_pixels.py diff --git a/tests/test_reinterpolate_pixels.py b/tests/test_reinterpolate_pixels.py new file mode 100644 index 000000000..8bc23418f --- /dev/null +++ b/tests/test_reinterpolate_pixels.py @@ -0,0 +1,65 @@ +# This file is part of pipe_tasks. +# +# Developed for the LSST Data Management System. +# This product includes software developed by the LSST Project +# (https://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 . + +import unittest + +import lsst.ip.isr as ipIsr +import lsst.ip.isr.isrMock as isrMock +import lsst.utils.tests +from lsst.meas.algorithms import ReinterpolatePixelsConfig, ReinterpolatePixelsTask +from lsst.utils.tests import methodParameters + + +class TestReinterpolatePixels(lsst.utils.tests.TestCase): + """Test that ReinterpolatePixelsTask for meas_algorithms produces expected + outputs. + """ + + def setUp(self): + self.inputExp = isrMock.TrimmedRawMock().run() + self.mi = self.inputExp.getMaskedImage() + + @methodParameters(growFootprints=range(3)) + def test_reinterpolate_pixels(self, growFootprints): + """Expect number of interpolated pixels to be non-zero.""" + ipIsr.makeThresholdMask(self.mi, 200, growFootprints=2, maskName="SAT") + config = ReinterpolatePixelsConfig() + config.growFootprints = growFootprints + config.kernelFwhm = 2.0 + config.maskNameList = ["SAT"] + task = ReinterpolatePixelsTask(config=config) + task.run(self.inputExp) + interpMaskedImage = self.inputExp.getMaskedImage() + numBit = ipIsr.countMaskedPixels(interpMaskedImage, "INTRP") + self.assertEqual(numBit, 40800, msg=f"ReinterpolatePixels with growFootprints={growFootprints}") + + +class TestMemory(lsst.utils.tests.MemoryTestCase): + pass + + +def setup_module(module): + lsst.utils.tests.init() + + +if __name__ == "__main__": + lsst.utils.tests.init() + unittest.main() From 883df7ac772f388d2a01c14db65954b6480c5e77 Mon Sep 17 00:00:00 2001 From: Erfan Nourbakhsh Date: Wed, 28 Jun 2023 19:13:25 -0400 Subject: [PATCH 2/2] Update to reflect changes made in lsst.meas.algorithms --- tests/test_reinterpolate_pixels.py | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/tests/test_reinterpolate_pixels.py b/tests/test_reinterpolate_pixels.py index 8bc23418f..08bb30105 100644 --- a/tests/test_reinterpolate_pixels.py +++ b/tests/test_reinterpolate_pixels.py @@ -22,10 +22,8 @@ import unittest import lsst.ip.isr as ipIsr -import lsst.ip.isr.isrMock as isrMock import lsst.utils.tests from lsst.meas.algorithms import ReinterpolatePixelsConfig, ReinterpolatePixelsTask -from lsst.utils.tests import methodParameters class TestReinterpolatePixels(lsst.utils.tests.TestCase): @@ -34,22 +32,19 @@ class TestReinterpolatePixels(lsst.utils.tests.TestCase): """ def setUp(self): - self.inputExp = isrMock.TrimmedRawMock().run() + self.inputExp = ipIsr.isrMock.TrimmedRawMock().run() self.mi = self.inputExp.getMaskedImage() - @methodParameters(growFootprints=range(3)) - def test_reinterpolate_pixels(self, growFootprints): + def test_reinterpolate_pixels(self): """Expect number of interpolated pixels to be non-zero.""" ipIsr.makeThresholdMask(self.mi, 200, growFootprints=2, maskName="SAT") config = ReinterpolatePixelsConfig() - config.growFootprints = growFootprints - config.kernelFwhm = 2.0 config.maskNameList = ["SAT"] task = ReinterpolatePixelsTask(config=config) task.run(self.inputExp) interpMaskedImage = self.inputExp.getMaskedImage() numBit = ipIsr.countMaskedPixels(interpMaskedImage, "INTRP") - self.assertEqual(numBit, 40800, msg=f"ReinterpolatePixels with growFootprints={growFootprints}") + self.assertEqual(numBit, 40800) class TestMemory(lsst.utils.tests.MemoryTestCase):