lsst.afw  15.0-25-gacd707fca
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, CrosstalkMatrix const &crosstalk)
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  _crosstalk(crosstalk) {
47  _init();
48 }
49 
50 Detector::Detector(Detector const &) = default;
51 Detector::Detector(Detector &&) = default;
52 
54  std::vector<geom::Point2D> nativeCorners = geom::Box2D(_bbox).getCorners();
55  auto nativeToCameraSys = _transformMap.getTransform(_nativeSys, cameraSys);
56  return nativeToCameraSys->applyForward(nativeCorners);
57 }
58 
60  return getCorners(makeCameraSys(cameraSysPrefix));
61 }
62 
63 geom::Point2D Detector::getCenter(CameraSys const &cameraSys) const {
64  auto ctrPix = geom::Box2D(_bbox).getCenter();
65  auto transform = getTransform(PIXELS, cameraSys);
66  return transform->applyForward(ctrPix);
67 }
68 
69 geom::Point2D Detector::getCenter(CameraSysPrefix const &cameraSysPrefix) const {
70  return getCenter(makeCameraSys(cameraSysPrefix));
71 }
72 
73 const table::AmpInfoRecord &Detector::operator[](std::string const &name) const { return *(_get(name)); }
74 
76  if (i < 0) {
77  i = _ampInfoCatalog.size() + i;
78  };
79  return _ampInfoCatalog.get(i);
80 }
81 
83  _AmpInfoMap::const_iterator ampIter = _ampNameIterMap.find(name);
84  if (ampIter == _ampNameIterMap.end()) {
86  os << "Unknown amplifier \"" << name << "\"";
88  }
89  return ampIter->second;
90 }
91 
92 bool Detector::hasTransform(CameraSys const &cameraSys) const { return _transformMap.contains(cameraSys); }
93 
94 bool Detector::hasTransform(CameraSysPrefix const &cameraSysPrefix) const {
95  return hasTransform(makeCameraSys(cameraSysPrefix));
96 }
97 
98 template <typename FromSysT, typename ToSysT>
100  ToSysT const &toSys) const {
101  return _transformMap.getTransform(makeCameraSys(fromSys), makeCameraSys(toSys));
102 }
103 
104 template <typename FromSysT, typename ToSysT>
105 geom::Point2D Detector::transform(geom::Point2D const &point, FromSysT const &fromSys,
106  ToSysT const &toSys) const {
107  return _transformMap.transform(point, makeCameraSys(fromSys), makeCameraSys(toSys));
108 }
109 
110 template <typename FromSysT, typename ToSysT>
112  FromSysT const &fromSys, ToSysT const &toSys) const {
113  return _transformMap.transform(points, makeCameraSys(fromSys), makeCameraSys(toSys));
114 }
115 
116 void Detector::_init() {
117  // make _ampNameIterMap
118  for (table::AmpInfoCatalog::const_iterator ampIter = _ampInfoCatalog.begin();
119  ampIter != _ampInfoCatalog.end(); ++ampIter) {
120  _ampNameIterMap.insert(std::make_pair(ampIter->getName(), ampIter));
121  }
122  if (_ampNameIterMap.size() != _ampInfoCatalog.size()) {
124  "Invalid ampInfoCatalog: not all amplifier names are unique");
125  }
126 
127  // check detector name in CoordSys in transform registry
128  for (CameraSys sys : _transformMap) {
129  if (sys.hasDetectorName() && sys.getDetectorName() != _name) {
131  os << "Invalid transformMap: " << sys << " detector name != \"" << _name << "\"";
133  }
134  }
135 
136  // ensure crosstalk coefficients matrix is square
137  if (hasCrosstalk()) {
138  auto shape = _crosstalk.getShape();
139  assert(shape.size() == 2); // we've declared this as a 2D array
140  if (shape[0] != shape[1]) {
142  os << "Non-square crosstalk matrix: " << _crosstalk << " for detector \"" << _name << "\"";
144  }
145  if (shape[0] != _ampInfoCatalog.size()) {
147  os << "Wrong size crosstalk matrix: " << _crosstalk << " for detector \"" << _name << "\"";
149  }
150  }
151 }
152 
153 //
154 // Explicit instantiations
155 //
156 #define INSTANTIATE(FROMSYS, TOSYS) \
157  template std::shared_ptr<geom::TransformPoint2ToPoint2> Detector::getTransform(FROMSYS const &, \
158  TOSYS const &) const; \
159  template geom::Point2D Detector::transform(geom::Point2D const &, FROMSYS const &, TOSYS const &) const; \
160  template std::vector<geom::Point2D> Detector::transform(std::vector<geom::Point2D> const &, \
161  FROMSYS const &, TOSYS const &) const;
162 
163 INSTANTIATE(CameraSys, CameraSys);
164 INSTANTIATE(CameraSys, CameraSysPrefix);
165 INSTANTIATE(CameraSysPrefix, CameraSys);
166 INSTANTIATE(CameraSysPrefix, CameraSysPrefix);
167 
168 } // namespace cameraGeom
169 } // namespace afw
170 } // namespace lsst
Camera coordinate system; used as a key in in TransformMap.
Definition: CameraSys.h:83
Geometry and electronic information about raw amplifier images.
Definition: AmpInfo.h:79
std::string const & _name
Definition: Mask.cc:576
CameraSysPrefix const PIXELS
Nominal pixels on the detector (unbinned) This ignores manufacturing imperfections, "tree ring" distortions and all other such effects.
Definition: CameraSys.cc:33
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:75
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:99
T end(T... args)
std::vector< geom::Point2D > getCorners(CameraSys const &cameraSys) const
Get the corners of the detector in the specified camera coordinate system.
Definition: Detector.cc:53
An integer coordinate rectangle.
Definition: Box.h:55
Describe a detector&#39;s orientation in the focal plane.
Definition: Orientation.h:51
STL class.
CameraSys const makeCameraSys(CameraSys const &cameraSys) const
Get a coordinate system from a coordinate system (return input unchanged and untested) ...
Definition: Detector.h:231
geom::Point2D transform(geom::Point2D const &point, FromSysT const &fromSys, ToSysT const &toSys) const
Transform a point from one camera system to another.
Definition: Detector.cc:105
A base class for image defects.
iterator end()
Iterator access.
Definition: Catalog.h:397
int _id
Definition: Mask.cc:577
Point2D const getCenter() const
Definition: Box.h:368
Iterator class for CatalogT.
Definition: Catalog.h:38
bool hasTransform(CameraSys const &cameraSys) const
Can this object convert between PIXELS and the specified camera coordinate system?
Definition: Detector.cc:92
bool hasCrosstalk() const
Have we got crosstalk coefficients?
Definition: Detector.h:143
#define INSTANTIATE(FROMSYS, TOSYS)
Definition: Detector.cc:156
T str(T... args)
T make_pair(T... args)
std::vector< Point2D > getCorners() const
Get the corner points.
Definition: Box.cc:385
Camera coordinate system prefix.
Definition: CameraSys.h:44
T insert(T... args)
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, CrosstalkMatrix const &crosstalk=CrosstalkMatrix())
Make a Detector.
Definition: Detector.cc:31
T find(T... args)
T size(T... args)
#define LSST_EXCEPT(type,...)
STL class.
Information about a CCD or other imaging detector.
Definition: Detector.h:63
geom::Point2D getCenter(CameraSys const &cameraSys) const
Get the center of the detector in the specified camera coordinate system.
Definition: Detector.cc:63
std::shared_ptr< RecordT > const get(size_type i) const
Return a pointer to the record at index i.
Definition: Catalog.h:446
table::Box2IKey bbox
size_type size() const
Return the number of elements in the catalog.
Definition: Catalog.h:408
A floating-point coordinate rectangle geometry.
Definition: Box.h:266
iterator begin()
Iterator access.
Definition: Catalog.h:396
lsst::afw::table::AmpInfoRecord const & operator[](size_t i) const
Get the amplifier specified by index.
Definition: Detector.h:161
DetectorType
Type of imaging detector.
Definition: Detector.h:42
std::ostream * os
Definition: Schema.cc:736
ndarray::Array< float const, 2 > CrosstalkMatrix
Definition: Detector.h:65