74 class OldWcsFactory :
public table::io::PersistableFactory {
76 explicit OldWcsFactory(
std::string const&
name) : table::io::PersistableFactory(name) {}
79 CatalogVector
const& catalogs)
const override {
82 auto const& record = catalogs.front().front();
83 auto const metadata = getOldWcsMetadata(record);
84 return std::make_shared<SkyWcs>(*metadata);
88 OldWcsFactory registerWcs(
"Wcs");
91 class OldTanWcsFactory :
public table::io::PersistableFactory {
93 explicit OldTanWcsFactory(
std::string const&
name) : table::io::PersistableFactory(name) {}
96 CatalogVector
const& catalogs)
const override {
98 auto const& record = catalogs.front().front();
99 auto const metadata = getOldWcsMetadata(record);
101 if (catalogs.size() > 1u) {
109 for (
auto i = 1; i <= 2; ++i) {
111 auto const ctypeValue = metadata->getAsString(ctypeName);
112 if (!endsWith(ctypeValue, ctypeSuffix)) {
113 metadata->set(ctypeName, ctypeValue + ctypeSuffix);
117 auto sipMetadata = getOldSipMetadata(*sipRecord);
118 metadata->combine(sipMetadata);
120 return std::make_shared<SkyWcs>(*metadata);
124 OldTanWcsFactory registerTanWcs(
"TanWcs");
128 struct OldWcsPersistenceHelper {
132 table::Key<table::Array<double>>
cd;
140 static OldWcsPersistenceHelper
const&
get() {
141 static OldWcsPersistenceHelper instance;
146 OldWcsPersistenceHelper(
const OldWcsPersistenceHelper&) =
delete;
147 OldWcsPersistenceHelper& operator=(
const OldWcsPersistenceHelper&) =
delete;
150 OldWcsPersistenceHelper(OldWcsPersistenceHelper&&) =
delete;
151 OldWcsPersistenceHelper& operator=(OldWcsPersistenceHelper&&) =
delete;
154 OldWcsPersistenceHelper()
158 cd(schema.addField<table::Array<double>>(
159 "cd",
"linear transform matrix, ordered (1_1, 2_1, 1_2, 2_2)", 4)),
162 equinox(schema.addField<
double>(
"equinox",
"equinox of coordinates")),
163 radesys(schema.addField<
std::string>(
"radesys",
"coordinate system for equinox", 72)),
166 schema.getCitizen().markPersistent();
171 auto const&
keys = OldWcsPersistenceHelper::get();
174 auto metadata = std::make_shared<daf::base::PropertyList>();
176 auto crvalDeg = record.get(
keys.crval);
178 auto cd = record.get(
keys.cd);
179 metadata->set(
"CRVAL1", crvalDeg[0]);
180 metadata->set(
"CRVAL2", crvalDeg[1]);
182 metadata->set(
"CRPIX1",
crpix[0] + 1);
183 metadata->set(
"CRPIX2",
crpix[1] + 1);
184 metadata->set(
"CD1_1",
cd[0]);
185 metadata->set(
"CD2_1",
cd[1]);
186 metadata->set(
"CD1_2",
cd[2]);
187 metadata->set(
"CD2_2",
cd[3]);
188 metadata->set(
"CTYPE1", record.get(
keys.ctype1));
189 metadata->set(
"CTYPE2", record.get(
keys.ctype2));
190 metadata->set(
"EQUINOX", record.get(
keys.equinox));
191 metadata->set(
"RADESYS", record.get(
keys.radesys));
192 metadata->set(
"CUNIT1", record.get(
keys.cunit1));
193 metadata->set(
"CUNIT2", record.get(
keys.cunit2));
200 afw::table::Key<table::Array<double>> kA;
201 afw::table::Key<table::Array<double>> kB;
202 afw::table::Key<table::Array<double>> kAp;
203 afw::table::Key<table::Array<double>> kBp;
205 kA = record.getSchema()[
"A"];
206 kB = record.getSchema()[
"B"];
207 kAp = record.getSchema()[
"Ap"];
208 kBp = record.getSchema()[
"Bp"];
210 throw LSST_EXCEPT(afw::table::io::MalformedArchiveError,
211 "Incorrect schema for TanWcs distortion terms");
216 int nA =
static_cast<int>(
std::sqrt(kA.getSize() + 0.5));
217 int nB =
static_cast<int>(
std::sqrt(kB.getSize() + 0.5));
218 int nAp =
static_cast<int>(
std::sqrt(kAp.getSize() + 0.5));
219 int nBp =
static_cast<int>(
std::sqrt(kBp.getSize() + 0.5));
220 if (nA * nA != kA.getSize()) {
221 throw LSST_EXCEPT(table::io::MalformedArchiveError,
"Forward X SIP matrix is not square.");
223 if (nB * nB != kB.getSize()) {
224 throw LSST_EXCEPT(table::io::MalformedArchiveError,
"Forward Y SIP matrix is not square.");
226 if (nAp * nAp != kAp.getSize()) {
227 throw LSST_EXCEPT(table::io::MalformedArchiveError,
"Reverse X SIP matrix is not square.");
229 if (nBp * nBp != kBp.getSize()) {
230 throw LSST_EXCEPT(table::io::MalformedArchiveError,
"Reverse Y SIP matrix is not square.");
232 Eigen::Map<Eigen::MatrixXd const> mapA((record)[kA].getData(), nA, nA);
233 Eigen::Map<Eigen::MatrixXd const> mapB((record)[kB].getData(), nB, nB);
234 Eigen::Map<Eigen::MatrixXd const> mapAp((record)[kAp].getData(), nAp, nAp);
235 Eigen::Map<Eigen::MatrixXd const> mapBp((record)[kBp].getData(), nBp, nBp);
table::Key< std::string > ctype2
table::Key< table::Array< double > > cd
table::Key< std::string > cunit2
table::PointKey< double > crpix
static PointKey addFields(Schema &schema, std::string const &name, std::string const &doc, std::string const &unit)
Add a pair of _x, _y fields to a Schema, and return a PointKey that points to them.
table::PointKey< double > crval
A base class for image defects.
table::Key< std::string > radesys
#define LSST_ARCHIVE_ASSERT(EXPR)
An assertion macro used to validate the structure of an InputArchive.
table::Key< std::string > cunit1
table::Key< double > equinox
#define LSST_EXCEPT(type,...)
Create an exception with a given type.
std::shared_ptr< daf::base::PropertyList > makeSipMatrixMetadata(Eigen::MatrixXd const &matrix, std::string const &name)
table::Key< std::string > ctype1