Coverage for tests/test_pickles.py: 30%
174 statements
« prev ^ index » next coverage.py v6.5.0, created at 2024-03-20 00:40 -0700
« prev ^ index » next coverage.py v6.5.0, created at 2024-03-20 00:40 -0700
1#
2# LSST Data Management System
3# Copyright 2008, 2009, 2010 LSST Corporation.
4#
5# This product includes software developed by the
6# LSST Project (http://www.lsst.org/).
7#
8# This program is free software: you can redistribute it and/or modify
9# it under the terms of the GNU General Public License as published by
10# the Free Software Foundation, either version 3 of the License, or
11# (at your option) any later version.
12#
13# This program is distributed in the hope that it will be useful,
14# but WITHOUT ANY WARRANTY; without even the implied warranty of
15# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16# GNU General Public License for more details.
17#
18# You should have received a copy of the LSST License Statement and
19# the GNU General Public License along with this program. If not,
20# see <http://www.lsstcorp.org/LegalNotices/>.
21#
23"""
24Tests for pickles of some afw types
25"""
27import unittest
28import pickle
30import lsst.daf.base as dafBase
31import lsst.utils.tests
32import lsst.geom
33import lsst.afw.geom as afwGeom
34import lsst.afw.geom.ellipses as geomEllip
37class PickleBase:
38 """A test case for pickles"""
40 def setUp(self):
41 raise NotImplementedError(
42 "Need to inherit and create the 'data' element.")
44 def tearDown(self):
45 del self.data
47 def assertPickled(self, new):
48 """Assert that the pickled data is the same as the original
50 Subclasses should override this method if the particular data
51 doesn't support the == operator.
52 """
53 self.assertEqual(new, self.data)
55 def testPickle(self):
56 """Test round-trip pickle"""
57 pickled = pickle.dumps(self.data)
58 newData = pickle.loads(pickled)
59 self.assertPickled(newData)
62class AngleTestCase(PickleBase, unittest.TestCase):
64 def setUp(self):
65 self.data = 1.0*lsst.geom.degrees
68class QuadrupoleTestCase(PickleBase, unittest.TestCase):
70 def setUp(self):
71 ixx, iyy, ixy = 1.0, 1.0, 0.0
72 self.data = afwGeom.Quadrupole(ixx, iyy, ixy)
75class AxesTestCase(PickleBase, unittest.TestCase):
77 def setUp(self):
78 a, b, theta = 1.0, 1.0, 0.0
79 self.data = geomEllip.Axes(a, b, theta)
82class Point2DTestCase(PickleBase, unittest.TestCase):
84 def setUp(self):
85 x, y = 1.0, 1.0
86 self.data = lsst.geom.Point2D(x, y)
89class Point2ITestCase(PickleBase, unittest.TestCase):
91 def setUp(self):
92 x, y = 1, 1
93 self.data = lsst.geom.Point2I(x, y)
96class Point3DTestCase(PickleBase, unittest.TestCase):
98 def setUp(self):
99 x, y, z = 1.0, 1.0, 1.0
100 self.data = lsst.geom.Point3D(x, y, z)
103class Point3ITestCase(PickleBase, unittest.TestCase):
105 def setUp(self):
106 x, y, z = 1, 1, 1
107 self.data = lsst.geom.Point3I(x, y, z)
110class Extent2DTestCase(PickleBase, unittest.TestCase):
112 def setUp(self):
113 x, y = 1.0, 1.0
114 self.data = lsst.geom.Extent2D(x, y)
117class Extent3DTestCase(PickleBase, unittest.TestCase):
119 def setUp(self):
120 x, y, z = 1, 1, 1
121 self.data = lsst.geom.Extent3D(x, y, z)
124class Extent2ITestCase(PickleBase, unittest.TestCase):
126 def setUp(self):
127 x, y = 1, 1
128 self.data = lsst.geom.Extent2I(x, y)
131class Extent3ITestCase(PickleBase, unittest.TestCase):
133 def setUp(self):
134 x, y, z = 1, 1, 1
135 self.data = lsst.geom.Extent3I(x, y, z)
138class Box2DTestCase(PickleBase, unittest.TestCase):
140 def setUp(self):
141 p, e = lsst.geom.Point2D(1.0, 1.0), lsst.geom.Extent2D(0.5, 0.5)
142 self.data = lsst.geom.Box2D(p, e)
145class Box2ITestCase(PickleBase, unittest.TestCase):
147 def setUp(self):
148 p, e = lsst.geom.Point2I(1, 2), lsst.geom.Extent2I(1, 1)
149 self.data = lsst.geom.Box2I(p, e)
152class AffineTransformTestCase(PickleBase, unittest.TestCase):
154 def setUp(self):
155 scale = 2.2
156 linear = lsst.geom.LinearTransform().makeScaling(scale)
157 dx, dy = 1.1, 3.3
158 trans = lsst.geom.Extent2D(dx, dy)
159 self.data = lsst.geom.AffineTransform(linear, trans)
161 def assertPickled(self, new):
162 self.assertListEqual(new.getMatrix().flatten().tolist(),
163 self.data.getMatrix().flatten().tolist())
166class LinearTransformTestCase(PickleBase, unittest.TestCase):
168 def setUp(self):
169 scale = 2.0
170 self.data = lsst.geom.LinearTransform().makeScaling(scale)
172 def assertPickled(self, new):
173 self.assertListEqual(new.getMatrix().flatten().tolist(),
174 self.data.getMatrix().flatten().tolist())
177class WcsPickleBase(PickleBase, unittest.TestCase):
179 def setUp(self):
180 # define a TAN-SIP WCS
181 hdr = dafBase.PropertyList()
182 hdr.add("NAXIS", 2)
183 hdr.add("EQUINOX", 2000.0000000000)
184 hdr.add("RADESYS", "FK5")
185 hdr.add("CRPIX1", 947.04531175212)
186 hdr.add("CRPIX2", -305.70042176782)
187 hdr.add("CD1_1", -5.6081060666063e-05)
188 hdr.add("CD1_2", 1.1941349711530e-10)
189 hdr.add("CD2_1", 1.1938226362497e-10)
190 hdr.add("CD2_2", 5.6066392248206e-05)
191 hdr.add("CRVAL1", 5.5350859380564)
192 hdr.add("CRVAL2", -0.57805534748292)
193 hdr.add("CUNIT1", "deg")
194 hdr.add("CUNIT2", "deg")
195 hdr.add("A_ORDER", 3)
196 hdr.add("A_0_0", -3.4299726900155e-05)
197 hdr.add("A_0_2", 2.9999243742039e-08)
198 hdr.add("A_0_3", 5.3160367322875e-12)
199 hdr.add("A_1_0", -1.1102230246252e-16)
200 hdr.add("A_1_1", 1.7804837804549e-07)
201 hdr.add("A_1_2", -3.9117665277930e-10)
202 hdr.add("A_2_0", 1.2614116305773e-07)
203 hdr.add("A_2_1", 2.4753748298399e-12)
204 hdr.add("A_3_0", -4.0559790823371e-10)
205 hdr.add("B_ORDER", 3)
206 hdr.add("B_0_0", -0.00040333633853922)
207 hdr.add("B_0_2", 2.7329405108287e-07)
208 hdr.add("B_0_3", -4.1945333823804e-10)
209 hdr.add("B_1_1", 1.0211300606274e-07)
210 hdr.add("B_1_2", -1.1907781112538e-12)
211 hdr.add("B_2_0", 7.1256679698479e-08)
212 hdr.add("B_2_1", -4.0026664120969e-10)
213 hdr.add("B_3_0", 7.2509034631981e-14)
214 hdr.add("AP_ORDER", 5)
215 hdr.add("AP_0_0", 0.065169424373537)
216 hdr.add("AP_0_1", 3.5323035231808e-05)
217 hdr.add("AP_0_2", -2.4878457741060e-08)
218 hdr.add("AP_0_3", -1.4288745247360e-11)
219 hdr.add("AP_0_4", -2.0000000098183)
220 hdr.add("AP_0_5", 4.3337569354109e-19)
221 hdr.add("AP_1_0", 1.9993638555698)
222 hdr.add("AP_1_1", -2.0722860000493e-07)
223 hdr.add("AP_1_2", 4.7562056847339e-10)
224 hdr.add("AP_1_3", -8.5172068319818e-06)
225 hdr.add("AP_1_4", -1.3242986537057e-18)
226 hdr.add("AP_2_0", -1.4594781790233e-07)
227 hdr.add("AP_2_1", -2.9254828606617e-12)
228 hdr.add("AP_2_2", -2.7203380713516e-11)
229 hdr.add("AP_2_3", 1.5030517486646e-19)
230 hdr.add("AP_3_0", 4.7856034999197e-10)
231 hdr.add("AP_3_1", 1.5571061278960e-15)
232 hdr.add("AP_3_2", -3.2422164667295e-18)
233 hdr.add("AP_4_0", 5.8904402441647e-16)
234 hdr.add("AP_4_1", -4.5488928339401e-20)
235 hdr.add("AP_5_0", -1.3198044795585e-18)
236 hdr.add("BP_ORDER", 5)
237 hdr.add("BP_0_0", 0.00025729974056661)
238 hdr.add("BP_0_1", -0.00060857907313083)
239 hdr.add("BP_0_2", -3.1283728005742e-07)
240 hdr.add("BP_0_3", 5.0413932972962e-10)
241 hdr.add("BP_0_4", -0.0046142128142681)
242 hdr.add("BP_0_5", -2.2359607268985e-18)
243 hdr.add("BP_1_0", 0.0046783112625990)
244 hdr.add("BP_1_1", -1.2304042740813e-07)
245 hdr.add("BP_1_2", -2.3756827881344e-12)
246 hdr.add("BP_1_3", -3.9300202582816e-08)
247 hdr.add("BP_1_4", -9.7385290942256e-21)
248 hdr.add("BP_2_0", -6.5238116398890e-08)
249 hdr.add("BP_2_1", 4.7855579009100e-10)
250 hdr.add("BP_2_2", -1.2297758131839e-13)
251 hdr.add("BP_2_3", -3.0849793267035e-18)
252 hdr.add("BP_3_0", -9.3923321275113e-12)
253 hdr.add("BP_3_1", -1.3193479628568e-17)
254 hdr.add("BP_3_2", 2.1762350028059e-19)
255 hdr.add("BP_4_0", -5.9687252632035e-16)
256 hdr.add("BP_4_1", -1.4096893423344e-18)
257 hdr.add("BP_5_0", 2.8085458107813e-19)
258 hdr.add("CTYPE1", "RA---TAN-SIP")
259 hdr.add("CTYPE2", "DEC--TAN-SIP")
260 self.data = afwGeom.makeSkyWcs(hdr)
263class TestMemory(lsst.utils.tests.MemoryTestCase):
264 pass
267def setup_module(module):
268 lsst.utils.tests.init()
271if __name__ == "__main__": 271 ↛ 272line 271 didn't jump to line 272, because the condition on line 271 was never true
272 lsst.utils.tests.init()
273 unittest.main()