Coverage for tests/test_RBTransiNetTask.py: 29%
65 statements
« prev ^ index » next coverage.py v7.4.4, created at 2024-04-06 12:12 +0000
« prev ^ index » next coverage.py v7.4.4, created at 2024-04-06 12:12 +0000
1# This file is part of meas_transiNet.
2#
3# Developed for the LSST Data Management System.
4# This product includes software developed by the LSST Project
5# (https://www.lsst.org).
6# See the COPYRIGHT file at the top-level directory of this distribution
7# for details of code ownership.
8#
9# This program is free software: you can redistribute it and/or modify
10# it under the terms of the GNU General Public License as published by
11# the Free Software Foundation, either version 3 of the License, or
12# (at your option) any later version.
13#
14# This program is distributed in the hope that it will be useful,
15# but WITHOUT ANY WARRANTY; without even the implied warranty of
16# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17# GNU General Public License for more details.
18#
19# You should have received a copy of the GNU General Public License
20# along with this program. If not, see <https://www.gnu.org/licenses/>.
22import unittest
23import numpy as np
25import lsst.afw.table
26from lsst.geom import Point2I, Point2D, Box2I
27import lsst.meas.base.tests
28import lsst.utils.tests
30from lsst.meas.transiNet import RBTransiNetTask
33class TestRBTransiNetTask(lsst.utils.tests.TestCase):
34 def create_sample_datasets(self):
35 bbox = Box2I(Point2I(0, 0), Point2I(400, 400))
36 dataset = lsst.meas.base.tests.TestDataset(bbox)
37 dataset.addSource(5000, Point2D(50, 50.))
38 # TODO: make one of these centered in a different corner of the pixel,
39 # to test that the cutout is properly centered.
40 dataset.addSource(10000, Point2D(100, 50.))
41 dataset.addSource(20000, Point2D(1, 1)) # close-to-border source
42 self.exposure, self.catalog = dataset.realize(10.0, dataset.makeMinimalSchema())
44 def setUp(self):
45 self.create_sample_datasets()
47 # Task configuration
48 self.config = RBTransiNetTask.ConfigClass()
49 self.config.modelPackageName = "dummy"
50 self.config.modelPackageStorageMode = "local"
52 def test_make_cutouts(self):
53 task = RBTransiNetTask(config=self.config)
54 for record in self.catalog:
55 result = task._make_cutouts(self.exposure, self.exposure, self.exposure, record)
56 self._check_cutout(result.science, task.config.cutoutSize)
57 self._check_cutout(result.template, task.config.cutoutSize)
58 self._check_cutout(result.difference, task.config.cutoutSize)
60 if record.getX() == 1 and record.getY() == 1: # This is the "border"-source
61 self._check_empty_cutout(result.science)
62 self._check_empty_cutout(result.template)
63 self._check_empty_cutout(result.difference)
65 def _check_cutout(self, image, size):
66 """Test that the image cutout was made correctly.
68 Parameters
69 ----------
70 image : `np.ndarray` (N, 2)
71 Square cutout made from image.
72 size : `int`
73 Expected size of the cutout.
74 """
75 self.assertEqual(image.shape, (size, size))
76 return
78 # TODO: below test should be removed/fixed -- disabled for now.
79 # It only passes with very specific cutout dimensions and in
80 # very specific configurations.
81 # See https://jira.lsstcorp.org/browse/DM-35635 for more info.
83 max_index = np.unravel_index(image.argmax(), image.shape)
84 # TODO: I'm not comfortable with this particular test: the exact
85 # position of the max pixel depends on where in that pixel the
86 # centroid is. We can assume Box2I.makeCenteredBox works correctly...
87 self.assertEqual(max_index, ((size/2)-1, (size/2)-1))
89 def _check_empty_cutout(self, cutout):
90 """Test that the cutout is empty.
92 Parameters
93 ----------
94 cutout : `np.ndarray` (N, 2)
95 Square cutout made from image.
96 """
97 np.testing.assert_array_equal(cutout, np.zeros_like(cutout))
99 def test_run(self):
100 """Test that run passes an appropriate object to the interface.
101 """
102 task = RBTransiNetTask(config=self.config)
103 result = task.run(self.exposure, self.exposure, self.exposure, self.catalog)
104 self.assertIsInstance(result.classifications, lsst.afw.table.BaseCatalog)
105 np.testing.assert_array_equal(self.catalog["id"], result.classifications["id"])
107 def test_config_butlerblock(self):
108 config = RBTransiNetTask.ConfigClass()
109 config.modelPackageName = "dummy"
110 config.modelPackageStorageMode = "butler"
111 with self.assertRaises(ValueError):
112 config.validate()
114 def test_config_butlerpass_none(self):
115 config = RBTransiNetTask.ConfigClass()
116 config.modelPackageName = None
117 config.modelPackageStorageMode = "butler"
118 # Should not raise
119 config.validate()
121 def test_config_butlerblock_empty(self):
122 config = RBTransiNetTask.ConfigClass()
123 config.modelPackageName = "" # Want *only* None for butler packages
124 config.modelPackageStorageMode = "butler"
125 with self.assertRaises(ValueError):
126 config.validate()
129class MemoryTester(lsst.utils.tests.MemoryTestCase):
130 pass
133def setup_module(module):
134 lsst.utils.tests.init()
137if __name__ == "__main__": 137 ↛ 138line 137 didn't jump to line 138, because the condition on line 137 was never true
138 lsst.utils.tests.init()
139 unittest.main()