30 #define __attribute__(x) 37 #include <boost/archive/binary_iarchive.hpp> 38 #include <boost/archive/binary_oarchive.hpp> 39 #include <boost/archive/text_iarchive.hpp> 40 #include <boost/archive/text_oarchive.hpp> 42 #include "wcslib/wcs.h" 44 #include "lsst/daf/base.h" 45 #include "lsst/daf/persistence.h" 46 #include "lsst/daf/persistence/PropertySetFormatter.h" 47 #include "lsst/pex/exceptions.h" 48 #include "lsst/log/Log.h" 56 LOG_LOGGER _log = LOG_GET(
"afw.TanWcsFormatter");
61 namespace formatters {
66 namespace pexExcept = lsst::pex::exceptions;
68 dafPersist::FormatterRegistration TanWcsFormatter::registration(
"TanWcs",
typeid(
image::TanWcs),
71 TanWcsFormatter::TanWcsFormatter(std::shared_ptr<pexPolicy::Policy>) : dafPersist::Formatter(
typeid(
this)) {}
76 std::shared_ptr<dafPersist::FormatterStorage> storage,
77 std::shared_ptr<dafBase::PropertySet>) {
78 LOGL_DEBUG(_log,
"TamWcsFormatter write start");
81 throw LSST_EXCEPT(pexExcept::RuntimeError,
"Persisting non-TanWcs");
84 auto boost = std::dynamic_pointer_cast<dafPersist::BoostStorage>(storage);
86 LOGL_DEBUG(_log,
"TanWcsFormatter write BoostStorage");
87 boost->getOArchive() & *ip;
88 LOGL_DEBUG(_log,
"TanWcsFormatter write end");
91 throw LSST_EXCEPT(pexExcept::RuntimeError,
"Unrecognized FormatterStorage for TanWcs");
95 std::shared_ptr<dafBase::PropertySet> additionalData) {
96 LOGL_DEBUG(_log,
"TanWcsFormatter read start");
98 auto boost = std::dynamic_pointer_cast<dafPersist::BoostStorage>(storage);
101 LOGL_DEBUG(_log,
"TanWcsFormatter read BoostStorage");
102 boost->getIArchive() & *ip;
103 LOGL_DEBUG(_log,
"TanWcsFormatter read end");
106 auto fits = std::dynamic_pointer_cast<dafPersist::FitsStorage>(storage);
108 LOGL_DEBUG(_log,
"TanWcsFormatter read FitsStorage");
109 int hdu = additionalData->get<
int>(
"hdu", INT_MIN);
112 LOGL_DEBUG(_log,
"TanWcsFormatter read end");
115 throw LSST_EXCEPT(pexExcept::RuntimeError,
"Unrecognized FormatterStorage for TanWcs");
119 std::shared_ptr<dafBase::PropertySet>) {
120 throw LSST_EXCEPT(pexExcept::RuntimeError,
"Unexpected call to update for TanWcs");
124 template <
class Archive>
129 if (Archive::is_loading::value) {
130 m = Eigen::Matrix<double, Eigen::Dynamic, Eigen::Dynamic>(rows, cols);
132 for (
int j = 0; j < m.cols(); ++j) {
133 for (
int i = 0; i < m.rows(); ++i) {
139 static void encodeSipHeader(std::shared_ptr<daf::base::PropertySet> wcsProps,
140 std::string
const& which,
141 Eigen::Matrix<double, Eigen::Dynamic, Eigen::Dynamic>
const& m) {
142 int order = m.rows();
143 if (m.cols() != order) {
144 throw LSST_EXCEPT(pexExcept::DomainError,
"sip" + which +
" matrix is not square");
148 wcsProps->add(which +
"_ORDER", static_cast<int>(order));
149 for (
int i = 0; i <= order; ++i) {
150 for (
int j = 0; j <= order; ++j) {
151 double val = m(i, j);
153 wcsProps->add((boost::format(
"%1%_%2%_%3%") % which % i % j).str(), val);
168 wcsProps->add(
"NAXIS", wcs.
_wcsInfo[0].naxis,
"number of data axes");
171 if (strncmp(wcs.
_wcsInfo[0].radesys,
"ICRS", 4) != 0) {
172 wcsProps->add(
"EQUINOX", wcs.
_wcsInfo[0].equinox,
"Equinox of coordinates");
174 wcsProps->add(
"RADESYS", std::string(wcs.
_wcsInfo[0].radesys),
"Coordinate system for equinox");
175 wcsProps->add(
"CRPIX1", wcs.
_wcsInfo[0].crpix[0],
"WCS Coordinate reference pixel");
176 wcsProps->add(
"CRPIX2", wcs.
_wcsInfo[0].crpix[1],
"WCS Coordinate reference pixel");
177 wcsProps->add(
"CD1_1", wcs.
_wcsInfo[0].cd[0],
"WCS Coordinate scale matrix");
178 wcsProps->add(
"CD1_2", wcs.
_wcsInfo[0].cd[1],
"WCS Coordinate scale matrix");
179 wcsProps->add(
"CD2_1", wcs.
_wcsInfo[0].cd[2],
"WCS Coordinate scale matrix");
180 wcsProps->add(
"CD2_2", wcs.
_wcsInfo[0].cd[3],
"WCS Coordinate scale matrix");
181 wcsProps->add(
"CRVAL1", wcs.
_wcsInfo[0].crval[0],
"WCS Ref value (RA in decimal degrees)");
182 wcsProps->add(
"CRVAL2", wcs.
_wcsInfo[0].crval[1],
"WCS Ref value (DEC in decimal degrees)");
183 wcsProps->add(
"CUNIT1", std::string(wcs.
_wcsInfo[0].cunit[0]));
184 wcsProps->add(
"CUNIT2", std::string(wcs.
_wcsInfo[0].cunit[1]));
195 if (wcs._hasDistortion) {
196 if (ctype1.rfind(
"-SIP") == std::string::npos) {
199 if (ctype2.rfind(
"-SIP") == std::string::npos) {
202 encodeSipHeader(wcsProps,
"A", wcs._sipA);
203 encodeSipHeader(wcsProps,
"B", wcs._sipB);
204 encodeSipHeader(wcsProps,
"AP", wcs._sipAp);
205 encodeSipHeader(wcsProps,
"BP", wcs._sipBp);
207 wcsProps->add(
"CTYPE1", ctype1,
"WCS Coordinate type");
208 wcsProps->add(
"CTYPE2", ctype2,
"WCS Coordinate type");
213 template <
class Archive>
215 LOGL_DEBUG(_log,
"TanWcsFormatter delegateSerialize start");
218 throw LSST_EXCEPT(pexExcept::RuntimeError,
"Serializing non-TanWcs");
226 ar & ip->_hasDistortion;
228 if (ip->_hasDistortion) {
236 if (Archive::is_loading::value) {
237 ip->
_wcsInfo =
reinterpret_cast<wcsprm*
>(malloc(ip->
_nWcsInfo *
sizeof(wcsprm)));
240 for (
int i = 0; i < ip->
_nWcsInfo; ++i) {
242 if (Archive::is_loading::value) {
266 if (Archive::is_loading::value) {
271 LOGL_DEBUG(_log,
"TanWcsFormatter delegateSerialize end");
279 dafBase::Persistable*);
281 dafBase::Persistable*);
285 std::shared_ptr<pexPolicy::Policy> policy) {
286 return std::shared_ptr<dafPersist::Formatter>(
new TanWcsFormatter(policy));
lsst::daf::base::PropertyList PropertyList
table::Key< std::string > ctype2
std::shared_ptr< daf::base::PropertyList > readMetadata(std::string const &fileName, int hdu=INT_MIN, bool strip=false)
Read FITS header.
A base class for image defects.
Implementation of the WCS standard for the special case of the Gnomonic (tangent plane) projection...
int _wcshdrCtrl
Controls messages to stderr from wcshdr (0 for none); see wcshdr.h for details.
int _relax
Degree of permissiveness for wcspih (0 for strict); see wcshdr.h for details.
int _wcsfixCtrl
Do potentially unsafe translations of non-standard unit strings? 0/1 = no/yes.
table::Key< std::string > ctype1
coord::CoordSystem _coordSystem