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

# 

# LSST Data Management System 

# Copyright 2008-2017 LSST Corporation. 

# 

# 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 <http://www.lsstcorp.org/LegalNotices/>. 

# 

 

import unittest 

 

import lsst.utils.tests 

import lsst.geom 

import lsst.afw.geom 

import lsst.meas.base.tests 

import lsst.meas.base as measBase 

import lsst.meas.base.catalogCalculation as catCalc 

 

 

class ClassificationTestCase(lsst.meas.base.tests.AlgorithmTestCase, lsst.utils.tests.TestCase): 

 

def setUp(self): 

self.bbox = lsst.geom.Box2I(lsst.geom.Point2I(-20, -20), 

lsst.geom.Extent2I(250, 150)) 

self.dataset = lsst.meas.base.tests.TestDataset(self.bbox) 

# first source is a point 

self.dataset.addSource(100000.0, lsst.geom.Point2D(50.1, 49.8)) 

# second source is extended 

self.dataset.addSource(100000.0, lsst.geom.Point2D(149.9, 50.3), 

lsst.afw.geom.Quadrupole(8, 9, 3)) 

 

def tearDown(self): 

del self.bbox 

del self.dataset 

 

def testSingleFramePlugin(self): 

config = measBase.SingleFrameMeasurementConfig() 

# n.b. we use the truth value as ModelFlux 

config.slots.psfFlux = "base_PsfFlux" 

config.slots.modelFlux = "truth" 

task = self.makeSingleFrameMeasurementTask(config=config) 

abTask = catCalc.CatalogCalculationTask(schema=task.schema) 

exposure, catalog = self.dataset.realize(10.0, task.schema, randomSeed=0) 

task.run(catalog, exposure) 

abTask.run(catalog) 

self.assertLess(catalog[0].get("base_ClassificationExtendedness_value"), 0.5) 

self.assertGreater(catalog[1].get("base_ClassificationExtendedness_value"), 0.5) 

 

def testFlags(self): 

"""Test all the failure modes of this algorithm, as well as checking that it succeeds when it should. 

 

Since this algorithm depends on having a ModelFlux and a PsfFlux measurement, it is a failure 

mode when either is NAN, or when ModelFluxFlag or PsfFluxFlag is True. 

 

When psfFluxFactor != 0, the PsfFluxErr cannot be NAN, but otherwise is ignored 

 

When modelFluxFactor != 0, the ModelFluxErr cannot be NAN, but otherwise is ignored 

""" 

config = measBase.SingleFrameMeasurementConfig() 

config.slots.psfFlux = "base_PsfFlux" 

config.slots.modelFlux = "base_GaussianFlux" 

 

abConfig = catCalc.CatalogCalculationConfig() 

 

def runFlagTest(psfFlux=100.0, modelFlux=200.0, 

psfFluxSigma=1.0, modelFluxSigma=2.0, 

psfFluxFlag=False, modelFluxFlag=False): 

task = self.makeSingleFrameMeasurementTask(config=config) 

abTask = catCalc.CatalogCalculationTask(schema=task.schema, config=abConfig) 

exposure, catalog = self.dataset.realize(10.0, task.schema, randomSeed=1) 

source = catalog[0] 

source.set("base_PsfFlux_flux", psfFlux) 

source.set("base_PsfFlux_fluxSigma", psfFluxSigma) 

source.set("base_PsfFlux_flag", psfFluxFlag) 

source.set("base_GaussianFlux_flux", modelFlux) 

source.set("base_GaussianFlux_fluxSigma", modelFluxSigma) 

source.set("base_GaussianFlux_flag", modelFluxFlag) 

abTask.plugins["base_ClassificationExtendedness"].calculate(source) 

return source.get("base_ClassificationExtendedness_flag") 

 

# Test no error case - all necessary values are set 

self.assertFalse(runFlagTest()) 

 

# Test psfFlux flag case - failure in PsfFlux 

self.assertTrue(runFlagTest(psfFluxFlag=True)) 

 

# Test modelFlux flag case - failure in ModelFlux 

self.assertTrue(runFlagTest(modelFluxFlag=True)) 

 

# Test modelFlux NAN case 

self.assertTrue(runFlagTest(modelFlux=float("NaN"), modelFluxFlag=True)) 

 

# Test psfFlux NAN case 

self.assertTrue(runFlagTest(psfFlux=float("NaN"), psfFluxFlag=True)) 

 

# Test modelFluxErr NAN case when modelErrFactor is zero and non-zero 

abConfig.plugins["base_ClassificationExtendedness"].modelErrFactor = 0. 

self.assertFalse(runFlagTest(modelFluxSigma=float("NaN"))) 

abConfig.plugins["base_ClassificationExtendedness"].modelErrFactor = 1. 

self.assertTrue(runFlagTest(modelFluxSigma=float("NaN"))) 

 

# Test psfFluxErr NAN case when psfErrFactor is zero and non-zero 

abConfig.plugins["base_ClassificationExtendedness"].psfErrFactor = 0. 

self.assertFalse(runFlagTest(psfFluxSigma=float("NaN"))) 

abConfig.plugins["base_ClassificationExtendedness"].psfErrFactor = 1. 

self.assertTrue(runFlagTest(psfFluxSigma=float("NaN"))) 

 

 

class TestMemory(lsst.utils.tests.MemoryTestCase): 

pass 

 

 

def setup_module(module): 

lsst.utils.tests.init() 

 

 

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

lsst.utils.tests.init() 

unittest.main()