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

148

149

150

151

152

153

154

# 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 lsst.geom as geom 

 

from .diaCalculation import ( 

DiaObjectCalculationPluginConfig, 

DiaObjectCalculationPlugin) 

from lsst.meas.base.pluginRegistry import register 

 

__all__ = ("MeanDiaPositionConfig", "MeanDiaPosition", 

"WeightedMeanDiaPsFluxConfig", "WeightedMeanDiaPsFlux") 

 

 

class MeanDiaPositionConfig(DiaObjectCalculationPluginConfig): 

pass 

 

 

@register("ap_meanPosition") 

class MeanDiaPosition(DiaObjectCalculationPlugin): 

"""Compute the mean position of a DiaObject given a set of DiaSources. 

""" 

 

ConfigClass = MeanDiaPositionConfig 

outputCols = ["ra", "decl"] 

 

@classmethod 

def getExecutionOrder(cls): 

return cls.DEFAULT_CATALOGCALCULATION 

 

def calculate(self, diaObject, diaSources, **kwargs): 

"""Compute the mean ra/dec position of the diaObject given the 

diaSource locations. 

 

Parameters 

---------- 

diaObject : `dict` 

Summary object to store values in. 

diaSources : `pandas.DataFrame` 

Catalog of DiaSources summarized by this DiaObject. 

""" 

aveCoord = geom.averageSpherePoint( 

list(geom.SpherePoint(src["ra"], src["decl"], geom.degrees) 

for idx, src in diaSources.iterrows())) 

if not (np.isfinite(aveCoord.getRa().asDegrees()) and 

np.isfinite(aveCoord.getDec().asDegrees())): 

self.fail(diaObject) 

else: 

diaObject["ra"] = aveCoord.getRa().asDegrees() 

diaObject["decl"] = aveCoord.getDec().asDegrees() 

 

def fail(self, diaObject, error=None): 

"""Set diaObject position values to nan. 

 

Parameters 

---------- 

diaObject : `dict` 

Summary object to store values in. 

error : `BaseException` 

Error to pass. Kept for consistency with CatologCalculationPlugin. 

Unused. 

""" 

diaObject["ra"] = np.nan 

diaObject["decl"] = np.nan 

 

 

class WeightedMeanDiaPsFluxConfig(DiaObjectCalculationPluginConfig): 

pass 

 

 

@register("ap_meanFlux") 

class WeightedMeanDiaPsFlux(DiaObjectCalculationPlugin): 

"""Compute the weighted mean and mean error on the point source fluxes 

of the DiaSource measured on the difference image. 

""" 

 

ConfigClass = WeightedMeanDiaPsFluxConfig 

outputCols = ["PSFluxMean", "PSFluxMeanErr"] 

 

@classmethod 

def getExecutionOrder(cls): 

return cls.DEFAULT_CATALOGCALCULATION 

 

def calculate(self, 

diaObject, 

diaSources, 

filterDiaFluxes, 

filterName, 

**kwargs): 

"""Compute the weighted mean and mean error of the point source flux. 

 

Parameters 

---------- 

diaObject : `dict` 

Summary object to store values in. 

diaSources : `pandas.DataFrame` 

DataFrame representing all diaSources associated with this 

diaObject. 

filterDiaFluxes : `pandas.DataFrame` 

DataFrame representing diaSources associated with this 

diaObject that are observed in the band pass ``filterName``. 

filterName : `str` 

Simple, string name of the filter for the flux being calculated. 

""" 

if len(filterDiaFluxes) > 0: 

tot_weight = np.nansum(1 / filterDiaFluxes["psFluxErr"] ** 2) 

fluxMean = np.nansum(filterDiaFluxes["psFlux"] / 

filterDiaFluxes["psFluxErr"] ** 2) 

fluxMean /= tot_weight 

fluxMeanErr = np.sqrt(1 / tot_weight) 

else: 

fluxMean = np.nan 

fluxMeanErr = np.nan 

 

if np.isfinite(fluxMean) and np.isfinite(fluxMeanErr): 

diaObject["%sPSFluxMean" % filterName] = fluxMean 

diaObject["%sPSFluxMeanErr" % filterName] = fluxMeanErr 

else: 

self.fail(diaObject, filterName) 

 

def fail(self, diaObject, filterName, error=None): 

"""Set diaObject position values to nan. 

 

Parameters 

---------- 

diaObject : `dict` 

Summary object to store values in. 

filterName : `str` 

Simple name of the filter for the flux being calculated. 

error : `BaseException` 

Error to pass. 

""" 

diaObject["%sPSFluxMean" % filterName] = np.nan 

diaObject["%sPSFluxMeanErr" % filterName] = np.nan