74 class OldWcsFactory :
public table::io::PersistableFactory {
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 {
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()
156 crval(table::PointKey<double>::addFields(
schema,
"crval",
"celestial reference point",
"deg")),
157 crpix(table::PointKey<double>::addFields(
schema,
"crpix",
"pixel reference point",
"pixel")),
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)),
164 cunit1(
schema.addField<
std::string>(
"cunit1",
"coordinate units", 72)),
165 cunit2(
schema.addField<
std::string>(
"cunit2",
"coordinate units", 72)) {}
169 auto const&
keys = OldWcsPersistenceHelper::get();
172 auto metadata = std::make_shared<daf::base::PropertyList>();
174 auto crvalDeg = record.get(
keys.crval);
176 auto cd = record.get(
keys.cd);
177 metadata->set(
"CRVAL1", crvalDeg[0]);
178 metadata->set(
"CRVAL2", crvalDeg[1]);
180 metadata->set(
"CRPIX1",
crpix[0] + 1);
181 metadata->set(
"CRPIX2",
crpix[1] + 1);
182 metadata->set(
"CD1_1",
cd[0]);
183 metadata->set(
"CD2_1",
cd[1]);
184 metadata->set(
"CD1_2",
cd[2]);
185 metadata->set(
"CD2_2",
cd[3]);
186 metadata->set(
"CTYPE1", record.get(
keys.ctype1));
187 metadata->set(
"CTYPE2", record.get(
keys.ctype2));
188 metadata->set(
"EQUINOX", record.get(
keys.equinox));
189 metadata->set(
"RADESYS", record.get(
keys.radesys));
190 metadata->set(
"CUNIT1", record.get(
keys.cunit1));
191 metadata->set(
"CUNIT2", record.get(
keys.cunit2));
198 afw::table::Key<table::Array<double>> kA;
199 afw::table::Key<table::Array<double>> kB;
200 afw::table::Key<table::Array<double>> kAp;
201 afw::table::Key<table::Array<double>> kBp;
203 kA = record.getSchema()[
"A"];
204 kB = record.getSchema()[
"B"];
205 kAp = record.getSchema()[
"Ap"];
206 kBp = record.getSchema()[
"Bp"];
208 throw LSST_EXCEPT(afw::table::io::MalformedArchiveError,
209 "Incorrect schema for TanWcs distortion terms");
214 int nA =
static_cast<int>(
std::sqrt(kA.getSize() + 0.5));
215 int nB =
static_cast<int>(
std::sqrt(kB.getSize() + 0.5));
216 int nAp =
static_cast<int>(
std::sqrt(kAp.getSize() + 0.5));
217 int nBp =
static_cast<int>(
std::sqrt(kBp.getSize() + 0.5));
218 if (nA * nA != kA.getSize()) {
219 throw LSST_EXCEPT(table::io::MalformedArchiveError,
"Forward X SIP matrix is not square.");
221 if (nB * nB != kB.getSize()) {
222 throw LSST_EXCEPT(table::io::MalformedArchiveError,
"Forward Y SIP matrix is not square.");
224 if (nAp * nAp != kAp.getSize()) {
225 throw LSST_EXCEPT(table::io::MalformedArchiveError,
"Reverse X SIP matrix is not square.");
227 if (nBp * nBp != kBp.getSize()) {
228 throw LSST_EXCEPT(table::io::MalformedArchiveError,
"Reverse Y SIP matrix is not square.");
230 Eigen::Map<Eigen::MatrixXd const> mapA((record)[kA].getData(), nA, nA);
231 Eigen::Map<Eigen::MatrixXd const> mapB((record)[kB].getData(), nB, nB);
232 Eigen::Map<Eigen::MatrixXd const> mapAp((record)[kAp].getData(), nAp, nAp);
233 Eigen::Map<Eigen::MatrixXd const> mapBp((record)[kBp].getData(), nBp, nBp);
table::Key< std::string > name
#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)
FilterProperty & operator=(FilterProperty const &)=default
A base class for image defects.