39 # define __attribute__(x)
44 #include <boost/archive/binary_iarchive.hpp>
45 #include <boost/archive/binary_oarchive.hpp>
46 #include <boost/archive/text_iarchive.hpp>
47 #include <boost/archive/text_oarchive.hpp>
49 #include "wcslib/wcs.h"
62 static void execTrace(std::string s,
int level =
EXEC_TRACE) {
67 namespace afwForm = lsst::afw::formatters;
69 namespace dafBase = lsst::daf::base;
70 namespace dafPersist = lsst::daf::persistence;
71 namespace pexPolicy = lsst::pex::policy;
72 namespace pexExcept = lsst::pex::exceptions;
80 dafPersist::Formatter(typeid(this)) {
90 execTrace(
"TamWcsFormatter write start");
93 throw LSST_EXCEPT(pexExcept::RuntimeError,
"Persisting non-TanWcs");
96 execTrace(
"TanWcsFormatter write BoostStorage");
99 execTrace(
"TanWcsFormatter write end");
102 throw LSST_EXCEPT(pexExcept::RuntimeError,
"Unrecognized Storage for TanWcs");
108 execTrace(
"TanWcsFormatter read start");
111 execTrace(
"TanWcsFormatter read BoostStorage");
114 execTrace(
"TanWcsFormatter read end");
118 execTrace(
"TanWcsFormatter read FitsStorage");
120 int hdu = additionalData->get<
int>(
"hdu", 0);
124 execTrace(
"TanWcsFormatter read end");
127 throw LSST_EXCEPT(pexExcept::RuntimeError,
"Unrecognized Storage for TanWcs");
134 throw LSST_EXCEPT(pexExcept::RuntimeError,
"Unexpected call to update for TanWcs");
139 template <
class Archive>
144 if (Archive::is_loading::value) {
145 m = Eigen::Matrix<double, Eigen::Dynamic, Eigen::Dynamic>(rows, cols);
147 for (
int j = 0; j < m.cols(); ++j) {
148 for (
int i = 0; i < m.rows(); ++i) {
156 std::string
const& which,
157 Eigen::Matrix<double, Eigen::Dynamic, Eigen::Dynamic>
const&
m) {
158 int order = m.rows();
159 if (m.cols() != order) {
161 "sip" + which +
" matrix is not square");
165 wcsProps->add(which +
"_ORDER", static_cast<int>(order));
166 for (
int i = 0; i <= order; ++i) {
167 for (
int j = 0; j <= order; ++j) {
168 double val =
m(i, j);
171 % which % i % j).str(), val);
187 wcsProps->add(
"NAXIS", wcs.
_wcsInfo[0].naxis,
"number of data axes");
188 wcsProps->add(
"EQUINOX", wcs.
_wcsInfo[0].equinox,
"Equinox of coordinates");
189 wcsProps->add(
"RADESYS", std::string(wcs.
_wcsInfo[0].radesys),
"Coordinate system for equinox");
190 wcsProps->add(
"CRPIX1", wcs.
_wcsInfo[0].crpix[0],
"WCS Coordinate reference pixel");
191 wcsProps->add(
"CRPIX2", wcs.
_wcsInfo[0].crpix[1],
"WCS Coordinate reference pixel");
192 wcsProps->add(
"CD1_1", wcs.
_wcsInfo[0].cd[0],
"WCS Coordinate scale matrix");
193 wcsProps->add(
"CD1_2", wcs.
_wcsInfo[0].cd[1],
"WCS Coordinate scale matrix");
194 wcsProps->add(
"CD2_1", wcs.
_wcsInfo[0].cd[2],
"WCS Coordinate scale matrix");
195 wcsProps->add(
"CD2_2", wcs.
_wcsInfo[0].cd[3],
"WCS Coordinate scale matrix");
196 wcsProps->add(
"CRVAL1", wcs.
_wcsInfo[0].crval[0],
"WCS Ref value (RA in decimal degrees)");
197 wcsProps->add(
"CRVAL2", wcs.
_wcsInfo[0].crval[1],
"WCS Ref value (DEC in decimal degrees)");
198 wcsProps->add(
"CUNIT1", std::string(wcs.
_wcsInfo[0].cunit[0]));
199 wcsProps->add(
"CUNIT2", std::string(wcs.
_wcsInfo[0].cunit[1]));
211 if (ctype1.rfind(
"-SIP") == std::string::npos) {
214 if (ctype2.rfind(
"-SIP") == std::string::npos) {
217 encodeSipHeader(wcsProps,
"A", wcs.
_sipA);
218 encodeSipHeader(wcsProps,
"B", wcs.
_sipB);
219 encodeSipHeader(wcsProps,
"AP", wcs.
_sipAp);
220 encodeSipHeader(wcsProps,
"BP", wcs.
_sipBp);
222 wcsProps->add(
"CTYPE1", ctype1,
"WCS Coordinate type");
223 wcsProps->add(
"CTYPE2", ctype2,
"WCS Coordinate type");
228 template <
class Archive>
231 execTrace(
"TanWcsFormatter delegateSerialize start");
234 throw LSST_EXCEPT(pexExcept::RuntimeError,
"Serializing non-TanWcs");
252 if (Archive::is_loading::value) {
254 reinterpret_cast<wcsprm*
>(malloc(ip->
_nWcsInfo *
sizeof(wcsprm)));
257 for (
int i = 0; i < ip->
_nWcsInfo; ++i) {
259 if (Archive::is_loading::value) {
283 if (Archive::is_loading::value) {
288 execTrace(
"TanWcsFormatter delegateSerialize end");
int _wcsfixCtrl
Do potentially unsafe translations of non-standard unit strings? 0/1 = no/yes.
coord::CoordSystem _coordSystem
Class for storing ordered metadata with comments.
daf_persistence package header file
virtual boost::archive::text_iarchive & getIArchive(void)
boost::shared_ptr< PropertySet > Ptr
virtual std::string const & getPath(void)
definition of the Trace messaging facilities
boost::shared_ptr< Policy > Ptr
limited backward compatibility to the DC2 run-time trace facilities
Class for FITS file storage.
table::Key< std::string > ctype2
table::Key< table::Array< Kernel::Pixel > > image
boost::shared_ptr< PropertyList > Ptr
Implementation of the WCS standard for the special case of the Gnomonic (tangent plane) projection...
#define LSST_EXCEPT(type,...)
virtual boost::archive::text_oarchive & getOArchive(void)
int _relax
Degree of permissiveness for wcspih (0 for strict); see wcshdr.h for details.
boost::shared_ptr< daf::base::PropertySet > readMetadata(std::string const &fileName, int hdu=0, bool strip=false)
Return the metadata (header entries) from a FITS file.
boost::shared_ptr< Storage > Ptr
Class for boost::serialization storage.
Base class for all persistable classes.
int _wcshdrCtrl
Controls messages to stderr from wcshdr (0 for none); see wcshdr.h for details.
table::Key< std::string > ctype1
Include files required for standard LSST Exception handling.