Skip to content

Commit

Permalink
Add backwards compatibility to CoaddPsf input.
Browse files Browse the repository at this point in the history
This adds support for reading very old Exposures with CoaddPsfs
written before 7/10/2013.  It will not in general preserve the
PSF's "average position" exactly, which is used when no position is
provided to the PSF, because the information needed to reconstruct
that has already been lost.
  • Loading branch information
TallJimbo committed Nov 2, 2016
1 parent c4667cd commit ffc5754
Showing 1 changed file with 27 additions and 1 deletion.
28 changes: 27 additions & 1 deletion src/CoaddPsf.cc
Original file line number Diff line number Diff line change
Expand Up @@ -354,8 +354,11 @@ class CoaddPsf::Factory : public tbl::io::PersistableFactory {

virtual PTR(tbl::io::Persistable)
read(InputArchive const & archive, CatalogVector const & catalogs) const {
CoaddPsfPersistenceHelper const & keys1 = CoaddPsfPersistenceHelper::get();
if (catalogs.size() == 1u) {
return readV0(archive, catalogs);
}
LSST_ARCHIVE_ASSERT(catalogs.size() == 2u);
CoaddPsfPersistenceHelper const & keys1 = CoaddPsfPersistenceHelper::get();
LSST_ARCHIVE_ASSERT(catalogs.front().getSchema() == keys1.schema);
tbl::BaseRecord const & record1 = catalogs.front().front();
return PTR(CoaddPsf)(
Expand All @@ -369,6 +372,29 @@ class CoaddPsf::Factory : public tbl::io::PersistableFactory {
);
}


// Backwards compatibility for files saved before meas_algorithms commit
// 53e61fae (7/10/2013). Prior to that change, the warping configuration
// and the average position were not saved at all, making it impossible to
// reconstruct the average position exactly, but it's better to
// approximate than to fail completely.
std::shared_ptr<tbl::io::Persistable>
readV0(InputArchive const & archive, CatalogVector const & catalogs) const {
auto internalCat = tbl::ExposureCatalog::readFromArchive(archive, catalogs.front());
// Coadd WCS is stored in a special last record.
auto coaddWcs = internalCat.back().getWcs();
internalCat.pop_back();
// Attempt to reconstruct the average position. We can't do this
// exactly, since the catalog we saved isn't the same one that was
// used to compute the original average position.
tbl::Key<double> weightKey;
try {
weightKey = internalCat.getSchema()["weight"];
} catch (pex::exceptions::NotFoundError &) {}
auto averagePos = computeAveragePosition(internalCat, *coaddWcs, weightKey);
return std::shared_ptr<CoaddPsf>(new CoaddPsf(internalCat, coaddWcs, averagePos));
}

Factory(std::string const & name) : tbl::io::PersistableFactory(name) {}

};
Expand Down

0 comments on commit ffc5754

Please sign in to comment.