LSSTApplications  19.0.0-14-gb0260a2+72efe9b372,20.0.0+7927753e06,20.0.0+8829bf0056,20.0.0+995114c5d2,20.0.0+b6f4b2abd1,20.0.0+bddc4f4cbe,20.0.0-1-g253301a+8829bf0056,20.0.0-1-g2b7511a+0d71a2d77f,20.0.0-1-g5b95a8c+7461dd0434,20.0.0-12-g321c96ea+23efe4bbff,20.0.0-16-gfab17e72e+fdf35455f6,20.0.0-2-g0070d88+ba3ffc8f0b,20.0.0-2-g4dae9ad+ee58a624b3,20.0.0-2-g61b8584+5d3db074ba,20.0.0-2-gb780d76+d529cf1a41,20.0.0-2-ged6426c+226a441f5f,20.0.0-2-gf072044+8829bf0056,20.0.0-2-gf1f7952+ee58a624b3,20.0.0-20-geae50cf+e37fec0aee,20.0.0-25-g3dcad98+544a109665,20.0.0-25-g5eafb0f+ee58a624b3,20.0.0-27-g64178ef+f1f297b00a,20.0.0-3-g4cc78c6+e0676b0dc8,20.0.0-3-g8f21e14+4fd2c12c9a,20.0.0-3-gbd60e8c+187b78b4b8,20.0.0-3-gbecbe05+48431fa087,20.0.0-38-ge4adf513+a12e1f8e37,20.0.0-4-g97dc21a+544a109665,20.0.0-4-gb4befbc+087873070b,20.0.0-4-gf910f65+5d3db074ba,20.0.0-5-gdfe0fee+199202a608,20.0.0-5-gfbfe500+d529cf1a41,20.0.0-6-g64f541c+d529cf1a41,20.0.0-6-g9a5b7a1+a1cd37312e,20.0.0-68-ga3f3dda+5fca18c6a4,20.0.0-9-g4aef684+e18322736b,w.2020.45
LSSTDataManagementBasePackage
SkyWcs.h
Go to the documentation of this file.
1 // -*- lsst-c++ -*-
2 /*
3  * LSST Data Management System
4  * Copyright 2017 AURA/LSST.
5  *
6  * This product includes software developed by the
7  * LSST Project (http://www.lsst.org/).
8  *
9  * This program is free software: you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation, either version 3 of the License, or
12  * (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the LSST License Statement and
20  * the GNU General Public License along with this program. If not,
21  * see <http://www.lsstcorp.org/LegalNotices/>.
22  */
23 
24 #ifndef LSST_AFW_GEOM_SKYWCS_H
25 #define LSST_AFW_GEOM_SKYWCS_H
26 
27 #include <memory>
28 #include <utility>
29 #include <vector>
30 
31 #include "Eigen/Core"
32 #include "astshim.h"
33 #include "ndarray.h"
34 
37 #include "lsst/geom/Angle.h"
38 #include "lsst/geom/Point.h"
39 #include "lsst/afw/geom/Endpoint.h"
43 
44 namespace lsst {
45 namespace afw {
46 namespace geom {
47 
61 Eigen::Matrix2d makeCdMatrix(lsst::geom::Angle const &scale,
63  bool flipX = false);
64 
117 class SkyWcs final : public table::io::PersistableFacade<SkyWcs>, public typehandling::Storable {
118 public:
119  SkyWcs(SkyWcs const &) = default;
120  SkyWcs(SkyWcs &&) = default;
121  SkyWcs &operator=(SkyWcs const &) = delete;
122  SkyWcs &operator=(SkyWcs &&) = delete;
123  ~SkyWcs() override = default;
124 
135  bool operator==(SkyWcs const &other) const;
136  bool operator!=(SkyWcs const &other) const { return !(*this == other); }
137 
149  explicit SkyWcs(daf::base::PropertySet &metadata, bool strip = false);
150 
163  explicit SkyWcs(ast::FrameDict const &frameDict);
164 
173 
190  std::shared_ptr<daf::base::PropertyList> getFitsMetadata(bool precise = false) const;
191 
200 
208  lsst::geom::Angle getPixelScale() const { return _pixelScaleAtOrigin; };
209 
215  lsst::geom::Point2D getPixelOrigin() const { return _pixelOrigin; };
216 
223 
229  Eigen::Matrix2d getCdMatrix(lsst::geom::Point2D const &pixel) const;
230 
236  Eigen::Matrix2d getCdMatrix() const;
237 
242 
252 
258 
266  bool isFlipped() const;
267 
268  bool isPersistable() const noexcept override { return true; }
269 
283  lsst::geom::AngleUnit const &skyUnit) const;
284 
298  lsst::geom::AngleUnit const &skyUnit) const;
299 
313  lsst::geom::AngleUnit const &skyUnit) const;
314 
328  lsst::geom::AngleUnit const &skyUnit) const;
329 
335  return _transform->applyForward(pixel);
336  }
337  lsst::geom::SpherePoint pixelToSky(double x, double y) const {
338  return pixelToSky(lsst::geom::Point2D(x, y));
339  }
341  return _transform->applyForward(pixels);
342  }
344 
350  return _transform->applyInverse(sky);
351  }
353  return _transform->applyInverse(sky);
354  }
356 
358 
364  bool hasFitsApproximation() const { return false; }
365 
371  bool isFits() const;
372 
379 
382 
400  void writeStream(std::ostream &os) const;
401 
403  std::string writeString() const;
404 
405  // Override methods required by afw::typehandling::Storable
406 
409 
420  std::string toString() const override;
421 
427  bool equals(typehandling::Storable const &other) const noexcept override;
428 
429 protected:
430  // Override methods required by afw::table::io::Persistable
431  std::string getPersistenceName() const override;
432  std::string getPythonModule() const override;
433  void write(OutputArchiveHandle &handle) const override;
434 
435 private:
436  /*
437  * Construct a SkyWcs from a shared pointer to an ast::FrameDict
438  *
439  * The frameDict may be modified.
440  */
441  explicit SkyWcs(std::shared_ptr<ast::FrameDict> frameDict);
442 
443  /*
444  * Check a FrameDict to see if it can safely be used for a SkyWcs
445  * Return a copy so that it can be used as an argument to the SkyWcs(shared_ptr<FrameDict>) constructor
446  */
447  std::shared_ptr<ast::FrameDict> _checkFrameDict(ast::FrameDict const &frameDict) const;
448 
449  // the full FrameDict, for operations that need intermediate frames
451  // cached transform from _frameDict, for fast computation of pixels<->sky
453  lsst::geom::Point2D _pixelOrigin; // cached pixel origin
454  lsst::geom::Angle _pixelScaleAtOrigin; // cached pixel scale at pixel origin
455 
456  /*
457  * Implementation for the overloaded public linearizePixelToSky methods, requiring both a pixel coordinate
458  * and the corresponding sky coordinate.
459  */
460  lsst::geom::AffineTransform _linearizePixelToSky(lsst::geom::Point2D const &pix,
461  lsst::geom::SpherePoint const &coord,
462  lsst::geom::AngleUnit const &skyUnit) const;
463 
464  /*
465  * Implementation for the overloaded public linearizeSkyToPixel methods, requiring both a pixel coordinate
466  * and the corresponding sky coordinate.
467  */
468  lsst::geom::AffineTransform _linearizeSkyToPixel(lsst::geom::Point2D const &pix,
469  lsst::geom::SpherePoint const &coord,
470  lsst::geom::AngleUnit const &skyUnit) const;
471 
473  void _computeCache() {
474  _transform = std::make_shared<TransformPoint2ToSpherePoint>(*_frameDict->getMapping(), true);
475  _pixelOrigin = skyToPixel(getSkyOrigin());
476  _pixelScaleAtOrigin = getPixelScale(_pixelOrigin);
477  }
478 };
479 
488 std::shared_ptr<SkyWcs> makeFlippedWcs(SkyWcs const &wcs, bool flipLR, bool flipTB,
489  lsst::geom::Point2D const &center);
490 
517 std::shared_ptr<SkyWcs> makeModifiedWcs(TransformPoint2ToPoint2 const &pixelTransform, SkyWcs const &wcs,
518  bool modifyActualPixels);
519 
536 
548  Eigen::Matrix2d const &cdMatrix, std::string const &projection = "TAN");
549 
567  lsst::geom::Angle const &orientation, bool flipX,
568  lsst::geom::SpherePoint const &boresight,
569  std::string const &projection = "TAN");
570 
583  Eigen::Matrix2d const &cdMatrix, Eigen::MatrixXd const &sipA,
584  Eigen::MatrixXd const &sipB);
585 
600  Eigen::Matrix2d const &cdMatrix, Eigen::MatrixXd const &sipA,
601  Eigen::MatrixXd const &sipB, Eigen::MatrixXd const &sipAp,
602  Eigen::MatrixXd const &sipBp);
614 std::shared_ptr<TransformPoint2ToPoint2> makeWcsPairTransform(SkyWcs const &src, SkyWcs const &dst);
615 
620  bool simplify = true);
621 
628  bool simplify = true);
629 
633 std::ostream &operator<<(std::ostream &os, SkyWcs const &wcs);
634 
635 } // namespace geom
636 } // namespace afw
637 } // namespace lsst
638 
639 #endif
y
int y
Definition: SpanSet.cc:49
lsst::geom::degrees
constexpr AngleUnit degrees
constant with units of degrees
Definition: Angle.h:109
ast::FrameDict::getMapping
std::shared_ptr< Mapping > getMapping(int from, std::string const &to) const
Variant of FrameSet::getMapping with the second frame specified by domain.
Definition: FrameDict.h:162
lsst::afw::geom::SkyWcs::linearizeSkyToPixel
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:289
lsst::afw::geom::SkyWcs::isFits
bool isFits() const
Return true getFitsMetadata(true) will succeed, false if not.
Definition: SkyWcs.cc:269
lsst::afw::geom::SkyWcs::getPersistenceName
std::string getPersistenceName() const override
Return the unique name used to persist this object and look up its factory.
Definition: SkyWcs.cc:382
lsst::afw::geom::SkyWcs::isFlipped
bool isFlipped() const
Does the WCS follow the convention of North=Up, East=Left?
Definition: SkyWcs.cc:301
lsst::afw::geom::SkyWcs::readString
static std::shared_ptr< SkyWcs > readString(std::string &str)
Deserialize a SkyWcs from a string, using the same format as readStream.
Definition: SkyWcs.cc:337
std::string
STL class.
std::shared_ptr
STL class.
Persistable.h
wcs
table::Key< table::Array< std::uint8_t > > wcs
Definition: SkyWcs.cc:71
lsst::sphgeom::orientation
int orientation(UnitVector3d const &a, UnitVector3d const &b, UnitVector3d const &c)
orientation computes and returns the orientations of 3 unit vectors a, b and c.
Definition: orientation.cc:135
std::vector
STL class.
AffineTransform.h
lsst::afw::geom::SkyWcs::toString
std::string toString() const override
Create a string representation of this object.
Definition: SkyWcs.cc:357
lsst::afw::geom::SkyWcs::copyAtShiftedPixelOrigin
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:213
lsst::afw
Definition: imageAlgorithm.dox:1
lsst::afw::geom::SkyWcs::isPersistable
bool isPersistable() const noexcept override
Return true if this particular object can be persisted using afw::table::io.
Definition: SkyWcs.h:268
ast::FrameDict
A FrameSet whose frames can be referenced by domain name.
Definition: FrameDict.h:67
lsst::afw::geom::SkyWcs::operator=
SkyWcs & operator=(SkyWcs const &)=delete
lsst::afw::geom::SkyWcs::getPythonModule
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:384
lsst::afw::geom::SkyWcs::skyToPixel
std::vector< lsst::geom::Point2D > skyToPixel(std::vector< lsst::geom::SpherePoint > const &sky) const
Definition: SkyWcs.h:352
strip
bool strip
Definition: fits.cc:911
lsst::afw::geom::makeModifiedWcs
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:491
lsst::afw::geom::SkyWcs::operator!=
bool operator!=(SkyWcs const &other) const
Definition: SkyWcs.h:136
lsst::afw::geom::SkyWcs
A 2-dimensional celestial WCS that transform pixels to ICRS RA/Dec, using the LSST standard for pixel...
Definition: SkyWcs.h:117
lsst::afw::typehandling::Storable
Interface supporting iteration over heterogenous containers.
Definition: Storable.h:58
Endpoint.h
crval
table::PointKey< double > crval
Definition: OldWcs.cc:130
astshim.h
Angle.h
lsst::afw::geom::SkyWcs::write
void write(OutputArchiveHandle &handle) const override
Write the object to one or more catalogs.
Definition: SkyWcs.cc:386
src
std::shared_ptr< RecordT > src
Definition: Match.cc:48
lsst::afw::geom::SkyWcs::cloneStorable
std::shared_ptr< typehandling::Storable > cloneStorable() const override
Create a new SkyWcs that is a copy of this one.
Definition: SkyWcs.cc:353
PropertyList.h
lsst::geom::AffineTransform
An affine coordinate transformation consisting of a linear transformation and an offset.
Definition: AffineTransform.h:75
lsst::afw::geom::SkyWcs::SkyWcs
SkyWcs(SkyWcs const &)=default
lsst::afw::geom::operator<<
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
Point.h
lsst::afw::geom::SkyWcs::SkyWcs
SkyWcs(SkyWcs &&)=default
lsst::afw::geom::getPixelToIntermediateWorldCoords
std::shared_ptr< TransformPoint2ToPoint2 > getPixelToIntermediateWorldCoords(SkyWcs const &wcs, bool simplify=true)
Return a transform from pixel coordinates to intermediate world coordinates.
Definition: SkyWcs.cc:564
lsst::afw::geom::SkyWcs::pixelToSky
std::vector< lsst::geom::SpherePoint > pixelToSky(std::vector< lsst::geom::Point2D > const &pixels) const
Definition: SkyWcs.h:340
lsst::afw::geom::SkyWcs::getShortClassName
static std::string getShortClassName()
Definition: SkyWcs.cc:299
lsst::afw::geom::SkyWcs::skyToPixel
lsst::geom::Point2D skyToPixel(lsst::geom::SpherePoint const &sky) const
Compute pixel position(s) from sky position(s)
Definition: SkyWcs.h:349
lsst::afw::geom::SkyWcs::operator==
bool operator==(SkyWcs const &other) const
Equality is based on the string representations being equal.
Definition: SkyWcs.cc:161
lsst::afw::geom::makeTanSipWcs
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:543
std::ostream
STL class.
x
double x
Definition: ChebyshevBoundedField.cc:277
crpix
table::PointKey< double > crpix
Definition: OldWcs.cc:131
lsst::afw::geom::SkyWcs::getCdMatrix
Eigen::Matrix2d getCdMatrix() const
Get the 2x2 CD matrix at the pixel origin.
Definition: SkyWcs.cc:204
other
ItemVariant const * other
Definition: Schema.cc:56
lsst::afw::geom::SkyWcs::equals
bool equals(typehandling::Storable const &other) const noexcept override
Compare this object to another Storable.
Definition: SkyWcs.cc:378
lsst::afw::geom::makeFlippedWcs
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:472
lsst::afw::geom::TransformPoint2ToPoint2
Transform< Point2Endpoint, Point2Endpoint > TransformPoint2ToPoint2
Definition: Transform.h:300
Transform.h
lsst::afw::geom::SkyWcs::operator=
SkyWcs & operator=(SkyWcs &&)=delete
Storable.h
pixel
table::PointKey< int > pixel
Definition: DeltaFunctionKernel.cc:101
lsst::afw::geom::SkyWcs::pixelToSky
lsst::geom::SpherePoint pixelToSky(lsst::geom::Point2D const &pixel) const
Compute sky position(s) from pixel position(s)
Definition: SkyWcs.h:334
lsst
A base class for image defects.
Definition: imageAlgorithm.dox:1
lsst::afw::geom::getIntermediateWorldCoordsToSky
std::shared_ptr< TransformPoint2ToSpherePoint > getIntermediateWorldCoordsToSky(SkyWcs const &wcs, bool simplify=true)
Return a transform from intermediate world coordinates to sky.
Definition: SkyWcs.cc:558
lsst::geom
Definition: AffineTransform.h:36
lsst::afw::geom::SkyWcs::linearizePixelToSky
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:280
os
std::ostream * os
Definition: Schema.cc:746
lsst::afw::geom::SkyWcs::getTanWcs
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:206
lsst::afw::geom::SkyWcs::getFrameDict
std::shared_ptr< const ast::FrameDict > getFrameDict() const
Get the contained FrameDict.
Definition: SkyWcs.cc:267
lsst::afw::geom::makeCdMatrix
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:138
lsst::afw::geom::makeWcsPairTransform
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:151
lsst::geom::Point
A coordinate class intended to represent absolute positions.
Definition: CoordinateBase.h:39
lsst::afw::geom::SkyWcs::getFitsMetadata
std::shared_ptr< daf::base::PropertyList > getFitsMetadata(bool precise=false) const
Return the WCS as FITS WCS metadata.
Definition: SkyWcs.cc:218
lsst::afw::table::io::PersistableFacade
A CRTP facade class for subclasses of Persistable.
Definition: Persistable.h:176
lsst::geom::AngleUnit
A class used to convert scalar POD types such as double to Angle.
Definition: Angle.h:70
lsst::afw::geom::SkyWcs::getPixelScale
lsst::geom::Angle getPixelScale() const
Get the pixel scale at the pixel origin.
Definition: SkyWcs.h:208
lsst::afw::geom::SkyWcs::hasFitsApproximation
bool hasFitsApproximation() const
Does this SkyWcs have an approximate SkyWcs that can be represented as standard FITS WCS?
Definition: SkyWcs.h:364
lsst::geom::Angle
A class representing an angle.
Definition: Angle.h:127
lsst::daf::base::PropertySet
Class for storing generic metadata.
Definition: PropertySet.h:67
lsst::afw.display.ds9.scale
def scale(algorithm, min, max=None, frame=None)
Definition: ds9.py:109
lsst::afw::geom::makeSkyWcs
std::shared_ptr< SkyWcs > makeSkyWcs(daf::base::PropertySet &metadata, bool strip=false)
Construct a SkyWcs from FITS keywords.
Definition: SkyWcs.cc:526
lsst::afw::geom::SkyWcs::getPixelOrigin
lsst::geom::Point2D getPixelOrigin() const
Get the pixel origin, in pixels, using the LSST convention.
Definition: SkyWcs.h:215
lsst::geom::SpherePoint
Point in an unspecified spherical coordinate system.
Definition: SpherePoint.h:57
lsst::afw::geom::SkyWcs::writeString
std::string writeString() const
Serialize this SkyWcs to a string, using the same format as writeStream.
Definition: SkyWcs.cc:347
lsst::afw::geom::SkyWcs::readStream
static std::shared_ptr< SkyWcs > readStream(std::istream &is)
Deserialize a SkyWcs from an input stream.
Definition: SkyWcs.cc:309
std::istream
STL class.
lsst::afw::geom::SkyWcs::getTransform
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:257
lsst::afw::geom::SkyWcs::getSkyOrigin
lsst::geom::SpherePoint getSkyOrigin() const
Get the sky origin, the celestial fiducial point.
Definition: SkyWcs.cc:187
lsst::afw::table::io::Persistable::OutputArchiveHandle
io::OutputArchiveHandle OutputArchiveHandle
Definition: Persistable.h:108
lsst::geom::Extent
A coordinate class intended to represent offsets and dimensions.
Definition: CoordinateBase.h:41
lsst::afw::geom::SkyWcs::writeStream
void writeStream(std::ostream &os) const
Serialize this SkyWcs to an output stream.
Definition: SkyWcs.cc:342
lsst::afw::geom::SkyWcs::~SkyWcs
~SkyWcs() override=default
lsst::afw::geom::SkyWcs::pixelToSky
lsst::geom::SpherePoint pixelToSky(double x, double y) const
Definition: SkyWcs.h:337