LSSTApplications  8.0.0.0+107,8.0.0.1+13,9.1+18,9.2,master-g084aeec0a4,master-g0aced2eed8+6,master-g15627eb03c,master-g28afc54ef9,master-g3391ba5ea0,master-g3d0fb8ae5f,master-g4432ae2e89+36,master-g5c3c32f3ec+17,master-g60f1e072bb+1,master-g6a3ac32d1b,master-g76a88a4307+1,master-g7bce1f4e06+57,master-g8ff4092549+31,master-g98e65bf68e,master-ga6b77976b1+53,master-gae20e2b580+3,master-gb584cd3397+53,master-gc5448b162b+1,master-gc54cf9771d,master-gc69578ece6+1,master-gcbf758c456+22,master-gcec1da163f+63,master-gcf15f11bcc,master-gd167108223,master-gf44c96c709
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 
142  Eigen::Matrix2d getCDMatrix() const;
143  virtual void flipImage(int flipLR, int flipTB, lsst::afw::geom::Extent2I dimensions) const;
144  virtual void rotateImageBy90(int nQuarter, lsst::afw::geom::Extent2I dimensions) const;
145 
148 
155  bool isFlipped() const;
156 
158  double pixArea(lsst::afw::geom::Point2D pix00) const;
159 
161  geom::Angle pixelScale() const;
162 
164  PTR(coord::Coord) pixelToSky(double pix1, double pix2) const;
165 
167  PTR(coord::Coord) pixelToSky(lsst::afw::geom::Point2D const & pixel) const;
168 
169 
177  void pixelToSky(
178  double pixel1, double pixel2, geom::Angle& sky1, geom::Angle& sky2
179  ) const;
180 
186  geom::Point2D skyToPixel(geom::Angle sky1, geom::Angle sky2) const;
187 
189  geom::Point2D skyToPixel(coord::Coord const & coord) const;
190 
196  geom::Point2D skyToIntermediateWorldCoord(coord::Coord const & coord) const;
197 
198  virtual bool hasDistortion() const { return false;};
199 
201 
218  coord::Coord const & coord,
220  ) const;
221 
238  geom::Point2D const & pix,
240  ) const;
241 
258  coord::Coord const & coord,
260  ) const;
261 
278  geom::Point2D const & pix,
280  ) const;
281 
282  //Mutators
283  void shiftReferencePixel(geom::Extent2D const & d) {shiftReferencePixel(d.getX(), d.getY());}
284  void shiftReferencePixel(double dx, double dy);
285 
287  virtual bool isPersistable() const;
288 
289 private:
290  //Allow the formatter to access private goo
292 
293  void initWcsLib(geom::Point2D const & crval, geom::Point2D const & crpix,
294  Eigen::Matrix2d const & CD,
295  std::string const & ctype1, std::string const & ctype2,
296  double equinox, std::string const & raDecSys,
297  std::string const & cunits1, std::string const & cunits2
298  );
299 
300  virtual void pixelToSkyImpl(double pixel1, double pixel2, geom::Angle skyTmp[2]) const;
301  virtual geom::Point2D skyToPixelImpl(geom::Angle sky1, geom::Angle sky2) const;
302 
303 protected:
304 
305  friend class WcsFactory;
306 
307  // See afw::table::io::Persistable
308  virtual std::string getPersistenceName() const;
309  virtual std::string getPythonModule() const;
310  virtual void write(OutputArchiveHandle & handle) const;
311 
312  // Protected virtual implementation for operator== (must be true in both directions for equality).
313  virtual bool _isSubset(Wcs const & other) const;
314 
315  // Default constructor, only used by WcsFormatter
316  Wcs();
317 
318  //If you want to create a Wcs from a fits header, use makeWcs().
319  //This is protected because the derived classes need to be able to see it.
320  Wcs(CONST_PTR(lsst::daf::base::PropertySet) const& fitsMetadata);
321 
322  // Construct from a record; used by WcsFactory for afw::table::io persistence.
323  explicit Wcs(afw::table::BaseRecord const & record);
324 
325  Wcs(Wcs const & rhs);
326  Wcs& operator= (const Wcs &);
327 
328  afw::coord::Coord::Ptr makeCorrectCoord(geom::Angle sky0, geom::Angle sky1) const;
329 
334  afw::coord::Coord::Ptr convertCoordToSky(coord::Coord const & coord) const;
335 
336  virtual geom::AffineTransform linearizePixelToSkyInternal(
337  geom::Point2D const & pix,
338  coord::Coord const & coord,
339  geom::AngleUnit skyUnit
340  ) const;
341 
342  virtual geom::AffineTransform linearizeSkyToPixelInternal(
343  geom::Point2D const & pix,
344  coord::Coord const & coord,
345  geom::AngleUnit skyUnit
346  ) const;
347 
348 
349  void initWcsLibFromFits(CONST_PTR(lsst::daf::base::PropertySet) const& fitsMetadata);
350  void _initWcs();
351  void _setWcslibParams();
352 
353  struct wcsprm* _wcsInfo;
355  int _relax;
358  int _nReject;
360 };
361 
362 namespace detail {
364  createTrivialWcsAsPropertySet(std::string const& wcsName, int const x0=0, int const y0=0);
365 
366  geom::Point2I getImageXY0FromMetadata(std::string const& wcsName, lsst::daf::base::PropertySet *metadata);
367 }
368 
369 Wcs::Ptr makeWcs(PTR(lsst::daf::base::PropertySet) const& fitsMetadata, bool stripMetadata=false);
370 
371 /*
372  Note, CD matrix elements must be in degrees/pixel.
373  */
375  double CD11, double CD12, double CD21, double CD22);
376 
377 namespace detail {
378  int stripWcsKeywords(PTR(lsst::daf::base::PropertySet) const& metadata,
379  CONST_PTR(Wcs) const& wcs
380  );
381 }
382 
383 
395 {
396 public:
399 
400  virtual PTR(afw::geom::XYTransform) invert() const;
401 
403  virtual PTR(afw::geom::XYTransform) clone() const;
404  virtual Point2D forwardTransform(Point2D const &pixel) const;
405  virtual Point2D reverseTransform(Point2D const &pixel) const;
406 
407 protected:
408  CONST_PTR(Wcs) _dst;
409  CONST_PTR(Wcs) _src;
410 };
411 
412 
413 }}} // lsst::afw::image
414 
415 #endif // LSST_AFW_IMAGE_WCS_H
416 
417 // LocalWords: LSST
geom::Point2I getImageXY0FromMetadata(std::string const &wcsName, lsst::daf::base::PropertySet *metadata)
Definition: Wcs.cc:1251
void _setWcslibParams()
Definition: Wcs.cc:68
void shiftReferencePixel(geom::Extent2D const &d)
Definition: Wcs.h:283
virtual bool hasDistortion() const
Definition: Wcs.h:198
A coordinate class intended to represent absolute positions.
#define PTR(...)
Definition: base.h:41
double dx
Definition: ImageUtils.cc:90
lsst::afw::geom::Angle Angle
Definition: misc.h:37
lsst::afw::coord::Coord Coord
Definition: misc.h:34
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:977
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:73
virtual void pixelToSkyImpl(double pixel1, double pixel2, geom::Angle skyTmp[2]) const
Definition: Wcs.cc:857
Class for storing ordered metadata with comments.
Definition: PropertyList.h:81
afw::table::Key< afw::table::Point< int > > dimensions
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:808
afw::coord::Coord::Ptr convertCoordToSky(coord::Coord const &coord) const
Definition: Wcs.cc:798
virtual bool _isSubset(Wcs const &other) const
Definition: Wcs.cc:530
XYTransformFromWcsPair: Represents an XYTransform obtained by putting two Wcs&#39;s &quot;back to back&quot;...
Definition: Wcs.h:394
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:922
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
Point< double, 2 > Point2D
Definition: Point.h:277
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:1042
virtual void write(OutputArchiveHandle &handle) const
Write the object to one or more catalogs.
Definition: Wcs.cc:1128
geom::Point2D skyToIntermediateWorldCoord(coord::Coord const &coord) const
Convert from sky coordinates (e.g ra/dec) to intermediate world coordinates.
Definition: Wcs.cc:812
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
Interface for Persistable base class.
double dy
Definition: ImageUtils.cc:90
boost::shared_ptr< coord::Coord > pixelToSky(double pix1, double pix2) const
Convert from celestial coordinates to pixel coordinates.
Definition: Wcs.cc:894
table::Key< std::string > ctype2
Definition: Wcs.cc:1089
A class used to convert scalar POD types such as double to Angle.
Definition: Angle.h:71
#define LSST_PERSIST_FORMATTER(formatter...)
Definition: Persistable.h:98
virtual geom::Point2D skyToPixelImpl(geom::Angle sky1, geom::Angle sky2) const
Definition: Wcs.cc:752
table::Key< table::Point< double > > crval
Definition: Wcs.cc:1085
table::Key< table::Point< int > > pixel
std::map< Citizen const *, CitizenInfo > table
Definition: Citizen.h:93
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:1126
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:678
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
Definition: Wcs.cc:627
table::Key< double > equinox
Definition: Wcs.cc:1090
bool operator==(Wcs const &other) const
Definition: Wcs.cc:496
Eigen::Matrix2d getCDMatrix() const
Returns CD matrix. You would never have guessed that from the name.
Definition: Wcs.cc:587
geom::Angle pixelScale() const
Returns the pixel scale [Angle/pixel].
Definition: Wcs.cc:745
table::Key< table::Point< double > > crpix
Definition: Wcs.cc:1086
Wcs()
Construct an invalid Wcs given no arguments.
Definition: Wcs.cc:87
lsst::afw::geom::Point2D getPixelOrigin() const
Returns CRPIX (corrected to LSST convention).
Definition: Wcs.cc:577
virtual void flipImage(int flipLR, int flipTB, lsst::afw::geom::Extent2I dimensions) const
Flip CD matrix around the y-axis.
Definition: Wcs.cc:605
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:1228
lsst::afw::coord::Coord::Ptr getSkyOrigin() const
Returns CRVAL.
Definition: Wcs.cc:571
virtual geom::AffineTransform linearizePixelToSkyInternal(geom::Point2D const &pix, coord::Coord const &coord, geom::AngleUnit skyUnit) const
Definition: Wcs.cc:994
#define CONST_PTR(...)
Definition: base.h:47
boost::shared_ptr< Wcs > Ptr
Definition: Wcs.h:113
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:1124
bool isFlipped() const
Definition: Wcs.cc:696
int _wcshdrCtrl
Controls messages to stderr from wcshdr (0 for none); see wcshdr.h for details.
Definition: Wcs.h:357
geom::LinearTransform getLinearTransform() const
Definition: Wcs.cc:1058
int _relax
Degree of permissiveness for wcspih (0 for strict); see wcshdr.h for details.
Definition: Wcs.h:355
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:356
virtual bool isPersistable() const
Whether the Wcs is persistable using afw::table::io archives.
Definition: Wcs.cc:1146
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:712
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:1024
lsst::afw::image::XYTransformFromWcsPair XYTransformFromWcsPair
Definition: Wcs.cc:62
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:1294
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:1088
struct wcsprm * _wcsInfo
Definition: Wcs.h:353
coord::CoordSystem _coordSystem
Definition: Wcs.h:359
afw::table::SourceRecord * record
Functions to handle coordinates.