Coverage for tests/test_composite.py: 40%
Shortcuts 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
Shortcuts 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 obs_test.
2#
3# Developed for the LSST Data Management System.
4# This product includes software developed by the LSST Project
5# (http://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 <http://www.gnu.org/licenses/>.
21#
23import filecmp
24import os
25import pickle
26import shutil
27import tempfile
28import unittest
31from lsst.afw.image.testUtils import makeRampImage
32import lsst.geom as geom
33import lsst.afw.image as afwImage
34import lsst.daf.persistence as dafPersist
35import lsst.obs.test
36import lsst.utils.tests
37from lsst.utils import getPackageDir
39ROOT = getPackageDir('obs_test')
42def makeRampDecoratedImage(bbox, start, **metadataDict):
43 """Make a DecoratedImageU that is a ramp."""
44 rampArr = makeRampImage(bbox=bbox, start=start, imageClass=afwImage.ImageU).getArray()
45 decoratedImage = afwImage.DecoratedImageU(bbox)
46 imarr = decoratedImage.getImage().getArray()
47 imarr[:] = rampArr
48 md = decoratedImage.getMetadata()
49 for (key, val) in metadataDict.items():
50 md.set(key, val)
51 return decoratedImage
54class TestCompositeTestCase(lsst.utils.tests.TestCase):
55 """A test case for composite object I/0."""
56 def setUp(self):
57 self.testDir = tempfile.mkdtemp(dir=os.path.join(ROOT, 'tests'), prefix=type(self).__name__+'-')
58 self.input = os.path.join(ROOT, 'data', 'input')
59 self.output = os.path.join(self.testDir, 'tests', 'outputs')
60 self.compositeOutput = os.path.join(self.output, 'composite')
61 self.nonCompositeOutput = os.path.join(self.output, 'noncomposite')
62 self.dataId = {'visit': 1, 'filter': 'g'}
64 def tearDown(self):
65 if os.path.exists(self.testDir):
66 shutil.rmtree(self.testDir)
68 def testGet(self):
69 """Verify get of individual components vs a composite.
70 """
71 butler = dafPersist.Butler(
72 inputs=dafPersist.RepositoryArgs(root=self.input, mapper='lsst.obs.test.testMapper.TestMapper'),
73 )
74 rawAndFlat = butler.get('rawAndFlat', dataId=self.dataId)
75 raw = butler.get('raw', dataId=self.dataId)
76 flat = butler.get('flat', dataId=self.dataId)
78 # Exposures (which is how these are retrieved) cannot be directly compared,
79 # including associated objects and metadata, so pickle them and cmpare the pickles
80 self.assertEqual(pickle.dumps(raw), pickle.dumps(rawAndFlat.raw))
81 self.assertEqual(pickle.dumps(flat), pickle.dumps(rawAndFlat.flat))
83 def testPut(self):
84 """Compare put of individual components vs a composite.
86 Notes
87 -----
88 Raw and calibration frames do not round trip (they are saved as
89 DecoratedImageU and read in as ExposureU), so create the raw
90 and flat manually.
91 """
92 outputs = (dafPersist.RepositoryArgs(root=self.compositeOutput, tags='composite'),
93 dafPersist.RepositoryArgs(root=self.nonCompositeOutput, tags='noncomposite'))
94 butler = dafPersist.Butler(
95 inputs=dafPersist.RepositoryArgs(root=self.input, mapper='lsst.obs.test.testMapper.TestMapper'),
96 outputs=outputs)
97 bbox = geom.Box2I(geom.Point2I(0, 0), geom.Point2I(10, 10))
98 raw = makeRampDecoratedImage(bbox=bbox, start=100, raw1=5, raw2="hello")
99 flat = makeRampDecoratedImage(bbox=bbox, start=-55, flat1="me", flat2=47)
101 # a hack-ish way of creating a rawAndFlat object; read in the data, then replace it with our own
102 rawAndFlat = butler.get('rawAndFlat', dataId=self.dataId)
103 rawAndFlat.raw = raw
104 rawAndFlat.flat = flat
106 butler.put(rawAndFlat, 'rawAndFlat', dataId=self.dataId, tags='composite')
107 butler.put(raw, 'raw', dataId=self.dataId, tags='noncomposite')
108 butler.put(raw, 'flat', dataId=self.dataId, tags='noncomposite')
110 self.assertTrue(filecmp.cmp(os.path.join(self.compositeOutput, 'raw', 'raw_v1_fg.fits.gz'),
111 os.path.join(self.nonCompositeOutput, 'raw', 'raw_v1_fg.fits.gz')))
113 self.assertTrue(filecmp.cmp(os.path.join(self.compositeOutput, 'flat', 'flat_fg.fits.gz'),
114 os.path.join(self.nonCompositeOutput, 'flat', 'flat_fg.fits.gz')))
117class MemoryTester(lsst.utils.tests.MemoryTestCase):
118 pass
121def setup_module(module):
122 lsst.utils.tests.init()
125if __name__ == "__main__": 125 ↛ 126line 125 didn't jump to line 126, because the condition on line 125 was never true
126 lsst.utils.tests.init()
127 unittest.main()