LSSTApplications  16.0-10-g0ee56ad+5,16.0-11-ga33d1f2+5,16.0-12-g3ef5c14+3,16.0-12-g71e5ef5+18,16.0-12-gbdf3636+3,16.0-13-g118c103+3,16.0-13-g8f68b0a+3,16.0-15-gbf5c1cb+4,16.0-16-gfd17674+3,16.0-17-g7c01f5c+3,16.0-18-g0a50484+1,16.0-20-ga20f992+8,16.0-21-g0e05fd4+6,16.0-21-g15e2d33+4,16.0-22-g62d8060+4,16.0-22-g847a80f+4,16.0-25-gf00d9b8+1,16.0-28-g3990c221+4,16.0-3-gf928089+3,16.0-32-g88a4f23+5,16.0-34-gd7987ad+3,16.0-37-gc7333cb+2,16.0-4-g10fc685+2,16.0-4-g18f3627+26,16.0-4-g5f3a788+26,16.0-5-gaf5c3d7+4,16.0-5-gcc1f4bb+1,16.0-6-g3b92700+4,16.0-6-g4412fcd+3,16.0-6-g7235603+4,16.0-69-g2562ce1b+2,16.0-8-g14ebd58+4,16.0-8-g2df868b+1,16.0-8-g4cec79c+6,16.0-8-gadf6c7a+1,16.0-8-gfc7ad86,16.0-82-g59ec2a54a+1,16.0-9-g5400cdc+2,16.0-9-ge6233d7+5,master-g2880f2d8cf+3,v17.0.rc1
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"
42 
43 namespace lsst {
44 namespace afw {
45 namespace geom {
46 
60 Eigen::Matrix2d makeCdMatrix(lsst::geom::Angle const &scale,
62  bool flipX = false);
63 
115 class SkyWcs final : public table::io::PersistableFacade<SkyWcs>, public table::io::Persistable {
116 public:
117  SkyWcs(SkyWcs const &) = default;
118  SkyWcs(SkyWcs &&) = default;
119  SkyWcs &operator=(SkyWcs const &) = delete;
120  SkyWcs &operator=(SkyWcs &&) = delete;
121  ~SkyWcs() override = default;
122 
133  bool operator==(SkyWcs const &other) const;
134  bool operator!=(SkyWcs const &other) const { return !(*this == other); }
135 
147  explicit SkyWcs(daf::base::PropertySet &metadata, bool strip = false);
148 
161  explicit SkyWcs(ast::FrameDict const &frameDict);
162 
171 
188  std::shared_ptr<daf::base::PropertyList> getFitsMetadata(bool precise = false) const;
189 
198 
206  lsst::geom::Angle getPixelScale() const { return _pixelScaleAtOrigin; };
207 
213  lsst::geom::Point2D getPixelOrigin() const { return _pixelOrigin; };
214 
221 
227  Eigen::Matrix2d getCdMatrix(lsst::geom::Point2D const &pixel) const;
228 
234  Eigen::Matrix2d getCdMatrix() const;
235 
240 
250 
256 
264  bool isFlipped() const;
265 
266  bool isPersistable() const noexcept override { return true; }
267 
281  lsst::geom::AngleUnit const &skyUnit) const;
282 
296  lsst::geom::AngleUnit const &skyUnit) const;
297 
311  lsst::geom::AngleUnit const &skyUnit) const;
312 
326  lsst::geom::AngleUnit const &skyUnit) const;
327 
333  return _transform->applyForward(pixel);
334  }
335  lsst::geom::SpherePoint pixelToSky(double x, double y) const {
336  return pixelToSky(lsst::geom::Point2D(x, y));
337  }
339  return _transform->applyForward(pixels);
340  }
342 
348  return _transform->applyInverse(sky);
349  }
351  return _transform->applyInverse(sky);
352  }
354 
356 
362  bool hasFitsApproximation() const { return false; }
363 
369  bool isFits() const;
370 
377 
380 
398  void writeStream(std::ostream &os) const;
399 
401  std::string writeString() const;
402 
403 protected:
404  // Override methods required by afw::table::io::Persistable
405  std::string getPersistenceName() const override;
406  std::string getPythonModule() const override;
407  void write(OutputArchiveHandle &handle) const override;
408 
409 private:
410  /*
411  * Construct a SkyWcs from a shared pointer to an ast::FrameDict
412  *
413  * The frameDict may be modified.
414  */
415  explicit SkyWcs(std::shared_ptr<ast::FrameDict> frameDict);
416 
417  /*
418  * Check a FrameDict to see if it can safely be used for a SkyWcs
419  * Return a copy so that it can be used as an argument to the SkyWcs(shared_ptr<FrameDict>) constructor
420  */
421  std::shared_ptr<ast::FrameDict> _checkFrameDict(ast::FrameDict const &frameDict) const;
422 
423  // the full FrameDict, for operations that need intermediate frames
425  // cached transform from _frameDict, for fast computation of pixels<->sky
427  lsst::geom::Point2D _pixelOrigin; // cached pixel origin
428  lsst::geom::Angle _pixelScaleAtOrigin; // cached pixel scale at pixel origin
429 
430  /*
431  * Implementation for the overloaded public linearizePixelToSky methods, requiring both a pixel coordinate
432  * and the corresponding sky coordinate.
433  */
434  lsst::geom::AffineTransform _linearizePixelToSky(lsst::geom::Point2D const &pix,
435  lsst::geom::SpherePoint const &coord,
436  lsst::geom::AngleUnit const &skyUnit) const;
437 
438  /*
439  * Implementation for the overloaded public linearizeSkyToPixel methods, requiring both a pixel coordinate
440  * and the corresponding sky coordinate.
441  */
442  lsst::geom::AffineTransform _linearizeSkyToPixel(lsst::geom::Point2D const &pix,
443  lsst::geom::SpherePoint const &coord,
444  lsst::geom::AngleUnit const &skyUnit) const;
445 
447  void _computeCache() {
448  _transform = std::make_shared<TransformPoint2ToSpherePoint>(*_frameDict->getMapping(), true);
449  _pixelOrigin = skyToPixel(getSkyOrigin());
450  _pixelScaleAtOrigin = getPixelScale(_pixelOrigin);
451  }
452 };
453 
462 std::shared_ptr<SkyWcs> makeFlippedWcs(SkyWcs const &wcs, bool flipLR, bool flipTB,
463  lsst::geom::Point2D const &center);
464 
492  bool modifyActualPixels);
493 
510 
522  Eigen::Matrix2d const &cdMatrix, std::string const &projection = "TAN");
523 
541  lsst::geom::Angle const &orientation, bool flipX,
542  lsst::geom::SpherePoint const &boresight,
543  std::string const &projection = "TAN");
544 
557  Eigen::Matrix2d const &cdMatrix, Eigen::MatrixXd const &sipA,
558  Eigen::MatrixXd const &sipB);
559 
574  Eigen::Matrix2d const &cdMatrix, Eigen::MatrixXd const &sipA,
575  Eigen::MatrixXd const &sipB, Eigen::MatrixXd const &sipAp,
576  Eigen::MatrixXd const &sipBp);
589 
594  bool simplify = true);
595 
602  bool simplify = true);
603 
610 
611 } // namespace geom
612 } // namespace afw
613 } // namespace lsst
614 
615 #endif
A 2-dimensional celestial WCS that transform pixels to ICRS RA/Dec, using the LSST standard for pixel...
Definition: SkyWcs.h:115
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:205
lsst::geom::Point2D skyToPixel(lsst::geom::SpherePoint const &sky) const
Compute pixel position(s) from sky position(s)
Definition: SkyWcs.h:347
bool isPersistable() const noexcept override
Return true if this particular object can be persisted using afw::table::io.
Definition: SkyWcs.h:266
An object passed to Persistable::write to allow it to persist itself.
An affine coordinate transformation consisting of a linear transformation and an offset.
lsst::geom::SpherePoint pixelToSky(lsst::geom::Point2D const &pixel) const
Compute sky position(s) from pixel position(s)
Definition: SkyWcs.h:332
bool isFits() const
Return true getFitsMetadata(true) will succeed, false if not.
Definition: SkyWcs.cc:248
table::PointKey< double > crpix
Definition: OldWcs.cc:131
def scale(algorithm, min, max=None, frame=None)
Definition: ds9.py:109
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
int y
Definition: SpanSet.cc:49
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:441
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:334
table::PointKey< double > crval
Definition: OldWcs.cc:130
std::vector< lsst::geom::SpherePoint > pixelToSky(std::vector< lsst::geom::Point2D > const &pixels) const
Compute sky position(s) from pixel position(s)
Definition: SkyWcs.h:338
lsst::geom::SpherePoint getSkyOrigin() const
Get the sky origin, the celestial fiducial point.
Definition: SkyWcs.cc:186
~SkyWcs() override=default
STL class.
std::shared_ptr< const ast::FrameDict > getFrameDict() const
Get the contained FrameDict.
Definition: SkyWcs.cc:246
A class representing an angle.
Definition: Angle.h:127
table::Key< table::Array< std::uint8_t > > wcs
Definition: SkyWcs.cc:71
STL class.
A base class for objects that can be persisted via afw::table::io Archive classes.
Definition: Persistable.h:74
std::string getPersistenceName() const override
Return the unique name used to persist this object and look up its factory.
Definition: SkyWcs.cc:332
Eigen::Matrix2d getCdMatrix() const
Get the 2x2 CD matrix at the pixel origin.
Definition: SkyWcs.cc:203
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:255
AngleUnit constexpr degrees
constant with units of degrees
Definition: Angle.h:109
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:362
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:422
static std::shared_ptr< SkyWcs > readStream(std::istream &is)
Deserialize a SkyWcs from an input stream.
Definition: SkyWcs.cc:288
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:259
std::vector< lsst::geom::Point2D > skyToPixel(std::vector< lsst::geom::SpherePoint > const &sky) const
Compute pixel position(s) from sky position(s)
Definition: SkyWcs.h:350
static std::string getShortClassName()
Definition: SkyWcs.cc:278
std::shared_ptr< TransformPoint2ToPoint2 > getPixelToIntermediateWorldCoords(SkyWcs const &wcs, bool simplify=true)
Return a transform from pixel coordinates to intermediate world coordinates.
Definition: SkyWcs.cc:514
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:493
std::shared_ptr< TransformPoint2ToSpherePoint > getIntermediateWorldCoordsToSky(SkyWcs const &wcs, bool simplify=true)
Return a transform from intermediate world coordinates to sky.
Definition: SkyWcs.cc:508
double x
std::shared_ptr< RecordT > src
Definition: Match.cc:48
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:212
bool operator!=(SkyWcs const &other) const
Definition: SkyWcs.h:134
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:152
STL class.
Point in an unspecified spherical coordinate system.
Definition: SpherePoint.h:57
static std::shared_ptr< SkyWcs > readString(std::string &str)
Deserialize a SkyWcs from a string, using the same format as readStream.
Definition: SkyWcs.cc:316
lsst::geom::Point2D getPixelOrigin() const
Get the pixel origin, in pixels, using the LSST convention.
Definition: SkyWcs.h:213
void write(OutputArchiveHandle &handle) const override
Write the object to one or more catalogs.
Definition: SkyWcs.cc:336
SkyWcs(SkyWcs const &)=default
Class for storing generic metadata.
Definition: PropertySet.h:68
std::string writeString() const
Serialize this SkyWcs to a string, using the same format as writeStream.
Definition: SkyWcs.cc:326
std::shared_ptr< SkyWcs > makeSkyWcs(daf::base::PropertySet &metadata, bool strip=false)
Construct a SkyWcs from FITS keywords.
Definition: SkyWcs.cc:476
std::shared_ptr< daf::base::PropertyList > getFitsMetadata(bool precise=false) const
Return the WCS as FITS WCS metadata.
Definition: SkyWcs.cc:217
lsst::geom::SpherePoint pixelToSky(double x, double y) const
Compute sky position(s) from pixel position(s)
Definition: SkyWcs.h:335
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:139
table::PointKey< int > pixel
void writeStream(std::ostream &os) const
Serialize this SkyWcs to an output stream.
Definition: SkyWcs.cc:321
ItemVariant const * other
Definition: Schema.cc:56
bool isFlipped() const
Does the WCS follow the convention of North=Up, East=Left?
Definition: SkyWcs.cc:280
SkyWcs & operator=(SkyWcs const &)=delete
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:268
lsst::geom::Angle getPixelScale() const
Get the pixel scale at the pixel origin.
Definition: SkyWcs.h:206
A FrameSet whose frames can be referenced by domain name.
Definition: FrameDict.h:67
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.
Definition: SkyWcs.cc:162
bool strip
Definition: fits.cc:831
A class used to convert scalar POD types such as double to Angle.
Definition: Angle.h:70
std::ostream * os
Definition: Schema.cc:746
Transform LSST spatial data, such as lsst::geom::Point2D and lsst::geom::SpherePoint, using an AST mapping.
Definition: Transform.h:67