lsst.afw  16.0-9-gdf7162dbc+1
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 
34 #include "lsst/geom/Angle.h"
35 #include "lsst/geom/Point.h"
36 #include "lsst/geom/SpherePoint.h"
38 #include "lsst/afw/table.h"
43 #include "lsst/afw/geom/wcsUtils.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(lsst::geom::Angle const& scale, lsst::geom::Angle const& orientation,
112  bool flipX) {
113  Eigen::Matrix2d cdMatrix;
114  double orientRad = orientation.asRadians();
115  double scaleDeg = scale.asDegrees();
116  double xmult = flipX ? 1.0 : -1.0;
117  cdMatrix(0, 0) = std::cos(orientRad) * scaleDeg * xmult;
118  cdMatrix(0, 1) = std::sin(orientRad) * scaleDeg;
119  cdMatrix(1, 0) = -std::sin(orientRad) * scaleDeg * xmult;
120  cdMatrix(1, 1) = std::cos(orientRad) * scaleDeg;
121  return cdMatrix;
122 }
123 
125  auto const dstInverse = dst.getTransform()->getInverse();
126  return src.getTransform()->then(*dstInverse);
127 }
128 
130  : SkyWcs(detail::readLsstSkyWcs(metadata, strip)) {}
131 
132 SkyWcs::SkyWcs(ast::FrameDict const& frameDict) : SkyWcs(_checkFrameDict(frameDict)) {}
133 
134 bool SkyWcs::operator==(SkyWcs const& other) const { return writeString() == other.writeString(); }
135 
137  // Compute pixVec containing the pixel position and two nearby points
138  // (use a vector so all three points can be converted to sky in a single call)
139  double const side = 1.0;
141  pixel, pixel + lsst::geom::Extent2D(side, 0), pixel + lsst::geom::Extent2D(0, side),
142  };
143 
144  auto skyVec = pixelToSky(pixVec);
145 
146  // Work in 3-space to avoid RA wrapping and pole issues
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.cross(skyDy).getSquaredNorm();
155  return (std::pow(skyAreaSq, 0.25) / side) * lsst::geom::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 lsst::geom::SpherePoint(crvalRad[0] * lsst::geom::radians, crvalRad[1] * lsst::geom::radians);
167 }
168 
169 Eigen::Matrix2d SkyWcs::getCdMatrix(lsst::geom::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 
220 bool SkyWcs::isFits() const {
221  try {
222  getFitsMetadata(true);
223  } catch (const lsst::pex::exceptions::RuntimeError&) {
224  return false;
225  } catch (const std::runtime_error&) {
226  return false;
227  }
228  return true;
229 }
230 
232  lsst::geom::AngleUnit const& skyUnit) const {
233  return _linearizePixelToSky(skyToPixel(coord), coord, skyUnit);
234 }
236  lsst::geom::AngleUnit const& skyUnit) const {
237  return _linearizePixelToSky(pix, pixelToSky(pix), skyUnit);
238 }
239 
241  lsst::geom::AngleUnit const& skyUnit) const {
242  return _linearizeSkyToPixel(skyToPixel(coord), coord, skyUnit);
243 }
244 
246  lsst::geom::AngleUnit const& skyUnit) const {
247  return _linearizeSkyToPixel(pix, pixelToSky(pix), skyUnit);
248 }
249 
250 std::string SkyWcs::getShortClassName() { return "SkyWcs"; };
251 
252 bool SkyWcs::isFlipped() const {
253  double det = getCdMatrix().determinant();
254  if (det == 0) {
255  throw(LSST_EXCEPT(pex::exceptions::RuntimeError, "CD matrix is singular"));
256  }
257  return (det > 0);
258 }
259 
261  int version;
262  is >> version;
263  if (version != 1) {
264  throw LSST_EXCEPT(pex::exceptions::TypeError, "Unsupported version " + std::to_string(version));
265  }
266  std::string shortClassName;
267  is >> shortClassName;
268  if (shortClassName != SkyWcs::getShortClassName()) {
270  os << "Class name in stream " << shortClassName << " != " << SkyWcs::getShortClassName();
272  }
274  is >> hasFitsApproximation;
275  auto astStream = ast::Stream(&is, nullptr);
276  auto astObjectPtr = ast::Channel(astStream).read();
277  auto frameSet = std::dynamic_pointer_cast<ast::FrameSet>(astObjectPtr);
278  if (!frameSet) {
280  os << "The AST serialization was read as a " << astObjectPtr->getClassName()
281  << " instead of a FrameSet";
283  }
284  ast::FrameDict frameDict(*frameSet);
285  return std::make_shared<SkyWcs>(frameDict);
286 }
287 
289  std::istringstream is(str);
290  return SkyWcs::readStream(is);
291 }
292 
294  os << SERIALIZATION_VERSION << " " << SkyWcs::getShortClassName() << " " << hasFitsApproximation() << " ";
295  getFrameDict()->show(os, false); // false = do not write comments
296 }
297 
300  writeStream(os);
301  return os.str();
302 }
303 
304 std::string SkyWcs::getPersistenceName() const { return getSkyWcsPersistenceName(); }
305 
306 std::string SkyWcs::getPythonModule() const { return "lsst.afw.geom"; }
307 
308 void SkyWcs::write(OutputArchiveHandle& handle) const {
309  SkyWcsPersistenceHelper const& keys = SkyWcsPersistenceHelper::get();
310  table::BaseCatalog cat = handle.makeCatalog(keys.schema);
312  record->set(keys.wcs, formatters::stringToBytes(writeString()));
313  handle.saveCatalog(cat);
314 }
315 
317  : _frameDict(frameDict), _transform(), _pixelOrigin(), _pixelScaleAtOrigin(0 * lsst::geom::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 lsst::geom::AffineTransform SkyWcs::_linearizePixelToSky(lsst::geom::Point2D const& pix00,
363  lsst::geom::SpherePoint const& coord,
364  lsst::geom::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 + lsst::geom::Extent2D(side, 0)));
371  auto const dsky01 = coord.getTangentPlaneOffset(pixelToSky(pix00 + lsst::geom::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 lsst::geom::AffineTransform(m, lsst::geom::Extent2D(sky00v - m * pix00v));
384  return lsst::geom::AffineTransform(m, (sky00v - m * pix00v));
385 }
386 
387 lsst::geom::AffineTransform SkyWcs::_linearizeSkyToPixel(lsst::geom::Point2D const& pix00,
388  lsst::geom::SpherePoint const& coord,
389  lsst::geom::AngleUnit const& skyUnit) const {
390  lsst::geom::AffineTransform inverse = _linearizePixelToSky(pix00, coord, skyUnit);
391  return inverse.invert();
392 }
393 
394 std::shared_ptr<SkyWcs> makeFlippedWcs(SkyWcs const& wcs, bool flipLR, bool flipTB,
395  lsst::geom::Point2D const& center) {
396  double const dx = 1000; // any "reasonable" number of pixels will do
397  std::vector<double> inLL = {center[0] - dx, center[1] - dx};
398  std::vector<double> inUR = {center[0] + dx, center[1] + dx};
399  std::vector<double> outLL(inLL);
400  std::vector<double> outUR(inUR);
401  if (flipLR) {
402  outLL[0] = inUR[0];
403  outUR[0] = inLL[0];
404  }
405  if (flipTB) {
406  outLL[1] = inUR[1];
407  outUR[1] = inLL[1];
408  }
409  auto const flipPix = TransformPoint2ToPoint2(ast::WinMap(inLL, inUR, outLL, outUR));
410  return makeModifiedWcs(flipPix, wcs, true);
411 }
412 
414  bool modifyActualPixels) {
415  auto const pixelMapping = pixelTransform.getMapping();
416  auto oldFrameDict = wcs.getFrameDict();
417  bool const hasActualPixels = oldFrameDict->hasDomain("ACTUAL_PIXELS");
418  auto const pixelFrame = oldFrameDict->getFrame("PIXELS", false);
419  auto const iwcFrame = oldFrameDict->getFrame("IWC", false);
420  auto const skyFrame = oldFrameDict->getFrame("SKY", false);
421  auto const oldPixelToIwc = oldFrameDict->getMapping("PIXELS", "IWC");
422  auto const iwcToSky = oldFrameDict->getMapping("IWC", "SKY");
423 
424  std::shared_ptr<ast::FrameDict> newFrameDict;
425  std::shared_ptr<ast::Mapping> newPixelToIwc;
426  if (hasActualPixels) {
427  auto const actualPixelFrame = oldFrameDict->getFrame("ACTUAL_PIXELS", false);
428  auto const oldActualPixelToPixels = oldFrameDict->getMapping("ACTUAL_PIXELS", "PIXELS");
429  std::shared_ptr<ast::Mapping> newActualPixelsToPixels;
430  if (modifyActualPixels) {
431  newActualPixelsToPixels = pixelMapping->then(*oldActualPixelToPixels).simplify();
432  newPixelToIwc = oldPixelToIwc;
433  } else {
434  newActualPixelsToPixels = oldActualPixelToPixels;
435  newPixelToIwc = pixelMapping->then(*oldPixelToIwc).simplify();
436  }
437  newFrameDict =
438  std::make_shared<ast::FrameDict>(*actualPixelFrame, *newActualPixelsToPixels, *pixelFrame);
439  newFrameDict->addFrame("PIXELS", *newPixelToIwc, *iwcFrame);
440  } else {
441  newPixelToIwc = pixelMapping->then(*oldPixelToIwc).simplify();
442  newFrameDict = std::make_shared<ast::FrameDict>(*pixelFrame, *newPixelToIwc, *iwcFrame);
443  }
444  newFrameDict->addFrame("IWC", *iwcToSky, *skyFrame);
445  return std::make_shared<SkyWcs>(*newFrameDict);
446 }
447 
449  return std::make_shared<SkyWcs>(metadata, strip);
450 }
451 
453  Eigen::Matrix2d const& cdMatrix, std::string const& projection) {
454  auto metadata = makeSimpleWcsMetadata(crpix, crval, cdMatrix, projection);
455  return std::make_shared<SkyWcs>(*metadata);
456 }
457 
459  Eigen::Matrix2d const& cdMatrix, Eigen::MatrixXd const& sipA,
460  Eigen::MatrixXd const& sipB) {
461  auto metadata = makeTanSipMetadata(crpix, crval, cdMatrix, sipA, sipB);
462  return std::make_shared<SkyWcs>(*metadata);
463 }
464 
466  Eigen::Matrix2d const& cdMatrix, Eigen::MatrixXd const& sipA,
467  Eigen::MatrixXd const& sipB, Eigen::MatrixXd const& sipAp,
468  Eigen::MatrixXd const& sipBp) {
469  auto metadata = makeTanSipMetadata(crpix, crval, cdMatrix, sipA, sipB, sipAp, sipBp);
470  return std::make_shared<SkyWcs>(*metadata);
471 }
472 
474  bool simplify) {
475  auto iwcToSky = wcs.getFrameDict()->getMapping("IWC", "SKY");
476  return std::make_shared<TransformPoint2ToSpherePoint>(*iwcToSky, simplify);
477 }
478 
480  auto pixelToIwc = wcs.getFrameDict()->getMapping(ast::FrameSet::BASE, "IWC");
481  return std::make_shared<TransformPoint2ToPoint2>(*pixelToIwc, simplify);
482 }
483 
485  os << "SkyWcs";
486  return os;
487 };
488 
489 } // namespace geom
490 } // namespace afw
491 } // namespace lsst
int m
Definition: SpanSet.cc:44
std::pair< Angle, Angle > getTangentPlaneOffset(SpherePoint const &other) const
A 2-dimensional celestial WCS that transform pixels to ICRS RA/Dec, using the LSST standard for pixel...
Definition: SkyWcs.h:115
std::shared_ptr< SkyWcs > getTanWcs(lsst::geom::Point2D const &pixel) const
Get a local TAN WCS approximation to this WCS at the specified pixel position.
Definition: SkyWcs.cc:177
def keys(self)
constexpr double asRadians() const noexcept
constexpr double asDegrees() const noexcept
lsst::geom::Point2D skyToPixel(lsst::geom::SpherePoint const &sky) const
Compute pixel position(s) from sky position(s)
Definition: SkyWcs.h:347
An object passed to Persistable::write to allow it to persist itself.
#define LSST_ARCHIVE_ASSERT(EXPR)
An assertion macro used to validate the structure of an InputArchive.
Definition: Persistable.h:48
lsst::geom::SpherePoint pixelToSky(lsst::geom::Point2D const &pixel) const
Compute sky position(s) from pixel position(s)
Definition: SkyWcs.h:332
std::shared_ptr< const ast::Mapping > getMapping() const
Get the contained mapping.
Definition: Transform.h:135
bool isFits() const
Return true getFitsMetadata(true) will succeed, false if not.
Definition: SkyWcs.cc:220
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)
std::ostream & operator<<(std::ostream &os, GenericEndpoint const &endpoint)
Print "GenericEndpoint(_n_)" to the ostream where _n_ is the number of axes, e.g. "GenericAxes(4)"...
Definition: Endpoint.cc:240
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:413
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:306
bool strip
Definition: fits.cc:817
table::PointKey< double > crval
Definition: OldWcs.cc:130
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
lsst::geom::SpherePoint getSkyOrigin() const
Get the sky origin, the celestial fiducial point.
Definition: SkyWcs.cc:158
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:202
STL class.
std::shared_ptr< const ast::FrameDict > getFrameDict() const
Get the contained FrameDict.
Definition: SkyWcs.cc:218
AngleUnit constexpr radians
Transform< Point2Endpoint, Point2Endpoint > TransformPoint2ToPoint2
Definition: Transform.h:300
STL class.
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:304
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:255
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:362
std::shared_ptr< SkyWcs > makeFlippedWcs(SkyWcs const &wcs, bool flipLR, bool flipTB, lsst::geom::Point2D const &center)
Return a copy of a FITS-WCS with pixel positions flipped around a specified center.
Definition: SkyWcs.cc:394
std::shared_ptr< RecordT > src
Definition: Match.cc:48
std::shared_ptr< Frame > getFrame(std::string const &domain, bool copy=true) const
std::shared_ptr< FrameDict > copy() const
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:260
lsst::geom::AffineTransform linearizePixelToSky(lsst::geom::SpherePoint const &coord, lsst::geom::AngleUnit const &skyUnit) const
Return the local linear approximation to pixelToSky at a point given in sky coordinates.
Definition: SkyWcs.cc:231
T str(T... args)
Point2D getPosition(AngleUnit unit) const
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:250
std::shared_ptr< TransformPoint2ToPoint2 > getPixelToIntermediateWorldCoords(SkyWcs const &wcs, bool simplify=true)
Return a transform from pixel coordinates to intermediate world coordinates.
Definition: SkyWcs.cc:479
std::shared_ptr< SkyWcs > makeTanSipWcs(lsst::geom::Point2D const &crpix, lsst::geom::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:458
std::shared_ptr< TransformPoint2ToSpherePoint > getIntermediateWorldCoordsToSky(SkyWcs const &wcs, bool simplify=true)
Return a transform from intermediate world coordinates to sky.
Definition: SkyWcs.cc:473
BaseCatalog makeCatalog(Schema const &schema)
Return a new, empty catalog with the given schema.
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.
Definition: wcsUtils.cc:198
std::shared_ptr< SkyWcs > copyAtShiftedPixelOrigin(lsst::geom::Extent2D const &shift) const
Return a copy of this SkyWcs with the pixel origin shifted by the specified amount.
Definition: SkyWcs.cc:184
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:124
#define LSST_EXCEPT(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).
Definition: wcsUtils.cc:172
STL class.
static std::shared_ptr< SkyWcs > readString(std::string &str)
Deserialize a SkyWcs from a string, using the same format as readStream.
Definition: SkyWcs.cc:288
lsst::geom::Point2D getPixelOrigin() const
Get the pixel origin, in pixels, using the LSST convention.
Definition: SkyWcs.h:213
void write(OutputArchiveHandle &handle) const override
Write the object to one or more catalogs.
Definition: SkyWcs.cc:308
T pow(T... args)
SkyWcs(SkyWcs const &)=default
std::string writeString() const
Serialize this SkyWcs to a string, using the same format as writeStream.
Definition: SkyWcs.cc:298
std::shared_ptr< SkyWcs > makeSkyWcs(daf::base::PropertySet &metadata, bool strip=false)
Construct a SkyWcs from FITS keywords.
Definition: SkyWcs.cc:448
std::shared_ptr< daf::base::PropertyList > getFitsMetadata(bool precise=false) const
Return the WCS as FITS WCS metadata.
Definition: SkyWcs.cc:189
Eigen::Matrix2d makeCdMatrix(lsst::geom::Angle const &scale, lsst::geom::Angle const &orientation=0 *lsst::geom::degrees, bool flipX=false)
Make a WCS CD matrix.
Definition: SkyWcs.cc:111
AffineTransform const invert() const
lsst::geom::SpherePoint SpherePoint
Definition: misc.h:35
table::PointKey< int > pixel
void writeStream(std::ostream &os) const
Serialize this SkyWcs to an output stream.
Definition: SkyWcs.cc:293
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:252
ndarray::Array< std::uint8_t, 1, 1 > stringToBytes(std::string const &str)
Encode a std::string as a vector of uint8.
Definition: Utils.cc:191
Extent< double, 2 > Extent2D
lsst::geom::AffineTransform linearizeSkyToPixel(lsst::geom::SpherePoint const &coord, lsst::geom::AngleUnit const &skyUnit) const
Return the local linear approximation to skyToPixel at a point given in sky coordinates.
Definition: SkyWcs.cc:240
lsst::geom::Angle getPixelScale() const
Get the pixel scale at the pixel origin.
Definition: SkyWcs.h:206
std::ostream * os
Definition: Schema.cc:737
STL class.
bool operator==(SkyWcs const &other) const
Equality is based on the string representations being equal.
Definition: SkyWcs.cc:134
std::shared_ptr< Object > read()
Transform LSST spatial data, such as lsst::geom::Point2D and lsst::geom::SpherePoint, using an AST mapping.
Definition: Transform.h:67
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