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

# This file is part of ap_association. 

# 

# Developed for the LSST Data Management System. 

# This product includes software developed by the LSST Project 

# (https://www.lsst.org). 

# See the COPYRIGHT file at the top-level directory of this distribution 

# for details of code ownership. 

# 

# 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 GNU General Public License 

# along with this program. If not, see <https://www.gnu.org/licenses/>. 

 

import numpy as np 

import pandas as pd 

import unittest 

 

from lsst.ap.association import ( 

MeanDiaPosition, 

MeanDiaPositionConfig, 

WeightedMeanDiaPsFlux, 

WeightedMeanDiaPsFluxConfig) 

import lsst.utils.tests 

 

 

class TestMeanPosition(unittest.TestCase): 

 

def testCalculate(self): 

"""Test that forced source catalogs are successfully created and have 

sensible values. 

""" 

n_sources = 10 

 

# Test expected means. 

diaObject = dict() 

diaSources = pd.DataFrame(data={"ra": np.linspace(-1, 1, n_sources), 

"decl": np.zeros(n_sources)}) 

mean_pos = MeanDiaPosition(MeanDiaPositionConfig(), 

"ap_meanPosition", 

None) 

mean_pos.calculate(diaObject, diaSources) 

 

self.assertAlmostEqual(diaObject["ra"], 0.0) 

self.assertAlmostEqual(diaObject["decl"], 0.0) 

 

diaObject = dict() 

diaSources = pd.DataFrame(data={"ra": np.zeros(n_sources), 

"decl": np.linspace(-1, 1, n_sources)}) 

mean_pos.calculate(diaObject, diaSources) 

 

self.assertAlmostEqual(diaObject["ra"], 0.0) 

self.assertAlmostEqual(diaObject["decl"], 0.0) 

 

# Test failure modes. 

diaObject = dict() 

diaSources = pd.DataFrame(data={"ra": np.full(n_sources, np.nan), 

"decl": np.zeros(n_sources)}) 

mean_pos.calculate(diaObject, diaSources) 

 

self.assertTrue(np.isnan(diaObject["ra"])) 

self.assertTrue(np.isnan(diaObject["decl"])) 

 

diaObject = dict() 

diaSources = pd.DataFrame(data={"ra": np.zeros(n_sources), 

"decl": np.full(n_sources, np.nan)}) 

mean_pos.calculate(diaObject, diaSources) 

 

self.assertTrue(np.isnan(diaObject["ra"])) 

self.assertTrue(np.isnan(diaObject["decl"])) 

 

 

class TestWeightedMeanDiaPsFlux(unittest.TestCase): 

 

def testCalculate(self): 

"""Test that forced source catalogs are successfully created and have 

sensible values. 

""" 

n_sources = 10 

diaObject = dict() 

diaSources = pd.DataFrame(data={"psFlux": np.linspace(-1, 1, n_sources), 

"psFluxErr": np.ones(n_sources)}) 

 

mean_flux = WeightedMeanDiaPsFlux(WeightedMeanDiaPsFluxConfig(), 

"ap_meanFlux", 

None) 

mean_flux.calculate(diaObject, diaSources, diaSources, "u") 

 

self.assertAlmostEqual(diaObject["uPSFluxMean"], 0.0) 

self.assertAlmostEqual(diaObject["uPSFluxMeanErr"], np.sqrt(1 / n_sources)) 

 

diaObject = dict() 

mean_flux.calculate(diaObject, [], [], "g") 

 

self.assertTrue(np.isnan(diaObject["gPSFluxMean"])) 

self.assertTrue(np.isnan(diaObject["gPSFluxMeanErr"])) 

 

diaObject = dict() 

diaSources.loc[4, "psFlux"] = np.nan 

mean_flux.calculate(diaObject, diaSources, diaSources, "r") 

 

self.assertTrue(~np.isnan(diaObject["rPSFluxMean"])) 

self.assertTrue(~np.isnan(diaObject["rPSFluxMeanErr"])) 

 

 

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

pass 

 

 

def setup_module(module): 

lsst.utils.tests.init() 

 

 

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

lsst.utils.tests.init() 

unittest.main()