LSSTApplications  1.1.2+25,10.0+13,10.0+132,10.0+133,10.0+224,10.0+41,10.0+8,10.0-1-g0f53050+14,10.0-1-g4b7b172+19,10.0-1-g61a5bae+98,10.0-1-g7408a83+3,10.0-1-gc1e0f5a+19,10.0-1-gdb4482e+14,10.0-11-g3947115+2,10.0-12-g8719d8b+2,10.0-15-ga3f480f+1,10.0-2-g4f67435,10.0-2-gcb4bc6c+26,10.0-28-gf7f57a9+1,10.0-3-g1bbe32c+14,10.0-3-g5b46d21,10.0-4-g027f45f+5,10.0-4-g86f66b5+2,10.0-4-gc4fccf3+24,10.0-40-g4349866+2,10.0-5-g766159b,10.0-5-gca2295e+25,10.0-6-g462a451+1
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;
340 
341  // See afw::table::io::Persistable
342  virtual std::string getPersistenceName() const;
343  virtual std::string getPythonModule() const;
344  virtual void write(OutputArchiveHandle & handle) const;
345 
346  // Protected virtual implementation for operator== (must be true in both directions for equality).
347  virtual bool _isSubset(Wcs const & other) const;
348 
349  // Default constructor, only used by WcsFormatter
350  Wcs();
351 
352  //If you want to create a Wcs from a FITS header, use makeWcs().
353  //This is protected because the derived classes need to be able to see it.
354  Wcs(CONST_PTR(lsst::daf::base::PropertySet) const& fitsMetadata);
355 
356  // Construct from a record; used by WcsFactory for afw::table::io persistence.
357  explicit Wcs(afw::table::BaseRecord const & record);
358 
359  Wcs(Wcs const & rhs);
360  Wcs& operator= (const Wcs &);
361 
362  virtual void pixelToSkyImpl(double pixel1, double pixel2, geom::Angle skyTmp[2]) const;
363  virtual geom::Point2D skyToPixelImpl(geom::Angle sky1, geom::Angle sky2) const;
364 
365  afw::coord::Coord::Ptr makeCorrectCoord(geom::Angle sky0, geom::Angle sky1) const;
366 
371  afw::coord::Coord::Ptr convertCoordToSky(coord::Coord const & coord) const;
372 
373  virtual geom::AffineTransform linearizePixelToSkyInternal(
374  geom::Point2D const & pix,
375  coord::Coord const & coord,
376  geom::AngleUnit skyUnit
377  ) const;
378 
379  virtual geom::AffineTransform linearizeSkyToPixelInternal(
380  geom::Point2D const & pix,
381  coord::Coord const & coord,
382  geom::AngleUnit skyUnit
383  ) const;
384 
385 
386  void initWcsLibFromFits(CONST_PTR(lsst::daf::base::PropertySet) const& fitsMetadata);
387  void _initWcs();
388  void _setWcslibParams();
389 
390  struct wcsprm* _wcsInfo;
392  int _relax;
395  int _nReject;
397 };
398 
399 namespace detail {
401  createTrivialWcsAsPropertySet(std::string const& wcsName, int const x0=0, int const y0=0);
402 
403  geom::Point2I getImageXY0FromMetadata(std::string const& wcsName, lsst::daf::base::PropertySet *metadata);
404 }
405 
406 Wcs::Ptr makeWcs(PTR(lsst::daf::base::PropertySet) const& fitsMetadata, bool stripMetadata=false);
407 
408 /*
409  Note, CD matrix elements must be in degrees/pixel.
410  */
412  double CD11, double CD12, double CD21, double CD22);
413 
414 namespace detail {
415  int stripWcsKeywords(PTR(lsst::daf::base::PropertySet) const& metadata,
416  CONST_PTR(Wcs) const& wcs
417  );
418 }
419 
420 
432 {
433 public:
436 
437  virtual PTR(afw::geom::XYTransform) invert() const;
438 
440  virtual PTR(afw::geom::XYTransform) clone() const;
441  virtual Point2D forwardTransform(Point2D const &pixel) const;
442  virtual Point2D reverseTransform(Point2D const &pixel) const;
443 
444 protected:
445  CONST_PTR(Wcs) _dst;
446  CONST_PTR(Wcs) _src;
447 };
448 
449 
450 }}} // lsst::afw::image
451 
452 #endif // LSST_AFW_IMAGE_WCS_H
453 
454 // LocalWords: LSST
int _wcsfixCtrl
Do potentially unsafe translations of non-standard unit strings? 0/1 = no/yes.
Definition: Wcs.h:393
geom::Point2I getImageXY0FromMetadata(std::string const &wcsName, lsst::daf::base::PropertySet *metadata)
Definition: Wcs.cc:1207
boost::shared_ptr< Coord > Ptr
Definition: Coord.h:72
#define CONST_PTR(...)
Definition: base.h:47
virtual std::string getPersistenceName() const
Return the unique name used to persist this object and look up its factory.
Definition: Wcs.cc:1080
double dx
Definition: ImageUtils.cc:90
lsst::afw::coord::Coord Coord
Definition: misc.h:39
virtual void shiftReferencePixel(geom::Extent2D const &d)
Definition: Wcs.h:321
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:940
Class implementing persistence and retrieval for Wcs objects.
Definition: WcsFormatter.h:55
An object passed to Persistable::write to allow it to persist itself.
virtual void pixelToSkyImpl(double pixel1, double pixel2, geom::Angle skyTmp[2]) const
Definition: Wcs.cc:837
coord::CoordSystem _coordSystem
Definition: Wcs.h:396
void _setWcslibParams()
Definition: Wcs.cc:68
Class for storing ordered metadata with comments.
Definition: PropertyList.h:81
afw::table::Key< afw::table::Point< int > > dimensions
boost::shared_ptr< Wcs > Ptr
Definition: Wcs.h:113
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:788
afw::coord::Coord::Ptr convertCoordToSky(coord::Coord const &coord) const
Definition: Wcs.cc:784
virtual bool _isSubset(Wcs const &other) const
Definition: Wcs.cc:530
XYTransformFromWcsPair: An XYTransform obtained by putting two Wcs objects &quot;back to back&quot;...
Definition: Wcs.h:431
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:885
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:172
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:371
virtual geom::AffineTransform linearizeSkyToPixelInternal(geom::Point2D const &pix, coord::Coord const &coord, geom::AngleUnit skyUnit) const
Definition: Wcs.cc:1005
geom::Point2D skyToIntermediateWorldCoord(coord::Coord const &coord) const
Convert from sky coordinates (e.g. RA/dec) to intermediate world coordinates.
Definition: Wcs.cc:792
virtual ~Wcs()
Definition: Wcs.cc:555
virtual Ptr clone(void) const
Definition: Wcs.cc:562
Implementation of the WCS standard for a any projection.
Definition: Wcs.h:107
#define PTR(...)
Definition: base.h:41
double dy
Definition: ImageUtils.cc:90
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:864
table::Key< std::string > ctype2
Definition: Wcs.cc:1045
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:1161
virtual geom::Point2D skyToPixelImpl(geom::Angle sky1, geom::Angle sky2) const
Definition: Wcs.cc:738
table::Key< table::Point< double > > crval
Definition: Wcs.cc:1041
table::Key< table::Point< int > > pixel
table::Key< table::Array< Kernel::Pixel > > image
Definition: FixedKernel.cc:117
int d
Definition: KDTree.cc:89
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:1082
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:674
AngleUnit const degrees
Definition: Angle.h:92
struct wcsprm * _wcsInfo
Definition: Wcs.h:390
virtual bool isPersistable() const
Whether the Wcs is persistable using afw::table::io archives.
Definition: Wcs.cc:1102
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:623
table::Key< double > equinox
Definition: Wcs.cc:1046
bool operator==(Wcs const &other) const
Definition: Wcs.cc:496
Eigen::Matrix2d getCDMatrix() const
Returns the CD matrix.
Definition: Wcs.cc:583
geom::Angle pixelScale() const
Returns the pixel scale [Angle/pixel].
Definition: Wcs.cc:731
table::Key< table::Point< double > > crpix
Definition: Wcs.cc:1042
#define LSST_PERSIST_FORMATTER(formatter...)
Definition: Persistable.h:98
lsst::afw::geom::Point2D getPixelOrigin() const
Returns CRPIX (corrected to LSST convention).
Definition: Wcs.cc:575
virtual bool hasDistortion() const
Definition: Wcs.h:220
virtual void flipImage(int flipLR, int flipTB, lsst::afw::geom::Extent2I dimensions) const
Flip CD matrix around the y-axis.
Definition: Wcs.cc:601
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:1184
lsst::afw::coord::Coord::Ptr getSkyOrigin() const
Returns CRVAL. This need not be the centre of the image.
Definition: Wcs.cc:570
virtual geom::AffineTransform linearizePixelToSkyInternal(geom::Point2D const &pix, coord::Coord const &coord, geom::AngleUnit skyUnit) const
Definition: Wcs.cc:957
A coordinate class intended to represent absolute positions.
void _initWcs()
Definition: Wcs.cc:117
int _relax
Degree of permissiveness for wcspih (0 for strict); see wcshdr.h for details.
Definition: Wcs.h:392
bool isFlipped() const
Definition: Wcs.cc:678
bool operator!=(Wcs const &other) const
Definition: Wcs.h:135
geom::LinearTransform getLinearTransform() const
Definition: Wcs.cc:1014
lsst::afw::geom::Angle Angle
Definition: misc.h:42
Wcs()
Construct an invalid Wcs given no arguments.
Definition: Wcs.cc:87
Class for storing generic metadata.
Definition: PropertySet.h:82
Virtual base class for 2D transforms.
Definition: XYTransform.h:48
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:698
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:987
Interface for Persistable base class.
lsst::afw::image::XYTransformFromWcsPair XYTransformFromWcsPair
Definition: Wcs.cc:62
Point< double, 2 > Point2D
Definition: Point.h:286
Base class for all persistable classes.
Definition: Persistable.h:74
virtual void write(OutputArchiveHandle &handle) const
Write the object to one or more catalogs.
Definition: Wcs.cc:1084
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:1250
int const y0
Definition: saturated.cc:45
std::map< Citizen const *, CitizenInfo > table
Definition: Citizen.h:93
A coordinate class intended to represent offsets and dimensions.
A CRTP facade class for subclasses of Persistable.
Definition: Persistable.h:182
int _wcshdrCtrl
Controls messages to stderr from wcshdr (0 for none); see wcshdr.h for details.
Definition: Wcs.h:394
Class representing an invertible 2D transform.
table::Key< std::string > ctype1
Definition: Wcs.cc:1044
Functions to handle coordinates.