Loading [MathJax]/extensions/tex2jax.js
LSST Applications g0fba68d861+05816baf74,g1ec0fe41b4+f536777771,g1fd858c14a+a9301854fb,g35bb328faa+fcb1d3bbc8,g4af146b050+a5c07d5b1d,g4d2262a081+6e5fcc2a4e,g53246c7159+fcb1d3bbc8,g56a49b3a55+9c12191793,g5a012ec0e7+3632fc3ff3,g60b5630c4e+ded28b650d,g67b6fd64d1+ed4b5058f4,g78460c75b0+2f9a1b4bcd,g786e29fd12+cf7ec2a62a,g8352419a5c+fcb1d3bbc8,g87b7deb4dc+7b42cf88bf,g8852436030+e5453db6e6,g89139ef638+ed4b5058f4,g8e3bb8577d+d38d73bdbd,g9125e01d80+fcb1d3bbc8,g94187f82dc+ded28b650d,g989de1cb63+ed4b5058f4,g9d31334357+ded28b650d,g9f33ca652e+50a8019d8c,gabe3b4be73+1e0a283bba,gabf8522325+fa80ff7197,gb1101e3267+d9fb1f8026,gb58c049af0+f03b321e39,gb665e3612d+2a0c9e9e84,gb89ab40317+ed4b5058f4,gcf25f946ba+e5453db6e6,gd6cbbdb0b4+bb83cc51f8,gdd1046aedd+ded28b650d,gde0f65d7ad+941d412827,ge278dab8ac+d65b3c2b70,ge410e46f29+ed4b5058f4,gf23fb2af72+b7cae620c0,gf5e32f922b+fcb1d3bbc8,gf67bdafdda+ed4b5058f4,w.2025.16
LSST Data Management Base Package
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
warpAndPsfMatch.py
Go to the documentation of this file.
1# This file is part of pipe_tasks.
2#
3# Developed for the LSST Data Management System.
4# This product includes software developed by the LSST Project
5# (https://www.lsst.org).
6# See the COPYRIGHT file at the top-level directory of this distribution
7# for details of code ownership.
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 GNU General Public License
20# along with this program. If not, see <https://www.gnu.org/licenses/>.
21
22__all__ = ["WarpAndPsfMatchTask"]
23
24import lsst.pex.config as pexConfig
25import lsst.afw.math as afwMath
26import lsst.geom as geom
27import lsst.afw.geom as afwGeom
28import lsst.pipe.base as pipeBase
29from deprecated.sphinx import deprecated
30from lsst.ip.diffim import ModelPsfMatchTask
31from lsst.meas.algorithms import WarpedPsf
32
33
34@deprecated(reason="The Task corresponding to this Config is no longer in use. Will be removed after v29.",
35 version="v29.0", category=FutureWarning)
36class WarpAndPsfMatchConfig(pexConfig.Config):
37 """Config for WarpAndPsfMatchTask
38 """
39 psfMatch = pexConfig.ConfigurableField(
40 target=ModelPsfMatchTask,
41 doc="PSF matching model to model task",
42 )
43 warp = pexConfig.ConfigField(
44 dtype=afwMath.Warper.ConfigClass,
45 doc="warper configuration",
46 )
47
48
49@deprecated(reason="The WarpAndPsfMatchTask is no longer in use. Will be removed after v29. "
50 "Use MakeDirectWarp and MakePsfMatchedWarp instead.",
51 version="v29.0", category=FutureWarning)
52class WarpAndPsfMatchTask(pipeBase.Task):
53 """A task to warp and PSF-match an exposure
54 """
55 ConfigClass = WarpAndPsfMatchConfig
56
57 def __init__(self, *args, **kwargs):
58 pipeBase.Task.__init__(self, *args, **kwargs)
59 self.makeSubtask("psfMatch")
60 self.warper = afwMath.Warper.fromConfig(self.config.warp)
61
62 def run(self, exposure, wcs, modelPsf=None, maxBBox=None, destBBox=None,
63 makeDirect=True, makePsfMatched=False):
64 """Warp and optionally PSF-match exposure
65
66 Parameters
67 ----------
68 exposure : :cpp:class: `lsst::afw::image::Exposure`
69 Exposure to preprocess.
70 wcs : :cpp:class:`lsst::afw::image::Wcs`
71 Desired WCS of temporary images.
72 modelPsf : :cpp:class: `lsst::meas::algorithms::KernelPsf` or None
73 Target PSF to which to match.
74 maxBBox : :cpp:class:`lsst::afw::geom::Box2I` or None
75 Maximum allowed parent bbox of warped exposure.
76 If None then the warped exposure will be just big enough to contain all warped pixels;
77 if provided then the warped exposure may be smaller, and so missing some warped pixels;
78 ignored if destBBox is not None.
79 destBBox: :cpp:class: `lsst::afw::geom::Box2I` or None
80 Exact parent bbox of warped exposure.
81 If None then maxBBox is used to determine the bbox, otherwise maxBBox is ignored.
82 makeDirect : bool
83 Return an exposure that has been only warped?
84 makePsfMatched : bool
85 Return an exposure that has been warped and PSF-matched?
86
87 Returns
88 -------
89 An lsst.pipe.base.Struct with the following fields:
90
91 direct : :cpp:class:`lsst::afw::image::Exposure`
92 warped exposure
93 psfMatched : :cpp:class: `lsst::afw::image::Exposure`
94 warped and psf-Matched temporary exposure
95 """
96 if makePsfMatched and modelPsf is None:
97 raise RuntimeError("makePsfMatched=True, but no model PSF was provided")
98
99 if not makePsfMatched and not makeDirect:
100 self.log.warning("Neither makeDirect nor makePsfMatched requested")
101
102 # Warp PSF before overwriting exposure
103 xyTransform = afwGeom.makeWcsPairTransform(exposure.getWcs(), wcs)
104 psfWarped = WarpedPsf(exposure.getPsf(), xyTransform)
105
106 if makePsfMatched and maxBBox is not None:
107 # grow warped region to provide sufficient area for PSF-matching
108 pixToGrow = 2 * max(self.psfMatch.kConfig.sizeCellX,
109 self.psfMatch.kConfig.sizeCellY)
110 # replace with copy
111 maxBBox = geom.Box2I(maxBBox)
112 maxBBox.grow(pixToGrow)
113
114 with self.timer("warp"):
115 exposure = self.warper.warpExposure(wcs, exposure, maxBBox=maxBBox, destBBox=destBBox)
116 exposure.setPsf(psfWarped)
117
118 if makePsfMatched:
119 try:
120 exposurePsfMatched = self.psfMatch.run(exposure, modelPsf).psfMatchedExposure
121 except Exception as e:
122 exposurePsfMatched = None
123 self.log.info("Cannot PSF-Match: %s", e)
124
125 return pipeBase.Struct(
126 direct=exposure if makeDirect else None,
127 psfMatched=exposurePsfMatched if makePsfMatched else None
128 )
An integer coordinate rectangle.
Definition Box.h:55
A Psf class that maps an arbitrary Psf through a coordinate transformation.
Definition WarpedPsf.h:52
run(self, exposure, wcs, modelPsf=None, maxBBox=None, destBBox=None, makeDirect=True, makePsfMatched=False)
std::shared_ptr< TransformPoint2ToPoint2 > makeWcsPairTransform(SkyWcs const &src, SkyWcs const &dst)
A Transform obtained by putting two SkyWcs objects "back to back".
Definition SkyWcs.cc:146