55 wcsMetaData->set(
"CTYPE1" + wcsName,
"LINEAR",
"Type of projection");
56 wcsMetaData->set(
"CTYPE2" + wcsName,
"LINEAR",
"Type of projection");
57 wcsMetaData->set(
"CRPIX1" + wcsName, static_cast<double>(1),
"Column Pixel Coordinate of Reference");
58 wcsMetaData->set(
"CRPIX2" + wcsName, static_cast<double>(1),
"Row Pixel Coordinate of Reference");
59 wcsMetaData->set(
"CRVAL1" + wcsName, static_cast<double>(xy0[0]),
"Column pixel of Reference Pixel");
60 wcsMetaData->set(
"CRVAL2" + wcsName, static_cast<double>(xy0[1]),
"Row pixel of Reference Pixel");
61 wcsMetaData->set(
"CUNIT1" + wcsName,
"PIXEL",
"Column unit");
62 wcsMetaData->set(
"CUNIT2" + wcsName,
"PIXEL",
"Row unit");
69 "CTYPE2",
"CUNIT1",
"CUNIT2",
"CD1_1",
"CD1_2",
70 "CD2_1",
"CD2_2",
"WCSAXES"};
71 for (
auto const&
name : names) {
79 Eigen::Matrix2d matrix;
81 for (
int i = 0; i < 2; ++i) {
82 for (
int j = 0; j < 2; ++j) {
84 if (metadata.
exists(cardName)) {
103 if (metadata.
exists(
"CRPIX1" + wcsName) && metadata.
exists(
"CRPIX2" + wcsName) &&
104 metadata.
exists(
"CRVAL1" + wcsName) && metadata.
exists(
"CRVAL2" + wcsName) &&
105 (metadata.
getAsDouble(
"CRPIX1" + wcsName) == 1.0) &&
106 (metadata.
getAsDouble(
"CRPIX2" + wcsName) == 1.0)) {
118 if (!metadata.
exists(cardName)) {
120 "metadata does not contain SIP matrix " + name +
": " + cardName +
" not found");
122 int order = metadata.
getAsInt(cardName);
127 Eigen::MatrixXd matrix(order + 1, order + 1);
128 auto const coeffName = name +
"_";
129 for (
int i = 0; i <= order; ++i) {
130 for (
int j = 0; j <= order; ++j) {
131 std::string const cardName = getSipCoeffCardName(coeffName, i, j);
132 if (metadata.
exists(cardName)) {
144 if (!metadata.
exists(cardName)) {
147 return metadata.
getAsInt(cardName) >= 0;
152 if (matrix.rows() != matrix.cols() || matrix.rows() < 1) {
154 "Matrix must be square and at least 1 x 1; dimensions = " +
157 int const order = matrix.rows() - 1;
158 auto metadata = std::make_shared<daf::base::PropertyList>();
160 metadata->set(cardName, order);
161 auto const coeffName = name +
"_";
162 for (
int i = 0; i <= order; ++i) {
163 for (
int j = 0; j <= order; ++j) {
164 if (matrix(i, j) != 0.0) {
165 metadata->set(getSipCoeffCardName(coeffName, i, j), matrix(i, j));
174 Eigen::Matrix2d
const& cdMatrix,
176 auto pl = std::make_shared<daf::base::PropertyList>();
177 pl->add(
"RADESYS",
"ICRS");
178 pl->add(
"EQUINOX", 2000);
179 pl->add(
"CTYPE1",
"RA---" + projection);
180 pl->add(
"CTYPE2",
"DEC--" + projection);
181 pl->add(
"CRPIX1", crpix[0] + 1);
182 pl->add(
"CRPIX2", crpix[1] + 1);
183 pl->add(
"CRVAL1", crval[0].asDegrees());
184 pl->add(
"CRVAL2", crval[1].asDegrees());
185 pl->add(
"CUNIT1",
"deg");
186 pl->add(
"CUNIT2",
"deg");
187 for (
int i = 0; i < 2; ++i) {
188 for (
int j = 0; j < 2; ++j) {
189 if (cdMatrix(i, j) != 0.0) {
191 pl->add(name, cdMatrix(i, j));
200 Eigen::Matrix2d
const& cdMatrix,
201 Eigen::MatrixXd
const& sipA,
202 Eigen::MatrixXd
const& sipB) {
211 Eigen::Matrix2d
const& cdMatrix, Eigen::MatrixXd
const& sipA, Eigen::MatrixXd
const& sipB,
212 Eigen::MatrixXd
const& sipAp, Eigen::MatrixXd
const& sipBp) {
double getAsDouble(std::string const &name) const
Get the last value for any arithmetic property name (possibly hierarchical).
Eigen::Matrix2d getCdMatrixFromMetadata(daf::base::PropertySet &metadata)
Read a CD matrix from FITS WCS metadata.
Class for storing ordered metadata with comments.
bool hasSipMatrix(daf::base::PropertySet const &metadata, std::string const &name)
table::PointKey< double > crpix
int getAsInt(std::string const &name) const
Get the last value for a bool/char/short/int property name (possibly hierarchical).
table::PointKey< double > crval
virtual void remove(std::string const &name)
Remove all values for a property name (possibly hierarchical).
A base class for image defects.
std::shared_ptr< daf::base::PropertyList > createTrivialWcsMetadata(std::string const &wcsName, lsst::geom::Point2I const &xy0)
bool exists(std::string const &name) const
Determine if a name (possibly hierarchical) exists.
std::shared_ptr< daf::base::PropertyList > makeTanSipMetadata(lsst::geom::Point2D const &crpix, lsst::geom::SpherePoint const &crval, Eigen::Matrix2d const &cdMatrix, Eigen::MatrixXd const &sipA, Eigen::MatrixXd const &sipB)
Make metadata for a TAN-SIP WCS without inverse matrices.
#define LSST_EXCEPT(type,...)
Create an exception with a given type.
std::shared_ptr< daf::base::PropertyList > makeSimpleWcsMetadata(lsst::geom::Point2D const &crpix, lsst::geom::SpherePoint const &crval, Eigen::Matrix2d const &cdMatrix, std::string const &projection="TAN")
Make FITS metadata for a simple FITS WCS (one with no distortion).
Point in an unspecified spherical coordinate system.
lsst::geom::Point2I getImageXY0FromMetadata(daf::base::PropertySet &metadata, std::string const &wcsName, bool strip=false)
Class for storing generic metadata.
std::shared_ptr< daf::base::PropertyList > makeSipMatrixMetadata(Eigen::MatrixXd const &matrix, std::string const &name)
Reports errors from accepting an object of an unexpected or inappropriate type.
void deleteBasicWcsMetadata(daf::base::PropertySet &metadata, std::string const &wcsName)
Eigen::MatrixXd getSipMatrixFromMetadata(daf::base::PropertySet const &metadata, std::string const &name)