Coverage for tests/test_filters.py : 23%

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 obs_base.
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 unittest
24import lsst.utils.tests
25import lsst.afw.image
26from lsst.obs.base import FilterDefinition, FilterDefinitionCollection
27import lsst.pex.exceptions
30class TestFilterDefinitionCollection(lsst.utils.tests.TestCase):
31 def setUp(self):
32 self.filters1 = FilterDefinitionCollection(FilterDefinition(physical_filter='abc', lambdaEff=123),
33 FilterDefinition(physical_filter='def', lambdaEff=456))
34 self.filters2 = FilterDefinitionCollection(FilterDefinition(physical_filter='abc', lambdaEff=321),
35 FilterDefinition(physical_filter='def', lambdaEff=654))
36 FilterDefinitionCollection.reset()
38 def test_singleton(self):
39 self.filters1.defineFilters()
40 self.assertEqual(lsst.afw.image.Filter('abc').getFilterProperty().getLambdaEff(), 123)
41 self.assertEqual(lsst.afw.image.Filter('def').getFilterProperty().getLambdaEff(), 456)
42 self.filters1.defineFilters() # this should not change anything
43 self.assertEqual(lsst.afw.image.Filter('abc').getFilterProperty().getLambdaEff(), 123)
44 self.assertEqual(lsst.afw.image.Filter('def').getFilterProperty().getLambdaEff(), 456)
45 with self.assertRaises(RuntimeError):
46 self.filters2.defineFilters()
47 # the defined filters should be unchanged
48 self.assertEqual(lsst.afw.image.Filter('abc').getFilterProperty().getLambdaEff(), 123)
49 self.assertEqual(lsst.afw.image.Filter('def').getFilterProperty().getLambdaEff(), 456)
51 def test_reset(self):
52 self.filters1.defineFilters()
53 with self.assertRaises(RuntimeError):
54 self.filters2.defineFilters()
55 self.filters1.reset()
56 # The new filters can be defiend and should replace the old ones.
57 self.filters2.defineFilters()
58 self.assertEqual(lsst.afw.image.Filter('abc').getFilterProperty().getLambdaEff(), 321)
59 self.assertEqual(lsst.afw.image.Filter('def').getFilterProperty().getLambdaEff(), 654)
62class TestFilterDefinition(lsst.utils.tests.TestCase):
63 def setUp(self):
64 lsst.afw.image.utils.resetFilters()
65 self.filter_g = FilterDefinition(band="g",
66 physical_filter="HSC-G",
67 lambdaEff=1234,
68 alias={'ABCDEFG'})
69 self.filter_g2 = FilterDefinition(band="g",
70 physical_filter="HSC-G2",
71 afw_name='g2',
72 lambdaEff=1235,
73 alias={'HIJK'})
75 self.physical_only = FilterDefinition(physical_filter="physical", lambdaEff=0)
76 self.afw_name = FilterDefinition(physical_filter="afw_name",
77 lambdaEff=5, afw_name="afw only")
78 self.abstract = FilterDefinition(physical_filter="abstract", lambdaEff=42,
79 band="abstract only")
81 def testDefineFilters(self):
82 """Test that a filter is properly defined in afw."""
83 # the filter should not exist until we define it
84 with self.assertRaises(lsst.pex.exceptions.NotFoundError):
85 lsst.afw.image.Filter('g')
86 with self.assertRaises(lsst.pex.exceptions.NotFoundError):
87 lsst.afw.image.Filter('g2')
88 with self.assertRaises(lsst.pex.exceptions.NotFoundError):
89 lsst.afw.image.Filter('HSC-G')
91 self.filter_g.defineFilter()
92 filter = lsst.afw.image.Filter('g')
93 filter_alias = lsst.afw.image.Filter('HSC-G')
94 self.assertEqual(filter.getName(), 'g')
95 # afw Filter stores the aliased name as the CannonicalName
96 self.assertEqual(filter_alias.getCanonicalName(), 'g')
97 self.assertEqual(filter, filter_alias)
98 self.assertEqual(['ABCDEFG', 'HSC-G'], sorted(filter.getAliases()))
100 self.filter_g2.defineFilter()
101 filter2 = lsst.afw.image.Filter('g2')
102 filter2_alias = lsst.afw.image.Filter('HSC-G2')
103 self.assertEqual(filter2.getName(), 'g2')
104 self.assertEqual(filter2_alias.getCanonicalName(), 'g2')
105 self.assertEqual(filter2, filter2_alias)
106 self.assertEqual(['HIJK', 'HSC-G2', 'g'], sorted(filter2.getAliases()))
108 def test_physical_only(self):
109 """physical_filter is the only name this filter has.
110 """
111 self.physical_only.defineFilter()
112 filter = lsst.afw.image.Filter('physical')
113 self.assertEqual(filter.getName(), 'physical')
114 self.assertEqual([], sorted(filter.getAliases()))
116 def test_afw_name(self):
117 """afw_name is the Filter name, physical_filter is an alias.
118 """
119 self.afw_name.defineFilter()
120 filter = lsst.afw.image.Filter('afw only')
121 filter_alias = lsst.afw.image.Filter('afw_name')
122 self.assertEqual(filter.getName(), 'afw only')
123 self.assertEqual(filter_alias.getCanonicalName(), 'afw only')
124 self.assertEqual(['afw_name'], sorted(filter.getAliases()))
126 def test_abstract_only(self):
127 """band is the Filter name, physical_filter is an alias.
128 """
129 self.abstract.defineFilter()
130 filter = lsst.afw.image.Filter('abstract only')
131 filter_alias = lsst.afw.image.Filter('abstract')
132 self.assertEqual(filter.getName(), 'abstract only')
133 self.assertEqual(filter_alias.getCanonicalName(), 'abstract only')
134 self.assertEqual(['abstract'], sorted(filter.getAliases()))
137class MemoryTester(lsst.utils.tests.MemoryTestCase):
138 pass
141def setup_module(module):
142 lsst.utils.tests.init()
145if __name__ == '__main__': 145 ↛ 146line 145 didn't jump to line 146, because the condition on line 145 was never true
146 lsst.utils.tests.init()
147 unittest.main()