LSSTApplications  11.0-22-g33de520,13.0+153,14.0+52,14.0+57,14.0-1-g013352c+36,14.0-1-g13ef843+9,14.0-1-g4b114ac+14,14.0-1-g7257b6a+12,14.0-1-g8b7e855+51,14.0-13-g7a60b79+2,14.0-14-g87d16e8+10,14.0-14-gbf7a6f8a,14.0-17-g4f4ea82+5,14.0-2-g319577b+11,14.0-2-ga5af9b6+10,14.0-22-gc48c03f+3,14.0-3-g20413be+3,14.0-46-g76222d5f+3,14.0-47-g0a51fac97,14.0-5-g744ff5f+2,14.0-5-g86eb1bd+31,14.0-6-gd5b81a9+6,14.0-6-ge2c9487+42,14.0-8-g7f6dd6b+6,14.0-8-gb81b6e9+4,14.0-9-g11010eb,14.0-9-g330837b+5
LSSTDataManagementBasePackage
Wcs.h
Go to the documentation of this file.
1 // -*- LSST-C++ -*-
2 
3 /*
4  * LSST Data Management System
5  * Copyright 2008, 2009, 2010 LSST Corporation.
6  *
7  * This product includes software developed by the
8  * LSST Project (http://www.lsst.org/).
9  *
10  * This program is free software: you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation, either version 3 of the License, or
13  * (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the LSST License Statement and
21  * the GNU General Public License along with this program. If not,
22  * see <http://www.lsstcorp.org/LegalNotices/>.
23  */
24 
25 #ifndef LSST_AFW_IMAGE_WCS_H
26 #define LSST_AFW_IMAGE_WCS_H
27 
28 #include <limits>
29 #include "Eigen/Core"
30 #include "lsst/base.h"
32 #include "lsst/daf/base/Citizen.h"
33 #include "lsst/afw/image/Image.h"
34 #include "lsst/afw/coord/Coord.h"
36 #include "lsst/afw/geom/Point.h"
37 #include "lsst/afw/geom/Extent.h"
40 
41 struct wcsprm; // defined in wcs.h
42 
43 namespace lsst {
44 namespace daf {
45 namespace base {
46 class PropertySet;
47 }
48 }
49 namespace afw {
50 namespace formatters {
51 class WcsFormatter;
52 }
53 namespace table {
54 class BaseRecord;
55 }
56 namespace image {
57 
103 
108 public:
115  bool stripMetadata);
116 
133  Eigen::Matrix2d const& CD, std::string const& ctype1 = "RA---TAN",
134  std::string const& ctype2 = "DEC--TAN", double equinox = 2000, std::string const& raDecSys = "ICRS",
135  std::string const& cunits1 = "deg", std::string const& cunits2 = "deg");
136 
137  virtual ~Wcs();
138  virtual std::shared_ptr<Wcs> clone(void) const;
139 
140  bool operator==(Wcs const& other) const;
141  bool operator!=(Wcs const& other) const { return !(*this == other); }
142 
144  std::shared_ptr<lsst::afw::coord::Coord> getSkyOrigin() const;
145 
147  lsst::afw::geom::Point2D getPixelOrigin() const;
148 
150  Eigen::Matrix2d getCDMatrix() const;
151 
153  virtual void flipImage(int flipLR, int flipTB, lsst::afw::geom::Extent2I dimensions) const;
154 
156  virtual void rotateImageBy90(int nQuarter, lsst::afw::geom::Extent2I dimensions) const;
157 
159  virtual std::shared_ptr<lsst::daf::base::PropertyList> getFitsMetadata() const;
160 
169  bool isFlipped() const;
170 
175  double pixArea(lsst::afw::geom::Point2D pix00) const;
176 
178  geom::Angle pixelScale() const;
179 
187  std::shared_ptr<coord::Coord> pixelToSky(double pix1, double pix2) const;
188 
197 
204  void pixelToSky(double pixel1, double pixel2, geom::Angle& sky1, geom::Angle& sky2) const;
205 
215  geom::Point2D skyToPixel(geom::Angle sky1, geom::Angle sky2) const;
216 
218  geom::Point2D skyToPixel(coord::Coord const& coord) const;
219 
225  geom::Point2D skyToIntermediateWorldCoord(coord::Coord const& coord) const;
226 
227  virtual bool hasDistortion() const { return false; };
228 
229  afw::coord::CoordSystem getCoordSystem() const { return _coordSystem; };
230 
231  double getEquinox() const;
232 
240  bool isSameSkySystem(Wcs const& wcs) const;
241 
245  geom::LinearTransform getLinearTransform() const;
246 
262  geom::AffineTransform linearizePixelToSky(coord::Coord const& coord,
263  geom::AngleUnit skyUnit = geom::degrees) const;
264 
280  geom::AffineTransform linearizePixelToSky(geom::Point2D const& pix,
281  geom::AngleUnit skyUnit = geom::degrees) const;
282 
298  geom::AffineTransform linearizeSkyToPixel(coord::Coord const& coord,
299  geom::AngleUnit skyUnit = geom::degrees) const;
300 
316  geom::AffineTransform linearizeSkyToPixel(geom::Point2D const& pix,
317  geom::AngleUnit skyUnit = geom::degrees) const;
318 
319  // Mutators; the first one is virtual, even though it will never be overridden,
320  // to make sure subclasses use the correct version of both
321 
330  virtual void shiftReferencePixel(double dx, double dy);
331 
332  // Virtual to make sure subclasses use the correct version of both shiftReferencePixel mutators.
333  virtual void shiftReferencePixel(geom::Extent2D const& d) { shiftReferencePixel(d.getX(), d.getY()); }
334 
336  virtual bool isPersistable() const;
337 
338 private:
339  // Allow the formatter to access private goo
341 
342 
354  void initWcsLib(geom::Point2D const& crval, geom::Point2D const& crpix, Eigen::Matrix2d const& CD,
355  std::string const& ctype1, std::string const& ctype2, double equinox,
356  std::string const& raDecSys, std::string const& cunits1, std::string const& cunits2);
357 
358 protected:
359  friend class WcsFactory;
361  bool _mayBePersistable() const;
362  // See afw::table::io::Persistable
363  virtual std::string getPersistenceName() const;
364  virtual std::string getPythonModule() const;
365  virtual void write(OutputArchiveHandle& handle) const;
366 
367  // Protected virtual implementation for operator== (must be true in both directions for equality).
368  virtual bool _isSubset(Wcs const& other) const;
369 
370  // Return true if coordinate system is ICRS or FK5 J2000
371  bool _isIcrs() const {
372  return (getCoordSystem() == afw::coord::ICRS) ||
373  ((getCoordSystem() == afw::coord::FK5) && (getEquinox() == 2000));
374  }
375 
376  // Default constructor, only used by WcsFormatter
378  Wcs();
379 
380  // If you want to create a Wcs from a FITS header, use makeWcs().
381  // This is protected because the derived classes need to be able to see it.
388 
389  // Construct from a record; used by WcsFactory for afw::table::io persistence.
390  explicit Wcs(afw::table::BaseRecord const& record);
391 
393  Wcs(Wcs const& rhs);
394  Wcs(Wcs&& rhs);
395  Wcs& operator=(const Wcs&);
396  Wcs& operator=(Wcs&&);
397 
401  virtual void pixelToSkyImpl(double pixel1, double pixel2, geom::Angle skyTmp[2]) const;
408  virtual geom::Point2D skyToPixelImpl(geom::Angle sky1, geom::Angle sky2) const;
409 
414  std::shared_ptr<afw::coord::Coord> makeCorrectCoord(geom::Angle sky0, geom::Angle sky1) const;
415 
420  std::shared_ptr<afw::coord::Coord> convertCoordToSky(coord::Coord const& coord) const;
421 
426  virtual geom::AffineTransform linearizePixelToSkyInternal(geom::Point2D const& pix,
427  coord::Coord const& coord,
428  geom::AngleUnit skyUnit) const;
429 
434  virtual geom::AffineTransform linearizeSkyToPixelInternal(geom::Point2D const& pix,
435  coord::Coord const& coord,
436  geom::AngleUnit skyUnit) const;
437 
439  void initWcsLibFromFits(std::shared_ptr<lsst::daf::base::PropertySet const> const& fitsMetadata);
443  void _initWcs();
444  void _setWcslibParams();
445 
446  struct wcsprm* _wcsInfo;
448  int _relax;
451  int _nReject;
454 };
455 
456 namespace detail {
458  int const x0 = 0,
459  int const y0 = 0);
460 
462 }
463 
474  bool stripMetadata = false);
475 
488 std::shared_ptr<Wcs> makeWcs(coord::Coord const& crval, geom::Point2D const& crpix, double CD11, double CD12,
489  double CD21, double CD22);
490 
491 namespace detail {
492 int stripWcsKeywords(
495  );
496 }
497 
509 public:
512 
513  virtual std::shared_ptr<afw::geom::XYTransform> invert() const;
514 
517  virtual Point2D forwardTransform(Point2D const& pixel) const;
518  virtual Point2D reverseTransform(Point2D const& pixel) const;
519 
520 protected:
523  bool const _isSameSkySystem;
524 };
525 }
526 }
527 } // lsst::afw::image
528 
529 #endif // LSST_AFW_IMAGE_WCS_H
530 
531 // LocalWords: LSST
bool _isIcrs() const
Definition: Wcs.h:371
Interface for Persistable base class.
virtual bool hasDistortion() const
Definition: Wcs.h:227
afw::coord::CoordSystem getCoordSystem() const
Definition: Wcs.h:229
Class implementing persistence and retrieval for Wcs objects.
Definition: WcsFormatter.h:45
std::shared_ptr< ImageT > flipImage(ImageT const &inImage, bool flipLR, bool flipTB)
Flip an image left–right and/or top–bottom.
Definition: rotateImage.cc:92
An object passed to Persistable::write to allow it to persist itself.
std::shared_ptr< Wcs > makeWcs(coord::Coord const &crval, geom::Point2D const &crpix, double CD11, double CD12, double CD21, double CD22)
Create a Wcs object from crval, crpix, CD, using CD elements (useful from python) ...
Definition: makeWcs.cc:128
Basic LSST definitions.
int stripWcsKeywords(std::shared_ptr< lsst::daf::base::PropertySet > const &metadata, std::shared_ptr< Wcs const > const &wcs)
Definition: Wcs.cc:1143
AngleUnit constexpr degrees
constant with units of degrees
Definition: Angle.h:88
XYTransformFromWcsPair: An XYTransform obtained by putting two Wcs objects "back to back"...
Definition: Wcs.h:508
table::PointKey< double > crval
Definition: Wcs.cc:934
bool operator==(CoordKey const &lhs, CoordKey const &rhs)
Compare CoordKeys for equality using the constituent Keys.
tbl::Key< int > wcs
Implementation of the WCS standard for a any projection.
Definition: Wcs.h:104
table::Key< std::string > ctype2
Definition: Wcs.cc:938
A class used to convert scalar POD types such as double to Angle.
Definition: Angle.h:52
STL class.
A base class for objects that can be persisted via afw::table::io Archive classes.
Definition: Persistable.h:74
A 2D linear coordinate transformation.
afw::table::PointKey< int > dimensions
Definition: GaussianPsf.cc:44
A class representing an angle.
Definition: Angle.h:102
A base class for image defects.
Definition: cameraGeom.dox:3
geom::Point2I getImageXY0FromMetadata(std::string const &wcsName, lsst::daf::base::PropertySet *metadata)
Definition: Wcs.cc:1101
std::shared_ptr< lsst::daf::base::PropertyList > createTrivialWcsAsPropertySet(std::string const &wcsName, int const x0=0, int const y0=0)
Definition: Wcs.cc:1074
An affine coordinate transformation consisting of a linear transformation and an offset.
table::Key< double > equinox
Definition: Wcs.cc:939
std::shared_ptr< ImageT > rotateImageBy90(ImageT const &image, int nQuarter)
Rotate an image by an integral number of quarter turns.
Definition: rotateImage.cc:39
bool _skyAxesSwapped
if true then the sky axes are swapped
Definition: Wcs.h:453
Base class for all records.
Definition: BaseRecord.h:29
bool operator!=(Wcs const &other) const
Definition: Wcs.h:141
int _wcshdrCtrl
Controls messages to stderr from wcshdr (0 for none); see wcshdr.h for details.
Definition: Wcs.h:450
int _relax
Degree of permissiveness for wcspih (0 for strict); see wcshdr.h for details.
Definition: Wcs.h:448
Class for storing generic metadata.
Definition: PropertySet.h:73
std::shared_ptr< Wcs const > _dst
Definition: Wcs.h:521
Virtual base class for 2D transforms.
Definition: XYTransform.h:49
int _wcsfixCtrl
Do potentially unsafe translations of non-standard unit strings? 0/1 = no/yes.
Definition: Wcs.h:449
table::PointKey< int > pixel
Base class for all persistable classes.
Definition: Persistable.h:74
Citizen is a class that should be among all LSST classes base classes, and handles basic memory manag...
Definition: Citizen.h:53
#define LSST_PERSIST_FORMATTER(formatter...)
Macro used to connect the persistable class with the Formatter and boost::serialization.
Definition: Persistable.h:98
This is the base class for spherical coordinates.
Definition: Coord.h:63
A CRTP facade class for subclasses of Persistable.
Definition: Persistable.h:176
table::Key< std::string > ctype1
Definition: Wcs.cc:937
std::shared_ptr< Wcs const > _src
Definition: Wcs.h:522
struct wcsprm * _wcsInfo
Definition: Wcs.h:446
coord::CoordSystem _coordSystem
Definition: Wcs.h:452
virtual void shiftReferencePixel(geom::Extent2D const &d)
Definition: Wcs.h:333
table::PointKey< double > crpix
Definition: Wcs.cc:935