lsst.afw  13.0-95-g793934f
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
Detector.cc
Go to the documentation of this file.
1 /*
2  * LSST Data Management System
3  * Copyright 2014 LSST Corporation.
4  *
5  * This product includes software developed by the
6  * LSST Project (http://www.lsst.org/).
7  *
8  * This program is free software: you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation, either version 3 of the License, or
11  * (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the LSST License Statement and
19  * the GNU General Public License along with this program. If not,
20  * see <http://www.lsstcorp.org/LegalNotices/>.
21  */
22 
23 #include <sstream>
24 #include <utility>
26 
27 namespace lsst {
28 namespace afw {
29 namespace cameraGeom {
30 
31 Detector::Detector(std::string const &name, int id, DetectorType type, std::string const &serial,
32  geom::Box2I const &bbox, table::AmpInfoCatalog const &ampInfoCatalog,
33  Orientation const &orientation, geom::Extent2D const &pixelSize,
34  TransformMap::Transforms const &transforms)
35  : _name(name),
36  _id(id),
37  _type(type),
38  _serial(serial),
39  _bbox(bbox),
40  _ampInfoCatalog(ampInfoCatalog),
41  _ampNameIterMap(),
42  _orientation(orientation),
43  _pixelSize(pixelSize),
44  _nativeSys(CameraSys(PIXELS, name)),
45  _transformMap(_nativeSys, transforms) {
46  _init();
47 }
48 
49 std::vector<geom::Point2D> Detector::getCorners(CameraSys const &cameraSys) const {
50  std::vector<geom::Point2D> fromVec = geom::Box2D(_bbox).getCorners();
51  return _transformMap.transform(fromVec, _nativeSys, cameraSys);
52 }
53 
54 std::vector<geom::Point2D> Detector::getCorners(CameraSysPrefix const &cameraSysPrefix) const {
55  return getCorners(makeCameraSys(cameraSysPrefix));
56 }
57 
58 CameraPoint Detector::getCenter(CameraSys const &cameraSys) const {
59  CameraPoint ctrPix = makeCameraPoint(geom::Box2D(_bbox).getCenter(), _nativeSys);
60  return transform(ctrPix, cameraSys);
61 }
62 
63 CameraPoint Detector::getCenter(CameraSysPrefix const &cameraSysPrefix) const {
64  return getCenter(makeCameraSys(cameraSysPrefix));
65 }
66 
67 const table::AmpInfoRecord &Detector::operator[](std::string const &name) const { return *(_get(name)); }
68 
69 std::shared_ptr<table::AmpInfoRecord const> Detector::_get(int i) const {
70  if (i < 0) {
71  i = _ampInfoCatalog.size() + i;
72  };
73  return _ampInfoCatalog.get(i);
74 }
75 
76 std::shared_ptr<table::AmpInfoRecord const> Detector::_get(std::string const &name) const {
77  _AmpInfoMap::const_iterator ampIter = _ampNameIterMap.find(name);
78  if (ampIter == _ampNameIterMap.end()) {
79  std::ostringstream os;
80  os << "Unknown amplifier \"" << name << "\"";
81  throw LSST_EXCEPT(pexExcept::InvalidParameterError, os.str());
82  }
83  return ampIter->second;
84 }
85 
86 bool Detector::hasTransform(CameraSys const &cameraSys) const { return _transformMap.contains(cameraSys); }
87 
88 bool Detector::hasTransform(CameraSysPrefix const &cameraSysPrefix) const {
89  return hasTransform(makeCameraSys(cameraSysPrefix));
90 }
91 
92 template <typename FromSysT, typename ToSysT>
93 std::shared_ptr<geom::TransformPoint2ToPoint2> Detector::getTransform(FromSysT const &fromSys,
94  ToSysT const &toSys) const {
95  return _transformMap.getTransform(makeCameraSys(fromSys), makeCameraSys(toSys));
96 }
97 
98 void Detector::_init() {
99  // make _ampNameIterMap
100  for (table::AmpInfoCatalog::const_iterator ampIter = _ampInfoCatalog.begin();
101  ampIter != _ampInfoCatalog.end(); ++ampIter) {
102  _ampNameIterMap.insert(std::make_pair(ampIter->getName(), ampIter));
103  }
104  if (_ampNameIterMap.size() != _ampInfoCatalog.size()) {
105  throw LSST_EXCEPT(pexExcept::InvalidParameterError,
106  "Invalid ampInfoCatalog: not all amplifier names are unique");
107  }
108 
109  // check detector name in CoordSys in transform registry
110  for (CameraSys sys : _transformMap) {
111  if (sys.hasDetectorName() && sys.getDetectorName() != _name) {
112  std::ostringstream os;
113  os << "Invalid transformMap: " << sys << " detector name != \"" << _name << "\"";
114  throw LSST_EXCEPT(pexExcept::InvalidParameterError, os.str());
115  }
116  }
117 }
118 
119 //
120 // Explicit instantiations
121 //
122 #define INSTANTIATE(FROMSYS, TOSYS) \
123  template std::shared_ptr<geom::TransformPoint2ToPoint2> Detector::getTransform(FROMSYS const &, \
124  TOSYS const &) const;
125 
126 INSTANTIATE(CameraSys, CameraSys);
127 INSTANTIATE(CameraSys, CameraSysPrefix);
128 INSTANTIATE(CameraSysPrefix, CameraSys);
129 INSTANTIATE(CameraSysPrefix, CameraSysPrefix);
130 
131 } // namespace cameraGeom
132 } // namespace afw
133 } // namespace lsst
geom::Point2D transform(geom::Point2D const &point, CameraSys const &fromSys, CameraSys const &toSys) const
Convert a point from one camera coordinate system to another.
std::shared_ptr< RecordT > const get(size_type i) const
Return a pointer to the record at index i.
Definition: Catalog.h:437
Camera coordinate system; used as a key in in TransformMap.
Definition: CameraSys.h:77
std::vector< geom::Point2D > getCorners(CameraSys const &cameraSys) const
Get the corners of the detector in the specified camera coordinate system.
Definition: Detector.cc:49
std::string const & _name
Definition: Mask.cc:546
Geometry and electronic information about raw amplifier images.
Definition: AmpInfo.h:79
A custom container class for records, based on std::vector.
Definition: Catalog.h:96
CameraSysPrefix const PIXELS
Nominal pixels on the detector (unbinned) This ignores manufacturing imperfections, &quot;tree ring&quot; distortions and all other such effects.
Definition: CameraSys.cc:33
lsst::afw::table::AmpInfoRecord const & operator[](size_t i) const
Get the amplifier specified by index.
Definition: Detector.h:145
CameraPoint transform(CameraPoint const &fromCameraPoint, CameraSys const &toSys) const
Convert a CameraPoint from one coordinate system to another.
Definition: Detector.h:260
CameraPoint getCenter(CameraSys const &cameraSys) const
Get the center of the detector in the specified camera coordinate system.
Definition: Detector.cc:58
size_type size() const
Return the number of elements in the catalog.
Definition: Catalog.h:399
An integer coordinate rectangle.
Definition: Box.h:55
Describe a detector&#39;s orientation in the focal plane.
Definition: Orientation.h:51
std::shared_ptr< geom::TransformPoint2ToPoint2 > getTransform(FromSysT const &fromSys, ToSysT const &toSys) const
Get a Transform from one camera coordinate system, or camera coordinate system prefix, to another.
Definition: Detector.cc:93
iterator end()
Iterator access.
Definition: Catalog.h:388
geom::Box2I const & _bbox
Definition: fits_io_mpl.h:84
CameraSys const makeCameraSys(CameraSys const &cameraSys) const
Get a coordinate system from a coordinate system (return input unchanged and untested) ...
Definition: Detector.h:239
Iterator class for CatalogT.
Definition: Catalog.h:37
table::Key< std::string > name
Definition: ApCorrMap.cc:71
bool contains(CameraSys const &system) const noexcept
Can this transform to and from the specified coordinate system?
std::vector< Point2D > getCorners() const
Get the corner points.
CameraPoint makeCameraPoint(geom::Point2D const &point, CameraSys const &cameraSys) const
Make a CameraPoint from a point and a camera system.
Definition: Detector.h:215
bool hasTransform(CameraSys const &cameraSys) const
Can this object convert between PIXELS and the specified camera coordinate system?
Definition: Detector.cc:86
int _id
Definition: Mask.cc:547
Camera coordinate system prefix.
Definition: CameraSys.h:44
Detector(std::string const &name, int id, DetectorType type, std::string const &serial, geom::Box2I const &bbox, lsst::afw::table::AmpInfoCatalog const &ampInfoCatalog, Orientation const &orientation, geom::Extent2D const &pixelSize, TransformMap::Transforms const &transforms)
Make a Detector.
Definition: Detector.cc:31
A Point2D with associated camera coordinate system.
Definition: CameraPoint.h:37
std::shared_ptr< lsst::afw::table::AmpInfoRecord const > _get(int i) const
Get the amplifier specified by index, returning a shared pointer to an AmpInfo record.
Definition: Detector.cc:69
A floating-point coordinate rectangle geometry.
Definition: Box.h:266
iterator begin()
Iterator access.
Definition: Catalog.h:387
DetectorType
Type of imaging detector.
Definition: Detector.h:43
std::shared_ptr< geom::TransformPoint2ToPoint2 > getTransform(CameraSys const &fromSys, CameraSys const &toSys) const
Get a Transform from one camera coordinate system to another.
std::unordered_map< CameraSys, std::shared_ptr< geom::TransformPoint2ToPoint2 >> Transforms
Definition: TransformMap.h:65
#define INSTANTIATE(FROMSYS, TOSYS)
Definition: Detector.cc:122