lsst.afw  14.0-40-g0271be365
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 
52  return _transformMap.transform(fromVec, _nativeSys, cameraSys);
53 }
54 
56  return getCorners(makeCameraSys(cameraSysPrefix));
57 }
58 
59 CameraPoint Detector::getCenter(CameraSys const &cameraSys) const {
60  CameraPoint ctrPix = makeCameraPoint(geom::Box2D(_bbox).getCenter(), _nativeSys);
61  return transform(ctrPix, cameraSys);
62 }
63 
64 CameraPoint Detector::getCenter(CameraSysPrefix const &cameraSysPrefix) const {
65  return getCenter(makeCameraSys(cameraSysPrefix));
66 }
67 
68 const table::AmpInfoRecord &Detector::operator[](std::string const &name) const { return *(_get(name)); }
69 
71  if (i < 0) {
72  i = _ampInfoCatalog.size() + i;
73  };
74  return _ampInfoCatalog.get(i);
75 }
76 
78  _AmpInfoMap::const_iterator ampIter = _ampNameIterMap.find(name);
79  if (ampIter == _ampNameIterMap.end()) {
81  os << "Unknown amplifier \"" << name << "\"";
83  }
84  return ampIter->second;
85 }
86 
87 bool Detector::hasTransform(CameraSys const &cameraSys) const { return _transformMap.contains(cameraSys); }
88 
89 bool Detector::hasTransform(CameraSysPrefix const &cameraSysPrefix) const {
90  return hasTransform(makeCameraSys(cameraSysPrefix));
91 }
92 
93 template <typename FromSysT, typename ToSysT>
95  ToSysT const &toSys) const {
96  return _transformMap.getTransform(makeCameraSys(fromSys), makeCameraSys(toSys));
97 }
98 
99 void Detector::_init() {
100  // make _ampNameIterMap
101  for (table::AmpInfoCatalog::const_iterator ampIter = _ampInfoCatalog.begin();
102  ampIter != _ampInfoCatalog.end(); ++ampIter) {
103  _ampNameIterMap.insert(std::make_pair(ampIter->getName(), ampIter));
104  }
105  if (_ampNameIterMap.size() != _ampInfoCatalog.size()) {
107  "Invalid ampInfoCatalog: not all amplifier names are unique");
108  }
109 
110  // check detector name in CoordSys in transform registry
111  for (CameraSys sys : _transformMap) {
112  if (sys.hasDetectorName() && sys.getDetectorName() != _name) {
114  os << "Invalid transformMap: " << sys << " detector name != \"" << _name << "\"";
116  }
117  }
118 
119  // ensure crosstalk coefficients matrix is square
120  if (hasCrosstalk()) {
121  auto shape = _crosstalk.getShape();
122  assert(shape.size() == 2); // we've declared this as a 2D array
123  if (shape[0] != shape[1]) {
125  os << "Non-square crosstalk matrix: " << _crosstalk << " for detector \"" << _name << "\"";
127  }
128  if (shape[0] != _ampInfoCatalog.size()) {
130  os << "Wrong size crosstalk matrix: " << _crosstalk << " for detector \"" << _name << "\"";
132  }
133  }
134 }
135 
136 //
137 // Explicit instantiations
138 //
139 #define INSTANTIATE(FROMSYS, TOSYS) \
140  template std::shared_ptr<geom::TransformPoint2ToPoint2> Detector::getTransform(FROMSYS const &, \
141  TOSYS const &) const;
142 
143 INSTANTIATE(CameraSys, CameraSys);
144 INSTANTIATE(CameraSys, CameraSysPrefix);
145 INSTANTIATE(CameraSysPrefix, CameraSys);
146 INSTANTIATE(CameraSysPrefix, CameraSysPrefix);
147 
148 } // namespace cameraGeom
149 } // namespace afw
150 } // namespace lsst
CameraPoint transform(CameraPoint const &fromCameraPoint, CameraSys const &toSys) const
Convert a CameraPoint from one coordinate system to another.
Definition: Detector.h:272
Camera coordinate system; used as a key in in TransformMap.
Definition: CameraSys.h:77
table::Key< std::string > name
Definition: ApCorrMap.cc:71
Geometry and electronic information about raw amplifier images.
Definition: AmpInfo.h:79
std::string const & _name
Definition: Mask.cc:566
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:70
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:94
CameraPoint makeCameraPoint(geom::Point2D const &point, CameraSys const &cameraSys) const
Make a CameraPoint from a point and a camera system.
Definition: Detector.h:227
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:50
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:251
A base class for image defects.
iterator end()
Iterator access.
Definition: Catalog.h:391
std::vector< Point2D > getCorners() const
Get the corner points.
int _id
Definition: Mask.cc:567
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:87
bool hasCrosstalk() const
Have we got crosstalk coefficients?
Definition: Detector.h:139
#define INSTANTIATE(FROMSYS, TOSYS)
Definition: Detector.cc:139
T str(T... args)
T make_pair(T... args)
CameraPoint getCenter(CameraSys const &cameraSys) const
Get the center of the detector in the specified camera coordinate system.
Definition: Detector.cc:59
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.
std::shared_ptr< RecordT > const get(size_type i) const
Return a pointer to the record at index i.
Definition: Catalog.h:440
A Point2D with associated camera coordinate system.
Definition: CameraPoint.h:37
table::Box2IKey bbox
size_type size() const
Return the number of elements in the catalog.
Definition: Catalog.h:402
A floating-point coordinate rectangle geometry.
Definition: Box.h:267
iterator begin()
Iterator access.
Definition: Catalog.h:390
lsst::afw::table::AmpInfoRecord const & operator[](size_t i) const
Get the amplifier specified by index.
Definition: Detector.h:157
DetectorType
Type of imaging detector.
Definition: Detector.h:43
ndarray::Array< float const, 2 > CrosstalkMatrix
Definition: Detector.h:66