lsst.afw  15.0-21-g91b8abf62
SkyWcs.cc
Go to the documentation of this file.
1 /*
2  * LSST Data Management System
3  * Copyright 2017 AURA/LSST.
4  *
5  * This product includes software developed by the
6  * LSST Project (http://www.lsst.org/).
7  *
8  * This program is free software: you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation, either version 3 of the License, or
11  * (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the LSST License Statement and
19  * the GNU General Public License along with this program. If not,
20  * see <http://www.lsstcorp.org/LegalNotices/>.
21  */
22 
23 #include <algorithm>
24 #include <cmath>
25 #include <cstdint>
26 #include <exception>
27 #include <memory>
28 #include <ostream>
29 #include <sstream>
30 #include <vector>
31 
32 #include "astshim.h"
33 
35 #include "lsst/afw/table.h"
40 #include "lsst/afw/geom/wcsUtils.h"
41 #include "lsst/afw/geom/Angle.h"
42 #include "lsst/afw/geom/Point.h"
44 #include "lsst/afw/geom/SkyWcs.h"
46 #include "lsst/pex/exceptions.h"
47 
48 namespace lsst {
49 namespace afw {
50 namespace geom {
51 namespace {
52 
53 int const SERIALIZATION_VERSION = 1;
54 
55 // TIGHT_FITS_TOL is used by getFitsMetadata to determine if a WCS can accurately be represented as a FITS
56 // WCS. It specifies the maximum departure from linearity (in pixels) allowed on either axis of the mapping
57 // from pixel coordinates to Intermediate World Coordinates over a range of 100 x 100 pixels
58 // (or the region specified by NAXIS[12], if provided, but we do not pass this to AST as of 2018-01-17).
59 // For more information,
60 // see FitsTol in the AST manual http://starlink.eao.hawaii.edu/devdocs/sun211.htx/sun211.html
61 double const TIGHT_FITS_TOL = 0.0001;
62 
63 class SkyWcsPersistenceHelper {
64 public:
65  table::Schema schema;
66  table::Key<table::Array<std::uint8_t>> wcs;
67 
68  static SkyWcsPersistenceHelper const& get() {
69  static SkyWcsPersistenceHelper instance;
70  return instance;
71  }
72 
73  // No copying
74  SkyWcsPersistenceHelper(const SkyWcsPersistenceHelper&) = delete;
75  SkyWcsPersistenceHelper& operator=(const SkyWcsPersistenceHelper&) = delete;
76 
77  // No moving
78  SkyWcsPersistenceHelper(SkyWcsPersistenceHelper&&) = delete;
79  SkyWcsPersistenceHelper& operator=(SkyWcsPersistenceHelper&&) = delete;
80 
81 private:
82  SkyWcsPersistenceHelper()
83  : schema(),
84  wcs(schema.addField<table::Array<std::uint8_t>>("wcs", "wcs string representation", "")) {
85  schema.getCitizen().markPersistent();
86  }
87 };
88 
89 class SkyWcsFactory : public table::io::PersistableFactory {
90 public:
91  explicit SkyWcsFactory(std::string const& name) : table::io::PersistableFactory(name) {}
92 
93  virtual std::shared_ptr<table::io::Persistable> read(InputArchive const& archive,
94  CatalogVector const& catalogs) const {
95  SkyWcsPersistenceHelper const& keys = SkyWcsPersistenceHelper::get();
96  LSST_ARCHIVE_ASSERT(catalogs.size() == 1u);
97  LSST_ARCHIVE_ASSERT(catalogs.front().size() == 1u);
98  LSST_ARCHIVE_ASSERT(catalogs.front().getSchema() == keys.schema);
99  table::BaseRecord const& record = catalogs.front().front();
100  std::string stringRep = formatters::bytesToString(record.get(keys.wcs));
101  return SkyWcs::readString(stringRep);
102  }
103 };
104 
105 std::string getSkyWcsPersistenceName() { return "SkyWcs"; }
106 
107 SkyWcsFactory registration(getSkyWcsPersistenceName());
108 
109 } // namespace
110 
111 Eigen::Matrix2d makeCdMatrix(Angle const& scale, Angle const& orientation, bool flipX) {
112  Eigen::Matrix2d cdMatrix;
113  double orientRad = orientation.asRadians();
114  double scaleDeg = scale.asDegrees();
115  double xmult = flipX ? 1.0 : -1.0;
116  cdMatrix(0, 0) = std::cos(orientRad) * scaleDeg * xmult;
117  cdMatrix(0, 1) = std::sin(orientRad) * scaleDeg;
118  cdMatrix(1, 0) = -std::sin(orientRad) * scaleDeg * xmult;
119  cdMatrix(1, 1) = std::cos(orientRad) * scaleDeg;
120  return cdMatrix;
121 }
122 
124  auto const dstInverse = dst.getTransform()->getInverse();
125  return src.getTransform()->then(*dstInverse);
126 }
127 
129  : SkyWcs(detail::readLsstSkyWcs(metadata, strip)) {}
130 
131 SkyWcs::SkyWcs(ast::FrameDict const& frameDict) : SkyWcs(_checkFrameDict(frameDict)) {}
132 
133 bool SkyWcs::operator==(SkyWcs const& other) const { return writeString() == other.writeString(); }
134 
136  // Compute pixVec containing the pixel position and two nearby points
137  // (use a vector so all three points can be converted to sky in a single call)
138  double const side = 1.0;
139  std::vector<Point2D> pixVec = {
140  pixel, pixel + Extent2D(side, 0), pixel + Extent2D(0, side),
141  };
142 
143  auto skyVec = pixelToSky(pixVec);
144 
145  // Work in 3-space to avoid RA wrapping and pole issues
146  // (warning: getVector().asEigen() here produces incorrect results; I'm not sure why)
147  auto skyLL = skyVec[0].getVector();
148  auto skyDx = skyVec[1].getVector() - skyLL;
149  auto skyDy = skyVec[2].getVector() - skyLL;
150 
151  // Compute pixel scale in radians = sqrt(pixel area in radians^2)
152  // pixel area in radians^2 = area of parallelogram with sides skyDx, skyDy = |skyDx cross skyDy|
153  // Use squared norm to avoid two square roots
154  double skyAreaSq = skyDx.asEigen().cross(skyDy.asEigen()).squaredNorm();
155  return (std::pow(skyAreaSq, 0.25) / side) * radians;
156 }
157 
159  // CRVAL is stored as the SkyRef property of the sky frame (the current frame of the SkyWcs)
160  auto skyFrame = std::dynamic_pointer_cast<ast::SkyFrame>(
161  getFrameDict()->getFrame(ast::FrameDict::CURRENT, false)); // false: do not copy
162  if (!skyFrame) {
163  throw LSST_EXCEPT(pex::exceptions::LogicError, "Current frame is not a SkyFrame");
164  }
165  auto const crvalRad = skyFrame->getSkyRef();
166  return SpherePoint(crvalRad[0] * radians, crvalRad[1] * radians);
167 }
168 
169 Eigen::Matrix2d SkyWcs::getCdMatrix(Point2D const& pixel) const {
170  auto const pixelToIwc = getFrameDict()->getMapping(ast::FrameSet::BASE, "IWC");
171  auto const pixelToIwcTransform = TransformPoint2ToPoint2(*pixelToIwc);
172  return pixelToIwcTransform.getJacobian(pixel);
173 }
174 
175 Eigen::Matrix2d SkyWcs::getCdMatrix() const { return getCdMatrix(getPixelOrigin()); }
176 
178  auto const crval = pixelToSky(pixel);
179  auto const cdMatrix = getCdMatrix(pixel);
180  auto metadata = makeSimpleWcsMetadata(pixel, crval, cdMatrix);
181  return std::make_shared<SkyWcs>(*metadata);
182 }
183 
185  auto newToOldPixel = TransformPoint2ToPoint2(ast::ShiftMap({-shift[0], -shift[1]}));
186  return makeModifiedWcs(newToOldPixel, *this, true);
187 }
188 
190  // Make a FrameSet that maps from GRID to SKY; GRID = the base frame (PIXELS or ACTUAL_PIXELS) + 1
191  auto const gridToPixel = ast::ShiftMap({-1.0, -1.0});
192  auto thisDict = getFrameDict();
193  auto const pixelToIwc = thisDict->getMapping(ast::FrameSet::BASE, "IWC");
194  auto const iwcToSky = thisDict->getMapping("IWC", "SKY");
195  auto const gridToSky = gridToPixel.then(*pixelToIwc).then(*iwcToSky);
196  ast::FrameSet frameSet(ast::Frame(2, "Domain=GRID"), gridToSky, *thisDict->getFrame("SKY", false));
197 
198  // Write frameSet to a FitsChan and extract the metadata
200  os << "Encoding=FITS-WCS, CDMatrix=1, FitsAxisOrder=<copy>, FitsTol=" << TIGHT_FITS_TOL;
201  ast::StringStream strStream;
202  ast::FitsChan fitsChan(strStream, os.str());
203  int const nObjectsWritten = fitsChan.write(frameSet);
204  if (nObjectsWritten == 0) {
205  if (precise) {
207  "Could not represent this SkyWcs using FITS-WCS metadata");
208  } else {
209  // An exact representation could not be written, so try to write a local TAN approximation;
210  // set precise true to avoid an infinite loop, should something go wrong
211  auto tanWcs = getTanWcs(getPixelOrigin());
212  return tanWcs->getFitsMetadata(true);
213  }
214  }
215  return detail::getPropertyListFromFitsChan(fitsChan);
216 }
217 
219  return _frameDict;
220 }
221 
222 bool SkyWcs::isFits() const {
223  try {
224  getFitsMetadata(true);
225  } catch (const lsst::pex::exceptions::RuntimeError&) {
226  return false;
227  } catch (const std::runtime_error&) {
228  return false;
229  }
230  return true;
231 }
232 
234  return _linearizePixelToSky(skyToPixel(coord), coord, skyUnit);
235 }
237  return _linearizePixelToSky(pix, pixelToSky(pix), skyUnit);
238 }
239 
241  return _linearizeSkyToPixel(skyToPixel(coord), coord, skyUnit);
242 }
243 
245  return _linearizeSkyToPixel(pix, pixelToSky(pix), skyUnit);
246 }
247 
248 std::string SkyWcs::getShortClassName() { return "SkyWcs"; };
249 
250 bool SkyWcs::isFlipped() const {
251  double det = getCdMatrix().determinant();
252  if (det == 0) {
253  throw(LSST_EXCEPT(pex::exceptions::RuntimeError, "CD matrix is singular"));
254  }
255  return (det > 0);
256 }
257 
259  int version;
260  is >> version;
261  if (version != 1) {
263  "Unsupported version " + std::to_string(version));
264  }
265  std::string shortClassName;
266  is >> shortClassName;
267  if (shortClassName != SkyWcs::getShortClassName()) {
269  os << "Class name in stream " << shortClassName << " != " << SkyWcs::getShortClassName();
271  }
273  is >> hasFitsApproximation;
274  auto astStream = ast::Stream(&is, nullptr);
275  auto astObjectPtr = ast::Channel(astStream).read();
276  auto frameSet = std::dynamic_pointer_cast<ast::FrameSet>(astObjectPtr);
277  if (!frameSet) {
279  os << "The AST serialization was read as a " << astObjectPtr->getClassName()
280  << " instead of a FrameSet";
282  }
283  ast::FrameDict frameDict(*frameSet);
284  return std::make_shared<SkyWcs>(frameDict);
285 }
286 
288  std::istringstream is(str);
289  return SkyWcs::readStream(is);
290 }
291 
293  os << SERIALIZATION_VERSION << " " << SkyWcs::getShortClassName() << " " << hasFitsApproximation() << " ";
294  getFrameDict()->show(os, false); // false = do not write comments
295 }
296 
299  writeStream(os);
300  return os.str();
301 }
302 
303 std::string SkyWcs::getPersistenceName() const { return getSkyWcsPersistenceName(); }
304 
305 std::string SkyWcs::getPythonModule() const { return "lsst.afw.geom"; }
306 
307 void SkyWcs::write(OutputArchiveHandle& handle) const {
308  SkyWcsPersistenceHelper const& keys = SkyWcsPersistenceHelper::get();
309  table::BaseCatalog cat = handle.makeCatalog(keys.schema);
311  record->set(keys.wcs, formatters::stringToBytes(writeString()));
312  handle.saveCatalog(cat);
313 }
314 
316  : _frameDict(frameDict), _transform(),
317  _pixelOrigin(),
318  _pixelScaleAtOrigin(0 * radians) {
319  _computeCache();
320 };
321 
322 std::shared_ptr<ast::FrameDict> SkyWcs::_checkFrameDict(ast::FrameDict const& frameDict) const {
323  // Check that each frame is present and has the right type and number of axes
324  std::vector<std::string> const domainNames = {"ACTUAL_PIXELS", "PIXELS", "IWC", "SKY"};
325  for (auto const& domainName : domainNames) {
326  if (frameDict.hasDomain(domainName)) {
327  auto const frame = frameDict.getFrame(domainName, false);
328  if (frame->getNAxes() != 2) {
330  "Frame " + domainName + " has " + std::to_string(frame->getNAxes()) +
331  " axes instead of 2");
332  }
333  auto desiredClassName = domainName == "SKY" ? "SkyFrame" : "Frame";
334  if (frame->getClassName() != desiredClassName) {
336  "Frame " + domainName + " is of type " + frame->getClassName() +
337  " instead of " + desiredClassName);
338  }
339  } else if (domainName != "ACTUAL_PIXELS") {
340  // This is a required frame
342  "No frame with domain " + domainName + " found");
343  }
344  }
345 
346  // The base frame must have domain "PIXELS" or "ACTUAL_PIXELS"
347  auto baseDomain = frameDict.getFrame(ast::FrameSet::BASE, false)->getDomain();
348  if (baseDomain != "ACTUAL_PIXELS" && baseDomain != "PIXELS") {
350  "Base frame has domain " + baseDomain + " instead of PIXELS or ACTUAL_PIXELS");
351  }
352 
353  // The current frame must have domain "SKY"
354  auto currentDomain = frameDict.getFrame(ast::FrameSet::CURRENT, false)->getDomain();
355  if (currentDomain != "SKY") {
357  "Current frame has domain " + currentDomain + " instead of SKY");
358  }
359 
360  return frameDict.copy();
361 }
362 
363 AffineTransform SkyWcs::_linearizePixelToSky(Point2D const& pix00, SpherePoint const& coord,
364  AngleUnit const& skyUnit) const {
365  // Figure out the (0, 0), (0, 1), and (1, 0) ra/dec coordinates of the corners
366  // of a square drawn in pixel. It'd be better to center the square at sky00,
367  // but that would involve another conversion between sky and pixel coordinates
368  const double side = 1.0; // length of the square's sides in pixels
369  auto const sky00 = coord.getPosition(skyUnit);
370  auto const dsky10 = coord.getTangentPlaneOffset(pixelToSky(pix00 + Extent2D(side, 0)));
371  auto const dsky01 = coord.getTangentPlaneOffset(pixelToSky(pix00 + Extent2D(0, side)));
372 
373  Eigen::Matrix2d m;
374  m(0, 0) = dsky10.first.asAngularUnits(skyUnit) / side;
375  m(0, 1) = dsky01.first.asAngularUnits(skyUnit) / side;
376  m(1, 0) = dsky10.second.asAngularUnits(skyUnit) / side;
377  m(1, 1) = dsky01.second.asAngularUnits(skyUnit) / side;
378 
379  Eigen::Vector2d sky00v;
380  sky00v << sky00.getX(), sky00.getY();
381  Eigen::Vector2d pix00v;
382  pix00v << pix00.getX(), pix00.getY();
383  // return AffineTransform(m, Extent2D(sky00v - m * pix00v));
384  return AffineTransform(m, (sky00v - m * pix00v));
385 }
386 
387 AffineTransform SkyWcs::_linearizeSkyToPixel(Point2D const& pix00, SpherePoint const& coord,
388  AngleUnit const& skyUnit) const {
389  AffineTransform inverse = _linearizePixelToSky(pix00, coord, skyUnit);
390  return inverse.invert();
391 }
392 
393 std::shared_ptr<SkyWcs> makeFlippedWcs(SkyWcs const& wcs, bool flipLR, bool flipTB,
394  geom::Point2D const& center) {
395  double const dx = 1000; // any "reasonable" number of pixels will do
396  std::vector<double> inLL = {center[0] - dx, center[1] - dx};
397  std::vector<double> inUR = {center[0] + dx, center[1] + dx};
398  std::vector<double> outLL(inLL);
399  std::vector<double> outUR(inUR);
400  if (flipLR) {
401  outLL[0] = inUR[0];
402  outUR[0] = inLL[0];
403  }
404  if (flipTB) {
405  outLL[1] = inUR[1];
406  outUR[1] = inLL[1];
407  }
408  auto const flipPix = TransformPoint2ToPoint2(ast::WinMap(inLL, inUR, outLL, outUR));
409  return makeModifiedWcs(flipPix, wcs, true);
410 }
411 
413  bool modifyActualPixels) {
414  auto const pixelMapping = pixelTransform.getMapping();
415  auto oldFrameDict = wcs.getFrameDict();
416  bool const hasActualPixels = oldFrameDict->hasDomain("ACTUAL_PIXELS");
417  auto const pixelFrame = oldFrameDict->getFrame("PIXELS", false);
418  auto const iwcFrame = oldFrameDict->getFrame("IWC", false);
419  auto const skyFrame = oldFrameDict->getFrame("SKY", false);
420  auto const oldPixelToIwc = oldFrameDict->getMapping("PIXELS", "IWC");
421  auto const iwcToSky = oldFrameDict->getMapping("IWC", "SKY");
422 
423  std::shared_ptr<ast::FrameDict> newFrameDict;
424  std::shared_ptr<ast::Mapping> newPixelToIwc;
425  if (hasActualPixels) {
426  auto const actualPixelFrame = oldFrameDict->getFrame("ACTUAL_PIXELS", false);
427  auto const oldActualPixelToPixels = oldFrameDict->getMapping("ACTUAL_PIXELS", "PIXELS");
428  std::shared_ptr<ast::Mapping> newActualPixelsToPixels;
429  if (modifyActualPixels) {
430  newActualPixelsToPixels = pixelMapping->then(*oldActualPixelToPixels).simplify();
431  newPixelToIwc = oldPixelToIwc;
432  } else {
433  newActualPixelsToPixels = oldActualPixelToPixels;
434  newPixelToIwc = pixelMapping->then(*oldPixelToIwc).simplify();
435  }
436  newFrameDict =
437  std::make_shared<ast::FrameDict>(*actualPixelFrame, *newActualPixelsToPixels, *pixelFrame);
438  newFrameDict->addFrame("PIXELS", *newPixelToIwc, *iwcFrame);
439  } else {
440  newPixelToIwc = pixelMapping->then(*oldPixelToIwc).simplify();
441  newFrameDict = std::make_shared<ast::FrameDict>(*pixelFrame, *newPixelToIwc, *iwcFrame);
442  }
443  newFrameDict->addFrame("IWC", *iwcToSky, *skyFrame);
444  return std::make_shared<SkyWcs>(*newFrameDict);
445 }
446 
448  return std::make_shared<SkyWcs>(metadata, strip);
449 }
450 
452  Eigen::Matrix2d const& cdMatrix, std::string const& projection) {
453  auto metadata = makeSimpleWcsMetadata(crpix, crval, cdMatrix, projection);
454  return std::make_shared<SkyWcs>(*metadata);
455 }
456 
458  Eigen::Matrix2d const& cdMatrix, Eigen::MatrixXd const& sipA,
459  Eigen::MatrixXd const& sipB) {
460  auto metadata = makeTanSipMetadata(crpix, crval, cdMatrix, sipA, sipB);
461  return std::make_shared<SkyWcs>(*metadata);
462 }
463 
465  Eigen::Matrix2d const& cdMatrix, Eigen::MatrixXd const& sipA,
466  Eigen::MatrixXd const& sipB, Eigen::MatrixXd const& sipAp,
467  Eigen::MatrixXd const& sipBp) {
468  auto metadata = makeTanSipMetadata(crpix, crval, cdMatrix, sipA, sipB, sipAp, sipBp);
469  return std::make_shared<SkyWcs>(*metadata);
470 }
471 
473  bool simplify) {
474  auto iwcToSky = wcs.getFrameDict()->getMapping("IWC", "SKY");
475  return std::make_shared<TransformPoint2ToSpherePoint>(*iwcToSky, simplify);
476 }
477 
479  auto pixelToIwc = wcs.getFrameDict()->getMapping(ast::FrameSet::BASE, "IWC");
480  return std::make_shared<TransformPoint2ToPoint2>(*pixelToIwc, simplify);
481 }
482 
484  os << "SkyWcs";
485  return os;
486 };
487 
488 } // namespace geom
489 } // namespace afw
490 } // namespace lsst
int m
Definition: SpanSet.cc:44
Point in an unspecified spherical coordinate system.
Definition: SpherePoint.h:59
A 2-dimensional celestial WCS that transform pixels to ICRS RA/Dec, using the LSST standard for pixel...
Definition: SkyWcs.h:113
def keys(self)
Extent< double, 2 > Extent2D
Definition: Extent.h:383
An object passed to Persistable::write to allow it to persist itself.
std::ostream & operator<<(std::ostream &os, lsst::afw::geom::AffineTransform const &transform)
std::shared_ptr< daf::base::PropertyList > makeTanSipMetadata(Point2D const &crpix, 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.
Definition: wcsUtils.cc:198
#define LSST_ARCHIVE_ASSERT(EXPR)
An assertion macro used to validate the structure of an InputArchive.
Definition: Persistable.h:48
AngleUnit constexpr radians
constant with units of radians
Definition: Angle.h:87
std::shared_ptr< const ast::Mapping > getMapping() const
Get the contained mapping.
Definition: Transform.h:137
bool isFits() const
Return true getFitsMetadata(true) will succeed, false if not.
Definition: SkyWcs.cc:222
table::PointKey< double > crpix
Definition: OldWcs.cc:131
def scale(algorithm, min, max=None, frame=None)
Definition: ds9.py:115
T to_string(T... args)
SeriesMap then(Mapping const &next) const
std::shared_ptr< SkyWcs > makeModifiedWcs(TransformPoint2ToPoint2 const &pixelTransform, SkyWcs const &wcs, bool modifyActualPixels)
Create a new SkyWcs whose pixels are transformed by pixelTransform, as described below.
Definition: SkyWcs.cc:412
std::string getPythonModule() const override
Return the fully-qualified Python module that should be imported to guarantee that its factory is reg...
Definition: SkyWcs.cc:305
bool strip
Definition: fits.cc:817
table::PointKey< double > crval
Definition: OldWcs.cc:130
Point2D getPosition(AngleUnit unit) const
Return longitude, latitude as a Point2D object.
Definition: SpherePoint.cc:119
std::shared_ptr< ast::FrameDict > readLsstSkyWcs(daf::base::PropertySet &metadata, bool strip=true)
Read an LSST celestial WCS FrameDict from a FITS header.
ItemVariant const * other
Definition: Schema.cc:55
static int constexpr CURRENT
std::string bytesToString(ndarray::Array< std::uint8_t const, 1, 1 > const &bytes)
Decode a std::string from a vector of uint8 returned by stringToBytes.
Definition: Utils.cc:204
A class used to convert scalar POD types such as double to Angle.
Definition: Angle.h:52
STL class.
std::shared_ptr< const ast::FrameDict > getFrameDict() const
Get the contained FrameDict.
Definition: SkyWcs.cc:218
Transform< Point2Endpoint, Point2Endpoint > TransformPoint2ToPoint2
Definition: Transform.h:302
STL class.
lsst::afw::geom::SpherePoint SpherePoint
Definition: misc.h:35
T sin(T... args)
std::string getPersistenceName() const override
Return the unique name used to persist this object and look up its factory.
Definition: SkyWcs.cc:303
Eigen::Matrix2d getCdMatrix() const
Get the 2x2 CD matrix at the pixel origin.
Definition: SkyWcs.cc:175
std::shared_ptr< const TransformPoint2ToSpherePoint > getTransform() const
Get a TransformPoint2ToSpherePoint that transforms pixels to sky in the forward direction and sky to ...
Definition: SkyWcs.h:253
A class representing an angle.
Definition: Angle.h:102
table::Key< table::Array< std::uint8_t > > wcs
Definition: SkyWcs.cc:66
A base class for image defects.
bool hasFitsApproximation() const
Does this SkyWcs have an approximate SkyWcs that can be represented as standard FITS WCS...
Definition: SkyWcs.h:350
An affine coordinate transformation consisting of a linear transformation and an offset.
std::shared_ptr< RecordT > src
Definition: Match.cc:48
std::shared_ptr< SkyWcs > getTanWcs(Point2D const &pixel) const
Get a local TAN WCS approximation to this WCS at the specified pixel position.
Definition: SkyWcs.cc:177
std::shared_ptr< Frame > getFrame(std::string const &domain, bool copy=true) const
std::shared_ptr< SkyWcs > makeFlippedWcs(SkyWcs const &wcs, bool flipLR, bool flipTB, geom::Point2D const &center)
Return a copy of a FITS-WCS with pixel positions flipped around a specified center.
Definition: SkyWcs.cc:393
Angle getPixelScale() const
Get the pixel scale at the pixel origin.
Definition: SkyWcs.h:204
std::shared_ptr< FrameDict > copy() const
std::shared_ptr< daf::base::PropertyList > makeSimpleWcsMetadata(Point2D const &crpix, SpherePoint const &crval, Eigen::Matrix2d const &cdMatrix, std::string const &projection="TAN")
Make FITS metadata for a simple FITS WCS (one with no distortion).
Definition: wcsUtils.cc:172
table::Key< table::Array< std::uint8_t > > frameSet
int write(Object const &object)
static std::shared_ptr< SkyWcs > readStream(std::istream &is)
Deserialize a SkyWcs from an input stream.
Definition: SkyWcs.cc:258
T str(T... args)
std::shared_ptr< daf::base::PropertyList > getPropertyListFromFitsChan(ast::FitsChan &fitsChan)
Copy values from an AST FitsChan into a PropertyList.
T cos(T... args)
T dynamic_pointer_cast(T... args)
static std::string getShortClassName()
Definition: SkyWcs.cc:248
std::shared_ptr< TransformPoint2ToPoint2 > getPixelToIntermediateWorldCoords(SkyWcs const &wcs, bool simplify=true)
Return a transform from pixel coordinates to intermediate world coordinates.
Definition: SkyWcs.cc:478
std::shared_ptr< TransformPoint2ToSpherePoint > getIntermediateWorldCoordsToSky(SkyWcs const &wcs, bool simplify=true)
Return a transform from intermediate world coordinates to sky.
Definition: SkyWcs.cc:472
BaseCatalog makeCatalog(Schema const &schema)
Return a new, empty catalog with the given schema.
AffineTransform linearizeSkyToPixel(SpherePoint const &coord, AngleUnit const &skyUnit) const
Return the local linear approximation to skyToPixel at a point given in sky coordinates.
Definition: SkyWcs.cc:240
Point2D getPixelOrigin() const
Get the pixel origin, in pixels, using the LSST convention.
Definition: SkyWcs.h:211
std::shared_ptr< TransformPoint2ToPoint2 > makeWcsPairTransform(SkyWcs const &src, SkyWcs const &dst)
A Transform obtained by putting two SkyWcs objects "back to back".
Definition: SkyWcs.cc:123
#define LSST_EXCEPT(type,...)
STL class.
std::shared_ptr< SkyWcs > copyAtShiftedPixelOrigin(Extent2D const &shift) const
Return a copy of this SkyWcs with the pixel origin shifted by the specified amount.
Definition: SkyWcs.cc:184
static std::shared_ptr< SkyWcs > readString(std::string &str)
Deserialize a SkyWcs from a string, using the same format as readStream.
Definition: SkyWcs.cc:287
SpherePoint pixelToSky(Point2D const &pixel) const
Compute sky position(s) from pixel position(s)
Definition: SkyWcs.h:326
void write(OutputArchiveHandle &handle) const override
Write the object to one or more catalogs.
Definition: SkyWcs.cc:307
T pow(T... args)
Point2D skyToPixel(SpherePoint const &sky) const
Compute pixel position(s) from sky position(s)
Definition: SkyWcs.h:337
SkyWcs(SkyWcs const &)=default
std::string writeString() const
Serialize this SkyWcs to a string, using the same format as writeStream.
Definition: SkyWcs.cc:297
std::shared_ptr< SkyWcs > makeSkyWcs(daf::base::PropertySet &metadata, bool strip=false)
Construct a SkyWcs from FITS keywords.
Definition: SkyWcs.cc:447
std::shared_ptr< daf::base::PropertyList > getFitsMetadata(bool precise=false) const
Return the WCS as FITS WCS metadata.
Definition: SkyWcs.cc:189
constexpr double asRadians() const noexcept
Return an Angle&#39;s value in radians.
Definition: Angle.h:141
AffineTransform linearizePixelToSky(SpherePoint const &coord, AngleUnit const &skyUnit) const
Return the local linear approximation to pixelToSky at a point given in sky coordinates.
Definition: SkyWcs.cc:233
Eigen::Matrix2d makeCdMatrix(Angle const &scale, Angle const &orientation=0 *degrees, bool flipX=false)
Make a WCS CD matrix.
Definition: SkyWcs.cc:111
table::PointKey< int > pixel
void writeStream(std::ostream &os) const
Serialize this SkyWcs to an output stream.
Definition: SkyWcs.cc:292
static int constexpr BASE
void saveCatalog(BaseCatalog const &catalog)
Save a catalog in the archive.
bool isFlipped() const
Does the WCS follow the convention of North=Up, East=Left?
Definition: SkyWcs.cc:250
ndarray::Array< std::uint8_t, 1, 1 > stringToBytes(std::string const &str)
Encode a std::string as a vector of uint8.
Definition: Utils.cc:193
constexpr double asDegrees() const noexcept
Return an Angle&#39;s value in degrees.
Definition: Angle.h:144
std::pair< Angle, Angle > getTangentPlaneOffset(SpherePoint const &other) const
Get the offset from a tangent plane centered at this point to another point.
Definition: SpherePoint.cc:199
std::ostream * os
Definition: Schema.cc:736
STL class.
SpherePoint getSkyOrigin() const
Get the sky origin, the celestial fiducial point.
Definition: SkyWcs.cc:158
bool operator==(SkyWcs const &other) const
Equality is based on the string representations being equal.
Definition: SkyWcs.cc:133
std::shared_ptr< Object > read()
AffineTransform const invert() const
Return the inverse transform.
Transform LSST spatial data, such as Point2D and SpherePoint, using an AST mapping.
Definition: Transform.h:67
std::shared_ptr< SkyWcs > makeTanSipWcs(Point2D const &crpix, SpherePoint const &crval, Eigen::Matrix2d const &cdMatrix, Eigen::MatrixXd const &sipA, Eigen::MatrixXd const &sipB)
Construct a TAN-SIP SkyWcs with forward SIP distortion terms and an iterative inverse.
Definition: SkyWcs.cc:457
table::Schema schema
Definition: SkyWcs.cc:65
bool hasDomain(std::string const &domain) const
std::shared_ptr< RecordT > addNew()
Create a new record, add it to the end of the catalog, and return a pointer to it.
Definition: Catalog.h:472