LSST Applications 30.0.7,g0e76e35be5+e8e946ae08,g19811a7679+138f7293ba,g199a45376c+5e234f8357,g1fd858c14a+2f48dbc4c4,g262e1987ae+fb36cac54d,g29ae962dfc+d9108a0941,g2c21b0017a+4f59a27f16,g31e44d4a5c+b0138be388,g33ac35c1f1+28b9f72785,g35bb328faa+b0138be388,g40c9b15c53+823ad735c1,g47891489e3+bcc48a0b46,g53246c7159+b0138be388,g64539dfbff+e8e946ae08,g67b6fd64d1+bcc48a0b46,g74acd417e5+422380537a,g76965917b2+a5ca99c4d9,g786e29fd12+796b79145d,g7aefaa3e3d+dc0c200193,g86b635cae8+734fe384f0,g87389fa792+d8b5378923,g89139ef638+bcc48a0b46,g8bbb235e95+3f4f7f9447,g8ea07a8fe4+78a4c88802,g9290983e33+ffdc83c6f7,g92c671f44c+e8e946ae08,gaa753fd333+03f406da14,gbf99507273+b0138be388,gc49b57b85e+8df26ee1f0,gca7fc764a6+bcc48a0b46,gd7ef33dd92+bcc48a0b46,gdab6d2f7ff+422380537a,ge1c02a5578+b0138be388,ge410e46f29+bcc48a0b46,ge80df9fc40+e6db5413d1,geaed405ab2+1de65a85c6,gf5dcc679e7+35a0ce2edd,gf5f1c85443+e8e946ae08
LSST Data Management Base Package
Loading...
Searching...
No Matches
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 <optional>
29#include <utility>
30#include <vector>
31
32#include "Eigen/Core"
33#include "astshim.h"
34#include "ndarray.h"
35
38#include "lsst/geom/Angle.h"
39#include "lsst/geom/Box.h"
40#include "lsst/geom/Point.h"
45
46namespace lsst {
47namespace afw {
48namespace geom {
49
63Eigen::Matrix2d makeCdMatrix(lsst::geom::Angle const &scale,
64 lsst::geom::Angle const &orientation = 0 * lsst::geom::degrees,
65 bool flipX = false);
66
119class SkyWcs final : public table::io::PersistableFacade<SkyWcs>, public typehandling::Storable {
120public:
121 SkyWcs(SkyWcs const &) = default;
122 SkyWcs(SkyWcs &&) = default;
123 SkyWcs &operator=(SkyWcs const &) = delete;
124 SkyWcs &operator=(SkyWcs &&) = delete;
125 ~SkyWcs() override = default;
126
137 bool operator==(SkyWcs const &other) const;
138 bool operator!=(SkyWcs const &other) const { return !(*this == other); }
139
151 explicit SkyWcs(daf::base::PropertySet &metadata, bool strip = false);
152
165 explicit SkyWcs(ast::FrameDict const &frameDict);
166
175
196 bool precise = false,
199 )
200 ) const;
201
210
218 lsst::geom::Angle getPixelScale() const { return _pixelScaleAtOrigin; };
219
225 lsst::geom::Point2D getPixelOrigin() const { return _pixelOrigin; };
226
233
239 Eigen::Matrix2d getCdMatrix(lsst::geom::Point2D const &pixel) const;
240
246 Eigen::Matrix2d getCdMatrix() const;
247
252
262
268
276 bool isFlipped() const;
277
278 bool isPersistable() const noexcept override { return true; }
279
293 lsst::geom::AngleUnit const &skyUnit) const;
294
308 lsst::geom::AngleUnit const &skyUnit) const;
309
323 lsst::geom::AngleUnit const &skyUnit) const;
324
338 lsst::geom::AngleUnit const &skyUnit) const;
339
345 return _transform->applyForward(pixel);
346 }
347 lsst::geom::SpherePoint pixelToSky(double x, double y) const {
348 return pixelToSky(lsst::geom::Point2D(x, y));
349 }
351 return _transform->applyForward(pixels);
352 }
353
354
360 return _transform->applyInverse(sky);
361 }
363 return _transform->applyInverse(sky);
364 }
365
366
368
372 bool hasFitsApproximation() const { return bool(_fitsApproximation); }
373
379 std::shared_ptr<SkyWcs> getFitsApproximation() const { return _fitsApproximation; }
380
385
391 bool isFits() const;
392
399
402
420 void writeStream(std::ostream &os) const;
421
423 std::string writeString() const;
424
425 // Override methods required by afw::typehandling::Storable
426
429
440 std::string toString() const override;
441
447 bool equals(typehandling::Storable const &other) const noexcept override;
448
449protected:
450 // Override methods required by afw::table::io::Persistable
451 std::string getPersistenceName() const override;
452 std::string getPythonModule() const override;
453 void write(OutputArchiveHandle &handle) const override;
454
455private:
456 /*
457 * Construct a SkyWcs from a shared pointer to an ast::FrameDict
458 *
459 * The frameDict may be modified.
460 */
461 explicit SkyWcs(std::shared_ptr<ast::FrameDict> frameDict);
462
463 /*
464 * Check a FrameDict to see if it can safely be used for a SkyWcs
465 * Return a copy so that it can be used as an argument to the SkyWcs(shared_ptr<FrameDict>) constructor
466 */
467 std::shared_ptr<ast::FrameDict> _checkFrameDict(ast::FrameDict const &frameDict) const;
468
469 // the full FrameDict, for operations that need intermediate frames
471 // cached transform from _frameDict, for fast computation of pixels<->sky
473 lsst::geom::Point2D _pixelOrigin; // cached pixel origin
474 lsst::geom::Angle _pixelScaleAtOrigin; // cached pixel scale at pixel origin
475
476 std::shared_ptr<SkyWcs> _fitsApproximation;
477
478 /*
479 * Implementation for the overloaded public linearizePixelToSky methods, requiring both a pixel coordinate
480 * and the corresponding sky coordinate.
481 */
482 lsst::geom::AffineTransform _linearizePixelToSky(lsst::geom::Point2D const &pix,
484 lsst::geom::AngleUnit const &skyUnit) const;
485
486 /*
487 * Implementation for the overloaded public linearizeSkyToPixel methods, requiring both a pixel coordinate
488 * and the corresponding sky coordinate.
489 */
490 lsst::geom::AffineTransform _linearizeSkyToPixel(lsst::geom::Point2D const &pix,
492 lsst::geom::AngleUnit const &skyUnit) const;
493
494 /*
495 * Compute the FITS representation of this WCS (without falling back to a FITS approximation) or return
496 * a null pointer if it is not FITS-compatible.
497 */
498 std::shared_ptr<daf::base::PropertyList> _getDirectFitsMetadata(lsst::geom::Box2I const & bbox) const;
499
501 void _computeCache() {
502 _transform = std::make_shared<TransformPoint2ToSpherePoint>(*_frameDict->getMapping(), true);
503 _pixelOrigin = skyToPixel(getSkyOrigin());
504 _pixelScaleAtOrigin = getPixelScale(_pixelOrigin);
505 }
506};
507
516std::shared_ptr<SkyWcs> makeFlippedWcs(SkyWcs const &wcs, bool flipLR, bool flipTB,
517 lsst::geom::Point2D const &center);
518
545std::shared_ptr<SkyWcs> makeModifiedWcs(TransformPoint2ToPoint2 const &pixelTransform, SkyWcs const &wcs,
546 bool modifyActualPixels);
547
563std::shared_ptr<SkyWcs> makeSkyWcs(daf::base::PropertySet &metadata, bool strip = false);
564
576 Eigen::Matrix2d const &cdMatrix, std::string const &projection = "TAN");
577
595 lsst::geom::Angle const &orientation, bool flipX,
596 lsst::geom::SpherePoint const &boresight,
597 std::string const &projection = "TAN");
598
611 Eigen::Matrix2d const &cdMatrix, Eigen::MatrixXd const &sipA,
612 Eigen::MatrixXd const &sipB);
613
628 Eigen::Matrix2d const &cdMatrix, Eigen::MatrixXd const &sipA,
629 Eigen::MatrixXd const &sipB, Eigen::MatrixXd const &sipAp,
630 Eigen::MatrixXd const &sipBp);
642std::shared_ptr<TransformPoint2ToPoint2> makeWcsPairTransform(SkyWcs const &src, SkyWcs const &dst);
643
648 bool simplify = true);
649
656 bool simplify = true);
657
661std::ostream &operator<<(std::ostream &os, SkyWcs const &wcs);
662
663} // namespace geom
664} // namespace afw
665} // namespace lsst
666
667#endif
A FrameSet whose frames can be referenced by domain name.
Definition FrameDict.h:67
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:224
static std::shared_ptr< SkyWcs > readStream(std::istream &is)
Deserialize a SkyWcs from an input stream.
Definition SkyWcs.cc:340
SkyWcs & operator=(SkyWcs const &)=delete
std::shared_ptr< const ast::FrameDict > getFrameDict() const
Get the contained FrameDict.
Definition SkyWcs.cc:293
lsst::geom::SpherePoint pixelToSky(lsst::geom::Point2D const &pixel) const
Compute sky position(s) from pixel position(s)
Definition SkyWcs.h:344
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:320
std::string toString() const override
Create a string representation of this object.
Definition SkyWcs.cc:388
bool isFlipped() const
Does the WCS follow the convention of North=Up, East=Left?
Definition SkyWcs.cc:332
std::shared_ptr< typehandling::Storable > cloneStorable() const override
Create a new SkyWcs that is a copy of this one.
Definition SkyWcs.cc:384
lsst::geom::Angle getPixelScale() const
Get the pixel scale at the pixel origin.
Definition SkyWcs.h:218
bool isPersistable() const noexcept override
Return true if this particular object can be persisted using afw::table::io.
Definition SkyWcs.h:278
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:217
lsst::geom::Point2D getPixelOrigin() const
Get the pixel origin, in pixels, using the LSST convention.
Definition SkyWcs.h:225
void writeStream(std::ostream &os) const
Serialize this SkyWcs to an output stream.
Definition SkyWcs.cc:373
std::string writeString() const
Serialize this SkyWcs to a string, using the same format as writeStream.
Definition SkyWcs.cc:378
Eigen::Matrix2d getCdMatrix() const
Get the 2x2 CD matrix at the pixel origin.
Definition SkyWcs.cc:215
SkyWcs(SkyWcs const &)=default
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:311
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:267
bool operator!=(SkyWcs const &other) const
Definition SkyWcs.h:138
lsst::geom::Point2D skyToPixel(lsst::geom::SpherePoint const &sky) const
Compute pixel position(s) from sky position(s)
Definition SkyWcs.h:359
lsst::geom::SpherePoint pixelToSky(double x, double y) const
Definition SkyWcs.h:347
static std::string getShortClassName()
Definition SkyWcs.cc:330
bool isFits() const
Return true getFitsMetadata(true) will succeed with no arguments, false if not.
Definition SkyWcs.cc:305
bool hasFitsApproximation() const
Does this SkyWcs have an approximate SkyWcs that can be represented as standard FITS WCS?
Definition SkyWcs.h:372
SkyWcs & operator=(SkyWcs &&)=delete
std::shared_ptr< SkyWcs > getFitsApproximation() const
Return FITS SkyWcs that approximates this one.
Definition SkyWcs.h:379
SkyWcs(SkyWcs &&)=default
~SkyWcs() override=default
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:415
std::string getPersistenceName() const override
Return the unique name used to persist this object and look up its factory.
Definition SkyWcs.cc:413
std::shared_ptr< daf::base::PropertyList > getFitsMetadata(bool precise=false, lsst::geom::Box2I const &bbox=lsst::geom::Box2I(lsst::geom::Point2I(0, 0), lsst::geom::Extent2I(100, 100))) const
Return the WCS as FITS WCS metadata.
Definition SkyWcs.cc:278
lsst::geom::SpherePoint getSkyOrigin() const
Get the sky origin, the celestial fiducial point.
Definition SkyWcs.cc:198
std::shared_ptr< SkyWcs > copyWithFitsApproximation(std::shared_ptr< SkyWcs > fitsApproximation) const
Return a copy of this SkyWcs with the given FITS approximation.
Definition SkyWcs.cc:295
static std::shared_ptr< SkyWcs > readString(std::string &str)
Deserialize a SkyWcs from a string, using the same format as readStream.
Definition SkyWcs.cc:368
std::vector< lsst::geom::SpherePoint > pixelToSky(std::vector< lsst::geom::Point2D > const &pixels) const
Definition SkyWcs.h:350
std::vector< lsst::geom::Point2D > skyToPixel(std::vector< lsst::geom::SpherePoint > const &sky) const
Definition SkyWcs.h:362
void write(OutputArchiveHandle &handle) const override
Write the object to one or more catalogs.
Definition SkyWcs.cc:417
bool equals(typehandling::Storable const &other) const noexcept override
Compare this object to another Storable.
Definition SkyWcs.cc:409
bool operator==(SkyWcs const &other) const
Equality is based on the string representations being equal.
Definition SkyWcs.cc:172
A CRTP facade class for subclasses of Persistable.
io::OutputArchiveHandle OutputArchiveHandle
Interface supporting iteration over heterogenous containers.
Definition Storable.h:58
Class for storing generic metadata.
Definition PropertySet.h:67
An affine coordinate transformation consisting of a linear transformation and an offset.
A class representing an angle.
Definition Angle.h:128
A class used to convert scalar POD types such as double to Angle.
Definition Angle.h:71
An integer coordinate rectangle.
Definition Box.h:55
Point in an unspecified spherical coordinate system.
Definition SpherePoint.h:57
T make_shared(T... args)
std::shared_ptr< SkyWcs > makeSkyWcs(daf::base::PropertySet &metadata, bool strip=false)
Construct a SkyWcs from FITS keywords.
Definition SkyWcs.cc:560
std::shared_ptr< TransformPoint2ToPoint2 > getPixelToIntermediateWorldCoords(SkyWcs const &wcs, bool simplify=true)
Return a transform from pixel coordinates to intermediate world coordinates.
Definition SkyWcs.cc:598
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:577
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:239
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:149
std::shared_ptr< TransformPoint2ToSpherePoint > getIntermediateWorldCoordsToSky(SkyWcs const &wcs, bool simplify=true)
Return a transform from intermediate world coordinates to sky.
Definition SkyWcs.cc:592
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:525
Transform< Point2Endpoint, Point2Endpoint > TransformPoint2ToPoint2
Definition Transform.h:300
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:162
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:506
AngleUnit constexpr degrees
constant with units of degrees
Definition Angle.h:110
Extent< double, 2 > Extent2D
Definition Extent.h:400
Point< double, 2 > Point2D
Definition Point.h:324
Extent< int, 2 > Extent2I
Definition Extent.h:397
Point< int, 2 > Point2I
Definition Point.h:321