Coverage for tests/test_loadReferenceCatalog.py: 25%
138 statements
« prev ^ index » next coverage.py v6.4.1, created at 2022-06-14 03:30 -0700
« prev ^ index » next coverage.py v6.4.1, created at 2022-06-14 03:30 -0700
1import unittest
2import copy
4import astropy.units as u
6import lsst.utils.tests
7import lsst.afw.geom
8import lsst.pipe.base as pipeBase
9from lsst.meas.algorithms import (LoadReferenceObjectsTask,
10 getRefFluxField,
11 ReferenceObjectLoader)
12from lsst.pipe.tasks.loadReferenceCatalog import LoadReferenceCatalogConfig, LoadReferenceCatalogTask
13from lsst.pipe.tasks.colorterms import Colorterm, ColortermDict, ColortermLibrary
16synthTerms = ColortermLibrary(data={
17 "synth*": ColortermDict(data={
18 "filter1": Colorterm(primary="ref1", secondary="ref2", c0=0.0, c1=0.01),
19 "filter2": Colorterm(primary="ref2", secondary="ref3", c0=0.0, c1=-0.01),
20 })
21})
24_synthFlux = 100.0
25_synthCenter = lsst.geom.SpherePoint(30, -30, lsst.geom.degrees)
28def setup_module(module):
29 lsst.utils.tests.init()
32class TrivialLoader(ReferenceObjectLoader):
33 """Minimal subclass of LoadReferenceObjectsTask"""
34 def make_synthetic_refcat(self, center, flux):
35 """Make a synthetic reference catalog."""
36 filters = ["ref1", "ref2", "ref3"]
37 schema = LoadReferenceObjectsTask.makeMinimalSchema(filters)
38 schema.addField('pm_ra', 'D')
39 schema.addField('pm_dec', 'D')
41 catalog = lsst.afw.table.SimpleCatalog(schema)
42 record = catalog.addNew()
43 record.setCoord(center)
44 record[filters[0] + '_flux'] = flux
45 record[filters[0] + '_fluxErr'] = flux*0.1
46 record[filters[1] + '_flux'] = flux*10
47 record[filters[1] + '_fluxErr'] = flux*10*0.1
48 record[filters[2] + '_flux'] = flux*100
49 record[filters[2] + '_fluxErr'] = flux*100*0.1
50 record['pm_ra'] = 0.0
51 record['pm_dec'] = 0.0
53 return catalog
55 def loadSkyCircle(self, ctrCoord, radius, filterName, **kwargs):
56 refCat = self.make_synthetic_refcat(_synthCenter, _synthFlux)
57 fluxField = getRefFluxField(schema=refCat.schema, filterName=filterName)
58 return pipeBase.Struct(
59 refCat=self.make_synthetic_refcat(_synthCenter, _synthFlux),
60 fluxField=fluxField
61 )
63 def loadPixelBox(self, bbox, wcs, referenceFilter, **kwargs):
64 return self.loadSkyCircle(None, None, referenceFilter)
67class LoadReferenceCatalogTestCase(lsst.utils.tests.TestCase):
68 @classmethod
69 def setUpClass(cls):
70 cls.config = LoadReferenceCatalogConfig()
71 cls.config.refObjLoader.filterMap = {"filter1": "ref1",
72 "filter2": "ref2"}
73 cls.config.refObjLoader.ref_dataset_name = 'synthCam'
74 cls.config.colorterms = synthTerms
75 cls.config.referenceSelector.doSignalToNoise = True
76 cls.config.referenceSelector.signalToNoise.fluxField = 'ref1_flux'
77 cls.config.referenceSelector.signalToNoise.errField = 'ref1_fluxErr'
78 cls.config.referenceSelector.signalToNoise.minimum = 20.0
80 cls.config.doApplyColorTerms = False
81 cls.config.doReferenceSelection = False
83 cls.synthMag1 = (_synthFlux*u.nanojansky).to(u.ABmag).value
84 cls.synthMag2 = ((_synthFlux*10)*u.nanojansky).to(u.ABmag).value
85 cls.synthMag3 = ((_synthFlux*100)*u.nanojansky).to(u.ABmag).value
87 cls.synthMag1Corr = cls.synthMag1 + 0.01*(cls.synthMag1 - cls.synthMag2)
88 cls.synthMag2Corr = cls.synthMag2 - 0.01*(cls.synthMag2 - cls.synthMag3)
90 cls.trivialLoader = TrivialLoader(dataIds=[], refCats=[], config=cls.config.refObjLoader)
92 def testGetReferenceCatalogCircle(self):
93 """Get a reference catalog skycircle."""
94 config = copy.copy(self.config)
95 config.freeze()
97 loaderTask = LoadReferenceCatalogTask(config=config, dataIds=[], refCats=[])
98 # Monkey-patch our testing trivial loader to bypass the butler
99 loaderTask.refObjLoader = self.trivialLoader
101 cat = loaderTask.getSkyCircleCatalog(_synthCenter,
102 1.0*lsst.geom.degrees,
103 ['filter1', 'filter2'])
105 self.assertAlmostEqual(cat['ra'], _synthCenter.getRa().asDegrees())
106 self.assertAlmostEqual(cat['dec'], _synthCenter.getDec().asDegrees())
107 self.assertFloatsAlmostEqual(cat['refMag'][0, 0], self.synthMag1, rtol=1e-7)
108 self.assertFloatsAlmostEqual(cat['refMag'][0, 1], self.synthMag2, rtol=1e-7)
110 def testGetReferenceCatalogBox(self):
111 """Get a reference catalog box."""
112 config = copy.copy(self.config)
113 config.freeze()
115 loaderTask = LoadReferenceCatalogTask(config=config, dataIds=[], refCats=[])
116 # Monkey-patch our testing trivial loader to bypass the butler
117 loaderTask.refObjLoader = self.trivialLoader
119 bbox = lsst.geom.Box2I(corner=lsst.geom.Point2I(0, 0),
120 dimensions=lsst.geom.Extent2I(100, 100))
121 crpix = lsst.geom.Point2D(50, 50)
122 crval = _synthCenter
123 cdMatrix = lsst.afw.geom.makeCdMatrix(scale=1.0*lsst.geom.arcseconds)
124 wcs = lsst.afw.geom.makeSkyWcs(crpix, crval, cdMatrix)
126 cat = loaderTask.getPixelBoxCatalog(bbox,
127 wcs,
128 ['filter1', 'filter2'])
130 self.assertAlmostEqual(cat['ra'], _synthCenter.getRa().asDegrees())
131 self.assertAlmostEqual(cat['dec'], _synthCenter.getDec().asDegrees())
132 self.assertFloatsAlmostEqual(cat['refMag'][0, 0], self.synthMag1, rtol=1e-7)
133 self.assertFloatsAlmostEqual(cat['refMag'][0, 1], self.synthMag2, rtol=1e-7)
135 def testGetReferenceCatalogCircleColorterms(self):
136 """Get a reference catalog circle, with color terms applied."""
137 config = copy.copy(self.config)
138 config.doApplyColorTerms = True
139 config.freeze()
141 loaderTask = LoadReferenceCatalogTask(config=config, dataIds=[], refCats=[])
142 # Monkey-patch our testing trivial loader to bypass the butler
143 loaderTask.refObjLoader = self.trivialLoader
145 cat = loaderTask.getSkyCircleCatalog(_synthCenter,
146 1.0*lsst.geom.degrees,
147 ['filter1', 'filter2'])
149 self.assertAlmostEqual(cat['ra'], _synthCenter.getRa().asDegrees())
150 self.assertAlmostEqual(cat['dec'], _synthCenter.getDec().asDegrees())
151 self.assertFloatsAlmostEqual(cat['refMag'][0, 0], self.synthMag1Corr, rtol=1e-7)
152 self.assertFloatsAlmostEqual(cat['refMag'][0, 1], self.synthMag2Corr, rtol=1e-7)
154 def testGetReferenceCatalogCircleSelection(self):
155 """Get a reference catalog circle, apply selection."""
156 config = copy.copy(self.config)
157 config.doReferenceSelection = True
158 config.freeze()
160 loaderTask = LoadReferenceCatalogTask(config=config, dataIds=[], refCats=[])
161 # Monkey-patch our testing trivial loader to bypass the butler
162 loaderTask.refObjLoader = self.trivialLoader
164 cat = loaderTask.getSkyCircleCatalog(_synthCenter,
165 1.0*lsst.geom.degrees,
166 ['filter1', 'filter2'])
168 # The selection removed all the objects.
169 self.assertEqual(len(cat), 0)
171 def testGetReferenceCatalogCircleSingleFilter(self):
172 """Get a reference catalog circle, single filter."""
173 config = copy.copy(self.config)
174 config.freeze()
176 loaderTask = LoadReferenceCatalogTask(config=config, dataIds=[], refCats=[])
177 # Monkey-patch our testing trivial loader to bypass the butler
178 loaderTask.refObjLoader = self.trivialLoader
180 cat = loaderTask.getSkyCircleCatalog(_synthCenter,
181 1.0*lsst.geom.degrees,
182 ['filter1'])
184 self.assertAlmostEqual(cat['ra'], _synthCenter.getRa().asDegrees())
185 self.assertAlmostEqual(cat['dec'], _synthCenter.getDec().asDegrees())
186 self.assertFloatsAlmostEqual(cat['refMag'][0, 0], self.synthMag1, rtol=1e-7)
188 def testGetReferenceCatalogAnyFilter(self):
189 """Get a reference catalog circle, using anyFilterMapsToThis."""
190 config = LoadReferenceCatalogConfig()
191 config.refObjLoader.anyFilterMapsToThis = 'ref1'
192 config.refObjLoader.ref_dataset_name = 'synthCam'
194 config.doApplyColorTerms = False
195 config.doReferenceSelection = False
196 config.freeze()
198 loaderTask = LoadReferenceCatalogTask(config=config, dataIds=[], refCats=[])
199 # Monkey-patch our testing trivial loader to bypass the butler
200 loaderTask.refObjLoader = self.trivialLoader
202 cat = loaderTask.getSkyCircleCatalog(_synthCenter,
203 1.0*lsst.geom.degrees,
204 ['filter1', 'filter2'])
206 self.assertFloatsAlmostEqual(cat['refMag'][0, 0], self.synthMag1, rtol=1e-7)
207 self.assertFloatsAlmostEqual(cat['refMag'][0, 1], self.synthMag1, rtol=1e-7)
209 def testGetReferenceCatalogRequirePm(self):
210 """Get a reference catalog circle, requiring proper motion."""
211 config = copy.copy(self.config)
212 config.refObjLoader.requireProperMotion = True
213 config.freeze()
215 loaderTask = LoadReferenceCatalogTask(config=config, dataIds=[], refCats=[])
216 # Monkey-patch our testing trivial loader to bypass the butler
217 trivialLoader2 = TrivialLoader(dataIds=[], refCats=[], config=config.refObjLoader)
218 loaderTask.refObjLoader = trivialLoader2
220 cat = loaderTask.getSkyCircleCatalog(_synthCenter,
221 1.0*lsst.geom.degrees,
222 ['filter1'])
224 self.assertAlmostEqual(cat['ra'], _synthCenter.getRa().asDegrees())
225 self.assertAlmostEqual(cat['dec'], _synthCenter.getDec().asDegrees())
226 self.assertFloatsAlmostEqual(cat['refMag'][0, 0], self.synthMag1, rtol=1e-7)
229class MemoryTester(lsst.utils.tests.MemoryTestCase):
230 pass
233if __name__ == "__main__": 233 ↛ 234line 233 didn't jump to line 234, because the condition on line 233 was never true
234 lsst.utils.tests.init()
235 unittest.main()