LSST Applications g0265f82a02+0e5473021a,g02d81e74bb+0dd8ce4237,g1470d8bcf6+3ea6592b6f,g2079a07aa2+86d27d4dc4,g2305ad1205+5ca4c0b359,g295015adf3+d10818ec9d,g2a9a014e59+6f9be1b9cd,g2bbee38e9b+0e5473021a,g337abbeb29+0e5473021a,g3ddfee87b4+703ba97ebf,g487adcacf7+4fa16da234,g50ff169b8f+96c6868917,g52b1c1532d+585e252eca,g591dd9f2cf+ffa42b374e,g5a732f18d5+53520f316c,g64a986408d+0dd8ce4237,g858d7b2824+0dd8ce4237,g8a8a8dda67+585e252eca,g99cad8db69+d39438377f,g9ddcbc5298+9a081db1e4,ga1e77700b3+15fc3df1f7,ga8c6da7877+f1d96605c8,gb0e22166c9+60f28cb32d,gb6a65358fc+0e5473021a,gba4ed39666+c2a2e4ac27,gbb8dafda3b+e5339d463f,gc120e1dc64+da31e9920e,gc28159a63d+0e5473021a,gcf0d15dbbd+703ba97ebf,gdaeeff99f8+f9a426f77a,ge6526c86ff+889fc9d533,ge79ae78c31+0e5473021a,gee10cc3b42+585e252eca,gf18bd8381d+7268b93478,gff1a9f87cc+0dd8ce4237,w.2024.16
LSST Data Management Base Package
Loading...
Searching...
No Matches
Public Member Functions | Static Public Attributes | List of all members
lsst.pipe.tasks.registerImage.RegisterTask Class Reference
Inheritance diagram for lsst.pipe.tasks.registerImage.RegisterTask:

Public Member Functions

 run (self, inputSources, inputWcs, inputBBox, templateSources)
 
 matchSources (self, inputSources, templateSources)
 
 fitWcs (self, matches, inputWcs, inputBBox)
 
 warpExposure (self, inputExp, newWcs, templateWcs, templateBBox)
 
 warpSources (self, inputSources, newWcs, templateWcs, templateBBox)
 

Static Public Attributes

 ConfigClass = RegisterConfig
 

Detailed Description

Task to register (align) multiple images.

The 'run' method provides a revised Wcs from matches and fitting sources.
Additional methods are provided as a convenience to warp an exposure
('warpExposure') and sources ('warpSources') with the new Wcs.

Definition at line 49 of file registerImage.py.

Member Function Documentation

◆ fitWcs()

lsst.pipe.tasks.registerImage.RegisterTask.fitWcs ( self,
matches,
inputWcs,
inputBBox )
Fit Wcs to matches.

The fitting includes iterative sigma-clipping.

Parameters
----------
matches : `list`
    List of matches (first is target, second is input).
inputWcs : `lsst.afw.geom.SkyWcs`
    Original input Wcs.
inputBBox : `lsst.geom.Box`
    Bounding box of input exposure.

Returns
-------
wcs: `lsst.afw.geom.SkyWcs`
    Wcs fitted to matches.

Definition at line 116 of file registerImage.py.

116 def fitWcs(self, matches, inputWcs, inputBBox):
117 """Fit Wcs to matches.
118
119 The fitting includes iterative sigma-clipping.
120
121 Parameters
122 ----------
123 matches : `list`
124 List of matches (first is target, second is input).
125 inputWcs : `lsst.afw.geom.SkyWcs`
126 Original input Wcs.
127 inputBBox : `lsst.geom.Box`
128 Bounding box of input exposure.
129
130 Returns
131 -------
132 wcs: `lsst.afw.geom.SkyWcs`
133 Wcs fitted to matches.
134 """
135 copyMatches = type(matches)(matches)
136 refCoordKey = copyMatches[0].first.getTable().getCoordKey()
137 inCentroidKey = copyMatches[0].second.getTable().getCentroidSlot().getMeasKey()
138 for i in range(self.config.sipIter):
139 sipFit = makeCreateWcsWithSip(copyMatches, inputWcs, self.config.sipOrder, inputBBox)
140 self.log.debug("Registration WCS RMS iteration %d: %f pixels",
141 i, sipFit.getScatterInPixels())
142 wcs = sipFit.getNewWcs()
143 dr = [m.first.get(refCoordKey).separation(
144 wcs.pixelToSky(m.second.get(inCentroidKey))).asArcseconds() for
145 m in copyMatches]
146 dr = numpy.array(dr)
147 rms = math.sqrt((dr*dr).mean()) # RMS from zero
148 rms = max(rms, 1.0e-9) # Don't believe any RMS smaller than this
149 self.log.debug("Registration iteration %d: rms=%f", i, rms)
150 good = numpy.where(dr < self.config.sipRej*rms)[0]
151 numBad = len(copyMatches) - len(good)
152 self.log.debug("Registration iteration %d: rejected %d", i, numBad)
153 if numBad == 0:
154 break
155 copyMatches = type(matches)(copyMatches[i] for i in good)
156
157 sipFit = makeCreateWcsWithSip(copyMatches, inputWcs, self.config.sipOrder, inputBBox)
158 self.log.info("Registration WCS: final WCS RMS=%f pixels from %d matches",
159 sipFit.getScatterInPixels(), len(copyMatches))
160 self.metadata["SIP_RMS"] = sipFit.getScatterInPixels()
161 self.metadata["SIP_GOOD"] = len(copyMatches)
162 self.metadata["SIP_REJECTED"] = len(matches) - len(copyMatches)
163 wcs = sipFit.getNewWcs()
164 return wcs
165
int max

