lsst.afw  13.0-94-ga1c444047
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  CameraTransformMap::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  _transformMap(CameraSys(PIXELS.getSysName(), name), transforms) {
45  _init();
46 }
47 
48 std::vector<geom::Point2D> Detector::getCorners(CameraSys const &cameraSys) const {
49  std::vector<geom::Point2D> fromVec = geom::Box2D(_bbox).getCorners();
50  return _transformMap.transform(fromVec, _transformMap.getNativeCoordSys(), cameraSys);
51 }
52 
53 std::vector<geom::Point2D> Detector::getCorners(CameraSysPrefix const &cameraSysPrefix) const {
54  return getCorners(makeCameraSys(cameraSysPrefix));
55 }
56 
57 CameraPoint Detector::getCenter(CameraSys const &cameraSys) const {
58  CameraPoint ctrPix = makeCameraPoint(geom::Box2D(_bbox).getCenter(), _transformMap.getNativeCoordSys());
59  return transform(ctrPix, cameraSys);
60 }
61 
62 CameraPoint Detector::getCenter(CameraSysPrefix const &cameraSysPrefix) const {
63  return getCenter(makeCameraSys(cameraSysPrefix));
64 }
65 
66 const table::AmpInfoRecord &Detector::operator[](std::string const &name) const { return *(_get(name)); }
67 
68 std::shared_ptr<table::AmpInfoRecord const> Detector::_get(int i) const {
69  if (i < 0) {
70  i = _ampInfoCatalog.size() + i;
71  };
72  return _ampInfoCatalog.get(i);
73 }
74 
75 std::shared_ptr<table::AmpInfoRecord const> Detector::_get(std::string const &name) const {
76  _AmpInfoMap::const_iterator ampIter = _ampNameIterMap.find(name);
77  if (ampIter == _ampNameIterMap.end()) {
78  std::ostringstream os;
79  os << "Unknown amplifier \"" << name << "\"";
80  throw LSST_EXCEPT(pexExcept::InvalidParameterError, os.str());
81  }
82  return ampIter->second;
83 }
84 
85 bool Detector::hasTransform(CameraSys const &cameraSys) const { return _transformMap.contains(cameraSys); }
86 
87 bool Detector::hasTransform(CameraSysPrefix const &cameraSysPrefix) const {
88  return hasTransform(makeCameraSys(cameraSysPrefix));
89 }
90 
91 std::shared_ptr<afw::geom::XYTransform const> Detector::getTransform(CameraSys const &cameraSys) const {
92  return _transformMap[cameraSys];
93 }
94 
95 std::shared_ptr<afw::geom::XYTransform const> Detector::getTransform(
96  CameraSysPrefix const &cameraSysPrefix) const {
97  return getTransform(makeCameraSys(cameraSysPrefix));
98 }
99 
100 void Detector::_init() {
101  // make _ampNameIterMap
102  for (table::AmpInfoCatalog::const_iterator ampIter = _ampInfoCatalog.begin();
103  ampIter != _ampInfoCatalog.end(); ++ampIter) {
104  _ampNameIterMap.insert(std::make_pair(ampIter->getName(), ampIter));
105  }
106  if (_ampNameIterMap.size() != _ampInfoCatalog.size()) {
107  throw LSST_EXCEPT(pexExcept::InvalidParameterError,
108  "Invalid ampInfoCatalog: not all amplifier names are unique");
109  }
110 
111  // check detector name in CoordSys in transform registry
112  for (CameraTransformMap::Transforms::const_iterator trIter = _transformMap.begin();
113  trIter != _transformMap.end(); ++trIter) {
114  if (trIter->first.hasDetectorName() && trIter->first.getDetectorName() != _name) {
115  std::ostringstream os;
116  os << "Invalid transformMap: " << trIter->first << " detector name != \"" << _name << "\"";
117  throw LSST_EXCEPT(pexExcept::InvalidParameterError, os.str());
118  }
119  }
120 }
121 } // namespace cameraGeom
122 } // namespace afw
123 } // namespace lsst
CameraPoint transform(CameraPoint const &fromCameraPoint, CameraSys const &toSys) const
Convert a CameraPoint from one coordinate system to another.
Definition: Detector.h:261
Camera coordinate system; used as a key in in TransformMap.
Definition: CameraSys.h:74
std::string const & _name
Definition: Mask.cc:546
Geometry and electronic information about raw amplifier images.
Definition: AmpInfo.h:79
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:68
CameraPoint makeCameraPoint(geom::Point2D const &point, CameraSys const &cameraSys) const
Make a CameraPoint from a point and a camera system.
Definition: Detector.h:216
std::vector< geom::Point2D > getCorners(CameraSys const &cameraSys) const
Get the corners of the detector in the specified camera coordinate system.
Definition: Detector.cc:48
CoordSysT getNativeCoordSys() const
Definition: TransformMap.h:109
An integer coordinate rectangle.
Definition: Box.h:55
Describe a detector&#39;s orientation in the focal plane.
Definition: Orientation.h:51
std::map< CameraSys, std::shared_ptr< XYTransform const > > Transforms
Definition: TransformMap.h:67
CameraSys const makeCameraSys(CameraSys const &cameraSys) const
Get a coordinate system from a coordinate system (return input unchanged and untested) ...
Definition: Detector.h:240
A base class for image defects.
Definition: cameraGeom.dox:3
Transforms::const_iterator begin() const
Definition: TransformMap.h:138
iterator end()
Iterator access.
Definition: Catalog.h:388
std::vector< Point2D > getCorners() const
Get the corner points.
Iterator class for CatalogT.
Definition: Catalog.h:37
bool hasTransform(CameraSys const &cameraSys) const
Does the specified camera coordinate system exist in the transform registry?
Definition: Detector.cc:85
table::Key< std::string > name
Definition: ApCorrMap.cc:71
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, CameraTransformMap::Transforms const &transforms)
Make a Detector.
Definition: Detector.cc:31
CameraPoint getCenter(CameraSys const &cameraSys) const
Get the center of the detector in the specified camera coordinate system.
Definition: Detector.cc:57
Point2D transform(Point2D const &fromPoint, CoordSysT const &fromSys, CoordSysT const &toCoordSys) const
Convert a point from one coordinate system to another.
std::shared_ptr< afw::geom::XYTransform const > getTransform(CameraSys const &cameraSys) const
Get an XYTransform that transforms from cameraSys to the native system in the forward direction...
Definition: Detector.cc:91
int _id
Definition: Mask.cc:547
Camera coordinate system prefix.
Definition: CameraSys.h:46
bool contains(CoordSysT const &coordSys) const
Return true if the coordinate system is supported.
std::shared_ptr< RecordT > const get(size_type i) const
Return a pointer to the record at index i.
Definition: Catalog.h:437
A Point2D with associated camera coordinate system.
Definition: CameraPoint.h:37
size_type size() const
Return the number of elements in the catalog.
Definition: Catalog.h:399
A floating-point coordinate rectangle geometry.
Definition: Box.h:266
iterator begin()
Iterator access.
Definition: Catalog.h:387
lsst::afw::table::AmpInfoRecord const & operator[](size_t i) const
Get the amplifier specified by index.
Definition: Detector.h:142
Transforms::const_iterator end() const
Definition: TransformMap.h:140
DetectorType
Type of imaging detector.
Definition: Detector.h:43