LSSTApplications  10.0+286,10.0+36,10.0+46,10.0-2-g4f67435,10.1+152,10.1+37,11.0,11.0+1,11.0-1-g47edd16,11.0-1-g60db491,11.0-1-g7418c06,11.0-2-g04d2804,11.0-2-g68503cd,11.0-2-g818369d,11.0-2-gb8b8ce7
LSSTDataManagementBasePackage
warpAndPsfMatch.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 #
3 # LSST Data Management System
4 # Copyright 2008, 2009, 2010, 2011, 2012 LSST Corporation.
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 <http://www.lsstcorp.org/LegalNotices/>.
22 #
23 import math
24 
25 import lsst.pex.config as pexConfig
26 import lsst.afw.detection as afwDetection
27 import lsst.afw.geom as afwGeom
28 import lsst.afw.math as afwMath
29 import lsst.pipe.base as pipeBase
30 import lsst.meas.algorithms as measAlg
31 from lsst.ip.diffim import ModelPsfMatchTask
32 
33 __all__ = ["WarpAndPsfMatchTask"]
34 
35 class WarpAndPsfMatchConfig(pexConfig.Config):
36  """Config for WarpAndPsfMatchTask
37  """
38  psfMatch = pexConfig.ConfigurableField(
39  target = ModelPsfMatchTask,
40  doc = "PSF matching model to model task",
41  )
42  warp = pexConfig.ConfigField(
43  dtype = afwMath.Warper.ConfigClass,
44  doc = "warper configuration",
45  )
46 
47 
48 class WarpAndPsfMatchTask(pipeBase.Task):
49  """A task to warp and PSF-match an exposure
50  """
51  ConfigClass = WarpAndPsfMatchConfig
52 
53  def __init__(self, *args, **kwargs):
54  pipeBase.Task.__init__(self, *args, **kwargs)
55  self.makeSubtask("psfMatch")
56  self.warper = afwMath.Warper.fromConfig(self.config.warp)
57 
58  def run(self, exposure, wcs, modelPsf=None, maxBBox=None, destBBox=None):
59  """PSF-match exposure (if modelPsf is not None) and warp
60 
61  Note that PSF-matching is performed before warping, which is incorrect:
62  a position-dependent warping (as is used in the general case) will
63  re-introduce a position-dependent PSF. However, this is easier, and
64  sufficient for now (until we are able to warp PSFs to determine the
65  correct target PSF).
66 
67  @param[in,out] exposure: exposure to preprocess; PSF matching is done in place
68  @param[in] wcs: desired WCS of temporary images
69  @param[in] modelPsf: target PSF to which to match (or None)
70  @param maxBBox: maximum allowed parent bbox of warped exposure (an afwGeom.Box2I or None);
71  if None then the warped exposure will be just big enough to contain all warped pixels;
72  if provided then the warped exposure may be smaller, and so missing some warped pixels;
73  ignored if destBBox is not None
74  @param destBBox: exact parent bbox of warped exposure (an afwGeom.Box2I or None);
75  if None then maxBBox is used to determine the bbox, otherwise maxBBox is ignored
76 
77  @return a pipe_base Struct containing:
78  - exposure: processed exposure
79  """
80  if modelPsf is not None:
81  exposure = self.psfMatch.run(exposure, modelPsf).psfMatchedExposure
82  with self.timer("warp"):
83  exposure = self.warper.warpExposure(wcs, exposure, maxBBox=maxBBox, destBBox=destBBox)
84  return pipeBase.Struct(
85  exposure = exposure,
86  )