LSSTApplications  10.0+286,10.0+36,10.0+46,10.0-2-g4f67435,10.1+152,10.1+37,11.0,11.0+1,11.0-1-g47edd16,11.0-1-g60db491,11.0-1-g7418c06,11.0-2-g04d2804,11.0-2-g68503cd,11.0-2-g818369d,11.0-2-gb8b8ce7
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 
26 #ifndef LSST_AFW_IMAGE_WCS_H
27 #define LSST_AFW_IMAGE_WCS_H
28 
29 
30 #include "Eigen/Core"
31 #include "lsst/base.h"
33 #include "lsst/daf/base/Citizen.h"
34 #include "lsst/afw/image/Image.h"
35 #include "lsst/afw/coord/Coord.h"
37 #include "lsst/afw/geom/Point.h"
38 #include "lsst/afw/geom/Extent.h"
41 
42 struct wcsprm; // defined in wcs.h
43 
44 namespace lsst {
45 namespace daf {
46  namespace base {
47  class PropertySet;
48  }
49 }
50 namespace afw {
51  namespace formatters {
52  class WcsFormatter;
53  }
54  namespace table {
55  class BaseRecord;
56  }
57 namespace image {
58 
106 
111 {
112 public:
113  typedef boost::shared_ptr<Wcs> Ptr;
114  typedef boost::shared_ptr<Wcs const> ConstPtr;
115 
121  friend Wcs::Ptr makeWcs(PTR(lsst::daf::base::PropertySet) const& fitsMetadata,
122  bool stripMetadata);
123 
125  Eigen::Matrix2d const & CD,
126  std::string const & ctype1="RA---TAN", std::string const & ctype2="DEC--TAN",
127  double equinox=2000, std::string const & raDecSys="ICRS",
128  std::string const & cunits1="deg", std::string const & cunits2="deg"
129  );
130 
131  virtual ~Wcs();
132  virtual Ptr clone(void) const;
133 
134  bool operator==(Wcs const & other) const;
135  bool operator!=(Wcs const & other) const { return !(*this == other); }
136 
139 
142 
144  Eigen::Matrix2d getCDMatrix() const;
145 
147  virtual void flipImage(int flipLR, int flipTB, lsst::afw::geom::Extent2I dimensions) const;
148 
150  virtual void rotateImageBy90(int nQuarter, lsst::afw::geom::Extent2I dimensions) const;
151 
154 
163  bool isFlipped() const;
164 
166  double pixArea(lsst::afw::geom::Point2D pix00) const;
167 
169  geom::Angle pixelScale() const;
170 
178  PTR(coord::Coord) pixelToSky(double pix1, double pix2) const;
179 
187  PTR(coord::Coord) pixelToSky(lsst::afw::geom::Point2D const & pixel) const;
188 
189  /*
190  * @brief Convert from pixel position to sky coordinates (e.g. RA/dec)
191  *
192  * @note This routine is designed for the knowledgeable user in need of performance;
193  * it's safer to call the version that returns a PTR(Coord).
194  */
195  void pixelToSky(
196  double pixel1, double pixel2, geom::Angle& sky1, geom::Angle& sky2
197  ) const;
198 
208  geom::Point2D skyToPixel(geom::Angle sky1, geom::Angle sky2) const;
209 
211  geom::Point2D skyToPixel(coord::Coord const & coord) const;
212 
218  geom::Point2D skyToIntermediateWorldCoord(coord::Coord const & coord) const;
219 
220  virtual bool hasDistortion() const { return false;};
221 
226 
243  coord::Coord const & coord,
245  ) const;
246 
263  geom::Point2D const & pix,
265  ) const;
266 
283  coord::Coord const & coord,
285  ) const;
286 
303  geom::Point2D const & pix,
305  ) const;
306 
307  // Mutators; the first one is virtual, even though it will never be overridden,
308  // to make sure subclasses use the correct version of both
309 
318  virtual void shiftReferencePixel(double dx, double dy);
319 
320  // Virtual to make sure subclasses use the correct version of both shiftReferencePixel mutators.
321  virtual void shiftReferencePixel(geom::Extent2D const & d) { shiftReferencePixel(d.getX(), d.getY()); }
322 
324  virtual bool isPersistable() const;
325 
326 private:
327  //Allow the formatter to access private goo
329 
330  void initWcsLib(geom::Point2D const & crval, geom::Point2D const & crpix,
331  Eigen::Matrix2d const & CD,
332  std::string const & ctype1, std::string const & ctype2,
333  double equinox, std::string const & raDecSys,
334  std::string const & cunits1, std::string const & cunits2
335  );
336 
337 protected:
338 
339  friend class WcsFactory;
341  bool _mayBePersistable() const;
342  // See afw::table::io::Persistable
343  virtual std::string getPersistenceName() const;
344  virtual std::string getPythonModule() const;
345  virtual void write(OutputArchiveHandle & handle) const;
346 
347  // Protected virtual implementation for operator== (must be true in both directions for equality).
348  virtual bool _isSubset(Wcs const & other) const;
349 
350  // Default constructor, only used by WcsFormatter
351  Wcs();
352 
353  //If you want to create a Wcs from a FITS header, use makeWcs().
354  //This is protected because the derived classes need to be able to see it.
355  Wcs(CONST_PTR(lsst::daf::base::PropertySet) const& fitsMetadata);
356 
357  // Construct from a record; used by WcsFactory for afw::table::io persistence.
358  explicit Wcs(afw::table::BaseRecord const & record);
359 
360  Wcs(Wcs const & rhs);
361  Wcs& operator= (const Wcs &);
362 
363  virtual void pixelToSkyImpl(double pixel1, double pixel2, geom::Angle skyTmp[2]) const;
364  virtual geom::Point2D skyToPixelImpl(geom::Angle sky1, geom::Angle sky2) const;
365 
366  afw::coord::Coord::Ptr makeCorrectCoord(geom::Angle sky0, geom::Angle sky1) const;
367 
372  afw::coord::Coord::Ptr convertCoordToSky(coord::Coord const & coord) const;
373 
374  virtual geom::AffineTransform linearizePixelToSkyInternal(
375  geom::Point2D const & pix,
376  coord::Coord const & coord,
377  geom::AngleUnit skyUnit
378  ) const;
379 
380  virtual geom::AffineTransform linearizeSkyToPixelInternal(
381  geom::Point2D const & pix,
382  coord::Coord const & coord,
383  geom::AngleUnit skyUnit
384  ) const;
385 
386 
387  void initWcsLibFromFits(CONST_PTR(lsst::daf::base::PropertySet) const& fitsMetadata);
388  void _initWcs();
389  void _setWcslibParams();
390 
391  struct wcsprm* _wcsInfo;
393  int _relax;
396  int _nReject;
398 };
399 
400 namespace detail {
402  createTrivialWcsAsPropertySet(std::string const& wcsName, int const x0=0, int const y0=0);
403 
404  geom::Point2I getImageXY0FromMetadata(std::string const& wcsName, lsst::daf::base::PropertySet *metadata);
405 }
406 
407 Wcs::Ptr makeWcs(PTR(lsst::daf::base::PropertySet) const& fitsMetadata, bool stripMetadata=false);
408 
409 /*
410  Note, CD matrix elements must be in degrees/pixel.
411  */
413  double CD11, double CD12, double CD21, double CD22);
414 
415 namespace detail {
416  int stripWcsKeywords(PTR(lsst::daf::base::PropertySet) const& metadata,
417  CONST_PTR(Wcs) const& wcs
418  );
419 }
420 
421 
433 {
434 public:
437 
438  virtual PTR(afw::geom::XYTransform) invert() const;
439 
441  virtual PTR(afw::geom::XYTransform) clone() const;
442  virtual Point2D forwardTransform(Point2D const &pixel) const;
443  virtual Point2D reverseTransform(Point2D const &pixel) const;
444 
445 protected:
446  CONST_PTR(Wcs) _dst;
447  CONST_PTR(Wcs) _src;
448 };
449 
450 
451 }}} // lsst::afw::image
452 
453 #endif // LSST_AFW_IMAGE_WCS_H
454 
455 // LocalWords: LSST
geom::Point2I getImageXY0FromMetadata(std::string const &wcsName, lsst::daf::base::PropertySet *metadata)
Definition: Wcs.cc:1210
void _setWcslibParams()
Definition: Wcs.cc:69
virtual bool hasDistortion() const
Definition: Wcs.h:220
A coordinate class intended to represent absolute positions.
lsst::afw::geom::Angle Angle
Definition: misc.h:39
lsst::afw::coord::Coord Coord
Definition: misc.h:36
geom::AffineTransform linearizePixelToSky(coord::Coord const &coord, geom::AngleUnit skyUnit=geom::degrees) const
Return the local linear approximation to Wcs::pixelToSky at a point given in sky coordinates.
Definition: Wcs.cc:934
Class implementing persistence and retrieval for Wcs objects.
Definition: WcsFormatter.h:55
An object passed to Persistable::write to allow it to persist itself.
boost::shared_ptr< Coord > Ptr
Definition: Coord.h:72
virtual void pixelToSkyImpl(double pixel1, double pixel2, geom::Angle skyTmp[2]) const
Definition: Wcs.cc:831
Class for storing ordered metadata with comments.
Definition: PropertyList.h:81
friend Wcs::Ptr makeWcs(boost::shared_ptr< lsst::daf::base::PropertySet > const &fitsMetadata, bool stripMetadata)
Create a Wcs of the correct class using a FITS header.
geom::Point2D skyToPixel(geom::Angle sky1, geom::Angle sky2) const
Convert from sky coordinates (e.g. RA/dec) to pixel positions.
Definition: Wcs.cc:782
afw::coord::Coord::Ptr convertCoordToSky(coord::Coord const &coord) const
Definition: Wcs.cc:778
virtual bool _isSubset(Wcs const &other) const
Definition: Wcs.cc:520
XYTransformFromWcsPair: An XYTransform obtained by putting two Wcs objects &quot;back to back&quot;...
Definition: Wcs.h:432
afw::coord::Coord::Ptr makeCorrectCoord(geom::Angle sky0, geom::Angle sky1) const
Given a sky position, use the values stored in ctype and radesys to return the correct sub-class of C...
Definition: Wcs.cc:879
void initWcsLibFromFits(boost::shared_ptr< lsst::daf::base::PropertySet const > const &fitsMetadata)
Parse a fits header, extract the relevant metadata and create a Wcs object.
Definition: Wcs.cc:173
table::PointKey< double > crval
Definition: Wcs.cc:1035
#define PTR(...)
Definition: base.h:41
Point< double, 2 > Point2D
Definition: Point.h:286
void initWcsLib(geom::Point2D const &crval, geom::Point2D const &crpix, Eigen::Matrix2d const &CD, std::string const &ctype1, std::string const &ctype2, double equinox, std::string const &raDecSys, std::string const &cunits1, std::string const &cunits2)
Manually initialise a wcs struct using values passed by the constructor.
Definition: Wcs.cc:361
tbl::Key< int > wcs
virtual geom::AffineTransform linearizeSkyToPixelInternal(geom::Point2D const &pix, coord::Coord const &coord, geom::AngleUnit skyUnit) const
Definition: Wcs.cc:999
virtual void write(OutputArchiveHandle &handle) const
Write the object to one or more catalogs.
Definition: Wcs.cc:1078
geom::Point2D skyToIntermediateWorldCoord(coord::Coord const &coord) const
Convert from sky coordinates (e.g. RA/dec) to intermediate world coordinates.
Definition: Wcs.cc:786
virtual ~Wcs()
Definition: Wcs.cc:545
virtual Ptr clone(void) const
Definition: Wcs.cc:552
Implementation of the WCS standard for a any projection.
Definition: Wcs.h:107
boost::shared_ptr< coord::Coord > pixelToSky(double pix1, double pix2) const
Convert from pixel position to sky coordinates (e.g. RA/dec)
Definition: Wcs.cc:858
table::Key< std::string > ctype2
Definition: Wcs.cc:1039
bool _mayBePersistable() const
Perform basic checks on whether *this might be persistable.
Definition: Wcs.cc:1096
A class used to convert scalar POD types such as double to Angle.
Definition: Angle.h:71
int const x0
Definition: saturated.cc:45
virtual void shiftReferencePixel(double dx, double dy)
Move the pixel reference position by (dx, dy)
Definition: Wcs.cc:1164
virtual geom::Point2D skyToPixelImpl(geom::Angle sky1, geom::Angle sky2) const
Definition: Wcs.cc:732
std::map< Citizen const *, CitizenInfo > table
Definition: Citizen.h:93
table::Key< table::Array< Kernel::Pixel > > image
Definition: FixedKernel.cc:117
A base class for objects that can be persisted via afw::table::io Archive classes.
Definition: Persistable.h:74
A 2D linear coordinate transformation.
virtual std::string getPythonModule() const
Return the fully-qualified Python module that should be imported to guarantee that its factory is reg...
Definition: Wcs.cc:1076
virtual boost::shared_ptr< lsst::daf::base::PropertyList > getFitsMetadata() const
Return a PropertyList containing FITS header keywords that can be used to save the Wcs...
Definition: Wcs.cc:668
afw::table::PointKey< int > dimensions
Definition: GaussianPsf.cc:42
boost::shared_ptr< Wcs const > ConstPtr
Definition: Wcs.h:114
An affine coordinate transformation consisting of a linear transformation and an offset.
virtual void rotateImageBy90(int nQuarter, lsst::afw::geom::Extent2I dimensions) const
Rotate image by nQuarter times 90 degrees.
Definition: Wcs.cc:614
table::Key< double > equinox
Definition: Wcs.cc:1040
bool operator==(Wcs const &other) const
Definition: Wcs.cc:486
Eigen::Matrix2d getCDMatrix() const
Returns the CD matrix.
Definition: Wcs.cc:573
geom::Angle pixelScale() const
Returns the pixel scale [Angle/pixel].
Definition: Wcs.cc:725
Wcs()
Construct an invalid Wcs given no arguments.
Definition: Wcs.cc:88
lsst::afw::geom::Point2D getPixelOrigin() const
Returns CRPIX (corrected to LSST convention).
Definition: Wcs.cc:565
virtual void flipImage(int flipLR, int flipTB, lsst::afw::geom::Extent2I dimensions) const
Flip CD matrix around the y-axis.
Definition: Wcs.cc:591
Support for 2-D images.
boost::shared_ptr< lsst::daf::base::PropertyList > createTrivialWcsAsPropertySet(std::string const &wcsName, int const x0=0, int const y0=0)
Definition: Wcs.cc:1187
lsst::afw::coord::Coord::Ptr getSkyOrigin() const
Returns CRVAL. This need not be the centre of the image.
Definition: Wcs.cc:560
virtual geom::AffineTransform linearizePixelToSkyInternal(geom::Point2D const &pix, coord::Coord const &coord, geom::AngleUnit skyUnit) const
Definition: Wcs.cc:951
#define LSST_PERSIST_FORMATTER(formatter...)
Definition: Persistable.h:98
boost::shared_ptr< Wcs > Ptr
Definition: Wcs.h:113
Interface for Persistable base class.
bool operator!=(Wcs const &other) const
Definition: Wcs.h:135
virtual std::string getPersistenceName() const
Return the unique name used to persist this object and look up its factory.
Definition: Wcs.cc:1074
bool isFlipped() const
Definition: Wcs.cc:672
Base class for all records.
Definition: BaseRecord.h:27
int _wcshdrCtrl
Controls messages to stderr from wcshdr (0 for none); see wcshdr.h for details.
Definition: Wcs.h:395
geom::LinearTransform getLinearTransform() const
Definition: Wcs.cc:1008
int _relax
Degree of permissiveness for wcspih (0 for strict); see wcshdr.h for details.
Definition: Wcs.h:393
Class for storing generic metadata.
Definition: PropertySet.h:82
Virtual base class for 2D transforms.
Definition: XYTransform.h:48
int _wcsfixCtrl
Do potentially unsafe translations of non-standard unit strings? 0/1 = no/yes.
Definition: Wcs.h:394
virtual bool isPersistable() const
Whether the Wcs is persistable using afw::table::io archives.
Definition: Wcs.cc:1104
double pixArea(lsst::afw::geom::Point2D pix00) const
Sky area covered by a pixel at position pix00 in units of square degrees.
Definition: Wcs.cc:692
#define CONST_PTR(...)
Definition: base.h:47
geom::AffineTransform linearizeSkyToPixel(coord::Coord const &coord, geom::AngleUnit skyUnit=geom::degrees) const
Return the local linear approximation to Wcs::skyToPixel at a point given in sky coordinates.
Definition: Wcs.cc:981
lsst::afw::image::XYTransformFromWcsPair XYTransformFromWcsPair
Definition: Wcs.cc:63
table::PointKey< int > pixel
Base class for all persistable classes.
Definition: Persistable.h:74
AngleUnit const degrees
Definition: Angle.h:92
Citizen is a class that should be among all LSST classes base classes, and handles basic memory manag...
Definition: Citizen.h:56
int stripWcsKeywords(boost::shared_ptr< lsst::daf::base::PropertySet > const &metadata, boost::shared_ptr< Wcs const > const &wcs)
Definition: Wcs.cc:1253
int const y0
Definition: saturated.cc:45
A coordinate class intended to represent offsets and dimensions.
A CRTP facade class for subclasses of Persistable.
Definition: Persistable.h:182
Class representing an invertible 2D transform.
table::Key< std::string > ctype1
Definition: Wcs.cc:1038
struct wcsprm * _wcsInfo
Definition: Wcs.h:391
coord::CoordSystem _coordSystem
Definition: Wcs.h:397
virtual void shiftReferencePixel(geom::Extent2D const &d)
Definition: Wcs.h:321
table::PointKey< double > crpix
Definition: Wcs.cc:1036
Functions to handle coordinates.