lsst.afw  14.0-42-g99f9a3040+1
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 
186 
194  Angle getPixelScale(Point2D const &pixel) const;
195 
203  Angle getPixelScale() const { return _pixelScaleAtOrigin; };
204 
210  Point2D getPixelOrigin() const { return _pixelOrigin; };
211 
218 
224  Eigen::Matrix2d getCdMatrix(Point2D const &pixel) const;
225 
231  Eigen::Matrix2d getCdMatrix() const;
232 
236  std::shared_ptr<SkyWcs> getTanWcs(Point2D const &pixel) const;
237 
245 
250 
258  bool isFlipped() const;
259 
260  bool isPersistable() const override { return true; }
261 
274  AffineTransform linearizePixelToSky(coord::IcrsCoord const &coord, AngleUnit const &skyUnit) const;
275 
288  AffineTransform linearizePixelToSky(Point2D const &pixel, AngleUnit const &skyUnit) const;
289 
302  AffineTransform linearizeSkyToPixel(coord::IcrsCoord const &coord, AngleUnit const &skyUnit) const;
303 
316  AffineTransform linearizeSkyToPixel(Point2D const &pixel, AngleUnit const &skyUnit) const;
317 
322  coord::IcrsCoord pixelToSky(Point2D const &pixel) const { return _transform->applyForward(pixel); }
323  coord::IcrsCoord pixelToSky(double x, double y) const { return pixelToSky(Point2D(x, y)); }
325  return _transform->applyForward(pixels);
326  }
328 
333  Point2D skyToPixel(coord::IcrsCoord const &sky) const { return _transform->applyInverse(sky); }
335  return _transform->applyInverse(sky);
336  }
338 
340 
346  bool hasFitsApproximation() const { return false; }
347 
353  bool isFits() const;
354 
361 
364 
382  void writeStream(std::ostream &os) const;
383 
385  std::string writeString() const;
386 
387 protected:
388  // Override methods required by afw::table::io::Persistable
389  std::string getPersistenceName() const override;
390  std::string getPythonModule() const override;
391  void write(OutputArchiveHandle &handle) const override;
392 
393 private:
394  /*
395  * Construct a SkyWcs from a shared pointer to an ast::FrameDict
396  *
397  * The frameDict may be modified.
398  */
399  explicit SkyWcs(std::shared_ptr<ast::FrameDict> frameDict);
400 
401  /*
402  * Check a FrameDict to see if it can safely be used for a SkyWcs
403  * Return a copy so that it can be used as an argument to the SkyWcs(shared_ptr<FrameDict>) constructor
404  */
405  std::shared_ptr<ast::FrameDict> _checkFrameDict(ast::FrameDict const &frameDict) const;
406 
408  Point2D _pixelOrigin; // cached pixel origin
409  Angle _pixelScaleAtOrigin; // cached pixel scale at pixel origin
410 
411  /*
412  * Implementation for the overloaded public linearizePixelToSky methods, requiring both a pixel coordinate
413  * and the corresponding sky coordinate.
414  */
415  AffineTransform _linearizePixelToSky(Point2D const &pix, coord::IcrsCoord const &coord,
416  AngleUnit const &skyUnit) const;
417 
418  /*
419  * Implementation for the overloaded public linearizeSkyToPixel methods, requiring both a pixel coordinate
420  * and the corresponding sky coordinate.
421  */
422  AffineTransform _linearizeSkyToPixel(Point2D const &pix, coord::IcrsCoord const &coord,
423  AngleUnit const &skyUnit) const;
424 
426  void _computeCache() {
427  _pixelOrigin = skyToPixel(getSkyOrigin());
428  _pixelScaleAtOrigin = getPixelScale(_pixelOrigin);
429  }
430 };
431 
440 std::shared_ptr<SkyWcs> makeFlippedWcs(SkyWcs const &wcs, bool flipLR, bool flipTB,
441  geom::Point2D const &center);
442 
470  bool modifyActualPixels);
471 
487 std::shared_ptr<SkyWcs> makeSkyWcs(daf::base::PropertySet &metadata, bool strip = false);
488 
500  Eigen::Matrix2d const &cdMatrix, std::string const &projection = "TAN");
501 
514  Eigen::Matrix2d const &cdMatrix, Eigen::MatrixXd const &sipA,
515  Eigen::MatrixXd const &sipB);
516 
531  Eigen::Matrix2d const &cdMatrix, Eigen::MatrixXd const &sipA,
532  Eigen::MatrixXd const &sipB, Eigen::MatrixXd const &sipAp,
533  Eigen::MatrixXd const &sipBp);
546 
551  bool simplify = true);
552 
559  bool simplify = true);
560 
561 } // namespace geom
562 } // namespace afw
563 } // namespace lsst
564 
565 #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.
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.
table::PointKey< double > crval
Definition: Wcs.cc:934
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:324
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:346
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:203
static std::string getShortClassName()
double x
coord::IcrsCoord pixelToSky(Point2D const &pixel) const
Compute sky position(s) from pixel position(s)
Definition: SkyWcs.h:322
Point2D skyToPixel(coord::IcrsCoord const &sky) const
Compute pixel position(s) from sky position(s)
Definition: SkyWcs.h:333
std::vector< Point2D > skyToPixel(std::vector< coord::IcrsCoord > const &sky) const
Compute pixel position(s) from sky position(s)
Definition: SkyWcs.h:334
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:210
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.
std::shared_ptr< daf::base::PropertyList > getFitsMetadata(bool precise) const
Return the WCS as FITS WCS metadata.
bool isPersistable() const override
Return true if this particular object can be persisted using afw::table::io.
Definition: SkyWcs.h:260
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:323
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:249
table::PointKey< double > crpix
Definition: Wcs.cc:935