lsst.afw  14.0-42-g99f9a3040+1
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 
55  return _transformMap.transform(fromVec, _nativeSys, cameraSys);
56 }
57 
59  return getCorners(makeCameraSys(cameraSysPrefix));
60 }
61 
62 CameraPoint Detector::getCenter(CameraSys const &cameraSys) const {
63  CameraPoint ctrPix = makeCameraPoint(geom::Box2D(_bbox).getCenter(), _nativeSys);
64  return transform(ctrPix, cameraSys);
65 }
66 
67 CameraPoint Detector::getCenter(CameraSysPrefix const &cameraSysPrefix) const {
68  return getCenter(makeCameraSys(cameraSysPrefix));
69 }
70 
71 const table::AmpInfoRecord &Detector::operator[](std::string const &name) const { return *(_get(name)); }
72 
74  if (i < 0) {
75  i = _ampInfoCatalog.size() + i;
76  };
77  return _ampInfoCatalog.get(i);
78 }
79 
81  _AmpInfoMap::const_iterator ampIter = _ampNameIterMap.find(name);
82  if (ampIter == _ampNameIterMap.end()) {
84  os << "Unknown amplifier \"" << name << "\"";
86  }
87  return ampIter->second;
88 }
89 
90 bool Detector::hasTransform(CameraSys const &cameraSys) const { return _transformMap.contains(cameraSys); }
91 
92 bool Detector::hasTransform(CameraSysPrefix const &cameraSysPrefix) const {
93  return hasTransform(makeCameraSys(cameraSysPrefix));
94 }
95 
96 template <typename FromSysT, typename ToSysT>
98  ToSysT const &toSys) const {
99  return _transformMap.getTransform(makeCameraSys(fromSys), makeCameraSys(toSys));
100 }
101 
102 void Detector::_init() {
103  // make _ampNameIterMap
104  for (table::AmpInfoCatalog::const_iterator ampIter = _ampInfoCatalog.begin();
105  ampIter != _ampInfoCatalog.end(); ++ampIter) {
106  _ampNameIterMap.insert(std::make_pair(ampIter->getName(), ampIter));
107  }
108  if (_ampNameIterMap.size() != _ampInfoCatalog.size()) {
110  "Invalid ampInfoCatalog: not all amplifier names are unique");
111  }
112 
113  // check detector name in CoordSys in transform registry
114  for (CameraSys sys : _transformMap) {
115  if (sys.hasDetectorName() && sys.getDetectorName() != _name) {
117  os << "Invalid transformMap: " << sys << " detector name != \"" << _name << "\"";
119  }
120  }
121 
122  // ensure crosstalk coefficients matrix is square
123  if (hasCrosstalk()) {
124  auto shape = _crosstalk.getShape();
125  assert(shape.size() == 2); // we've declared this as a 2D array
126  if (shape[0] != shape[1]) {
128  os << "Non-square crosstalk matrix: " << _crosstalk << " for detector \"" << _name << "\"";
130  }
131  if (shape[0] != _ampInfoCatalog.size()) {
133  os << "Wrong size crosstalk matrix: " << _crosstalk << " for detector \"" << _name << "\"";
135  }
136  }
137 }
138 
139 //
140 // Explicit instantiations
141 //
142 #define INSTANTIATE(FROMSYS, TOSYS) \
143  template std::shared_ptr<geom::TransformPoint2ToPoint2> Detector::getTransform(FROMSYS const &, \
144  TOSYS const &) const;
145 
146 INSTANTIATE(CameraSys, CameraSys);
147 INSTANTIATE(CameraSys, CameraSysPrefix);
148 INSTANTIATE(CameraSysPrefix, CameraSys);
149 INSTANTIATE(CameraSysPrefix, CameraSysPrefix);
150 
151 } // namespace cameraGeom
152 } // namespace afw
153 } // namespace lsst
CameraPoint transform(CameraPoint const &fromCameraPoint, CameraSys const &toSys) const
Convert a CameraPoint from one coordinate system to another.
Definition: Detector.h:277
Camera coordinate system; used as a key in in TransformMap.
Definition: CameraSys.h:83
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:577
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:73
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:97
CameraPoint makeCameraPoint(geom::Point2D const &point, CameraSys const &cameraSys) const
Make a CameraPoint from a point and a camera system.
Definition: Detector.h:232
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:256
A base class for image defects.
iterator end()
Iterator access.
Definition: Catalog.h:397
std::vector< Point2D > getCorners() const
Get the corner points.
int _id
Definition: Mask.cc:578
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:90
bool hasCrosstalk() const
Have we got crosstalk coefficients?
Definition: Detector.h:144
#define INSTANTIATE(FROMSYS, TOSYS)
Definition: Detector.cc:142
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:62
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:64
std::shared_ptr< RecordT > const get(size_type i) const
Return a pointer to the record at index i.
Definition: Catalog.h:446
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: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:162
DetectorType
Type of imaging detector.
Definition: Detector.h:43
ndarray::Array< float const, 2 > CrosstalkMatrix
Definition: Detector.h:66