lsst.afw  14.0-34-g2d9284d60+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 
131  bool operator==(SkyWcs const &other) const;
132  bool operator!=(SkyWcs const &other) const { return !(*this == other); }
133 
145  explicit SkyWcs(daf::base::PropertySet &metadata, bool strip = false);
146 
159  explicit SkyWcs(ast::FrameDict const &frameDict);
160 
169 
185 
193  Angle getPixelScale(Point2D const &pixel) const;
194 
202  Angle getPixelScale() const { return _pixelScaleAtOrigin; };
203 
209  Point2D getPixelOrigin() const { return _pixelOrigin; };
210 
217 
223  Eigen::Matrix2d getCdMatrix(Point2D const &pixel) const;
224 
230  Eigen::Matrix2d getCdMatrix() const;
231 
235  std::shared_ptr<SkyWcs> getTanWcs(Point2D const &pixel) const;
236 
244 
249 
257  bool isFlipped() const;
258 
259  bool isPersistable() const override { return true; }
260 
273  AffineTransform linearizePixelToSky(coord::IcrsCoord const &coord, AngleUnit const &skyUnit) const;
274 
287  AffineTransform linearizePixelToSky(Point2D const &pixel, AngleUnit const &skyUnit) const;
288 
301  AffineTransform linearizeSkyToPixel(coord::IcrsCoord const &coord, AngleUnit const &skyUnit) const;
302 
315  AffineTransform linearizeSkyToPixel(Point2D const &pixel, AngleUnit const &skyUnit) const;
316 
321  coord::IcrsCoord pixelToSky(Point2D const &pixel) const { return _transform->applyForward(pixel); }
322  coord::IcrsCoord pixelToSky(double x, double y) const { return pixelToSky(Point2D(x, y)); }
324  return _transform->applyForward(pixels);
325  }
327 
332  Point2D skyToPixel(coord::IcrsCoord const &sky) const { return _transform->applyInverse(sky); }
334  return _transform->applyInverse(sky);
335  }
337 
339 
345  bool hasFitsApproximation() const { return false; }
346 
352  bool isFits() const;
353 
360 
363 
381  void writeStream(std::ostream &os) const;
382 
384  std::string writeString() const;
385 
386 protected:
387  // Override methods required by afw::table::io::Persistable
388  std::string getPersistenceName() const override;
389  std::string getPythonModule() const override;
390  void write(OutputArchiveHandle &handle) const override;
391 
392 private:
393  /*
394  * Construct a SkyWcs from a shared pointer to an ast::FrameDict
395  *
396  * The frameDict may be modified.
397  */
398  explicit SkyWcs(std::shared_ptr<ast::FrameDict> frameDict);
399 
400  /*
401  * Check a FrameDict to see if it can safely be used for a SkyWcs
402  * Return a copy so that it can be used as an argument to the SkyWcs(shared_ptr<FrameDict>) constructor
403  */
404  std::shared_ptr<ast::FrameDict> _checkFrameDict(ast::FrameDict const &frameDict) const;
405 
407  Point2D _pixelOrigin; // cached pixel origin
408  Angle _pixelScaleAtOrigin; // cached pixel scale at pixel origin
409 
410  /*
411  * Implementation for the overloaded public linearizePixelToSky methods, requiring both a pixel coordinate
412  * and the corresponding sky coordinate.
413  */
414  AffineTransform _linearizePixelToSky(Point2D const &pix, coord::IcrsCoord const &coord,
415  AngleUnit const &skyUnit) const;
416 
417  /*
418  * Implementation for the overloaded public linearizeSkyToPixel methods, requiring both a pixel coordinate
419  * and the corresponding sky coordinate.
420  */
421  AffineTransform _linearizeSkyToPixel(Point2D const &pix, coord::IcrsCoord const &coord,
422  AngleUnit const &skyUnit) const;
423 
425  void _computeCache() {
426  _pixelOrigin = skyToPixel(getSkyOrigin());
427  _pixelScaleAtOrigin = getPixelScale(_pixelOrigin);
428  }
429 };
430 
439 std::shared_ptr<SkyWcs> makeFlippedWcs(SkyWcs const &wcs, bool flipLR, bool flipTB,
440  geom::Point2D const &center);
441 
469  bool modifyActualPixels);
470 
486 std::shared_ptr<SkyWcs> makeSkyWcs(daf::base::PropertySet &metadata, bool strip = false);
487 
499  Eigen::Matrix2d const &cdMatrix, std::string const &projection = "TAN");
500 
513  Eigen::Matrix2d const &cdMatrix, Eigen::MatrixXd const &sipA,
514  Eigen::MatrixXd const &sipB);
515 
530  Eigen::Matrix2d const &cdMatrix, Eigen::MatrixXd const &sipA,
531  Eigen::MatrixXd const &sipB, Eigen::MatrixXd const &sipAp,
532  Eigen::MatrixXd const &sipBp);
545 
550  bool simplify = true);
551 
558  bool simplify = true);
559 
560 } // namespace geom
561 } // namespace afw
562 } // namespace lsst
563 
564 #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:929
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:323
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:345
Point< double, 2 > Point2D
Definition: Point.h:273
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:202
static std::string getShortClassName()
double x
coord::IcrsCoord pixelToSky(Point2D const &pixel) const
Compute sky position(s) from pixel position(s)
Definition: SkyWcs.h:321
Point2D skyToPixel(coord::IcrsCoord const &sky) const
Compute pixel position(s) from sky position(s)
Definition: SkyWcs.h:332
std::vector< Point2D > skyToPixel(std::vector< coord::IcrsCoord > const &sky) const
Compute pixel position(s) from sky position(s)
Definition: SkyWcs.h:333
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:132
Point2D getPixelOrigin() const
Get the pixel origin, in pixels, using the LSST convention.
Definition: SkyWcs.h:209
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:259
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:174
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:288
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:322
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:248
table::PointKey< double > crpix
Definition: Wcs.cc:930