lsst.afw  15.0-29-ga12a2b06e
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  auto skyLL = skyVec[0].getVector();
147  auto skyDx = skyVec[1].getVector() - skyLL;
148  auto skyDy = skyVec[2].getVector() - skyLL;
149 
150  // Compute pixel scale in radians = sqrt(pixel area in radians^2)
151  // pixel area in radians^2 = area of parallelogram with sides skyDx, skyDy = |skyDx cross skyDy|
152  // Use squared norm to avoid two square roots
153  double skyAreaSq = skyDx.cross(skyDy).getSquaredNorm();
154  return (std::pow(skyAreaSq, 0.25) / side) * radians;
155 }
156 
158  // CRVAL is stored as the SkyRef property of the sky frame (the current frame of the SkyWcs)
159  auto skyFrame = std::dynamic_pointer_cast<ast::SkyFrame>(
160  getFrameDict()->getFrame(ast::FrameDict::CURRENT, false)); // false: do not copy
161  if (!skyFrame) {
162  throw LSST_EXCEPT(pex::exceptions::LogicError, "Current frame is not a SkyFrame");
163  }
164  auto const crvalRad = skyFrame->getSkyRef();
165  return SpherePoint(crvalRad[0] * radians, crvalRad[1] * radians);
166 }
167 
168 Eigen::Matrix2d SkyWcs::getCdMatrix(Point2D const& pixel) const {
169  auto const pixelToIwc = getFrameDict()->getMapping(ast::FrameSet::BASE, "IWC");
170  auto const pixelToIwcTransform = TransformPoint2ToPoint2(*pixelToIwc);
171  return pixelToIwcTransform.getJacobian(pixel);
172 }
173 
174 Eigen::Matrix2d SkyWcs::getCdMatrix() const { return getCdMatrix(getPixelOrigin()); }
175 
177  auto const crval = pixelToSky(pixel);
178  auto const cdMatrix = getCdMatrix(pixel);
179  auto metadata = makeSimpleWcsMetadata(pixel, crval, cdMatrix);
180  return std::make_shared<SkyWcs>(*metadata);
181 }
182 
184  auto newToOldPixel = TransformPoint2ToPoint2(ast::ShiftMap({-shift[0], -shift[1]}));
185  return makeModifiedWcs(newToOldPixel, *this, true);
186 }
187 
189  // Make a FrameSet that maps from GRID to SKY; GRID = the base frame (PIXELS or ACTUAL_PIXELS) + 1
190  auto const gridToPixel = ast::ShiftMap({-1.0, -1.0});
191  auto thisDict = getFrameDict();
192  auto const pixelToIwc = thisDict->getMapping(ast::FrameSet::BASE, "IWC");
193  auto const iwcToSky = thisDict->getMapping("IWC", "SKY");
194  auto const gridToSky = gridToPixel.then(*pixelToIwc).then(*iwcToSky);
195  ast::FrameSet frameSet(ast::Frame(2, "Domain=GRID"), gridToSky, *thisDict->getFrame("SKY", false));
196 
197  // Write frameSet to a FitsChan and extract the metadata
199  os << "Encoding=FITS-WCS, CDMatrix=1, FitsAxisOrder=<copy>, FitsTol=" << TIGHT_FITS_TOL;
200  ast::StringStream strStream;
201  ast::FitsChan fitsChan(strStream, os.str());
202  int const nObjectsWritten = fitsChan.write(frameSet);
203  if (nObjectsWritten == 0) {
204  if (precise) {
206  "Could not represent this SkyWcs using FITS-WCS metadata");
207  } else {
208  // An exact representation could not be written, so try to write a local TAN approximation;
209  // set precise true to avoid an infinite loop, should something go wrong
210  auto tanWcs = getTanWcs(getPixelOrigin());
211  return tanWcs->getFitsMetadata(true);
212  }
213  }
214  return detail::getPropertyListFromFitsChan(fitsChan);
215 }
216 
218  return _frameDict;
219 }
220 
221 bool SkyWcs::isFits() const {
222  try {
223  getFitsMetadata(true);
224  } catch (const lsst::pex::exceptions::RuntimeError&) {
225  return false;
226  } catch (const std::runtime_error&) {
227  return false;
228  }
229  return true;
230 }
231 
233  return _linearizePixelToSky(skyToPixel(coord), coord, skyUnit);
234 }
236  return _linearizePixelToSky(pix, pixelToSky(pix), skyUnit);
237 }
238 
240  return _linearizeSkyToPixel(skyToPixel(coord), coord, skyUnit);
241 }
242 
244  return _linearizeSkyToPixel(pix, pixelToSky(pix), skyUnit);
245 }
246 
247 std::string SkyWcs::getShortClassName() { return "SkyWcs"; };
248 
249 bool SkyWcs::isFlipped() const {
250  double det = getCdMatrix().determinant();
251  if (det == 0) {
252  throw(LSST_EXCEPT(pex::exceptions::RuntimeError, "CD matrix is singular"));
253  }
254  return (det > 0);
255 }
256 
258  int version;
259  is >> version;
260  if (version != 1) {
262  "Unsupported version " + std::to_string(version));
263  }
264  std::string shortClassName;
265  is >> shortClassName;
266  if (shortClassName != SkyWcs::getShortClassName()) {
268  os << "Class name in stream " << shortClassName << " != " << SkyWcs::getShortClassName();
270  }
272  is >> hasFitsApproximation;
273  auto astStream = ast::Stream(&is, nullptr);
274  auto astObjectPtr = ast::Channel(astStream).read();
275  auto frameSet = std::dynamic_pointer_cast<ast::FrameSet>(astObjectPtr);
276  if (!frameSet) {
278  os << "The AST serialization was read as a " << astObjectPtr->getClassName()
279  << " instead of a FrameSet";
281  }
282  ast::FrameDict frameDict(*frameSet);
283  return std::make_shared<SkyWcs>(frameDict);
284 }
285 
287  std::istringstream is(str);
288  return SkyWcs::readStream(is);
289 }
290 
292  os << SERIALIZATION_VERSION << " " << SkyWcs::getShortClassName() << " " << hasFitsApproximation() << " ";
293  getFrameDict()->show(os, false); // false = do not write comments
294 }
295 
298  writeStream(os);
299  return os.str();
300 }
301 
302 std::string SkyWcs::getPersistenceName() const { return getSkyWcsPersistenceName(); }
303 
304 std::string SkyWcs::getPythonModule() const { return "lsst.afw.geom"; }
305 
306 void SkyWcs::write(OutputArchiveHandle& handle) const {
307  SkyWcsPersistenceHelper const& keys = SkyWcsPersistenceHelper::get();
308  table::BaseCatalog cat = handle.makeCatalog(keys.schema);
310  record->set(keys.wcs, formatters::stringToBytes(writeString()));
311  handle.saveCatalog(cat);
312 }
313 
315  : _frameDict(frameDict), _transform(),
316  _pixelOrigin(),
317  _pixelScaleAtOrigin(0 * radians) {
318  _computeCache();
319 };
320 
321 std::shared_ptr<ast::FrameDict> SkyWcs::_checkFrameDict(ast::FrameDict const& frameDict) const {
322  // Check that each frame is present and has the right type and number of axes
323  std::vector<std::string> const domainNames = {"ACTUAL_PIXELS", "PIXELS", "IWC", "SKY"};
324  for (auto const& domainName : domainNames) {
325  if (frameDict.hasDomain(domainName)) {
326  auto const frame = frameDict.getFrame(domainName, false);
327  if (frame->getNAxes() != 2) {
329  "Frame " + domainName + " has " + std::to_string(frame->getNAxes()) +
330  " axes instead of 2");
331  }
332  auto desiredClassName = domainName == "SKY" ? "SkyFrame" : "Frame";
333  if (frame->getClassName() != desiredClassName) {
335  "Frame " + domainName + " is of type " + frame->getClassName() +
336  " instead of " + desiredClassName);
337  }
338  } else if (domainName != "ACTUAL_PIXELS") {
339  // This is a required frame
341  "No frame with domain " + domainName + " found");
342  }
343  }
344 
345  // The base frame must have domain "PIXELS" or "ACTUAL_PIXELS"
346  auto baseDomain = frameDict.getFrame(ast::FrameSet::BASE, false)->getDomain();
347  if (baseDomain != "ACTUAL_PIXELS" && baseDomain != "PIXELS") {
349  "Base frame has domain " + baseDomain + " instead of PIXELS or ACTUAL_PIXELS");
350  }
351 
352  // The current frame must have domain "SKY"
353  auto currentDomain = frameDict.getFrame(ast::FrameSet::CURRENT, false)->getDomain();
354  if (currentDomain != "SKY") {
356  "Current frame has domain " + currentDomain + " instead of SKY");
357  }
358 
359  return frameDict.copy();
360 }
361 
362 AffineTransform SkyWcs::_linearizePixelToSky(Point2D const& pix00, SpherePoint const& coord,
363  AngleUnit const& skyUnit) const {
364  // Figure out the (0, 0), (0, 1), and (1, 0) ra/dec coordinates of the corners
365  // of a square drawn in pixel. It'd be better to center the square at sky00,
366  // but that would involve another conversion between sky and pixel coordinates
367  const double side = 1.0; // length of the square's sides in pixels
368  auto const sky00 = coord.getPosition(skyUnit);
369  auto const dsky10 = coord.getTangentPlaneOffset(pixelToSky(pix00 + Extent2D(side, 0)));
370  auto const dsky01 = coord.getTangentPlaneOffset(pixelToSky(pix00 + Extent2D(0, side)));
371 
372  Eigen::Matrix2d m;
373  m(0, 0) = dsky10.first.asAngularUnits(skyUnit) / side;
374  m(0, 1) = dsky01.first.asAngularUnits(skyUnit) / side;
375  m(1, 0) = dsky10.second.asAngularUnits(skyUnit) / side;
376  m(1, 1) = dsky01.second.asAngularUnits(skyUnit) / side;
377 
378  Eigen::Vector2d sky00v;
379  sky00v << sky00.getX(), sky00.getY();
380  Eigen::Vector2d pix00v;
381  pix00v << pix00.getX(), pix00.getY();
382  // return AffineTransform(m, Extent2D(sky00v - m * pix00v));
383  return AffineTransform(m, (sky00v - m * pix00v));
384 }
385 
386 AffineTransform SkyWcs::_linearizeSkyToPixel(Point2D const& pix00, SpherePoint const& coord,
387  AngleUnit const& skyUnit) const {
388  AffineTransform inverse = _linearizePixelToSky(pix00, coord, skyUnit);
389  return inverse.invert();
390 }
391 
392 std::shared_ptr<SkyWcs> makeFlippedWcs(SkyWcs const& wcs, bool flipLR, bool flipTB,
393  geom::Point2D const& center) {
394  double const dx = 1000; // any "reasonable" number of pixels will do
395  std::vector<double> inLL = {center[0] - dx, center[1] - dx};
396  std::vector<double> inUR = {center[0] + dx, center[1] + dx};
397  std::vector<double> outLL(inLL);
398  std::vector<double> outUR(inUR);
399  if (flipLR) {
400  outLL[0] = inUR[0];
401  outUR[0] = inLL[0];
402  }
403  if (flipTB) {
404  outLL[1] = inUR[1];
405  outUR[1] = inLL[1];
406  }
407  auto const flipPix = TransformPoint2ToPoint2(ast::WinMap(inLL, inUR, outLL, outUR));
408  return makeModifiedWcs(flipPix, wcs, true);
409 }
410 
412  bool modifyActualPixels) {
413  auto const pixelMapping = pixelTransform.getMapping();
414  auto oldFrameDict = wcs.getFrameDict();
415  bool const hasActualPixels = oldFrameDict->hasDomain("ACTUAL_PIXELS");
416  auto const pixelFrame = oldFrameDict->getFrame("PIXELS", false);
417  auto const iwcFrame = oldFrameDict->getFrame("IWC", false);
418  auto const skyFrame = oldFrameDict->getFrame("SKY", false);
419  auto const oldPixelToIwc = oldFrameDict->getMapping("PIXELS", "IWC");
420  auto const iwcToSky = oldFrameDict->getMapping("IWC", "SKY");
421 
422  std::shared_ptr<ast::FrameDict> newFrameDict;
423  std::shared_ptr<ast::Mapping> newPixelToIwc;
424  if (hasActualPixels) {
425  auto const actualPixelFrame = oldFrameDict->getFrame("ACTUAL_PIXELS", false);
426  auto const oldActualPixelToPixels = oldFrameDict->getMapping("ACTUAL_PIXELS", "PIXELS");
427  std::shared_ptr<ast::Mapping> newActualPixelsToPixels;
428  if (modifyActualPixels) {
429  newActualPixelsToPixels = pixelMapping->then(*oldActualPixelToPixels).simplify();
430  newPixelToIwc = oldPixelToIwc;
431  } else {
432  newActualPixelsToPixels = oldActualPixelToPixels;
433  newPixelToIwc = pixelMapping->then(*oldPixelToIwc).simplify();
434  }
435  newFrameDict =
436  std::make_shared<ast::FrameDict>(*actualPixelFrame, *newActualPixelsToPixels, *pixelFrame);
437  newFrameDict->addFrame("PIXELS", *newPixelToIwc, *iwcFrame);
438  } else {
439  newPixelToIwc = pixelMapping->then(*oldPixelToIwc).simplify();
440  newFrameDict = std::make_shared<ast::FrameDict>(*pixelFrame, *newPixelToIwc, *iwcFrame);
441  }
442  newFrameDict->addFrame("IWC", *iwcToSky, *skyFrame);
443  return std::make_shared<SkyWcs>(*newFrameDict);
444 }
445 
447  return std::make_shared<SkyWcs>(metadata, strip);
448 }
449 
451  Eigen::Matrix2d const& cdMatrix, std::string const& projection) {
452  auto metadata = makeSimpleWcsMetadata(crpix, crval, cdMatrix, projection);
453  return std::make_shared<SkyWcs>(*metadata);
454 }
455 
457  Eigen::Matrix2d const& cdMatrix, Eigen::MatrixXd const& sipA,
458  Eigen::MatrixXd const& sipB) {
459  auto metadata = makeTanSipMetadata(crpix, crval, cdMatrix, sipA, sipB);
460  return std::make_shared<SkyWcs>(*metadata);
461 }
462 
464  Eigen::Matrix2d const& cdMatrix, Eigen::MatrixXd const& sipA,
465  Eigen::MatrixXd const& sipB, Eigen::MatrixXd const& sipAp,
466  Eigen::MatrixXd const& sipBp) {
467  auto metadata = makeTanSipMetadata(crpix, crval, cdMatrix, sipA, sipB, sipAp, sipBp);
468  return std::make_shared<SkyWcs>(*metadata);
469 }
470 
472  bool simplify) {
473  auto iwcToSky = wcs.getFrameDict()->getMapping("IWC", "SKY");
474  return std::make_shared<TransformPoint2ToSpherePoint>(*iwcToSky, simplify);
475 }
476 
478  auto pixelToIwc = wcs.getFrameDict()->getMapping(ast::FrameSet::BASE, "IWC");
479  return std::make_shared<TransformPoint2ToPoint2>(*pixelToIwc, simplify);
480 }
481 
483  os << "SkyWcs";
484  return os;
485 };
486 
487 } // namespace geom
488 } // namespace afw
489 } // namespace lsst
int m
Definition: SpanSet.cc:44
Point in an unspecified spherical coordinate system.
Definition: SpherePoint.h:61
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:221
table::PointKey< double > crpix
Definition: OldWcs.cc:131
def scale(algorithm, min, max=None, frame=None)
Definition: ds9.py:113
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:411
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:304
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:131
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:217
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:302
Eigen::Matrix2d getCdMatrix() const
Get the 2x2 CD matrix at the pixel origin.
Definition: SkyWcs.cc:174
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:176
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:392
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:257
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:247
std::shared_ptr< TransformPoint2ToPoint2 > getPixelToIntermediateWorldCoords(SkyWcs const &wcs, bool simplify=true)
Return a transform from pixel coordinates to intermediate world coordinates.
Definition: SkyWcs.cc:477
std::shared_ptr< TransformPoint2ToSpherePoint > getIntermediateWorldCoordsToSky(SkyWcs const &wcs, bool simplify=true)
Return a transform from intermediate world coordinates to sky.
Definition: SkyWcs.cc:471
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:239
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:183
static std::shared_ptr< SkyWcs > readString(std::string &str)
Deserialize a SkyWcs from a string, using the same format as readStream.
Definition: SkyWcs.cc:286
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:306
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:296
std::shared_ptr< SkyWcs > makeSkyWcs(daf::base::PropertySet &metadata, bool strip=false)
Construct a SkyWcs from FITS keywords.
Definition: SkyWcs.cc:446
std::shared_ptr< daf::base::PropertyList > getFitsMetadata(bool precise=false) const
Return the WCS as FITS WCS metadata.
Definition: SkyWcs.cc:188
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:232
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:291
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:249
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:211
std::ostream * os
Definition: Schema.cc:736
STL class.
SpherePoint getSkyOrigin() const
Get the sky origin, the celestial fiducial point.
Definition: SkyWcs.cc:157
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:456
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