lsst.afw  16.0-51-gb4b4a8566+2
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  lsst::geom::Box2I const &bbox, table::AmpInfoCatalog const &ampInfoCatalog,
33  Orientation const &orientation, lsst::geom::Extent2D const &pixelSize,
34  TransformMap::Transforms const &transforms, CrosstalkMatrix const &crosstalk) :
35  Detector(name, id, type, serial, bbox, ampInfoCatalog, orientation, pixelSize,
36  TransformMap::make(CameraSys(PIXELS, name), transforms),
37  crosstalk)
38 {}
39 
40 Detector::Detector(std::string const &name, int id, DetectorType type, std::string const &serial,
41  lsst::geom::Box2I const &bbox, table::AmpInfoCatalog const &ampInfoCatalog,
42  Orientation const &orientation, lsst::geom::Extent2D const &pixelSize,
44  _name(name),
45  _id(id),
46  _type(type),
47  _serial(serial),
48  _bbox(bbox),
49  _ampInfoCatalog(ampInfoCatalog),
50  _ampNameIterMap(),
51  _orientation(orientation),
52  _pixelSize(pixelSize),
53  _nativeSys(CameraSys(PIXELS, name)),
54  _transformMap(std::move(transformMap)),
55  _crosstalk(crosstalk)
56 {
57  // make _ampNameIterMap
58  for (auto ampIter = _ampInfoCatalog.begin(); ampIter != _ampInfoCatalog.end(); ++ampIter) {
59  _ampNameIterMap.insert(std::make_pair(ampIter->getName(), ampIter));
60  }
61  if (_ampNameIterMap.size() != _ampInfoCatalog.size()) {
63  "Invalid ampInfoCatalog: not all amplifier names are unique");
64  }
65 
66  // ensure crosstalk coefficients matrix is square
67  if (hasCrosstalk()) {
68  auto shape = _crosstalk.getShape();
69  assert(shape.size() == 2); // we've declared this as a 2D array
70  if (shape[0] != shape[1]) {
72  os << "Non-square crosstalk matrix: " << _crosstalk << " for detector \"" << _name << "\"";
74  }
75  if (shape[0] != _ampInfoCatalog.size()) {
77  os << "Wrong size crosstalk matrix: " << _crosstalk << " for detector \"" << _name << "\"";
79  }
80  }
81 }
82 
85  auto nativeToCameraSys = _transformMap->getTransform(_nativeSys, cameraSys);
86  return nativeToCameraSys->applyForward(nativeCorners);
87 }
88 
90  return getCorners(makeCameraSys(cameraSysPrefix));
91 }
92 
94  auto ctrPix = lsst::geom::Box2D(_bbox).getCenter();
95  auto transform = getTransform(PIXELS, cameraSys);
96  return transform->applyForward(ctrPix);
97 }
98 
100  return getCenter(makeCameraSys(cameraSysPrefix));
101 }
102 
103 const table::AmpInfoRecord &Detector::operator[](std::string const &name) const { return *(_get(name)); }
104 
106  if (i < 0) {
107  i = _ampInfoCatalog.size() + i;
108  };
109  return _ampInfoCatalog.get(i);
110 }
111 
113  _AmpInfoMap::const_iterator ampIter = _ampNameIterMap.find(name);
114  if (ampIter == _ampNameIterMap.end()) {
116  os << "Unknown amplifier \"" << name << "\"";
118  }
119  return ampIter->second;
120 }
121 
122 bool Detector::hasTransform(CameraSys const &cameraSys) const { return _transformMap->contains(cameraSys); }
123 
124 bool Detector::hasTransform(CameraSysPrefix const &cameraSysPrefix) const {
125  return hasTransform(makeCameraSys(cameraSysPrefix));
126 }
127 
128 template <typename FromSysT, typename ToSysT>
130  ToSysT const &toSys) const {
131  return _transformMap->getTransform(makeCameraSys(fromSys), makeCameraSys(toSys));
132 }
133 
134 template <typename FromSysT, typename ToSysT>
135 lsst::geom::Point2D Detector::transform(lsst::geom::Point2D const &point, FromSysT const &fromSys,
136  ToSysT const &toSys) const {
137  return _transformMap->transform(point, makeCameraSys(fromSys), makeCameraSys(toSys));
138 }
139 
140 template <typename FromSysT, typename ToSysT>
142  FromSysT const &fromSys, ToSysT const &toSys) const {
143  return _transformMap->transform(points, makeCameraSys(fromSys), makeCameraSys(toSys));
144 }
145 
146 //
147 // Explicit instantiations
148 //
149 #define INSTANTIATE(FROMSYS, TOSYS) \
150  template std::shared_ptr<geom::TransformPoint2ToPoint2> Detector::getTransform(FROMSYS const &, \
151  TOSYS const &) const; \
152  template lsst::geom::Point2D Detector::transform(lsst::geom::Point2D const &, FROMSYS const &, \
153  TOSYS const &) const; \
154  template std::vector<lsst::geom::Point2D> Detector::transform(std::vector<lsst::geom::Point2D> const &, \
155  FROMSYS const &, TOSYS const &) const;
156 
157 INSTANTIATE(CameraSys, CameraSys);
158 INSTANTIATE(CameraSys, CameraSysPrefix);
159 INSTANTIATE(CameraSysPrefix, CameraSys);
160 INSTANTIATE(CameraSysPrefix, CameraSysPrefix);
161 
162 } // namespace cameraGeom
163 } // namespace afw
164 } // namespace lsst
std::vector< Point2D > getCorners() const
A registry of 2-dimensional coordinate transforms for a specific camera.
Definition: TransformMap.h:63
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
Point2D const getCenter() const noexcept
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:105
STL namespace.
T end(T... args)
Describe a detector&#39;s orientation in the focal plane.
Definition: Orientation.h:52
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:254
A base class for image defects.
iterator end()
Iterator access.
Definition: Catalog.h:397
bool hasTransform(CameraSys const &cameraSys) const
Can this object convert between PIXELS and the specified camera coordinate system?
Definition: Detector.cc:122
bool hasCrosstalk() const
Have we got crosstalk coefficients?
Definition: Detector.h:166
std::vector< lsst::geom::Point2D > getCorners(CameraSys const &cameraSys) const
Get the corners of the detector in the specified camera coordinate system.
Definition: Detector.cc:83
#define INSTANTIATE(FROMSYS, TOSYS)
Definition: Detector.cc:149
T str(T... args)
T make_pair(T... args)
lsst::geom::Point2D getCenter(CameraSys const &cameraSys) const
Get the center of the detector in the specified camera coordinate system.
Definition: Detector.cc:93
Camera coordinate system prefix.
Definition: CameraSys.h:44
T insert(T... args)
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
table::Box2IKey bbox
size_type size() const
Return the number of elements in the catalog.
Definition: Catalog.h:408
Detector(std::string const &name, int id, DetectorType type, std::string const &serial, lsst::geom::Box2I const &bbox, lsst::afw::table::AmpInfoCatalog const &ampInfoCatalog, Orientation const &orientation, lsst::geom::Extent2D const &pixelSize, TransformMap::Transforms const &transforms, CrosstalkMatrix const &crosstalk=CrosstalkMatrix())
Make a Detector.
Definition: Detector.cc:31
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:184
DetectorType
Type of imaging detector.
Definition: Detector.h:43
std::ostream * os
Definition: Schema.cc:737
ndarray::Array< float const, 2 > CrosstalkMatrix
Definition: Detector.h:66
lsst::geom::Point2D transform(lsst::geom::Point2D const &point, FromSysT const &fromSys, ToSysT const &toSys) const
Transform a point from one camera system to another.
Definition: Detector.cc:135
std::shared_ptr< afw::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.