Coverage for tests/test_transformDiaSourceCatalog.py : 30%

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
1# This file is part of ap_association
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 os
23import unittest
25from lsst.ap.association.transformDiaSourceCatalog import (TransformDiaSourceCatalogConfig,
26 TransformDiaSourceCatalogTask)
27from lsst.afw.cameraGeom.testUtils import DetectorWrapper
28import lsst.daf.base as dafBase
29import lsst.afw.image as afwImage
30import lsst.geom as geom
31import lsst.meas.base.tests as measTests
32from lsst.utils import getPackageDir
33import lsst.utils.tests
36class TestTransformDiaSourceCatalogTask(unittest.TestCase):
38 def setUp(self):
39 nSources = 10
40 self.bboxSize = 18
41 self.xyLoc = 100
42 self.bbox = geom.Box2I(geom.Point2I(0, 0),
43 geom.Extent2I(1024, 1153))
44 dataset = measTests.TestDataset(self.bbox)
45 for srcIdx in range(nSources):
46 dataset.addSource(100000.0, geom.Point2D(self.xyLoc, self.xyLoc))
47 schema = dataset.makeMinimalSchema()
48 self.exposure, self.inputCatalog = dataset.realize(10.0, schema, randomSeed=1234)
50 self.expId = 4321
51 self.date = dafBase.DateTime(nsecs=1400000000 * 10**9)
52 detector = DetectorWrapper(id=23, bbox=self.exposure.getBBox()).detector
53 visit = afwImage.VisitInfo(
54 exposureId=self.expId,
55 exposureTime=200.,
56 date=self.date)
57 self.exposure.setDetector(detector)
58 self.exposure.getInfo().setVisitInfo(visit)
59 self.filterName = 'g'
60 self.exposure.setFilterLabel(afwImage.FilterLabel(band=self.filterName, physical='g.MP9401'))
61 scale = 2
62 scaleErr = 1
63 self.photoCalib = afwImage.PhotoCalib(scale, scaleErr)
64 self.exposure.setPhotoCalib(self.photoCalib)
66 def test_run(self):
67 """Test output dataFrame is created and values are correctly inserted
68 from the exposure.
69 """
70 transformConfig = TransformDiaSourceCatalogConfig()
71 transformConfig.functorFile = os.path.join(getPackageDir("ap_association"),
72 "tests/data/",
73 "testDiaSource.yaml")
74 transformTask = TransformDiaSourceCatalogTask(config=transformConfig)
75 result = transformTask.run(self.inputCatalog,
76 self.exposure,
77 self.filterName,
78 ccdVisitId=self.expId)
80 self.assertEqual(len(result.diaSourceTable), len(self.inputCatalog))
81 for idx, src in result.diaSourceTable.iterrows():
82 self.assertEqual(src["bboxSize"], self.bboxSize)
83 self.assertEqual(src["ccdVisitId"], self.expId)
84 self.assertEqual(src["filterName"], self.filterName)
85 self.assertEqual(src["midPointTai"],
86 self.date.get(system=dafBase.DateTime.MJD))
87 self.assertEqual(src["pixelId"], 0)
88 self.assertEqual(src["diaObjectId"], 0)
90 def test_computeBBoxSize(self):
91 """Test the values created for diaSourceBBox.
92 """
93 transform = TransformDiaSourceCatalogTask()
94 bboxArray = transform.computeBBoxSizes(self.inputCatalog)
96 # Default in catalog is 18.
97 self.assertEqual(bboxArray[0], self.bboxSize)
100class MemoryTester(lsst.utils.tests.MemoryTestCase):
101 pass
104def setup_module(module):
105 lsst.utils.tests.init()
108if __name__ == "__main__": 108 ↛ 109line 108 didn't jump to line 109, because the condition on line 108 was never true
109 lsst.utils.tests.init()
110 unittest.main()