lsst.afw  14.0-58-g91bfccb15
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 
36 #include "lsst/afw/coord/Coord.h"
38 #include "lsst/afw/geom/Angle.h"
39 #include "lsst/afw/geom/Point.h"
40 #include "lsst/afw/geom/Endpoint.h"
43 
44 namespace lsst {
45 namespace afw {
46 namespace geom {
47 
61 Eigen::Matrix2d makeCdMatrix(Angle const &scale, Angle const &orientation = 0 * degrees, bool flipX = false);
62 
114 class SkyWcs final : public table::io::PersistableFacade<SkyWcs>, public table::io::Persistable {
115 public:
116  SkyWcs(SkyWcs const &) = default;
117  SkyWcs(SkyWcs &&) = default;
118  SkyWcs &operator=(SkyWcs const &) = delete;
119  SkyWcs &operator=(SkyWcs &&) = delete;
120  ~SkyWcs() = default;
121 
132  bool operator==(SkyWcs const &other) const;
133  bool operator!=(SkyWcs const &other) const { return !(*this == other); }
134 
146  explicit SkyWcs(daf::base::PropertySet &metadata, bool strip = false);
147 
160  explicit SkyWcs(ast::FrameDict const &frameDict);
161 
170 
187  std::shared_ptr<daf::base::PropertyList> getFitsMetadata(bool precise = false) const;
188 
196  Angle getPixelScale(Point2D const &pixel) const;
197 
205  Angle getPixelScale() const { return _pixelScaleAtOrigin; };
206 
212  Point2D getPixelOrigin() const { return _pixelOrigin; };
213 
220 
226  Eigen::Matrix2d getCdMatrix(Point2D const &pixel) const;
227 
233  Eigen::Matrix2d getCdMatrix() const;
234 
238  std::shared_ptr<SkyWcs> getTanWcs(Point2D const &pixel) const;
239 
247 
252 
260  bool isFlipped() const;
261 
262  bool isPersistable() const override { return true; }
263 
276  AffineTransform linearizePixelToSky(coord::IcrsCoord const &coord, AngleUnit const &skyUnit) const;
277 
290  AffineTransform linearizePixelToSky(Point2D const &pixel, AngleUnit const &skyUnit) const;
291 
304  AffineTransform linearizeSkyToPixel(coord::IcrsCoord const &coord, AngleUnit const &skyUnit) const;
305 
318  AffineTransform linearizeSkyToPixel(Point2D const &pixel, AngleUnit const &skyUnit) const;
319 
324  coord::IcrsCoord pixelToSky(Point2D const &pixel) const { return _transform->applyForward(pixel); }
325  coord::IcrsCoord pixelToSky(double x, double y) const { return pixelToSky(Point2D(x, y)); }
327  return _transform->applyForward(pixels);
328  }
330 
335  Point2D skyToPixel(coord::IcrsCoord const &sky) const { return _transform->applyInverse(sky); }
337  return _transform->applyInverse(sky);
338  }
340 
342 
348  bool hasFitsApproximation() const { return false; }
349 
355  bool isFits() const;
356 
363 
366 
384  void writeStream(std::ostream &os) const;
385 
387  std::string writeString() const;
388 
389 protected:
390  // Override methods required by afw::table::io::Persistable
391  std::string getPersistenceName() const override;
392  std::string getPythonModule() const override;
393  void write(OutputArchiveHandle &handle) const override;
394 
395 private:
396  /*
397  * Construct a SkyWcs from a shared pointer to an ast::FrameDict
398  *
399  * The frameDict may be modified.
400  */
401  explicit SkyWcs(std::shared_ptr<ast::FrameDict> frameDict);
402 
403  /*
404  * Check a FrameDict to see if it can safely be used for a SkyWcs
405  * Return a copy so that it can be used as an argument to the SkyWcs(shared_ptr<FrameDict>) constructor
406  */
407  std::shared_ptr<ast::FrameDict> _checkFrameDict(ast::FrameDict const &frameDict) const;
408 
410  Point2D _pixelOrigin; // cached pixel origin
411  Angle _pixelScaleAtOrigin; // cached pixel scale at pixel origin
412 
413  /*
414  * Implementation for the overloaded public linearizePixelToSky methods, requiring both a pixel coordinate
415  * and the corresponding sky coordinate.
416  */
417  AffineTransform _linearizePixelToSky(Point2D const &pix, coord::IcrsCoord const &coord,
418  AngleUnit const &skyUnit) const;
419 
420  /*
421  * Implementation for the overloaded public linearizeSkyToPixel methods, requiring both a pixel coordinate
422  * and the corresponding sky coordinate.
423  */
424  AffineTransform _linearizeSkyToPixel(Point2D const &pix, coord::IcrsCoord const &coord,
425  AngleUnit const &skyUnit) const;
426 
428  void _computeCache() {
429  _pixelOrigin = skyToPixel(getSkyOrigin());
430  _pixelScaleAtOrigin = getPixelScale(_pixelOrigin);
431  }
432 };
433 
442 std::shared_ptr<SkyWcs> makeFlippedWcs(SkyWcs const &wcs, bool flipLR, bool flipTB,
443  geom::Point2D const &center);
444 
472  bool modifyActualPixels);
473 
489 std::shared_ptr<SkyWcs> makeSkyWcs(daf::base::PropertySet &metadata, bool strip = false);
490 
502  Eigen::Matrix2d const &cdMatrix, std::string const &projection = "TAN");
503 
516  Eigen::Matrix2d const &cdMatrix, Eigen::MatrixXd const &sipA,
517  Eigen::MatrixXd const &sipB);
518 
533  Eigen::Matrix2d const &cdMatrix, Eigen::MatrixXd const &sipA,
534  Eigen::MatrixXd const &sipB, Eigen::MatrixXd const &sipAp,
535  Eigen::MatrixXd const &sipBp);
548 
553  bool simplify = true);
554 
561  bool simplify = true);
562 
568 std::ostream &operator<<(std::ostream &os, SkyWcs const &wcs);
569 
570 } // namespace geom
571 } // namespace afw
572 } // namespace lsst
573 
574 #endif
coord::IcrsCoord getSkyOrigin() const
Get the sky origin, the celestial fiducial point.
std::shared_ptr< TransformPoint2ToPoint2 > makeWcsPairTransform(SkyWcs const &src, SkyWcs const &dst)
A Transform obtained by putting two SkyWcs objects "back to back".
A 2-dimensional celestial WCS that transform pixels to ICRS RA/Dec, using the LSST standard for pixel...
Definition: SkyWcs.h:114
lsst::afw::geom::Angle Angle
Definition: misc.h:36
std::shared_ptr< SkyWcs > getTanWcs(Point2D const &pixel) const
Get a local TAN WCS approximation to this WCS at the specified pixel position.
std::shared_ptr< SkyWcs > makeTanSipWcs(Point2D const &crpix, coord::IcrsCoord 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.
An object passed to Persistable::write to allow it to persist itself.
std::ostream & operator<<(std::ostream &os, lsst::afw::geom::AffineTransform const &transform)
bool isFits() const
Return true getFitsMetadata(true) will succeed, false if not.
def scale(algorithm, min, max=None, frame=None)
Definition: ds9.py:117
AngleUnit constexpr degrees
constant with units of degrees
Definition: Angle.h:88
AffineTransform linearizeSkyToPixel(coord::IcrsCoord const &coord, AngleUnit const &skyUnit) const
Return the local linear approximation to skyToPixel at a point given in sky coordinates.
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.
std::string getPythonModule() const override
Return the fully-qualified Python module that should be imported to guarantee that its factory is reg...
A class used to convert scalar POD types such as double to Angle.
Definition: Angle.h:52
STL class.
std::vector< coord::IcrsCoord > pixelToSky(std::vector< Point2D > const &pixels) const
Compute sky position(s) from pixel position(s)
Definition: SkyWcs.h:326
STL class.
A base class for objects that can be persisted via afw::table::io Archive classes.
Definition: Persistable.h:74
std::shared_ptr< const ast::FrameDict > getFrameDict() const
Get the contained FrameDict.
std::string getPersistenceName() const override
Return the unique name used to persist this object and look up its factory.
Eigen::Matrix2d getCdMatrix() const
Get the 2x2 CD matrix at the pixel origin.
A class representing an angle.
Definition: Angle.h:102
static std::shared_ptr< SkyWcs > readStream(std::istream &is)
Deserialize a SkyWcs from an input stream.
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:348
Point< double, 2 > Point2D
Definition: Point.h:300
std::shared_ptr< SkyWcs > makeSkyWcs(daf::base::PropertySet &metadata, bool strip=false)
Construct a SkyWcs from FITS keywords.
An affine coordinate transformation consisting of a linear transformation and an offset.
Angle getPixelScale() const
Get the pixel scale at the pixel origin.
Definition: SkyWcs.h:205
static std::string getShortClassName()
double x
coord::IcrsCoord pixelToSky(Point2D const &pixel) const
Compute sky position(s) from pixel position(s)
Definition: SkyWcs.h:324
Point2D skyToPixel(coord::IcrsCoord const &sky) const
Compute pixel position(s) from sky position(s)
Definition: SkyWcs.h:335
std::vector< Point2D > skyToPixel(std::vector< coord::IcrsCoord > const &sky) const
Compute pixel position(s) from sky position(s)
Definition: SkyWcs.h:336
static std::shared_ptr< SkyWcs > readString(std::string &str)
Deserialize a SkyWcs from a string, using the same format as readStream.
std::shared_ptr< SkyWcs > copyAtShiftedPixelOrigin(Extent2D const &shift) const
Return a copy of this SkyWcs with the pixel origin shifted by the specified amount.
bool operator!=(SkyWcs const &other) const
Definition: SkyWcs.h:133
Point2D getPixelOrigin() const
Get the pixel origin, in pixels, using the LSST convention.
Definition: SkyWcs.h:212
STL class.
AffineTransform linearizePixelToSky(coord::IcrsCoord const &coord, AngleUnit const &skyUnit) const
Return the local linear approximation to pixelToSky at a point given in sky coordinates.
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.
void write(OutputArchiveHandle &handle) const override
Write the object to one or more catalogs.
SkyWcs(SkyWcs const &)=default
std::string writeString() const
Serialize this SkyWcs to a string, using the same format as writeStream.
bool isPersistable() const override
Return true if this particular object can be persisted using afw::table::io.
Definition: SkyWcs.h:262
Eigen::Matrix2d makeCdMatrix(Angle const &scale, Angle const &orientation=0 *degrees, bool flipX=false)
Make a WCS CD matrix.
table::PointKey< int > pixel
void writeStream(std::ostream &os) const
Serialize this SkyWcs to an output stream.
bool isFlipped() const
Does the WCS follow the convention of North=Up, East=Left?
SkyWcs & operator=(SkyWcs const &)=delete
A CRTP facade class for subclasses of Persistable.
Definition: Persistable.h:176
STL class.
bool operator==(SkyWcs const &other) const
Equality is based on the string representations being equal.
A class to handle Icrs coordinates (inherits from Coord)
Definition: Coord.h:291
std::shared_ptr< TransformPoint2ToPoint2 > getPixelToIntermediateWorldCoords(SkyWcs const &wcs, bool simplify=true)
Return a transform from pixel coordinates to intermediate world coordinates.
std::shared_ptr< TransformPoint2ToIcrsCoord > getIntermediateWorldCoordsToSky(SkyWcs const &wcs, bool simplify=true)
Return a transform from intermediate world coordinates to sky.
coord::IcrsCoord pixelToSky(double x, double y) const
Compute sky position(s) from pixel position(s)
Definition: SkyWcs.h:325
Transform LSST spatial data, such as Point2D and IcrsCoord, using an AST transform.
Definition: Transform.h:69
std::shared_ptr< const TransformPoint2ToIcrsCoord > getTransform() const
Get the contained TransformPoint2ToIcrsCoord.
Definition: SkyWcs.h:251
std::shared_ptr< daf::base::PropertyList > getFitsMetadata(bool precise=false) const
Return the WCS as FITS WCS metadata.