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
makeWcs.cc
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 #include "boost/make_shared.hpp"
26 #include "Eigen/Core"
27 #include "lsst/afw/image/Wcs.h"
28 #include "lsst/afw/image/TanWcs.h"
29 
30 namespace except = lsst::pex::exceptions;
31 namespace afwImg = lsst::afw::image;
32 
40  PTR(lsst::daf::base::PropertySet) const& metadata,
41  bool stripMetadata
42  )
43 {
44  std::string ctype1;
45  if (metadata->exists("CTYPE1")) {
46  ctype1 = metadata->getAsString("CTYPE1");
47  } else {
48  return PTR(Wcs)();
49  }
50 
51  afwImg::Wcs::Ptr wcs; // we can't use make_shared as ctor is private
52  if (ctype1.substr(5, 3) == "TAN") {
53  wcs = afwImg::Wcs::Ptr(new afwImg::TanWcs(metadata));
54  } else if (ctype1.substr(5, 3) == "TPV") {
56  _metadata->set<std::string>("CTYPE1", "RA---TAN");
57  _metadata->set<std::string>("CTYPE2", "DEC--TAN");
58  _metadata->set<bool>("TPV_WCS", true);
59 
61  } else {
62  wcs = afwImg::Wcs::Ptr(new afwImg::Wcs(metadata));
63  }
64 
65  //If keywords LTV[1,2] are present, the image on disk is already a subimage, so
66  //we should shift the wcs to allow for this.
67  std::string key = "LTV1";
68  if (metadata->exists(key)) {
69  wcs->shiftReferencePixel(-metadata->getAsDouble(key), 0);
70  }
71 
72  key = "LTV2";
73  if (metadata->exists(key) ) {
74  wcs->shiftReferencePixel(0, -metadata->getAsDouble(key));
75  }
76 
77  if (stripMetadata) {
78  afwImg::detail::stripWcsKeywords(metadata, wcs);
79  }
80 
81  return wcs;
82 }
83 
90  double CD11,
91  double CD12,
92  double CD21,
93  double CD22
94  ) {
95  Eigen::Matrix2d CD;
96  CD << CD11, CD12, CD21, CD22;
97  lsst::afw::geom::Point2D crvalTmp;
98  crvalTmp[0] = crval.toIcrs().getLongitude().asDegrees();
99  crvalTmp[1] = crval.toIcrs().getLatitude().asDegrees();
100  return afwImg::Wcs::Ptr(new lsst::afw::image::Wcs(crvalTmp, crpix, CD));
101 }
boost::shared_ptr< Wcs > Ptr
Definition: Wcs.h:113
Implementation of the WCS standard for a any projection.
Definition: Wcs.h:107
bool exists(std::string const &name) const
Definition: PropertySet.cc:190
#define PTR(...)
Definition: base.h:41
double asDegrees() const
Definition: Angle.h:124
table::Key< table::Point< double > > crval
Definition: Wcs.cc:1041
table::Key< table::Array< Kernel::Pixel > > image
Definition: FixedKernel.cc:117
Wcs::Ptr makeWcs(boost::shared_ptr< lsst::daf::base::PropertySet > const &fitsMetadata, bool stripMetadata=false)
Definition: makeWcs.cc:39
virtual Ptr deepCopy(void) const
Definition: PropertySet.cc:70
Implementation of the WCS standard for the special case of the Gnomonic (tangent plane) projection...
Definition: TanWcs.h:68
std::string getAsString(std::string const &name) const
Definition: PropertySet.cc:444
table::Key< table::Point< double > > crpix
Definition: Wcs.cc:1042
lsst::afw::geom::Angle getLongitude() const
The main access method for the longitudinal coordinate.
Definition: Coord.h:111
Class for storing generic metadata.
Definition: PropertySet.h:82
virtual IcrsCoord toIcrs() const
Convert ourself to ICRS: RA, Dec (basically J2000)
Definition: Coord.cc:791
double getAsDouble(std::string const &name) const
Definition: PropertySet.cc:406
int stripWcsKeywords(boost::shared_ptr< lsst::daf::base::PropertySet > const &metadata, boost::shared_ptr< Wcs const > const &wcs)
Definition: Wcs.cc:1250
daf::base::PropertySet & _metadata
Definition: fits_io_mpl.h:79
lsst::afw::geom::Angle getLatitude() const
The main access method for the latitudinal coordinate.
Definition: Coord.h:118
table::Key< std::string > ctype1
Definition: Wcs.cc:1044