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

# 

# LSST Data Management System 

# 

# Copyright 2008-2017 AURA/LSST. 

# 

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

# 

__all__ = ["InstallGaussianPsfConfig", "InstallGaussianPsfTask"] 

 

import math 

 

import lsst.pex.config as pexConfig 

import lsst.pipe.base as pipeBase 

from lsst.meas.algorithms import SingleGaussianPsf 

 

FwhmPerSigma = 2.0*math.sqrt(2.0*math.log(2.0)) 

 

 

class InstallGaussianPsfConfig(pexConfig.Config): 

"""!Config for InstallGaussianPsfTask""" 

fwhm = pexConfig.Field( 

dtype=float, 

default=1.5 * FwhmPerSigma, 

doc="Estimated FWHM of simple Gaussian PSF model, in pixels. " 

"Ignored if input exposure has a PSF model." 

) 

width = pexConfig.RangeField( 

dtype=int, 

doc="Width and height of PSF model, in pixels. Must be odd.", 

default=11, 

min=1, 

) 

 

def validate(self): 

50 ↛ exitline 50 didn't return from function 'validate', because the condition on line 50 was never false if self.width % 2 == 0: 

raise RuntimeError("width=%s must be odd" % (self.width,)) 

 

 

## @addtogroup LSST_task_documentation 

## @{ 

## @page InstallGaussianPsfTask 

## @ref InstallGaussianPsfTask_ "InstallGaussianPsfTask" 

## @copybrief InstallGaussianPsfTask 

## @} 

 

class InstallGaussianPsfTask(pipeBase.Task): 

"""!Install a Gaussian PSF model in an exposure 

 

@anchor InstallGaussianPsfTask_ 

 

@section pipe_tasks_installGaussianPsf_Contents Contents 

 

- @ref pipe_tasks_installGaussianPsf_Purpose 

- @ref pipe_tasks_installGaussianPsf_Initialize 

- @ref pipe_tasks_installGaussianPsf_IO 

- @ref pipe_tasks_installGaussianPsf_Config 

- @ref pipe_tasks_installGaussianPsf_Metadata 

- @ref pipe_tasks_installGaussianPsf_Debug 

- @ref pipe_tasks_installGaussianPsf_Example 

 

@section pipe_tasks_installGaussianPsf_Purpose Description 

 

Install a Gaussian PSF model in an exposure. 

If the exposure already has a PSF model then the new model 

has the same sigma and size (width and height in pixels) of the existing model. 

If the exposure does not have a PSF model then the PSF sigma and size 

are taken from the config. 

 

At present the produced model is always circularly symmetric, but it is planned 

to change this to an elliptical PSF model (only for the case that the exposure 

already has a PSF model), once the necessary PSF object is available. 

 

A variant of this task may someday exist to estimate the PSF 

from the pixel data if no PSF model is present. 

 

@section pipe_tasks_installGaussianPsf_Initialize Task initialisation 

 

@copydoc \_\_init\_\_ 

 

@section pipe_tasks_installGaussianPsf_IO Invoking the Task 

 

The main method is `run`. 

 

@section pipe_tasks_installGaussianPsf_Config Configuration parameters 

 

See @ref InstallGaussianPsfConfig 

 

@section pipe_tasks_installGaussianPsf_Debug Debug variables 

 

This task has no debug display 

 

@section pipe_tasks_installGaussianPsf_Example A complete example of using InstallGaussianPsfTask 

 

from lsst.afw.image import ExposureF 

from lsst.meas.algorithms.installGaussianPsf import InstallGaussianPsfTask, FwhmPerSigma 

 

exposure = ExposureF(100, 100) 

task = InstallGaussianPsfTask() 

task.run(exposure=exposure) 

 

# This particular exposure had no PSF model to begin with, so the new PSF model 

# uses the config's FWHM. However, measured FWHM is based on the truncated 

# PSF image, so it does not exactly match the input 

measFwhm = exposure.getPsf().computeShape().getDeterminantRadius() * FwhmPerSigma 

assert abs(measFwhm - task.config.fwhm) < 1e-3 

""" 

ConfigClass = InstallGaussianPsfConfig 

_DefaultName = "installSimplePsfModel" 

 

def run(self, exposure): 

"""!Set exposure's PSF to a simple PSF model 

 

The sigma and width of the new simple PSF model matches the sigma and width of the current model, 

if any, else the config parameters are used. 

 

@param[in,out] exposure exposure to which to replace or add the PSF model 

""" 

if exposure.hasPsf(): 

psfModel = exposure.getPsf() 

psfSigma = psfModel.computeShape().getDeterminantRadius() 

width, height = psfModel.computeImage().getDimensions() 

else: 

psfSigma = self.config.fwhm / FwhmPerSigma 

width = height = self.config.width 

 

141 ↛ 142line 141 didn't jump to line 142, because the condition on line 141 was never true if psfSigma <= 0: 

raise RuntimeError("psfSigma = %s <= 0" % (psfSigma,)) 

 

self.log.debug("installing a simple Gaussian PSF model with width=%s, height=%s, FWHM=%0.3f", 

width, height, psfSigma*FwhmPerSigma) 

psfModel = SingleGaussianPsf(width, height, psfSigma) 

exposure.setPsf(psfModel)