Hide keyboard shortcuts

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

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

66

67

68

69

70

71

72

73

74

75

76

77

78

79

80

81

82

83

84

85

86

87

88

89

90

91

92

93

94

95

96

97

98

99

100

101

102

103

104

105

106

107

108

109

110

111

112

113

114

115

116

117

118

119

120

121

122

123

124

125

126

127

128

129

130

131

132

133

134

135

136

137

138

139

140

141

142

143

144

145

146

147

# 

# LSST Data Management System 

# 

# Copyright 2017 AURA/LSST. 

# 

# This product includes software developed by the 

# LSST Project (http://www.lsst.org/). 

# 

# This program is free software: you can redistribute it and/or modify 

# it under the terms of the GNU General Public License as published by 

# the Free Software Foundation, either version 3 of the License, or 

# (at your option) any later version. 

# 

# This program is distributed in the hope that it will be useful, 

# but WITHOUT ANY WARRANTY; without even the implied warranty of 

# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 

# GNU General Public License for more details. 

# 

# You should have received a copy of the LSST License Statement and 

# the GNU General Public License along with this program. If not, 

# see <https://www.lsstcorp.org/LegalNotices/>. 

# 

from __future__ import absolute_import, division, print_function 

 

import unittest 

 

import lsst.utils.tests 

from lsst.afw.image import ExposureF, CoaddInputs 

from lsst.afw.table import ExposureCatalog, SourceCatalog, Point2DKey 

from lsst.afw.geom import degrees, Point2D, Box2I, Point2I, SpherePoint, makeCdMatrix, makeSkyWcs 

from lsst.daf.base import PropertyList 

from lsst.meas.base import FatalAlgorithmError 

from lsst.obs.subaru.filterFraction import FilterFractionPlugin 

 

 

class FilterFractionTest(lsst.utils.tests.TestCase): 

 

def setUp(self): 

# Set up a Coadd with CoaddInputs tables that have blank filter columns to be filled 

# in by later test code. 

self.coadd = ExposureF(30, 90) 

# WCS is arbitrary, since it'll be the same for all images 

wcs = makeSkyWcs(crpix=Point2D(0, 0), crval=SpherePoint(45.0, 45.0, degrees), 

cdMatrix=makeCdMatrix(scale=0.17*degrees)) 

self.coadd.setWcs(wcs) 

schema = ExposureCatalog.Table.makeMinimalSchema() 

self.filterKey = schema.addField("filter", type=str, doc="", size=16) 

weightKey = schema.addField("weight", type=float, doc="") 

# First input image covers the first 2/3, second covers the last 2/3, so they 

# overlap in the middle 1/3. 

inputs = ExposureCatalog(schema) 

self.input1 = inputs.addNew() 

self.input1.setId(1) 

self.input1.setBBox(Box2I(Point2I(0, 0), Point2I(29, 59))) 

self.input1.setWcs(wcs) 

self.input1.set(weightKey, 2.0) 

self.input2 = inputs.addNew() 

self.input2.setId(2) 

self.input2.setBBox(Box2I(Point2I(0, 30), Point2I(29, 89))) 

self.input2.setWcs(wcs) 

self.input2.set(weightKey, 3.0) 

# Use the same catalog for visits and CCDs since the algorithm we're testing only cares 

# about CCDs. 

self.coadd.getInfo().setCoaddInputs(CoaddInputs(inputs, inputs)) 

 

# Set up a catalog with centroids and a FilterFraction plugin. 

# We have one record in each region (first input only, both inputs, second input only) 

schema = SourceCatalog.Table.makeMinimalSchema() 

centroidKey = Point2DKey.addFields(schema, "centroid", doc="position", unit="pixel") 

schema.getAliasMap().set("slot_Centroid", "centroid") 

self.plugin = FilterFractionPlugin(config=FilterFractionPlugin.ConfigClass(), 

schema=schema, name="subaru_FilterFraction", 

metadata=PropertyList()) 