◆ matchSources()

lsst.pipe.tasks.registerImage.RegisterTask.matchSources ( self,
inputSources,
templateSources )
Match sources between the input and template.

The order of the input arguments matters (because the later Wcs
fitting assumes a particular order).

Parameters
----------
inputSources : `lsst.afw.table.SourceCatalog`
    Source catalog of the input frame.
templateSources : `lsst.afw.table.SourceCatalog`
    Source of the target frame.

Returns
-------
matches: `list`
    Match list.

Definition at line 90 of file registerImage.py.

90 def matchSources(self, inputSources, templateSources):
91 """Match sources between the input and template.
92
93 The order of the input arguments matters (because the later Wcs
94 fitting assumes a particular order).
95
96 Parameters
97 ----------
98 inputSources : `lsst.afw.table.SourceCatalog`
99 Source catalog of the input frame.
100 templateSources : `lsst.afw.table.SourceCatalog`
101 Source of the target frame.
102
103 Returns
104 -------
105 matches: `list`
106 Match list.
107 """
108 matches = afwTable.matchRaDec(templateSources, inputSources,
109 self.config.matchRadius*geom.arcseconds)
110 self.log.info("Matching within %.1f arcsec: %d matches", self.config.matchRadius, len(matches))
111 self.metadata["MATCH_NUM"] = len(matches)
112 if len(matches) == 0:
113 raise RuntimeError("Unable to match source catalogs")
114 return matches
115
std::vector< Match< typename Cat1::Record, typename Cat2::Record > > matchRaDec(Cat1 const &cat1, Cat2 const &cat2, lsst::geom::Angle radius, MatchControl const &mc=MatchControl())
Compute all tuples (s1,s2,d) where s1 belings to cat1, s2 belongs to cat2 and d, the distance between...
Definition Match.cc:158

◆ run()

lsst.pipe.tasks.registerImage.RegisterTask.run ( self,
inputSources,
inputWcs,
inputBBox,
templateSources )
Register (align) an input exposure to the template
The sources must have RA,Dec set, and accurate to within the
'matchRadius' of the configuration in order to facilitate source
matching.  We fit a new Wcs, but do NOT set it in the input exposure.

Parameters
----------
inputSources : `lsst.afw.table.SourceCatalog`
    Sources from input exposure.
inputWcs : `lsst.afw.geom.SkyWcs`
    Wcs of input exposure.
inputBBox : `lsst.geom.Box`
    Bounding box of input exposure.
templateSources : `lsst.afw.table.SourceCatalog`
    Sources from template exposure.

Returns
-------
result : `lsst.pipe.base.Struct`
    Results as a struct with attributes:

    ``matches``
        Matches between sources (`list`).
    ``wcs``
        Wcs for input in frame of template (`lsst.afw.geom.SkyWcs`).

Definition at line 59 of file registerImage.py.

59 def run(self, inputSources, inputWcs, inputBBox, templateSources):
60 """Register (align) an input exposure to the template
61 The sources must have RA,Dec set, and accurate to within the
62 'matchRadius' of the configuration in order to facilitate source
63 matching. We fit a new Wcs, but do NOT set it in the input exposure.
64
65 Parameters
66 ----------
67 inputSources : `lsst.afw.table.SourceCatalog`
68 Sources from input exposure.
69 inputWcs : `lsst.afw.geom.SkyWcs`
70 Wcs of input exposure.
71 inputBBox : `lsst.geom.Box`
72 Bounding box of input exposure.
73 templateSources : `lsst.afw.table.SourceCatalog`
74 Sources from template exposure.
75
76 Returns
77 -------
78 result : `lsst.pipe.base.Struct`
79 Results as a struct with attributes:
80
81 ``matches``
82 Matches between sources (`list`).
83 ``wcs``
84 Wcs for input in frame of template (`lsst.afw.geom.SkyWcs`).
85 """
86 matches = self.matchSources(inputSources, templateSources)
87 wcs = self.fitWcs(matches, inputWcs, inputBBox)
88 return Struct(matches=matches, wcs=wcs)
89

