Coverage for tests/test_pixelScaleBoundedField.py : 28%

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 afw.
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.
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.
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.
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
24import numpy as np
26import lsst.utils.tests
27import lsst.geom
28import lsst.afw.geom
29from lsst.afw.math import PixelScaleBoundedField
32class PixelScaleBoundedFieldTestCase(lsst.utils.tests.TestCase):
33 def setUp(self):
34 # Trivial WCS:
35 crpix = lsst.geom.Point2D(100, 100)
36 crval = lsst.geom.SpherePoint(0, 45, lsst.geom.degrees)
37 cdMatrix = lsst.afw.geom.makeCdMatrix(1*lsst.geom.arcseconds, 0*lsst.geom.degrees)
38 self.skyWcs = lsst.afw.geom.makeSkyWcs(crpix=crpix, crval=crval, cdMatrix=cdMatrix)
40 self.bbox = lsst.geom.Box2I(lsst.geom.Point2I(0, 0), lsst.geom.Extent2I(200, 200))
41 self.points = [crpix, ]
42 # ensure that the points are all Point2D
43 self.points.extend(lsst.geom.Box2D(self.bbox).getCorners())
45 self.boundedField = PixelScaleBoundedField(self.bbox, self.skyWcs)
47 def testConstruct(self):
48 self.assertEqual(self.boundedField.getBBox(), self.bbox)
49 self.assertEqual(self.boundedField.getSkyWcs(), self.skyWcs)
50 self.assertEqual(self.boundedField.getInverseScale(),
51 1.0 / self.skyWcs.getPixelScale().asDegrees()**2)
53 def _computeExpected(self, points):
54 """Return an array with the expected result of evaluate(point)."""
55 expect = np.zeros(len(points), dtype=float)
56 for i, point in enumerate(points):
57 scale = self.skyWcs.getPixelScale(lsst.geom.Point2D(point)).asDegrees()
58 expect[i] = scale*scale / (self.skyWcs.getPixelScale().asDegrees())**2
59 return expect
61 def testEvaluate(self):
62 expect = self._computeExpected(self.points)
63 result = np.zeros(len(self.points), dtype=float)
64 for i, point in enumerate(self.points):
65 result[i] = self.boundedField.evaluate(point)
66 self.assertFloatsAlmostEqual(expect, result)
68 def testEvaluateArray(self):
69 xx = np.linspace(self.bbox.getMinX(), self.bbox.getMaxX())
70 yy = np.linspace(self.bbox.getMinY(), self.bbox.getMaxY())
71 xv, yv = np.meshgrid(xx, yy)
72 points = list(zip(xv.flatten(), yv.flatten()))
73 expect = self._computeExpected(points)
74 result = self.boundedField.evaluate(xv.flatten(), yv.flatten())
75 self.assertFloatsAlmostEqual(expect, result)
77 def testEquality(self):
78 # not equal to a different type of BoundedField
79 other = lsst.afw.math.ChebyshevBoundedField(self.bbox, np.random.random((2, 2)))
80 self.assertNotEqual(self.boundedField, other)
82 # equal to something created with the same parameters.
83 other = PixelScaleBoundedField(self.bbox, self.skyWcs)
84 self.assertEqual(self.boundedField, other)
86 # not equal to something with different bbox.
87 newBox = lsst.geom.Box2I(self.bbox)
88 newBox.grow(10)
89 other = PixelScaleBoundedField(newBox, self.skyWcs)
90 self.assertNotEqual(self.boundedField, other)
92 # not equal to something with different wcs
93 crpix = self.skyWcs.getPixelOrigin()
94 crpix.scale(10)
95 newWcs = lsst.afw.geom.makeSkyWcs(crpix=crpix,
96 crval=self.skyWcs.getSkyOrigin(),
97 cdMatrix=self.skyWcs.getCdMatrix())
98 other = PixelScaleBoundedField(self.bbox, newWcs)
99 self.assertNotEqual(self.boundedField, other)
101 def testString(self):
102 # NOTE: Nothing else currently to test in the str() output.
103 self.assertIn("PixelScaleBoundedField(", str(self.boundedField))
106class MemoryTester(lsst.utils.tests.MemoryTestCase):
107 pass
110def setup_module(module):
111 lsst.utils.tests.init()
114if __name__ == "__main__": 114 ↛ 115line 114 didn't jump to line 115, because the condition on line 114 was never true
115 lsst.utils.tests.init()
116 unittest.main()