catalog = SourceCatalog(schema) 

self.record1 = catalog.addNew() 

self.record1.set(centroidKey, Point2D(14.0, 14.0)) 

self.record12 = catalog.addNew() 

self.record12.set(centroidKey, Point2D(14.0, 44.0)) 

self.record2 = catalog.addNew() 

self.record2.set(centroidKey, Point2D(14.0, 74.0)) 

 

def tearDown(self): 

del self.coadd 

del self.input1 

del self.input2 

del self.record1 

del self.record2 

del self.record12 

del self.plugin 

 

def testSingleFilter(self): 

"""Test that we get FilterFraction=1 for filters with only one version.""" 

self.input1.set(self.filterKey, "g") 

self.input2.set(self.filterKey, "g") 

self.plugin.measure(self.record1, self.coadd) 

self.plugin.measure(self.record12, self.coadd) 

self.plugin.measure(self.record2, self.coadd) 

self.assertEqual(self.record1.get("subaru_FilterFraction_unweighted"), 1.0) 

self.assertEqual(self.record12.get("subaru_FilterFraction_unweighted"), 1.0) 

self.assertEqual(self.record2.get("subaru_FilterFraction_unweighted"), 1.0) 

self.assertEqual(self.record1.get("subaru_FilterFraction_weighted"), 1.0) 

self.assertEqual(self.record12.get("subaru_FilterFraction_weighted"), 1.0) 

self.assertEqual(self.record2.get("subaru_FilterFraction_weighted"), 1.0) 

 

def testTwoFiltersI(self): 

"""Test that we get the right answers for a mix of i and i2.""" 

self.input1.set(self.filterKey, "i") 

self.input2.set(self.filterKey, "i2") 

self.plugin.measure(self.record1, self.coadd) 

self.plugin.measure(self.record12, self.coadd) 

self.plugin.measure(self.record2, self.coadd) 

self.assertEqual(self.record1.get("subaru_FilterFraction_unweighted"), 0.0) 

self.assertEqual(self.record12.get("subaru_FilterFraction_unweighted"), 0.5) 

self.assertEqual(self.record2.get("subaru_FilterFraction_unweighted"), 1.0) 

self.assertEqual(self.record1.get("subaru_FilterFraction_weighted"), 0.0) 

self.assertEqual(self.record12.get("subaru_FilterFraction_weighted"), 0.6) 

self.assertEqual(self.record2.get("subaru_FilterFraction_weighted"), 1.0) 

 

def testTwoFiltersR(self): 

"""Test that we get the right answers for a mix of r and r2.""" 

self.input1.set(self.filterKey, "r") 

self.input2.set(self.filterKey, "r2") 

self.plugin.measure(self.record1, self.coadd) 

self.plugin.measure(self.record12, self.coadd) 

self.plugin.measure(self.record2, self.coadd) 

self.assertEqual(self.record1.get("subaru_FilterFraction_unweighted"), 0.0) 

self.assertEqual(self.record12.get("subaru_FilterFraction_unweighted"), 0.5) 

self.assertEqual(self.record2.get("subaru_FilterFraction_unweighted"), 1.0) 

self.assertEqual(self.record1.get("subaru_FilterFraction_weighted"), 0.0) 

self.assertEqual(self.record12.get("subaru_FilterFraction_weighted"), 0.6) 

self.assertEqual(self.record2.get("subaru_FilterFraction_weighted"), 1.0) 

 

def testInvalidCombination(self): 

"""Test that we get a fatal exception for weird combinations of filters.""" 

self.input1.set(self.filterKey, "i") 

self.input2.set(self.filterKey, "r") 

with self.assertRaises(FatalAlgorithmError): 

self.plugin.measure(self.record12, self.coadd) 

 

 

def setup_module(module): 

lsst.utils.tests.init() 

 

 

145 ↛ 146line 145 didn't jump to line 146, because the condition on line 145 was never trueif __name__ == "__main__": 

lsst.utils.tests.init() 

unittest.main()