◆ warpExposure()

lsst.pipe.tasks.registerImage.RegisterTask.warpExposure ( self,
inputExp,
newWcs,
templateWcs,
templateBBox )
Warp input exposure to template frame.

There are a variety of data attached to the exposure (e.g., PSF, PhotoCalib
and other metadata), but we do not attempt to warp these to the template
frame.

Parameters
----------
inputExp : `lsst.afw.image.Exposure`
    Input exposure, to be warped.
newWcs : `lsst.afw.geom.SkyWcs`
    Revised Wcs for input exposure.
templateWcs : `lsst.afw.geom.SkyWcs`
    Target Wcs.
templateBBox : `lsst.geom.Box`
    Target bounding box.

Returns
-------
alignedExp : `lsst.afw.image.Exposure`
    Warped exposure.

Definition at line 166 of file registerImage.py.

166 def warpExposure(self, inputExp, newWcs, templateWcs, templateBBox):
167 """Warp input exposure to template frame.
168
169 There are a variety of data attached to the exposure (e.g., PSF, PhotoCalib
170 and other metadata), but we do not attempt to warp these to the template
171 frame.
172
173 Parameters
174 ----------
175 inputExp : `lsst.afw.image.Exposure`
176 Input exposure, to be warped.
177 newWcs : `lsst.afw.geom.SkyWcs`
178 Revised Wcs for input exposure.
179 templateWcs : `lsst.afw.geom.SkyWcs`
180 Target Wcs.
181 templateBBox : `lsst.geom.Box`
182 Target bounding box.
183
184 Returns
185 -------
186 alignedExp : `lsst.afw.image.Exposure`
187 Warped exposure.
188 """
189 warper = Warper.fromConfig(self.config.warper)
190 copyExp = inputExp.Factory(inputExp.getMaskedImage(), newWcs)
191 alignedExp = warper.warpExposure(templateWcs, copyExp, destBBox=templateBBox)
192 return alignedExp
193

◆ warpSources()

lsst.pipe.tasks.registerImage.RegisterTask.warpSources ( self,
inputSources,
newWcs,
templateWcs,
templateBBox )
Warp sources to the new frame.

It would be difficult to transform all possible quantities of potential
interest between the two frames.  We therefore update only the sky and
pixel coordinates.

Parameters
----------
inputSources : `lsst.afw.table.SourceCatalog`
    Sources on input exposure, to be warped.
newWcs : `lsst.afw.geom.SkyWcs`
    Revised Wcs for input exposure.
templateWcs : `lsst.afw.geom.SkyWcs`
    Target Wcs.
templateBBox : `lsst.geom.Box`
    Target bounding box.

Returns
-------
alignedSources : `lsst.afw.table.SourceCatalog`
    Warped sources.

Definition at line 194 of file registerImage.py.

194 def warpSources(self, inputSources, newWcs, templateWcs, templateBBox):
195 """Warp sources to the new frame.
196
197 It would be difficult to transform all possible quantities of potential
198 interest between the two frames. We therefore update only the sky and
199 pixel coordinates.
200
201 Parameters
202 ----------
203 inputSources : `lsst.afw.table.SourceCatalog`
204 Sources on input exposure, to be warped.
205 newWcs : `lsst.afw.geom.SkyWcs`
206 Revised Wcs for input exposure.
207 templateWcs : `lsst.afw.geom.SkyWcs`
208 Target Wcs.
209 templateBBox : `lsst.geom.Box`
210 Target bounding box.
211
212 Returns
213 -------
214 alignedSources : `lsst.afw.table.SourceCatalog`
215 Warped sources.
216 """
217 alignedSources = inputSources.copy(True)
218 if not isinstance(templateBBox, geom.Box2D):
219 # There is no method Box2I::contains(Point2D)
220 templateBBox = geom.Box2D(templateBBox)
221 table = alignedSources.getTable()
222 coordKey = table.getCoordKey()
223 centroidKey = table.getCentroidSlot().getMeasKey()
224 deleteList = []
225 for i, s in enumerate(alignedSources):
226 oldCentroid = s.get(centroidKey)
227 newCoord = newWcs.pixelToSky(oldCentroid)
228 newCentroid = templateWcs.skyToPixel(newCoord)
229 if not templateBBox.contains(newCentroid):
230 deleteList.append(i)
231 continue
232 s.set(coordKey, newCoord)
233 s.set(centroidKey, newCentroid)
234
235 for i in reversed(deleteList): # Delete from back so we don't change indices
236 del alignedSources[i]
237
238 return alignedSources
A floating-point coordinate rectangle geometry.
Definition Box.h:413

Member Data Documentation

◆ ConfigClass

lsst.pipe.tasks.registerImage.RegisterTask.ConfigClass = RegisterConfig
static

Definition at line 57 of file registerImage.py.


The documentation for this class was generated from the following file: