LSST Applications g04e9c324dd+8c5ae1fdc5,g134cb467dc+1b3060144d,g18429d2f64+f642bf4753,g199a45376c+0ba108daf9,g1fd858c14a+2dcf163641,g262e1987ae+7b8c96d2ca,g29ae962dfc+3bd6ecb08a,g2cef7863aa+aef1011c0b,g35bb328faa+8c5ae1fdc5,g3fd5ace14f+53e1a9e7c5,g4595892280+fef73a337f,g47891489e3+2efcf17695,g4d44eb3520+642b70b07e,g53246c7159+8c5ae1fdc5,g67b6fd64d1+2efcf17695,g67fd3c3899+b70e05ef52,g74acd417e5+317eb4c7d4,g786e29fd12+668abc6043,g87389fa792+8856018cbb,g89139ef638+2efcf17695,g8d7436a09f+3be3c13596,g8ea07a8fe4+9f5ccc88ac,g90f42f885a+a4e7b16d9b,g97be763408+ad77d7208f,g9dd6db0277+b70e05ef52,ga681d05dcb+a3f46e7fff,gabf8522325+735880ea63,gac2eed3f23+2efcf17695,gb89ab40317+2efcf17695,gbf99507273+8c5ae1fdc5,gd8ff7fe66e+b70e05ef52,gdab6d2f7ff+317eb4c7d4,gdc713202bf+b70e05ef52,gdfd2d52018+b10e285e0f,ge365c994fd+310e8507c4,ge410e46f29+2efcf17695,geaed405ab2+562b3308c0,gffca2db377+8c5ae1fdc5,w.2025.35
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/Point.h"
44
45namespace lsst {
46namespace afw {
47namespace geom {
48
62Eigen::Matrix2d makeCdMatrix(lsst::geom::Angle const &scale,
63 lsst::geom::Angle const &orientation = 0 * lsst::geom::degrees,
64 bool flipX = false);
65
118class SkyWcs final : public table::io::PersistableFacade<SkyWcs>, public typehandling::Storable {
119public:
120 SkyWcs(SkyWcs const &) = default;
121 SkyWcs(SkyWcs &&) = default;
122 SkyWcs &operator=(SkyWcs const &) = delete;
123 SkyWcs &operator=(SkyWcs &&) = delete;
124 ~SkyWcs() override = default;
125
136 bool operator==(SkyWcs const &other) const;
137 bool operator!=(SkyWcs const &other) const { return !(*this == other); }
138
150 explicit SkyWcs(daf::base::PropertySet &metadata, bool strip = false);
151
164 explicit SkyWcs(ast::FrameDict const &frameDict);
165
174
191
200
208 lsst::geom::Angle getPixelScale() const { return _pixelScaleAtOrigin; };
209
215 lsst::geom::Point2D getPixelOrigin() const { return _pixelOrigin; };
216
223
229 Eigen::Matrix2d getCdMatrix(lsst::geom::Point2D const &pixel) const;
230
236 Eigen::Matrix2d getCdMatrix() const;
237
242
252
258
266 bool isFlipped() const;
267
268 bool isPersistable() const noexcept override { return true; }
269
283 lsst::geom::AngleUnit const &skyUnit) const;
284
298 lsst::geom::AngleUnit const &skyUnit) const;
299
313 lsst::geom::AngleUnit const &skyUnit) const;
314
328 lsst::geom::AngleUnit const &skyUnit) const;
329
335 return _transform->applyForward(pixel);
336 }
337 lsst::geom::SpherePoint pixelToSky(double x, double y) const {
338 return pixelToSky(lsst::geom::Point2D(x, y));
339 }
341 return _transform->applyForward(pixels);
342 }
343
344
350 return _transform->applyInverse(sky);
351 }
353 return _transform->applyInverse(sky);
354 }
355
356
358
362 bool hasFitsApproximation() const { return bool(_fitsApproximation); }
363
369 std::shared_ptr<SkyWcs> getFitsApproximation() const { return _fitsApproximation; }
370
375
381 bool isFits() const;
382
389
392
410 void writeStream(std::ostream &os) const;
411
413 std::string writeString() const;
414
415 // Override methods required by afw::typehandling::Storable
416
419
430 std::string toString() const override;
431
437 bool equals(typehandling::Storable const &other) const noexcept override;
438
439protected:
440 // Override methods required by afw::table::io::Persistable
441 std::string getPersistenceName() const override;
442 std::string getPythonModule() const override;
443 void write(OutputArchiveHandle &handle) const override;
444
445private:
446 /*
447 * Construct a SkyWcs from a shared pointer to an ast::FrameDict
448 *
449 * The frameDict may be modified.
450 */
451 explicit SkyWcs(std::shared_ptr<ast::FrameDict> frameDict);
452
453 /*
454 * Check a FrameDict to see if it can safely be used for a SkyWcs
455 * Return a copy so that it can be used as an argument to the SkyWcs(shared_ptr<FrameDict>) constructor
456 */
457 std::shared_ptr<ast::FrameDict> _checkFrameDict(ast::FrameDict const &frameDict) const;
458
459 // the full FrameDict, for operations that need intermediate frames
461 // cached transform from _frameDict, for fast computation of pixels<->sky
463 lsst::geom::Point2D _pixelOrigin; // cached pixel origin
464 lsst::geom::Angle _pixelScaleAtOrigin; // cached pixel scale at pixel origin
465
466 std::shared_ptr<SkyWcs> _fitsApproximation;
467
468 /*
469 * Implementation for the overloaded public linearizePixelToSky methods, requiring both a pixel coordinate
470 * and the corresponding sky coordinate.
471 */
472 lsst::geom::AffineTransform _linearizePixelToSky(lsst::geom::Point2D const &pix,
474 lsst::geom::AngleUnit const &skyUnit) const;
475
476 /*
477 * Implementation for the overloaded public linearizeSkyToPixel methods, requiring both a pixel coordinate
478 * and the corresponding sky coordinate.
479 */
480 lsst::geom::AffineTransform _linearizeSkyToPixel(lsst::geom::Point2D const &pix,
482 lsst::geom::AngleUnit const &skyUnit) const;
483
484 /*
485 * Compute the FITS representation of this WCS (without falling back to a FITS approximation) or return
486 * a null pointer if it is not FITS-compatible.
487 */
488 std::shared_ptr<daf::base::PropertyList> _getDirectFitsMetadata() const;
489
491 void _computeCache() {
492 _transform = std::make_shared<TransformPoint2ToSpherePoint>(*_frameDict->getMapping(), true);
493 _pixelOrigin = skyToPixel(getSkyOrigin());
494 _pixelScaleAtOrigin = getPixelScale(_pixelOrigin);
495 }
496};
497
506std::shared_ptr<SkyWcs> makeFlippedWcs(SkyWcs const &wcs, bool flipLR, bool flipTB,
507 lsst::geom::Point2D const &center);
508
535std::shared_ptr<SkyWcs> makeModifiedWcs(TransformPoint2ToPoint2 const &pixelTransform, SkyWcs const &wcs,
536 bool modifyActualPixels);
537
553std::shared_ptr<SkyWcs> makeSkyWcs(daf::base::PropertySet &metadata, bool strip = false);
554
566 Eigen::Matrix2d const &cdMatrix, std::string const &projection = "TAN");
567
585 lsst::geom::Angle const &orientation, bool flipX,
586 lsst::geom::SpherePoint const &boresight,
587 std::string const &projection = "TAN");
588
601 Eigen::Matrix2d const &cdMatrix, Eigen::MatrixXd const &sipA,
602 Eigen::MatrixXd const &sipB);
603
618 Eigen::Matrix2d const &cdMatrix, Eigen::MatrixXd const &sipA,
619 Eigen::MatrixXd const &sipB, Eigen::MatrixXd const &sipAp,
620 Eigen::MatrixXd const &sipBp);
632std::shared_ptr<TransformPoint2ToPoint2> makeWcsPairTransform(SkyWcs const &src, SkyWcs const &dst);
633
638 bool simplify = true);
639
646 bool simplify = true);
647
651std::ostream &operator<<(std::ostream &os, SkyWcs const &wcs);
652
653} // namespace geom
654} // namespace afw
655} // namespace lsst
656
657#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:223
static std::shared_ptr< SkyWcs > readStream(std::istream &is)
Deserialize a SkyWcs from an input stream.
Definition SkyWcs.cc:323
SkyWcs & operator=(SkyWcs const &)=delete
std::shared_ptr< const ast::FrameDict > getFrameDict() const
Get the contained FrameDict.
Definition SkyWcs.cc:280
lsst::geom::SpherePoint pixelToSky(lsst::geom::Point2D const &pixel) const
Compute sky position(s) from pixel position(s)
Definition SkyWcs.h:334
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:303
std::string toString() const override
Create a string representation of this object.
Definition SkyWcs.cc:371
bool isFlipped() const
Does the WCS follow the convention of North=Up, East=Left?
Definition SkyWcs.cc:315
std::shared_ptr< typehandling::Storable > cloneStorable() const override
Create a new SkyWcs that is a copy of this one.
Definition SkyWcs.cc:367
lsst::geom::Angle getPixelScale() const
Get the pixel scale at the pixel origin.
Definition SkyWcs.h:208
bool isPersistable() const noexcept override
Return true if this particular object can be persisted using afw::table::io.
Definition SkyWcs.h:268
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:216
lsst::geom::Point2D getPixelOrigin() const
Get the pixel origin, in pixels, using the LSST convention.
Definition SkyWcs.h:215
void writeStream(std::ostream &os) const
Serialize this SkyWcs to an output stream.
Definition SkyWcs.cc:356
std::string writeString() const
Serialize this SkyWcs to a string, using the same format as writeStream.
Definition SkyWcs.cc:361
Eigen::Matrix2d getCdMatrix() const
Get the 2x2 CD matrix at the pixel origin.
Definition SkyWcs.cc:214
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:294
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:257
bool operator!=(SkyWcs const &other) const
Definition SkyWcs.h:137
lsst::geom::Point2D skyToPixel(lsst::geom::SpherePoint const &sky) const
Compute pixel position(s) from sky position(s)
Definition SkyWcs.h:349
lsst::geom::SpherePoint pixelToSky(double x, double y) const
Definition SkyWcs.h:337
static std::string getShortClassName()
Definition SkyWcs.cc:313
bool isFits() const
Return true getFitsMetadata(true) will succeed, false if not.
Definition SkyWcs.cc:292
bool hasFitsApproximation() const
Does this SkyWcs have an approximate SkyWcs that can be represented as standard FITS WCS?
Definition SkyWcs.h:362
SkyWcs & operator=(SkyWcs &&)=delete
std::shared_ptr< SkyWcs > getFitsApproximation() const
Return FITS SkyWcs that approximates this one.
Definition SkyWcs.h:369
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:398
std::string getPersistenceName() const override
Return the unique name used to persist this object and look up its factory.
Definition SkyWcs.cc:396
lsst::geom::SpherePoint getSkyOrigin() const
Get the sky origin, the celestial fiducial point.
Definition SkyWcs.cc:197
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:282
static std::shared_ptr< SkyWcs > readString(std::string &str)
Deserialize a SkyWcs from a string, using the same format as readStream.
Definition SkyWcs.cc:351
std::vector< lsst::geom::SpherePoint > pixelToSky(std::vector< lsst::geom::Point2D > const &pixels) const
Definition SkyWcs.h:340
std::vector< lsst::geom::Point2D > skyToPixel(std::vector< lsst::geom::SpherePoint > const &sky) const
Definition SkyWcs.h:352
std::shared_ptr< daf::base::PropertyList > getFitsMetadata(bool precise=false) const
Return the WCS as FITS WCS metadata.
Definition SkyWcs.cc:267
void write(OutputArchiveHandle &handle) const override
Write the object to one or more catalogs.
Definition SkyWcs.cc:400
bool equals(typehandling::Storable const &other) const noexcept override
Compare this object to another Storable.
Definition SkyWcs.cc:392
bool operator==(SkyWcs const &other) const
Equality is based on the string representations being equal.
Definition SkyWcs.cc:171
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
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:543
std::shared_ptr< TransformPoint2ToPoint2 > getPixelToIntermediateWorldCoords(SkyWcs const &wcs, bool simplify=true)
Return a transform from pixel coordinates to intermediate world coordinates.
Definition SkyWcs.cc:581
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:560
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:148
std::shared_ptr< TransformPoint2ToSpherePoint > getIntermediateWorldCoordsToSky(SkyWcs const &wcs, bool simplify=true)
Return a transform from intermediate world coordinates to sky.
Definition SkyWcs.cc:575
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:508
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:161
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:489
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