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

# 

# LSST Data Management System 

# Copyright 2008, 2009, 2010 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/>. 

# 

 

""" 

Tests for Colorterm 

 

Run with: 

python colorterm.py 

or 

python 

>>> import colorterm; colorterm.run() 

""" 

 

import unittest 

import pickle 

 

import lsst.utils.tests 

from lsst.pipe.tasks.colorterms import Colorterm, ColortermDict, ColortermLibrary, ColortermNotFoundError 

 

# From the last page of http://www.naoj.org/staff/nakata/suprime/illustration/colorterm_report_ver3.pdf 

# Transformation for griz band between SDSS and SC (estimated with GS83 SEDs) 

hamamatsu = ColortermLibrary(data={ 

"ham*": ColortermDict(data={ 

"g": Colorterm(primary="g", secondary="r", c0=-0.00928, c1=-0.0824), 

"r": Colorterm(primary="r", secondary="i", c0=-0.00282, c1=-0.0498, c2=-0.0149), 

"i": Colorterm(primary="i", secondary="z", c0=0.00186, c1=-0.140, c2=-0.0196), 

"z": Colorterm(primary="z", secondary="i", c0=-4.03e-4, c1=0.0967, c2=0.0210), 

}) 

}) 

 

 

def setup_module(module): 

lsst.utils.tests.init() 

 

 

class ColortermTestCase(unittest.TestCase): 

"""A test case for MaskedImage""" 

 

def setUp(self): 

# A list of simple fake sources. The values are chosen so that the colorterm corrections are 

# predictable. 

self.sources = (dict(g=0.0, r=0.0, fluxErr_g=0.0, fluxErr_r=0.0, true_g=-0.00928, true_fluxErr_g=0.0), 

dict(g=0.0, r=-1.0, fluxErr_g=1.0, fluxErr_r=1.0, true_g=-0.09168, 

true_fluxErr_g=0.92129230974756315)) 

self.colorterms = hamamatsu 

 

def testTransformSource(self): 

"""Check if we can use colour terms""" 

 

ct = self.colorterms.getColorterm("g", photoCatName="ham") 

 

for s in self.sources: 

self.assertEqual(ct.transformSource(s), s["true_g"]) 

 

def testLibraryAccess(self): 

"""Test ColortermLibrary.getColorterm""" 

ctg = self.colorterms.getColorterm("g", photoCatName="ham") # exact match 

self.assertEqual(ctg.primary, "g") 

self.assertEqual(ctg.secondary, "r") 

self.assertAlmostEqual(ctg.c0, -0.00928) 

self.assertAlmostEqual(ctg.c1, -0.0824) 

self.assertAlmostEqual(ctg.c2, 0) 

 

ctr = self.colorterms.getColorterm("r", photoCatName="hambone") # glob should expand 

self.assertEqual(ctr.primary, "r") 

self.assertEqual(ctr.secondary, "i") 

self.assertAlmostEqual(ctr.c0, -0.00282) 

self.assertAlmostEqual(ctr.c1, -0.0498) 

self.assertAlmostEqual(ctr.c2, -0.0149) 

 

# bad filter name 

self.assertRaises(ColortermNotFoundError, self.colorterms.getColorterm, "x", photoCatName="ham") 

 

# bad catalog name: not in library 

self.assertRaises(ColortermNotFoundError, self.colorterms.getColorterm, "r", photoCatName="eggs") 

 

# bad catalog name: glob expression 

self.assertRaises(ColortermNotFoundError, self.colorterms.getColorterm, "r", photoCatName="ha*") 

 

def testTransformMags(self): 

"""Check if we can use colour terms via transformMags""" 

 

ct = self.colorterms.getColorterm("g", photoCatName="ham") 

 

for s in self.sources: 

self.assertEqual(ct.transformMags(s[ct.primary], s[ct.secondary]), s["true_g"]) 

 

def testPropagateFluxErrors(self): 

"""Check if we can propagate flux errors""" 

 

ct = self.colorterms.getColorterm("g", photoCatName="ham") 

for s in self.sources: 

self.assertEqual(ct.propagateFluxErrors(s["fluxErr_g"], s["fluxErr_r"]), s["true_fluxErr_g"]) 

 

def testPickle(self): 

"""Ensure color terms can be pickled""" 

colorterms = pickle.loads(pickle.dumps(self.colorterms)) 

self.assertEqual(colorterms, self.colorterms) 

 

 

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

pass 

 

 

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

lsst.utils.tests.init() 

unittest.main()