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
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 }
#define PTR(...)
Definition: base.h:41
lsst::afw::geom::Angle getLongitude() const
The main access method for the longitudinal coordinate.
Definition: Coord.h:112
Implementation of the WCS standard for a any projection.
Definition: Wcs.h:107
double asDegrees() const
Definition: Angle.h:124
table::Key< table::Point< double > > crval
Definition: Wcs.cc:1085
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
Implementation of the WCS standard for the special case of the Gnomonic (tangent plane) projection...
Definition: TanWcs.h:68
table::Key< table::Point< double > > crpix
Definition: Wcs.cc:1086
boost::shared_ptr< Wcs > Ptr
Definition: Wcs.h:113
double getAsDouble(std::string const &name) const
Definition: PropertySet.cc:406
Class for storing generic metadata.
Definition: PropertySet.h:82
virtual Ptr deepCopy(void) const
Definition: PropertySet.cc:70
std::string getAsString(std::string const &name) const
Definition: PropertySet.cc:444
virtual IcrsCoord toIcrs() const
Convert ourself to ICRS: RA, Dec (basically J2000)
Definition: Coord.cc:791
lsst::afw::geom::Angle getLatitude() const
The main access method for the latitudinal coordinate.
Definition: Coord.h:119
int stripWcsKeywords(boost::shared_ptr< lsst::daf::base::PropertySet > const &metadata, boost::shared_ptr< Wcs const > const &wcs)
Definition: Wcs.cc:1294
daf::base::PropertySet & _metadata
Definition: fits_io_mpl.h:79
bool exists(std::string const &name) const
Definition: PropertySet.cc:190
table::Key< std::string > ctype1
Definition: Wcs.cc:1088