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

# 

# LSST Data Management System 

# Copyright 2008-2016 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 numpy as np 

 

import lsst.utils.tests 

import lsst.afw.table as afwTable 

import lsst.afw.geom as afwGeom 

import lsst.afw.image as afwImage 

from lsst.meas.algorithms import LoadReferenceObjectsTask, getRefFluxField 

import lsst.ip.diffim as ipDiffim 

 

 

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

 

def setUp(self): 

schema = afwTable.SourceTable.makeMinimalSchema() 

schema.addField("test_instFlux", type=float) 

schema.addField("test_instFluxErr", type=float) 

self.sourceSelector = ipDiffim.DiaCatalogSourceSelectorTask() 

for flag in self.sourceSelector.config.badFlags: 

schema.addField(flag, type="Flag") 

table = afwTable.SourceTable.make(schema) 

table.definePsfFlux("test") 

self.srcCat = afwTable.SourceCatalog(table) 

self.exposure = afwImage.ExposureF() 

 

def tearDown(self): 

del self.sourceSelector 

del self.exposure 

del self.srcCat 

 

def makeRefCatalog(self): 

schema = LoadReferenceObjectsTask.makeMinimalSchema(filterNameList=["g", "r"], addFluxErr=False, 

addIsPhotometric=True, addIsResolved=True) 

catalog = afwTable.SimpleCatalog(schema) 

return catalog 

 

def makeMatches(self, refCat, srcCat, nSrc): 

for i in range(nSrc): 

 

refSrc = refCat.addNew() 

srcSrc = srcCat.addNew() 

 

raDeg, decDeg = np.random.randn(2) 

coord = afwGeom.SpherePoint(raDeg, decDeg, afwGeom.degrees) 

 

refSrc.set("g_flux", 10**(-0.4*18)) 

refSrc.set("r_flux", 10**(-0.4*18)) 

refSrc.set("resolved", False) 

refSrc.set("photometric", True) 

refSrc.setCoord(coord) 

 

srcSrc.setCoord(coord) 

srcSrc.set("slot_PsfFlux_instFlux", 10.) 

srcSrc.set("slot_PsfFlux_instFluxErr", 1.) 

for flag in self.sourceSelector.config.badFlags: 

srcSrc.set(flag, False) 

 

mc = afwTable.MatchControl() 

mc.symmetricMatch = False 

mat = afwTable.matchRaDec(refCat, srcCat, 1.0 * afwGeom.arcseconds, mc) 

self.assertEqual(len(mat), nSrc) 

return mat 

 

def testCuts(self): 

nSrc = 5 

 

refCat = self.makeRefCatalog() 

 

matches = self.makeMatches(refCat, self.srcCat, nSrc) 

sources = self.sourceSelector.run(self.srcCat, matches=matches, exposure=self.exposure).sourceCat 

self.assertEqual(len(sources), nSrc) 

 

# Set one of the source flags to be bad 

matches[0].second.set(self.sourceSelector.config.badFlags[0], True) 

sources = self.sourceSelector.run(self.srcCat, matches=matches, exposure=self.exposure).sourceCat 

self.assertEqual(len(sources), nSrc-1) 

 

# Set one of the ref flags to be bad 

matches[1].first.set("photometric", False) 

sources = self.sourceSelector.run(self.srcCat, matches=matches, exposure=self.exposure).sourceCat 

self.assertEqual(len(sources), nSrc-2) 

 

# Set one of the colors to be bad 

grMin = self.sourceSelector.config.grMin 

rFluxField = getRefFluxField(refCat.schema, "r") 

gFluxField = getRefFluxField(refCat.schema, "g") 

gFlux = 10**(-0.4 * (grMin - 0.1)) * matches[2].first.get(rFluxField) 

matches[2].first.set(gFluxField, gFlux) 

sources = self.sourceSelector.run(self.srcCat, matches=matches, exposure=self.exposure).sourceCat 

self.assertEqual(len(sources), nSrc-3) 

 

# Set one of the types to be bad 

115 ↛ exitline 115 didn't return from function 'testCuts', because the condition on line 115 was never false if self.sourceSelector.config.selectStar and not self.sourceSelector.config.selectGalaxy: 

matches[3].first.set("resolved", True) 

sources = self.sourceSelector.run(self.srcCat, matches=matches, exposure=self.exposure).sourceCat 

self.assertEqual(len(sources), nSrc-4) 

 

 

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

pass 

 

 

def setup_module(module): 

lsst.utils.tests.init() 

 

 

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

lsst.utils.tests.init() 

unittest.main()