LSSTApplications  16.0-10-g0ee56ad+5,16.0-11-ga33d1f2+5,16.0-12-g3ef5c14+3,16.0-12-g71e5ef5+18,16.0-12-gbdf3636+3,16.0-13-g118c103+3,16.0-13-g8f68b0a+3,16.0-15-gbf5c1cb+4,16.0-16-gfd17674+3,16.0-17-g7c01f5c+3,16.0-18-g0a50484+1,16.0-20-ga20f992+8,16.0-21-g0e05fd4+6,16.0-21-g15e2d33+4,16.0-22-g62d8060+4,16.0-22-g847a80f+4,16.0-25-gf00d9b8+1,16.0-28-g3990c221+4,16.0-3-gf928089+3,16.0-32-g88a4f23+5,16.0-34-gd7987ad+3,16.0-37-gc7333cb+2,16.0-4-g10fc685+2,16.0-4-g18f3627+26,16.0-4-g5f3a788+26,16.0-5-gaf5c3d7+4,16.0-5-gcc1f4bb+1,16.0-6-g3b92700+4,16.0-6-g4412fcd+3,16.0-6-g7235603+4,16.0-69-g2562ce1b+2,16.0-8-g14ebd58+4,16.0-8-g2df868b+1,16.0-8-g4cec79c+6,16.0-8-gadf6c7a+1,16.0-8-gfc7ad86,16.0-82-g59ec2a54a+1,16.0-9-g5400cdc+2,16.0-9-ge6233d7+5,master-g2880f2d8cf+3,v17.0.rc1
LSSTDataManagementBasePackage
installGaussianPsf.py
Go to the documentation of this file.
1 #
2 # LSST Data Management System
3 #
4 # Copyright 2008-2017 AURA/LSST.
5 #
6 # This product includes software developed by the
7 # LSST Project (http://www.lsst.org/).
8 #
9 # This program is free software: you can redistribute it and/or modify
10 # it under the terms of the GNU General Public License as published by
11 # the Free Software Foundation, either version 3 of the License, or
12 # (at your option) any later version.
13 #
14 # This program is distributed in the hope that it will be useful,
15 # but WITHOUT ANY WARRANTY; without even the implied warranty of
16 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 # GNU General Public License for more details.
18 #
19 # You should have received a copy of the LSST License Statement and
20 # the GNU General Public License along with this program. If not,
21 # see <https://www.lsstcorp.org/LegalNotices/>.
22 #
23 __all__ = ["InstallGaussianPsfConfig", "InstallGaussianPsfTask"]
24 
25 import math
26 
27 import lsst.pex.config as pexConfig
28 import lsst.pipe.base as pipeBase
29 from lsst.meas.algorithms import SingleGaussianPsf
30 
31 FwhmPerSigma = 2.0*math.sqrt(2.0*math.log(2.0))
32 
33 
34 class InstallGaussianPsfConfig(pexConfig.Config):
35  """!Config for InstallGaussianPsfTask"""
36  fwhm = pexConfig.Field(
37  dtype=float,
38  default=1.5 * FwhmPerSigma,
39  doc="Estimated FWHM of simple Gaussian PSF model, in pixels. "
40  "Ignored if input exposure has a PSF model."
41  )
42  width = pexConfig.RangeField(
43  dtype=int,
44  doc="Width and height of PSF model, in pixels. Must be odd.",
45  default=11,
46  min=1,
47  )
48 
49  def validate(self):
50  if self.width % 2 == 0:
51  raise RuntimeError("width=%s must be odd" % (self.width,))
52 
53 
54 
60 
61 class InstallGaussianPsfTask(pipeBase.Task):
62  r"""!Install a Gaussian PSF model in an exposure
63 
64  @anchor InstallGaussianPsfTask_
65 
66  @section pipe_tasks_installGaussianPsf_Contents Contents
67 
68  - @ref pipe_tasks_installGaussianPsf_Purpose
69  - @ref pipe_tasks_installGaussianPsf_Initialize
70  - @ref pipe_tasks_installGaussianPsf_IO
71  - @ref pipe_tasks_installGaussianPsf_Config
72  - @ref pipe_tasks_installGaussianPsf_Metadata
73  - @ref pipe_tasks_installGaussianPsf_Debug
74  - @ref pipe_tasks_installGaussianPsf_Example
75 
76  @section pipe_tasks_installGaussianPsf_Purpose Description
77 
78  Install a Gaussian PSF model in an exposure.
79  If the exposure already has a PSF model then the new model
80  has the same sigma and size (width and height in pixels) of the existing model.
81  If the exposure does not have a PSF model then the PSF sigma and size
82  are taken from the config.
83 
84  At present the produced model is always circularly symmetric, but it is planned
85  to change this to an elliptical PSF model (only for the case that the exposure
86  already has a PSF model), once the necessary PSF object is available.
87 
88  A variant of this task may someday exist to estimate the PSF
89  from the pixel data if no PSF model is present.
90 
91  @section pipe_tasks_installGaussianPsf_Initialize Task initialisation
92 
93  @copydoc \_\_init\_\_
94 
95  @section pipe_tasks_installGaussianPsf_IO Invoking the Task
96 
97  The main method is `run`.
98 
99  @section pipe_tasks_installGaussianPsf_Config Configuration parameters
100 
101  See @ref InstallGaussianPsfConfig
102 
103  @section pipe_tasks_installGaussianPsf_Debug Debug variables
104 
105  This task has no debug display
106 
107  @section pipe_tasks_installGaussianPsf_Example A complete example of using InstallGaussianPsfTask
108 
109  from lsst.afw.image import ExposureF
110  from lsst.meas.algorithms.installGaussianPsf import InstallGaussianPsfTask, FwhmPerSigma
111 
112  exposure = ExposureF(100, 100)
113  task = InstallGaussianPsfTask()
114  task.run(exposure=exposure)
115 
116  # This particular exposure had no PSF model to begin with, so the new PSF model
117  # uses the config's FWHM. However, measured FWHM is based on the truncated
118  # PSF image, so it does not exactly match the input
119  measFwhm = exposure.getPsf().computeShape().getDeterminantRadius() * FwhmPerSigma
120  assert abs(measFwhm - task.config.fwhm) < 1e-3
121  """
122  ConfigClass = InstallGaussianPsfConfig
123  _DefaultName = "installSimplePsfModel"
124 
125  def run(self, exposure):
126  """!Set exposure's PSF to a simple PSF model
127 
128  The sigma and width of the new simple PSF model matches the sigma and width of the current model,
129  if any, else the config parameters are used.
130 
131  @param[in,out] exposure exposure to which to replace or add the PSF model
132  """
133  if exposure.hasPsf():
134  psfModel = exposure.getPsf()
135  psfSigma = psfModel.computeShape().getDeterminantRadius()
136  width, height = psfModel.computeImage().getDimensions()
137  else:
138  psfSigma = self.config.fwhm / FwhmPerSigma
139  width = height = self.config.width
140 
141  if psfSigma <= 0:
142  raise RuntimeError("psfSigma = %s <= 0" % (psfSigma,))
143 
144  self.log.debug("installing a simple Gaussian PSF model with width=%s, height=%s, FWHM=%0.3f",
145  width, height, psfSigma*FwhmPerSigma)
146  psfModel = SingleGaussianPsf(width, height, psfSigma)
147  exposure.setPsf(psfModel)
Fit spatial kernel using approximate fluxes for candidates, and solving a linear system of equations...
Represent a PSF as a circularly symmetrical Gaussian.
def run(self, exposure)
Set exposure&#39;s PSF to a simple PSF model.