LSST Applications g180d380827+0f66a164bb,g2079a07aa2+86d27d4dc4,g2305ad1205+7d304bc7a0,g29320951ab+500695df56,g2bbee38e9b+0e5473021a,g337abbeb29+0e5473021a,g33d1c0ed96+0e5473021a,g3a166c0a6a+0e5473021a,g3ddfee87b4+e42ea45bea,g48712c4677+36a86eeaa5,g487adcacf7+2dd8f347ac,g50ff169b8f+96c6868917,g52b1c1532d+585e252eca,g591dd9f2cf+c70619cc9d,g5a732f18d5+53520f316c,g5ea96fc03c+341ea1ce94,g64a986408d+f7cd9c7162,g858d7b2824+f7cd9c7162,g8a8a8dda67+585e252eca,g99cad8db69+469ab8c039,g9ddcbc5298+9a081db1e4,ga1e77700b3+15fc3df1f7,gb0e22166c9+60f28cb32d,gba4ed39666+c2a2e4ac27,gbb8dafda3b+c92fc63c7e,gbd866b1f37+f7cd9c7162,gc120e1dc64+02c66aa596,gc28159a63d+0e5473021a,gc3e9b769f7+b0068a2d9f,gcf0d15dbbd+e42ea45bea,gdaeeff99f8+f9a426f77a,ge6526c86ff+84383d05b3,ge79ae78c31+0e5473021a,gee10cc3b42+585e252eca,gff1a9f87cc+f7cd9c7162,w.2024.17
LSST Data Management Base Package
Loading...
Searching...
No Matches
snapCombine.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__ = ["SnapCombineConfig", "SnapCombineTask"]
23
24import lsst.pex.config as pexConfig
25import lsst.daf.base as dafBase
26import lsst.afw.image as afwImage
27import lsst.pipe.base as pipeBase
28from lsst.coadd.utils import addToCoadd, setCoaddEdgeBits
29from lsst.utils.timer import timeMethod
30
31
32class SnapCombineConfig(pexConfig.Config):
33 bad_mask_planes = pexConfig.ListField(
34 dtype=str,
35 doc="Mask planes that, if set, the associated pixels are not included in the combined exposure.",
36 default=(),
37 )
38
39
40class SnapCombineTask(pipeBase.Task):
41 """Combine two snaps into a single visit image.
42 """
43
44 ConfigClass = SnapCombineConfig
45 _DefaultName = "snapCombine"
46
47 def __init__(self, *args, **kwargs):
48 pipeBase.Task.__init__(self, *args, **kwargs)
49
50 @timeMethod
51 def run(self, snap0, snap1):
52 """Combine two snaps, returning the combined image.
53
54 Parameters
55 ----------
56 snap0 : `lsst.afw.image.Exposure`
57 Snapshot exposure 0.
58 snap1 : `lsst.afw.image.Exposure`
59 Snapshot exposure 1.
60
61 Returns
62 -------
63 result : `lsst.pipe.base.Struct`
64 Results as a struct with attributes:
65
66 ``exposure``
67 Snap-combined exposure.
68 """
69 self.log.info("Merging two snaps with exposure ids: %s, %s", snap0.visitInfo.id, snap1.visitInfo.id)
70 combined = self._add_snaps(snap0, snap1)
71
72 return pipeBase.Struct(
73 exposure=combined,
74 )
75
76 def _add_snaps(self, snap0, snap1):
77 """Add two snap exposures together, returning a new exposure.
78
79 Parameters
80 ----------
81 snap0 : `lsst.afw.image.Exposure`
82 Snap exposure 0.
83 snap1 : `lsst.afw.image.Exposure`
84 Snap exposure 1.
85
86 Returns
87 -------
88 combined : `lsst.afw.image.Exposure`
89 Combined exposure.
90 """
91 combined = snap0.Factory(snap0, True)
92 combined.maskedImage.set(0)
93
94 weights = combined.maskedImage.image.Factory(combined.maskedImage.getBBox())
95 weight = 1.0
96 bad_mask = afwImage.Mask.getPlaneBitMask(self.config.bad_mask_planes)
97 addToCoadd(combined.maskedImage, weights, snap0.maskedImage, bad_mask, weight)
98 addToCoadd(combined.maskedImage, weights, snap1.maskedImage, bad_mask, weight)
99
100 # pre-scaling the weight map instead of post-scaling the combined.maskedImage saves a bit of time
101 # because the weight map is a simple Image instead of a MaskedImage
102 weights *= 0.5 # so result is sum of both images, instead of average
103 combined.maskedImage /= weights
104 setCoaddEdgeBits(combined.maskedImage.getMask(), weights)
105
106 combined.info.setVisitInfo(self._merge_visit_info(snap0.visitInfo, snap1.visitInfo))
107
108 return combined
109
110 def _merge_visit_info(self, info0, info1):
111 """Merge the visitInfo values from the two exposures.
112
113 In particular:
114 * id will be the id of snap 0.
115 * date will be the average of the dates.
116 * exposure time will be the sum of the times.
117
118 Parameters
119 ----------
120 info0, info1 : `lsst.afw.image.VisitInfo`
121 Metadata to combine.
122
123 Returns
124 -------
125 info : `lsst.afw.image.VisitInfo`
126 Combined metadata.
127
128 """
129 time = info0.exposureTime + info1.exposureTime
130 date = (info0.date.get() + info1.date.get()) / 2.0
131 result = info0.copyWith(exposureTime=time,
132 date=dafBase.DateTime(date)
133 )
134 return result
Class for handling dates/times, including MJD, UTC, and TAI.
Definition DateTime.h:64