@@ -139,7 +139,8 @@ geom::Point2D computeAveragePosition(afw::table::ExposureCatalog const &catalog,
139139
140140} // namespace
141141
142- CoaddPsf::CoaddPsf (afw::table::ExposureCatalog const &catalog, afw::geom::SkyWcs const &coaddWcs,
142+ CoaddPsf::CoaddPsf (afw::table::ExposureCatalog const &catalog,
143+ std::shared_ptr<afw::geom::SkyWcs const > coaddWcs,
143144 std::string const &weightFieldName, std::string const &warpingKernelName, int cacheSize)
144145 : _coaddWcs(coaddWcs),
145146 _warpingKernelName (warpingKernelName),
@@ -165,17 +166,29 @@ CoaddPsf::CoaddPsf(afw::table::ExposureCatalog const &catalog, afw::geom::SkyWcs
165166 record->assign (*i, mapper);
166167 _catalog.push_back (record);
167168 }
168- _averagePosition = computeAveragePosition (_catalog, _coaddWcs, _weightKey);
169+ _averagePosition = computeAveragePosition (_catalog, * _coaddWcs, _weightKey);
169170}
170171
171- CoaddPsf::CoaddPsf (afw::table::ExposureCatalog const &catalog, afw::geom::SkyWcs const &coaddWcs,
172+ CoaddPsf::CoaddPsf (afw::table::ExposureCatalog const &catalog,
173+ std::shared_ptr<afw::geom::SkyWcs const > coaddWcs,
172174 geom::Point2D const &averagePosition, std::string const &warpingKernelName, int cacheSize)
173175 : _catalog(catalog),
174176 _coaddWcs(coaddWcs),
175177 _weightKey(_catalog.getSchema()["weight"]),
178+ _tractKey(),
179+ _patchKey(),
176180 _averagePosition(averagePosition),
177181 _warpingKernelName(warpingKernelName),
178- _warpingControl(new afw::math::WarpingControl(warpingKernelName, " " , cacheSize)) {}
182+ _warpingControl(new afw::math::WarpingControl(warpingKernelName, " " , cacheSize)) {
183+ try {
184+ _tractKey = _catalog.getSchema ()[" tract" ];
185+ } catch (pex::exceptions::NotFoundError &) {
186+ }
187+ try {
188+ _patchKey = _catalog.getSchema ()[" patch" ];
189+ } catch (pex::exceptions::NotFoundError &) {
190+ }
191+ }
179192
180193std::shared_ptr<afw::detection::Psf> CoaddPsf::clone () const { return std::make_shared<CoaddPsf>(*this ); }
181194
@@ -227,7 +240,7 @@ void addToImage(std::shared_ptr<afw::image::Image<double>> image,
227240} // anonymous
228241
229242geom::Box2I CoaddPsf::doComputeBBox (geom::Point2D const &ccdXY, afw::image::Color const &color) const {
230- afw::table::ExposureCatalog subcat = _catalog.subsetContaining (ccdXY, _coaddWcs, true );
243+ afw::table::ExposureCatalog subcat = _catalog.subsetContaining (ccdXY, * _coaddWcs, true );
231244 if (subcat.empty ()) {
232245 throw LSST_EXCEPT (
233246 lsst::afw::detection::InvalidPsfError,
@@ -238,7 +251,7 @@ geom::Box2I CoaddPsf::doComputeBBox(geom::Point2D const &ccdXY, afw::image::Colo
238251 geom::Box2I ret;
239252 for (auto const &exposureRecord : subcat) {
240253 // compute transform from exposure pixels to coadd pixels
241- auto exposureToCoadd = afw::geom::makeWcsPairTransform (*exposureRecord.getWcs (), _coaddWcs);
254+ auto exposureToCoadd = afw::geom::makeWcsPairTransform (*exposureRecord.getWcs (), * _coaddWcs);
242255 WarpedPsf warpedPsf = WarpedPsf (exposureRecord.getPsf (), exposureToCoadd, _warpingControl);
243256 geom::Box2I componentBBox = warpedPsf.computeBBox (ccdXY, color);
244257 ret.include (componentBBox);
@@ -250,7 +263,7 @@ geom::Box2I CoaddPsf::doComputeBBox(geom::Point2D const &ccdXY, afw::image::Colo
250263std::shared_ptr<afw::detection::Psf::Image>
251264CoaddPsf::doComputeKernelImage (geom::Point2D const &ccdXY, afw::image::Color const &color) const {
252265 // Get the subset of exposures which contain our coordinate within their validPolygons.
253- afw::table::ExposureCatalog subcat = _catalog.subsetContaining (ccdXY, _coaddWcs, true );
266+ afw::table::ExposureCatalog subcat = _catalog.subsetContaining (ccdXY, * _coaddWcs, true );
254267 if (subcat.empty ()) {
255268 throw LSST_EXCEPT (
256269 lsst::afw::detection::InvalidPsfError,
@@ -267,7 +280,7 @@ CoaddPsf::doComputeKernelImage(geom::Point2D const &ccdXY, afw::image::Color con
267280
268281 for (auto const &exposureRecord : subcat) {
269282 // compute transform from exposure pixels to coadd pixels
270- auto exposureToCoadd = afw::geom::makeWcsPairTransform (*exposureRecord.getWcs (), _coaddWcs);
283+ auto exposureToCoadd = afw::geom::makeWcsPairTransform (*exposureRecord.getWcs (), * _coaddWcs);
271284 std::shared_ptr<afw::image::Image<double >> componentImg;
272285 try {
273286 WarpedPsf warpedPsf = WarpedPsf (exposureRecord.getPsf (), exposureToCoadd, _warpingControl);
@@ -295,48 +308,68 @@ CoaddPsf::doComputeKernelImage(geom::Point2D const &ccdXY, afw::image::Color con
295308
296309int CoaddPsf::getComponentCount () const { return _catalog.size (); }
297310
298- std::shared_ptr<afw::detection::Psf const > CoaddPsf::getPsf (int index) {
311+ std::shared_ptr<afw::detection::Psf const > CoaddPsf::getPsf (int index) const {
299312 if (index < 0 || index >= getComponentCount ()) {
300313 throw LSST_EXCEPT (pex::exceptions::RangeError, " index of CoaddPsf component out of range" );
301314 }
302315 return _catalog[index].getPsf ();
303316}
304317
305- afw::geom::SkyWcs CoaddPsf::getWcs (int index) {
318+ std::shared_ptr< afw::geom::SkyWcs const > CoaddPsf::getWcs (int index) const {
306319 if (index < 0 || index >= getComponentCount ()) {
307320 throw LSST_EXCEPT (pex::exceptions::RangeError, " index of CoaddPsf component out of range" );
308321 }
309- return * _catalog[index].getWcs ();
322+ return _catalog[index].getWcs ();
310323}
311324
312- std::shared_ptr<afw::geom::polygon::Polygon const > CoaddPsf::getValidPolygon (int index) {
325+ std::shared_ptr<afw::geom::polygon::Polygon const > CoaddPsf::getValidPolygon (int index) const {
313326 if (index < 0 || index >= getComponentCount ()) {
314327 throw LSST_EXCEPT (pex::exceptions::RangeError, " index of CoaddPsf component out of range" );
315328 }
316329 return _catalog[index].getValidPolygon ();
317330}
318331
319- double CoaddPsf::getWeight (int index) {
332+ double CoaddPsf::getWeight (int index) const {
320333 if (index < 0 || index >= getComponentCount ()) {
321334 throw LSST_EXCEPT (pex::exceptions::RangeError, " index of CoaddPsf component out of range" );
322335 }
323336 return _catalog[index].get (_weightKey);
324337}
325338
326- afw::table::RecordId CoaddPsf::getId (int index) {
339+ afw::table::RecordId CoaddPsf::getId (int index) const {
327340 if (index < 0 || index >= getComponentCount ()) {
328341 throw LSST_EXCEPT (pex::exceptions::RangeError, " index of CoaddPsf component out of range" );
329342 }
330343 return _catalog[index].getId ();
331344}
332345
333- geom::Box2I CoaddPsf::getBBox (int index) {
346+ geom::Box2I CoaddPsf::getBBox (int index) const {
334347 if (index < 0 || index >= getComponentCount ()) {
335348 throw LSST_EXCEPT (pex::exceptions::RangeError, " index of CoaddPsf component out of range" );
336349 }
337350 return _catalog[index].getBBox ();
338351}
339352
353+ int CoaddPsf::getTract (int index) const {
354+ if (index < 0 || index >= getComponentCount ()) {
355+ throw LSST_EXCEPT (pex::exceptions::RangeError, " index of CoaddPsf component out of range" );
356+ }
357+ if (!_tractKey.isValid ()) {
358+ throw LSST_EXCEPT (pex::exceptions::NotFoundError, " CoaddPsf has no tract column" );
359+ }
360+ return _catalog[index][_tractKey];
361+ }
362+
363+ int CoaddPsf::getPatch (int index) const {
364+ if (index < 0 || index >= getComponentCount ()) {
365+ throw LSST_EXCEPT (pex::exceptions::RangeError, " index of CoaddPsf component out of range" );
366+ }
367+ if (!_patchKey.isValid ()) {
368+ throw LSST_EXCEPT (pex::exceptions::NotFoundError, " CoaddPsf has no patch column" );
369+ }
370+ return _catalog[index][_patchKey];
371+ }
372+
340373// ---------- Persistence -----------------------------------------------------------------------------------
341374
342375// For persistence of CoaddPsf, we have two catalogs: the first has just one record, and contains
@@ -388,7 +421,7 @@ class CoaddPsf::Factory : public afw::table::io::PersistableFactory {
388421 afw::table::BaseRecord const &record1 = catalogs.front ().front ();
389422 return std::shared_ptr<CoaddPsf>(
390423 new CoaddPsf (afw::table::ExposureCatalog::readFromArchive (archive, catalogs.back ()),
391- * archive.get <afw::geom::SkyWcs>(record1.get (keys1.coaddWcs )),
424+ archive.get <afw::geom::SkyWcs>(record1.get (keys1.coaddWcs )),
392425 record1.get (keys1.averagePosition ), record1.get (keys1.warpingKernelName ),
393426 record1.get (keys1.cacheSize )));
394427 }
@@ -413,7 +446,7 @@ class CoaddPsf::Factory : public afw::table::io::PersistableFactory {
413446 } catch (pex::exceptions::NotFoundError &) {
414447 }
415448 auto averagePos = computeAveragePosition (internalCat, *coaddWcs, weightKey);
416- return std::shared_ptr<CoaddPsf>(new CoaddPsf (internalCat, * coaddWcs, averagePos));
449+ return std::shared_ptr<CoaddPsf>(new CoaddPsf (internalCat, coaddWcs, averagePos));
417450 }
418451
419452 Factory (std::string const &name) : afw::table::io::PersistableFactory(name) {}
@@ -435,8 +468,7 @@ void CoaddPsf::write(OutputArchiveHandle &handle) const {
435468 CoaddPsfPersistenceHelper const &keys1 = CoaddPsfPersistenceHelper::get ();
436469 afw::table::BaseCatalog cat1 = handle.makeCatalog (keys1.schema );
437470 std::shared_ptr<afw::table::BaseRecord> record1 = cat1.addNew ();
438- auto coaddWcsPtr = std::make_shared<afw::geom::SkyWcs>(_coaddWcs);
439- record1->set (keys1.coaddWcs , handle.put (coaddWcsPtr));
471+ record1->set (keys1.coaddWcs , handle.put (_coaddWcs));
440472 record1->set (keys1.cacheSize , _warpingControl->getCacheSize ());
441473 record1->set (keys1.averagePosition , _averagePosition);
442474 record1->set (keys1.warpingKernelName , _warpingKernelName);
0 commit comments