72class OldWcsFactory :
public table::io::PersistableFactory {
74 explicit OldWcsFactory(
std::string const& name) : table::io::PersistableFactory(name) {}
77 CatalogVector
const& catalogs)
const override {
80 auto const& record = catalogs.front().front();
81 auto const metadata = getOldWcsMetadata(record);
82 return std::make_shared<SkyWcs>(*metadata);
86OldWcsFactory registerWcs(
"Wcs");
89class OldTanWcsFactory :
public table::io::PersistableFactory {
91 explicit OldTanWcsFactory(
std::string const& name) : table::io::PersistableFactory(name) {}
94 CatalogVector
const& catalogs)
const override {
96 auto const& record = catalogs.front().front();
97 auto const metadata = getOldWcsMetadata(record);
99 if (catalogs.size() > 1u) {
107 for (
auto i = 1; i <= 2; ++i) {
109 auto const ctypeValue = metadata->getAsString(ctypeName);
110 if (!endsWith(ctypeValue, ctypeSuffix)) {
111 metadata->set(ctypeName, ctypeValue + ctypeSuffix);
115 auto sipMetadata = getOldSipMetadata(*sipRecord);
116 metadata->combine(*sipMetadata);
118 return std::make_shared<SkyWcs>(*metadata);
122OldTanWcsFactory registerTanWcs(
"TanWcs");
126struct OldWcsPersistenceHelper {
127 table::Schema schema;
130 table::Key<table::Array<double>>
cd;
138 static OldWcsPersistenceHelper
const& get() {
139 static OldWcsPersistenceHelper instance;
144 OldWcsPersistenceHelper(
const OldWcsPersistenceHelper&) =
delete;
145 OldWcsPersistenceHelper& operator=(
const OldWcsPersistenceHelper&) =
delete;
148 OldWcsPersistenceHelper(OldWcsPersistenceHelper&&) =
delete;
149 OldWcsPersistenceHelper& operator=(OldWcsPersistenceHelper&&) =
delete;
152 OldWcsPersistenceHelper()
154 crval(table::PointKey<double>::addFields(schema,
"crval",
"celestial reference point",
"deg")),
155 crpix(table::PointKey<double>::addFields(schema,
"crpix",
"pixel reference point",
"pixel")),
156 cd(schema.addField<table::Array<double>>(
157 "cd",
"linear transform matrix, ordered (1_1, 2_1, 1_2, 2_2)", 4)),
158 ctype1(schema.addField<
std::string>(
"ctype1",
"coordinate type", 72)),
159 ctype2(schema.addField<
std::string>(
"ctype2",
"coordinate type", 72)),
160 equinox(schema.addField<double>(
"equinox",
"equinox of coordinates")),
161 radesys(schema.addField<
std::string>(
"radesys",
"coordinate system for equinox", 72)),
162 cunit1(schema.addField<
std::string>(
"cunit1",
"coordinate units", 72)),
163 cunit2(schema.addField<
std::string>(
"cunit2",
"coordinate units", 72)) {}
167 auto const&
keys = OldWcsPersistenceHelper::get();
170 auto metadata = std::make_shared<daf::base::PropertyList>();
172 auto crvalDeg = record.get(
keys.crval);
174 auto cd = record.get(
keys.cd);
175 metadata->set(
"CRVAL1", crvalDeg[0]);
176 metadata->set(
"CRVAL2", crvalDeg[1]);
178 metadata->set(
"CRPIX1",
crpix[0] + 1);
179 metadata->set(
"CRPIX2",
crpix[1] + 1);
180 metadata->set(
"CD1_1",
cd[0]);
181 metadata->set(
"CD2_1",
cd[1]);
182 metadata->set(
"CD1_2",
cd[2]);
183 metadata->set(
"CD2_2",
cd[3]);
184 metadata->set(
"CTYPE1", record.get(
keys.ctype1));
185 metadata->set(
"CTYPE2", record.get(
keys.ctype2));
186 metadata->set(
"EQUINOX", record.get(
keys.equinox));
187 metadata->set(
"RADESYS", record.get(
keys.radesys));
188 metadata->set(
"CUNIT1", record.get(
keys.cunit1));
189 metadata->set(
"CUNIT2", record.get(
keys.cunit2));
196 afw::table::Key<table::Array<double>> kA;
197 afw::table::Key<table::Array<double>> kB;
198 afw::table::Key<table::Array<double>> kAp;
199 afw::table::Key<table::Array<double>> kBp;
201 kA = record.getSchema()[
"A"];
202 kB = record.getSchema()[
"B"];
203 kAp = record.getSchema()[
"Ap"];
204 kBp = record.getSchema()[
"Bp"];
206 throw LSST_EXCEPT(afw::table::io::MalformedArchiveError,
207 "Incorrect schema for TanWcs distortion terms");
212 int nA =
static_cast<int>(
std::sqrt(kA.getSize() + 0.5));
213 int nB =
static_cast<int>(
std::sqrt(kB.getSize() + 0.5));
214 int nAp =
static_cast<int>(
std::sqrt(kAp.getSize() + 0.5));
215 int nBp =
static_cast<int>(
std::sqrt(kBp.getSize() + 0.5));
216 if (nA * nA != kA.getSize()) {
217 throw LSST_EXCEPT(table::io::MalformedArchiveError,
"Forward X SIP matrix is not square.");
219 if (nB * nB != kB.getSize()) {
220 throw LSST_EXCEPT(table::io::MalformedArchiveError,
"Forward Y SIP matrix is not square.");
222 if (nAp * nAp != kAp.getSize()) {
223 throw LSST_EXCEPT(table::io::MalformedArchiveError,
"Reverse X SIP matrix is not square.");
225 if (nBp * nBp != kBp.getSize()) {
226 throw LSST_EXCEPT(table::io::MalformedArchiveError,
"Reverse Y SIP matrix is not square.");
228 Eigen::Map<Eigen::MatrixXd const> mapA((record)[kA].getData(), nA, nA);
229 Eigen::Map<Eigen::MatrixXd const> mapB((record)[kB].getData(), nB, nB);
230 Eigen::Map<Eigen::MatrixXd const> mapAp((record)[kAp].getData(), nAp, nAp);
231 Eigen::Map<Eigen::MatrixXd const> mapBp((record)[kBp].getData(), nBp, nBp);
#define LSST_EXCEPT(type,...)
Create an exception with a given type.
table::Key< std::string > ctype1
table::PointKey< double > crpix
table::Key< std::string > radesys
table::Key< table::Array< double > > cd
table::Key< std::string > cunit2
table::Key< std::string > cunit1
table::Key< std::string > ctype2
table::Key< double > equinox
table::PointKey< double > crval
#define LSST_ARCHIVE_ASSERT(EXPR)
An assertion macro used to validate the structure of an InputArchive.
std::shared_ptr< daf::base::PropertyList > makeSipMatrixMetadata(Eigen::MatrixXd const &matrix, std::string const &name)
std::shared_ptr< table::io::Persistable > read(table::io::InputArchive const &archive, table::io::CatalogVector const &catalogs) const override