lsst.afw  16.0-19-g2da375352+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 ast::FrameDict makeSkyWcsFrameDict(TransformPoint2ToPoint2 const& pixelsToFieldAngle,
110  lsst::geom::Angle const& orientation, bool flipX,
112  std::string const& projection = "TAN") {
113  auto const orientationAndFlipXMatrix = makeCdMatrix(1 * lsst::geom::degrees, orientation, flipX);
114  auto const initialWcs = makeSkyWcs(lsst::geom::Point2D(0, 0), crval, orientationAndFlipXMatrix, projection);
115  auto const initialFrameDict = initialWcs->getFrameDict();
116  auto const iwcToSkyMap = initialFrameDict->getMapping("IWC", "SKY");
117  auto const pixelFrame = initialFrameDict->getFrame("PIXELS");
118  auto const iwcFrame = initialFrameDict->getFrame("IWC");
119  auto const skyFrame = initialFrameDict->getFrame("SKY");
120  // Field angle is in radians and is aligned to focal plane x and y;
121  // IWC is basically the same thing, but in degrees and with rotation and flipX applied
122  ndarray::Array<double, 2, 2> fieldAngleToIwcNdArray = ndarray::allocate(2, 2);
123  asEigenMatrix(fieldAngleToIwcNdArray) = orientationAndFlipXMatrix * 180.0 / lsst::geom::PI;
124  auto const pixelsToFieldAngleMap = pixelsToFieldAngle.getMapping();
125  auto const fieldAngleToIwcMap = ast::MatrixMap(fieldAngleToIwcNdArray);
126  auto const pixelsToIwcMap = pixelsToFieldAngleMap->then(fieldAngleToIwcMap);
127  auto finalFrameDict = ast::FrameDict(*pixelFrame, pixelsToIwcMap, *iwcFrame);
128  finalFrameDict.addFrame("IWC", *iwcToSkyMap, *skyFrame);
129  return finalFrameDict;
130 }
131 
132 } // namespace
133 
135  bool flipX) {
136  Eigen::Matrix2d cdMatrix;
137  double orientRad = orientation.asRadians();
138  double scaleDeg = scale.asDegrees();
139  double xmult = flipX ? 1.0 : -1.0;
140  cdMatrix(0, 0) = std::cos(orientRad) * scaleDeg * xmult;
141  cdMatrix(0, 1) = std::sin(orientRad) * scaleDeg;
142  cdMatrix(1, 0) = -std::sin(orientRad) * scaleDeg * xmult;
143  cdMatrix(1, 1) = std::cos(orientRad) * scaleDeg;
144  return cdMatrix;
145 }
146 
148  auto const dstInverse = dst.getTransform()->getInverse();
149  return src.getTransform()->then(*dstInverse);
150 }
151 
153  : SkyWcs(detail::readLsstSkyWcs(metadata, strip)) {}
154 
155 SkyWcs::SkyWcs(ast::FrameDict const& frameDict) : SkyWcs(_checkFrameDict(frameDict)) {}
156 
157 bool SkyWcs::operator==(SkyWcs const& other) const { return writeString() == other.writeString(); }
158 
160  // Compute pixVec containing the pixel position and two nearby points
161  // (use a vector so all three points can be converted to sky in a single call)
162  double const side = 1.0;
164  pixel, pixel + lsst::geom::Extent2D(side, 0), pixel + lsst::geom::Extent2D(0, side),
165  };
166 
167  auto skyVec = pixelToSky(pixVec);
168 
169  // Work in 3-space to avoid RA wrapping and pole issues
170  auto skyLL = skyVec[0].getVector();
171  auto skyDx = skyVec[1].getVector() - skyLL;
172  auto skyDy = skyVec[2].getVector() - skyLL;
173 
174  // Compute pixel scale in radians = sqrt(pixel area in radians^2)
175  // pixel area in radians^2 = area of parallelogram with sides skyDx, skyDy = |skyDx cross skyDy|
176  // Use squared norm to avoid two square roots
177  double skyAreaSq = skyDx.cross(skyDy).getSquaredNorm();
178  return (std::pow(skyAreaSq, 0.25) / side) * lsst::geom::radians;
179 }
180 
182  // CRVAL is stored as the SkyRef property of the sky frame (the current frame of the SkyWcs)
183  auto skyFrame = std::dynamic_pointer_cast<ast::SkyFrame>(
184  getFrameDict()->getFrame(ast::FrameDict::CURRENT, false)); // false: do not copy
185  if (!skyFrame) {
186  throw LSST_EXCEPT(pex::exceptions::LogicError, "Current frame is not a SkyFrame");
187  }
188  auto const crvalRad = skyFrame->getSkyRef();
189  return lsst::geom::SpherePoint(crvalRad[0] * lsst::geom::radians, crvalRad[1] * lsst::geom::radians);
190 }
191 
192 Eigen::Matrix2d SkyWcs::getCdMatrix(lsst::geom::Point2D const& pixel) const {
193  auto const pixelToIwc = getFrameDict()->getMapping(ast::FrameSet::BASE, "IWC");
194  auto const pixelToIwcTransform = TransformPoint2ToPoint2(*pixelToIwc);
195  return pixelToIwcTransform.getJacobian(pixel);
196 }
197 
198 Eigen::Matrix2d SkyWcs::getCdMatrix() const { return getCdMatrix(getPixelOrigin()); }
199 
201  auto const crval = pixelToSky(pixel);
202  auto const cdMatrix = getCdMatrix(pixel);
203  auto metadata = makeSimpleWcsMetadata(pixel, crval, cdMatrix);
204  return std::make_shared<SkyWcs>(*metadata);
205 }
206 
208  auto newToOldPixel = TransformPoint2ToPoint2(ast::ShiftMap({-shift[0], -shift[1]}));
209  return makeModifiedWcs(newToOldPixel, *this, true);
210 }
211 
213  // Make a FrameSet that maps from GRID to SKY; GRID = the base frame (PIXELS or ACTUAL_PIXELS) + 1
214  auto const gridToPixel = ast::ShiftMap({-1.0, -1.0});
215  auto thisDict = getFrameDict();
216  auto const pixelToIwc = thisDict->getMapping(ast::FrameSet::BASE, "IWC");
217  auto const iwcToSky = thisDict->getMapping("IWC", "SKY");
218  auto const gridToSky = gridToPixel.then(*pixelToIwc).then(*iwcToSky);
219  ast::FrameSet frameSet(ast::Frame(2, "Domain=GRID"), gridToSky, *thisDict->getFrame("SKY", false));
220 
221  // Write frameSet to a FitsChan and extract the metadata
223  os << "Encoding=FITS-WCS, CDMatrix=1, FitsAxisOrder=<copy>, FitsTol=" << TIGHT_FITS_TOL;
224  ast::StringStream strStream;
225  ast::FitsChan fitsChan(strStream, os.str());
226  int const nObjectsWritten = fitsChan.write(frameSet);
227  if (nObjectsWritten == 0) {
228  if (precise) {
230  "Could not represent this SkyWcs using FITS-WCS metadata");
231  } else {
232  // An exact representation could not be written, so try to write a local TAN approximation;
233  // set precise true to avoid an infinite loop, should something go wrong
234  auto tanWcs = getTanWcs(getPixelOrigin());
235  return tanWcs->getFitsMetadata(true);
236  }
237  }
238  return detail::getPropertyListFromFitsChan(fitsChan);
239 }
240 
242 
243 bool SkyWcs::isFits() const {
244  try {
245  getFitsMetadata(true);
246  } catch (const lsst::pex::exceptions::RuntimeError&) {
247  return false;
248  } catch (const std::runtime_error&) {
249  return false;
250  }
251  return true;
252 }
253 
255  lsst::geom::AngleUnit const& skyUnit) const {
256  return _linearizePixelToSky(skyToPixel(coord), coord, skyUnit);
257 }
259  lsst::geom::AngleUnit const& skyUnit) const {
260  return _linearizePixelToSky(pix, pixelToSky(pix), skyUnit);
261 }
262 
264  lsst::geom::AngleUnit const& skyUnit) const {
265  return _linearizeSkyToPixel(skyToPixel(coord), coord, skyUnit);
266 }
267 
269  lsst::geom::AngleUnit const& skyUnit) const {
270  return _linearizeSkyToPixel(pix, pixelToSky(pix), skyUnit);
271 }
272 
273 std::string SkyWcs::getShortClassName() { return "SkyWcs"; };
274 
275 bool SkyWcs::isFlipped() const {
276  double det = getCdMatrix().determinant();
277  if (det == 0) {
278  throw(LSST_EXCEPT(pex::exceptions::RuntimeError, "CD matrix is singular"));
279  }
280  return (det > 0);
281 }
282 
284  int version;
285  is >> version;
286  if (version != 1) {
287  throw LSST_EXCEPT(pex::exceptions::TypeError, "Unsupported version " + std::to_string(version));
288  }
289  std::string shortClassName;
290  is >> shortClassName;
291  if (shortClassName != SkyWcs::getShortClassName()) {
293  os << "Class name in stream " << shortClassName << " != " << SkyWcs::getShortClassName();
295  }
297  is >> hasFitsApproximation;
298  auto astStream = ast::Stream(&is, nullptr);
299  auto astObjectPtr = ast::Channel(astStream).read();
300  auto frameSet = std::dynamic_pointer_cast<ast::FrameSet>(astObjectPtr);
301  if (!frameSet) {
303  os << "The AST serialization was read as a " << astObjectPtr->getClassName()
304  << " instead of a FrameSet";
306  }
307  ast::FrameDict frameDict(*frameSet);
308  return std::make_shared<SkyWcs>(frameDict);
309 }
310 
312  std::istringstream is(str);
313  return SkyWcs::readStream(is);
314 }
315 
317  os << SERIALIZATION_VERSION << " " << SkyWcs::getShortClassName() << " " << hasFitsApproximation() << " ";
318  getFrameDict()->show(os, false); // false = do not write comments
319 }
320 
323  writeStream(os);
324  return os.str();
325 }
326 
327 std::string SkyWcs::getPersistenceName() const { return getSkyWcsPersistenceName(); }
328 
329 std::string SkyWcs::getPythonModule() const { return "lsst.afw.geom"; }
330 
331 void SkyWcs::write(OutputArchiveHandle& handle) const {
332  SkyWcsPersistenceHelper const& keys = SkyWcsPersistenceHelper::get();
333  table::BaseCatalog cat = handle.makeCatalog(keys.schema);
335  record->set(keys.wcs, formatters::stringToBytes(writeString()));
336  handle.saveCatalog(cat);
337 }
338 
340  : _frameDict(frameDict), _transform(), _pixelOrigin(), _pixelScaleAtOrigin(0 * lsst::geom::radians) {
341  _computeCache();
342 };
343 
344 std::shared_ptr<ast::FrameDict> SkyWcs::_checkFrameDict(ast::FrameDict const& frameDict) const {
345  // Check that each frame is present and has the right type and number of axes
346  std::vector<std::string> const domainNames = {"ACTUAL_PIXELS", "PIXELS", "IWC", "SKY"};
347  for (auto const& domainName : domainNames) {
348  if (frameDict.hasDomain(domainName)) {
349  auto const frame = frameDict.getFrame(domainName, false);
350  if (frame->getNAxes() != 2) {
352  "Frame " + domainName + " has " + std::to_string(frame->getNAxes()) +
353  " axes instead of 2");
354  }
355  auto desiredClassName = domainName == "SKY" ? "SkyFrame" : "Frame";
356  if (frame->getClassName() != desiredClassName) {
358  "Frame " + domainName + " is of type " + frame->getClassName() +
359  " instead of " + desiredClassName);
360  }
361  } else if (domainName != "ACTUAL_PIXELS") {
362  // This is a required frame
364  "No frame with domain " + domainName + " found");
365  }
366  }
367 
368  // The base frame must have domain "PIXELS" or "ACTUAL_PIXELS"
369  auto baseDomain = frameDict.getFrame(ast::FrameSet::BASE, false)->getDomain();
370  if (baseDomain != "ACTUAL_PIXELS" && baseDomain != "PIXELS") {
372  "Base frame has domain " + baseDomain + " instead of PIXELS or ACTUAL_PIXELS");
373  }
374 
375  // The current frame must have domain "SKY"
376  auto currentDomain = frameDict.getFrame(ast::FrameSet::CURRENT, false)->getDomain();
377  if (currentDomain != "SKY") {
379  "Current frame has domain " + currentDomain + " instead of SKY");
380  }
381 
382  return frameDict.copy();
383 }
384 
385 lsst::geom::AffineTransform SkyWcs::_linearizePixelToSky(lsst::geom::Point2D const& pix00,
386  lsst::geom::SpherePoint const& coord,
387  lsst::geom::AngleUnit const& skyUnit) const {
388  // Figure out the (0, 0), (0, 1), and (1, 0) ra/dec coordinates of the corners
389  // of a square drawn in pixel. It'd be better to center the square at sky00,
390  // but that would involve another conversion between sky and pixel coordinates
391  const double side = 1.0; // length of the square's sides in pixels
392  auto const sky00 = coord.getPosition(skyUnit);
393  auto const dsky10 = coord.getTangentPlaneOffset(pixelToSky(pix00 + lsst::geom::Extent2D(side, 0)));
394  auto const dsky01 = coord.getTangentPlaneOffset(pixelToSky(pix00 + lsst::geom::Extent2D(0, side)));
395 
396  Eigen::Matrix2d m;
397  m(0, 0) = dsky10.first.asAngularUnits(skyUnit) / side;
398  m(0, 1) = dsky01.first.asAngularUnits(skyUnit) / side;
399  m(1, 0) = dsky10.second.asAngularUnits(skyUnit) / side;
400  m(1, 1) = dsky01.second.asAngularUnits(skyUnit) / side;
401 
402  Eigen::Vector2d sky00v;
403  sky00v << sky00.getX(), sky00.getY();
404  Eigen::Vector2d pix00v;
405  pix00v << pix00.getX(), pix00.getY();
406  // return lsst::geom::AffineTransform(m, lsst::geom::Extent2D(sky00v - m * pix00v));
407  return lsst::geom::AffineTransform(m, (sky00v - m * pix00v));
408 }
409 
410 lsst::geom::AffineTransform SkyWcs::_linearizeSkyToPixel(lsst::geom::Point2D const& pix00,
411  lsst::geom::SpherePoint const& coord,
412  lsst::geom::AngleUnit const& skyUnit) const {
413  lsst::geom::AffineTransform inverse = _linearizePixelToSky(pix00, coord, skyUnit);
414  return inverse.invert();
415 }
416 
417 std::shared_ptr<SkyWcs> makeFlippedWcs(SkyWcs const& wcs, bool flipLR, bool flipTB,
418  lsst::geom::Point2D const& center) {
419  double const dx = 1000; // any "reasonable" number of pixels will do
420  std::vector<double> inLL = {center[0] - dx, center[1] - dx};
421  std::vector<double> inUR = {center[0] + dx, center[1] + dx};
422  std::vector<double> outLL(inLL);
423  std::vector<double> outUR(inUR);
424  if (flipLR) {
425  outLL[0] = inUR[0];
426  outUR[0] = inLL[0];
427  }
428  if (flipTB) {
429  outLL[1] = inUR[1];
430  outUR[1] = inLL[1];
431  }
432  auto const flipPix = TransformPoint2ToPoint2(ast::WinMap(inLL, inUR, outLL, outUR));
433  return makeModifiedWcs(flipPix, wcs, true);
434 }
435 
437  bool modifyActualPixels) {
438  auto const pixelMapping = pixelTransform.getMapping();
439  auto oldFrameDict = wcs.getFrameDict();
440  bool const hasActualPixels = oldFrameDict->hasDomain("ACTUAL_PIXELS");
441  auto const pixelFrame = oldFrameDict->getFrame("PIXELS", false);
442  auto const iwcFrame = oldFrameDict->getFrame("IWC", false);
443  auto const skyFrame = oldFrameDict->getFrame("SKY", false);
444  auto const oldPixelToIwc = oldFrameDict->getMapping("PIXELS", "IWC");
445  auto const iwcToSky = oldFrameDict->getMapping("IWC", "SKY");
446 
447  std::shared_ptr<ast::FrameDict> newFrameDict;
448  std::shared_ptr<ast::Mapping> newPixelToIwc;
449  if (hasActualPixels) {
450  auto const actualPixelFrame = oldFrameDict->getFrame("ACTUAL_PIXELS", false);
451  auto const oldActualPixelToPixels = oldFrameDict->getMapping("ACTUAL_PIXELS", "PIXELS");
452  std::shared_ptr<ast::Mapping> newActualPixelsToPixels;
453  if (modifyActualPixels) {
454  newActualPixelsToPixels = pixelMapping->then(*oldActualPixelToPixels).simplify();
455  newPixelToIwc = oldPixelToIwc;
456  } else {
457  newActualPixelsToPixels = oldActualPixelToPixels;
458  newPixelToIwc = pixelMapping->then(*oldPixelToIwc).simplify();
459  }
460  newFrameDict =
461  std::make_shared<ast::FrameDict>(*actualPixelFrame, *newActualPixelsToPixels, *pixelFrame);
462  newFrameDict->addFrame("PIXELS", *newPixelToIwc, *iwcFrame);
463  } else {
464  newPixelToIwc = pixelMapping->then(*oldPixelToIwc).simplify();
465  newFrameDict = std::make_shared<ast::FrameDict>(*pixelFrame, *newPixelToIwc, *iwcFrame);
466  }
467  newFrameDict->addFrame("IWC", *iwcToSky, *skyFrame);
468  return std::make_shared<SkyWcs>(*newFrameDict);
469 }
470 
472  return std::make_shared<SkyWcs>(metadata, strip);
473 }
474 
476  Eigen::Matrix2d const& cdMatrix, std::string const& projection) {
477  auto metadata = makeSimpleWcsMetadata(crpix, crval, cdMatrix, projection);
478  return std::make_shared<SkyWcs>(*metadata);
479 }
480 
482  lsst::geom::Angle const& orientation, bool flipX,
483  lsst::geom::SpherePoint const& boresight, std::string const& projection) {
484  auto frameDict = makeSkyWcsFrameDict(pixelsToFieldAngle, orientation, flipX, boresight, projection);
485  return std::make_shared<SkyWcs>(frameDict);
486 }
487 
489  Eigen::Matrix2d const& cdMatrix, Eigen::MatrixXd const& sipA,
490  Eigen::MatrixXd const& sipB) {
491  auto metadata = makeTanSipMetadata(crpix, crval, cdMatrix, sipA, sipB);
492  return std::make_shared<SkyWcs>(*metadata);
493 }
494 
496  Eigen::Matrix2d const& cdMatrix, Eigen::MatrixXd const& sipA,
497  Eigen::MatrixXd const& sipB, Eigen::MatrixXd const& sipAp,
498  Eigen::MatrixXd const& sipBp) {
499  auto metadata = makeTanSipMetadata(crpix, crval, cdMatrix, sipA, sipB, sipAp, sipBp);
500  return std::make_shared<SkyWcs>(*metadata);
501 }
502 
504  bool simplify) {
505  auto iwcToSky = wcs.getFrameDict()->getMapping("IWC", "SKY");
506  return std::make_shared<TransformPoint2ToSpherePoint>(*iwcToSky, simplify);
507 }
508 
510  auto pixelToIwc = wcs.getFrameDict()->getMapping(ast::FrameSet::BASE, "IWC");
511  return std::make_shared<TransformPoint2ToPoint2>(*pixelToIwc, simplify);
512 }
513 
515  os << "SkyWcs";
516  return os;
517 };
518 
519 } // namespace geom
520 } // namespace afw
521 } // 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:200
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:243
table::PointKey< double > crpix
Definition: OldWcs.cc:131
Point2D getPosition(AngleUnit unit) const noexcept
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:436
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:329
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:181
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:241
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:327
Eigen::Matrix2d getCdMatrix() const
Get the 2x2 CD matrix at the pixel origin.
Definition: SkyWcs.cc:198
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
AngleUnit constexpr degrees
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:417
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:283
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:254
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:273
std::shared_ptr< TransformPoint2ToPoint2 > getPixelToIntermediateWorldCoords(SkyWcs const &wcs, bool simplify=true)
Return a transform from pixel coordinates to intermediate world coordinates.
Definition: SkyWcs.cc:509
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:488
std::shared_ptr< TransformPoint2ToSpherePoint > getIntermediateWorldCoordsToSky(SkyWcs const &wcs, bool simplify=true)
Return a transform from intermediate world coordinates to sky.
Definition: SkyWcs.cc:503
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:207
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:147
#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:311
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:331
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:321
std::shared_ptr< SkyWcs > makeSkyWcs(daf::base::PropertySet &metadata, bool strip=false)
Construct a SkyWcs from FITS keywords.
Definition: SkyWcs.cc:471
std::shared_ptr< daf::base::PropertyList > getFitsMetadata(bool precise=false) const
Return the WCS as FITS WCS metadata.
Definition: SkyWcs.cc:212
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:134
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:316
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:275
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:263
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:157
std::shared_ptr< Object > read()
double constexpr PI
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