lsst.afw  14.0-60-ga423a1d65+2
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/afw/geom/Angle.h"
38 #include "lsst/afw/geom/Point.h"
39 #include "lsst/afw/geom/Endpoint.h"
42 
43 namespace lsst {
44 namespace afw {
45 namespace geom {
46 
60 Eigen::Matrix2d makeCdMatrix(Angle const &scale, Angle const &orientation = 0 * degrees, bool flipX = false);
61 
113 class SkyWcs final : public table::io::PersistableFacade<SkyWcs>, public table::io::Persistable {
114 public:
115  SkyWcs(SkyWcs const &) = default;
116  SkyWcs(SkyWcs &&) = default;
117  SkyWcs &operator=(SkyWcs const &) = delete;
118  SkyWcs &operator=(SkyWcs &&) = delete;
119  ~SkyWcs() = default;
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 
186  std::shared_ptr<daf::base::PropertyList> getFitsMetadata(bool precise = false) const;
187 
195  Angle getPixelScale(Point2D const &pixel) const;
196 
204  Angle getPixelScale() const { return _pixelScaleAtOrigin; };
205 
211  Point2D getPixelOrigin() const { return _pixelOrigin; };
212 
218  SpherePoint getSkyOrigin() const;
219 
225  Eigen::Matrix2d getCdMatrix(Point2D const &pixel) const;
226 
232  Eigen::Matrix2d getCdMatrix() const;
233 
237  std::shared_ptr<SkyWcs> getTanWcs(Point2D const &pixel) const;
238 
246 
251 
259  bool isFlipped() const;
260 
261  bool isPersistable() const override { return true; }
262 
275  AffineTransform linearizePixelToSky(SpherePoint const &coord, AngleUnit const &skyUnit) const;
276 
289  AffineTransform linearizePixelToSky(Point2D const &pixel, AngleUnit const &skyUnit) const;
290 
303  AffineTransform linearizeSkyToPixel(SpherePoint const &coord, AngleUnit const &skyUnit) const;
304 
317  AffineTransform linearizeSkyToPixel(Point2D const &pixel, AngleUnit const &skyUnit) const;
318 
323  SpherePoint pixelToSky(Point2D const &pixel) const { return _transform->applyForward(pixel); }
324  SpherePoint pixelToSky(double x, double y) const { return pixelToSky(Point2D(x, y)); }
326  return _transform->applyForward(pixels);
327  }
329 
334  Point2D skyToPixel(SpherePoint const &sky) const { return _transform->applyInverse(sky); }
336  return _transform->applyInverse(sky);
337  }
339 
341 
347  bool hasFitsApproximation() const { return false; }
348 
354  bool isFits() const;
355 
362 
365 
383  void writeStream(std::ostream &os) const;
384 
386  std::string writeString() const;
387 
388 protected:
389  // Override methods required by afw::table::io::Persistable
390  std::string getPersistenceName() const override;
391  std::string getPythonModule() const override;
392  void write(OutputArchiveHandle &handle) const override;
393 
394 private:
395  /*
396  * Construct a SkyWcs from a shared pointer to an ast::FrameDict
397  *
398  * The frameDict may be modified.
399  */
400  explicit SkyWcs(std::shared_ptr<ast::FrameDict> frameDict);
401 
402  /*
403  * Check a FrameDict to see if it can safely be used for a SkyWcs
404  * Return a copy so that it can be used as an argument to the SkyWcs(shared_ptr<FrameDict>) constructor
405  */
406  std::shared_ptr<ast::FrameDict> _checkFrameDict(ast::FrameDict const &frameDict) const;
407 
409  Point2D _pixelOrigin; // cached pixel origin
410  Angle _pixelScaleAtOrigin; // cached pixel scale at pixel origin
411 
412  /*
413  * Implementation for the overloaded public linearizePixelToSky methods, requiring both a pixel coordinate
414  * and the corresponding sky coordinate.
415  */
416  AffineTransform _linearizePixelToSky(Point2D const &pix, SpherePoint const &coord,
417  AngleUnit const &skyUnit) const;
418 
419  /*
420  * Implementation for the overloaded public linearizeSkyToPixel methods, requiring both a pixel coordinate
421  * and the corresponding sky coordinate.
422  */
423  AffineTransform _linearizeSkyToPixel(Point2D const &pix, SpherePoint const &coord,
424  AngleUnit const &skyUnit) const;
425 
427  void _computeCache() {
428  _pixelOrigin = skyToPixel(getSkyOrigin());
429  _pixelScaleAtOrigin = getPixelScale(_pixelOrigin);
430  }
431 };
432 
441 std::shared_ptr<SkyWcs> makeFlippedWcs(SkyWcs const &wcs, bool flipLR, bool flipTB,
442  geom::Point2D const &center);
443 
471  bool modifyActualPixels);
472 
488 std::shared_ptr<SkyWcs> makeSkyWcs(daf::base::PropertySet &metadata, bool strip = false);
489 
500 std::shared_ptr<SkyWcs> makeSkyWcs(Point2D const &crpix, SpherePoint const &crval,
501  Eigen::Matrix2d const &cdMatrix, std::string const &projection = "TAN");
502 
514 std::shared_ptr<SkyWcs> makeTanSipWcs(Point2D const &crpix, SpherePoint const &crval,
515  Eigen::Matrix2d const &cdMatrix, Eigen::MatrixXd const &sipA,
516  Eigen::MatrixXd const &sipB);
517 
531 std::shared_ptr<SkyWcs> makeTanSipWcs(Point2D const &crpix, SpherePoint const &crval,
532  Eigen::Matrix2d const &cdMatrix, Eigen::MatrixXd const &sipA,
533  Eigen::MatrixXd const &sipB, Eigen::MatrixXd const &sipAp,
534  Eigen::MatrixXd const &sipBp);
547 
552  bool simplify = true);
553 
560  bool simplify = true);
561 
567 std::ostream &operator<<(std::ostream &os, SkyWcs const &wcs);
568 
569 } // namespace geom
570 } // namespace afw
571 } // namespace lsst
572 
573 #endif
Point in an unspecified spherical coordinate system.
Definition: SpherePoint.h:59
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:113
lsst::afw::geom::Angle Angle
Definition: misc.h:33
std::shared_ptr< SkyWcs > getTanWcs(Point2D const &pixel) const
Get a local TAN WCS approximation to this WCS at the specified pixel position.
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
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...
std::shared_ptr< TransformPoint2ToSpherePoint > getIntermediateWorldCoordsToSky(SkyWcs const &wcs, bool simplify=true)
Return a transform from intermediate world coordinates to sky.
A class used to convert scalar POD types such as double to Angle.
Definition: Angle.h:52
STL class.
std::vector< SpherePoint > pixelToSky(std::vector< Point2D > const &pixels) const
Compute sky position(s) from pixel position(s)
Definition: SkyWcs.h:325
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.
std::shared_ptr< SkyWcs > makeTanSipWcs(Point2D const &crpix, 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.
std::shared_ptr< const TransformPoint2ToSpherePoint > getTransform() const
Get the contained TransformPoint2ToSpherePoint.
Definition: SkyWcs.h:250
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:347
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.
std::vector< Point2D > skyToPixel(std::vector< SpherePoint > const &sky) const
Compute pixel position(s) from sky position(s)
Definition: SkyWcs.h:335
SpherePoint pixelToSky(double x, double y) const
Compute sky position(s) from pixel position(s)
Definition: SkyWcs.h:324
Angle getPixelScale() const
Get the pixel scale at the pixel origin.
Definition: SkyWcs.h:204
static std::string getShortClassName()
double x
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.
AffineTransform linearizeSkyToPixel(SpherePoint const &coord, AngleUnit const &skyUnit) const
Return the local linear approximation to skyToPixel at a point given in sky coordinates.
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:211
STL class.
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.
SpherePoint pixelToSky(Point2D const &pixel) const
Compute sky position(s) from pixel position(s)
Definition: SkyWcs.h:323
void write(OutputArchiveHandle &handle) const override
Write the object to one or more catalogs.
Point2D skyToPixel(SpherePoint const &sky) const
Compute pixel position(s) from sky position(s)
Definition: SkyWcs.h:334
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:261
AffineTransform linearizePixelToSky(SpherePoint const &coord, AngleUnit const &skyUnit) const
Return the local linear approximation to pixelToSky at a point given in sky coordinates.
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.
SpherePoint getSkyOrigin() const
Get the sky origin, the celestial fiducial point.
bool operator==(SkyWcs const &other) const
Equality is based on the string representations being equal.
std::shared_ptr< TransformPoint2ToPoint2 > getPixelToIntermediateWorldCoords(SkyWcs const &wcs, bool simplify=true)
Return a transform from pixel coordinates to intermediate world coordinates.
Transform LSST spatial data, such as Point2D and SpherePoint, using an AST transform.
Definition: Transform.h:69
std::shared_ptr< daf::base::PropertyList > getFitsMetadata(bool precise=false) const
Return the WCS as FITS WCS metadata.