34 namespace cameraGeom {
41 Detector(name, id, type, serial, bbox, ampInfoCatalog, orientation, pixelSize,
43 crosstalk, physicalType)
56 _ampInfoCatalog(ampInfoCatalog),
58 _orientation(orientation),
59 _pixelSize(pixelSize),
61 _transformMap(
std::move(transformMap)),
62 _crosstalk(crosstalk),
63 _physicalType(physicalType)
66 for (
auto ampIter = _ampInfoCatalog.
begin(); ampIter != _ampInfoCatalog.
end(); ++ampIter) {
69 if (_ampNameIterMap.
size() != _ampInfoCatalog.
size()) {
71 "Invalid ampInfoCatalog: not all amplifier names are unique");
76 auto shape = _crosstalk.getShape();
77 assert(shape.size() == 2);
78 if (shape[0] != shape[1]) {
80 os <<
"Non-square crosstalk matrix: " << _crosstalk <<
" for detector \"" << _name <<
"\"";
83 if (shape[0] != _ampInfoCatalog.
size()) {
85 os <<
"Wrong size crosstalk matrix: " << _crosstalk <<
" for detector \"" << _name <<
"\"";
93 auto nativeToCameraSys = _transformMap->getTransform(_nativeSys, cameraSys);
94 return nativeToCameraSys->applyForward(nativeCorners);
115 i = _ampInfoCatalog.
size() + i;
117 return _ampInfoCatalog.
get(i);
121 _AmpInfoMap::const_iterator ampIter = _ampNameIterMap.
find(name);
122 if (ampIter == _ampNameIterMap.
end()) {
124 os <<
"Unknown amplifier \"" << name <<
"\"";
127 return ampIter->second;
136 template <
typename FromSysT,
typename ToSysT>
138 ToSysT
const &toSys)
const {
142 template <
typename FromSysT,
typename ToSysT>
144 ToSysT
const &toSys)
const {
148 template <
typename FromSysT,
typename ToSysT>
150 FromSysT
const &fromSys, ToSysT
const &toSys)
const {
156 class PersistenceHelper {
159 static PersistenceHelper
const &
get() {
160 static PersistenceHelper
const instance;
173 table::Key<lsst::geom::Angle>
yaw;
174 table::Key<lsst::geom::Angle>
pitch;
175 table::Key<lsst::geom::Angle>
roll;
180 PersistenceHelper(table::Schema
const & existing) :
182 name(schema[
"name"]),
184 type(schema[
"type"]),
185 serial(schema[
"serial"]),
186 bbox(schema[
"bbox"]),
187 pixelSize(schema[
"pixelSize"]),
188 fpPosition(schema[
"fpPosition"]),
189 refPoint(schema[
"refPoint"]),
191 pitch(schema[
"pitch"]),
192 roll(schema[
"roll"]),
193 transformMap(schema[
"transformMap"]),
194 crosstalk(schema[
"crosstalk"])
199 }
catch (pex::exceptions::NotFoundError &) {}
203 setKeyIfPresent(physicalType,
"physicalType");
208 PersistenceHelper() :
210 name(schema.addField<
std::string>(
"name",
"Name of the detector",
"", 0)),
211 id(schema.addField<
int>(
"id",
"Integer ID for the detector",
"")),
212 type(schema.addField<
int>(
"type",
"Raw DetectorType enum value",
"")),
213 serial(schema.addField<
std::string>(
"serial",
"Serial name of the detector",
"", 0)),
217 "Focal plane position of reference point",
"mm")),
219 "Pixel position of reference point",
"pixel")),
222 roll(schema.addField<
lsst::geom::Angle>(
"roll",
"Rotation about X'' (Y''=Y' to Z''), 3rd rotation")),
223 transformMap(schema.addField<
int>(
"transformMap",
"Archive ID of TransformMap",
"")),
224 crosstalk(schema.addField<table::Array<float>>(
"crosstalk",
"Crosstalk matrix, flattened",
"", 0)),
228 PersistenceHelper(PersistenceHelper
const &) =
delete;
229 PersistenceHelper(PersistenceHelper &&) =
delete;
231 PersistenceHelper &
operator=(PersistenceHelper
const &) =
delete;
232 PersistenceHelper &
operator=(PersistenceHelper &&) =
delete;
237 class DetectorFactory :
public table::io::PersistableFactory {
240 DetectorFactory() : PersistableFactory(
"Detector") {}
243 CatalogVector
const& catalogs)
const override {
245 auto const &
keys = PersistenceHelper(catalogs.front().getSchema());
250 auto const & record = catalogs.front().front();
253 amps.
reserve(catalogs.back().size());
257 for (
auto const & amp : catalogs.back()) {
258 amps.addNew()->assign(amp);
261 auto flattenedMatrix = record.get(
keys.crosstalk);
263 if (!flattenedMatrix.isEmpty()) {
264 crosstalk = ndarray::allocate(amps.size(), amps.size());
265 ndarray::flatten<1>(
crosstalk) = flattenedMatrix;
271 return std::make_shared<Detector>(
272 record.get(
keys.name),
275 record.get(
keys.serial),
276 record.get(
keys.bbox),
279 record.get(
keys.fpPosition),
280 record.get(
keys.refPoint),
281 record.get(
keys.yaw),
282 record.get(
keys.pitch),
283 record.get(
keys.roll)
286 archive.get<TransformMap>(record.get(
keys.transformMap)),
294 DetectorFactory
const registration;
303 return "lsst.afw.cameraGeom";
307 auto const &
keys = PersistenceHelper::get();
309 auto cat = handle.makeCatalog(
keys.schema);
310 auto record = cat.addNew();
313 record->set(
keys.type, static_cast<int>(
getType()));
325 auto flattenMatrix = [](ndarray::Array<float const, 2>
const & matrix) {
328 ndarray::Array<float, 2, 2> copied = ndarray::copy(matrix);
330 ndarray::Array<float, 1, 1> flattened = ndarray::flatten<1>(copied);
336 handle.saveCatalog(cat);
338 auto amps = handle.makeCatalog(_ampInfoCatalog.getSchema());
339 amps.assign(_ampInfoCatalog.begin(), _ampInfoCatalog.end(),
true);
340 handle.saveCatalog(amps);
347 #define INSTANTIATE(FROMSYS, TOSYS) \ 348 template std::shared_ptr<geom::TransformPoint2ToPoint2> Detector::getTransform(FROMSYS const &, \ 349 TOSYS const &) const; \ 350 template lsst::geom::Point2D Detector::transform(lsst::geom::Point2D const &, FROMSYS const &, \ 351 TOSYS const &) const; \ 352 template std::vector<lsst::geom::Point2D> Detector::transform(std::vector<lsst::geom::Point2D> const &, \ 353 FROMSYS const &, TOSYS const &) const; 365 template class PersistableFacade<cameraGeom::Detector>;
std::vector< Point2D > getCorners() const
Camera coordinate system; used as a key in in TransformMap.
table::Point2DKey pixelSize
Detector(std::string const &name, int id, DetectorType type, std::string const &serial, lsst::geom::Box2I const &bbox, lsst::afw::table::AmpInfoCatalog const &InfoCatalog, Orientation const &orientation, lsst::geom::Extent2D const &pixelSize, TransformMap::Transforms const &transforms, CrosstalkMatrix const &crosstalk=CrosstalkMatrix(), std::string const &physicalType="")
Make a Detector.
Geometry and electronic information about raw amplifier images.
table::Key< lsst::geom::Angle > pitch
Point2D const getCenter() const noexcept
table::AmpInfoRecord const & operator[](size_t i) const
Get the amplifier specified by index.
BoxKey< lsst::geom::Box2I > Box2IKey
#define LSST_ARCHIVE_ASSERT(EXPR)
An assertion macro used to validate the structure of an InputArchive.
CameraSysPrefix const PIXELS
Pixel coordinates: Nominal position on the entry surface of a given detector (x, y unbinned pixels)...
table::Key< lsst::geom::Angle > roll
std::shared_ptr< table::AmpInfoRecord const > _get(int i) const
Get the amplifier specified by index, returning a shared pointer to an AmpInfo record.
table::Point2DKey fpPosition
static PointKey addFields(Schema &schema, std::string const &name, std::string const &doc, std::string const &unit)
Add a pair of _x, _y fields to a Schema, and return a PointKey that points to them.
table::Key< lsst::geom::Angle > yaw
std::string getPhysicalType() const
Get information about the physical type of the device (e.g.
PointKey< double > Point2DKey
table::Key< std::string > serial
DetectorType getType() const
Get the "type" (really purpose) of the Detector.
Describe a detector's orientation in the focal plane.
table::Key< std::string > name
CameraSys const makeCameraSys(CameraSys const &cameraSys) const
Get a coordinate system from a coordinate system (return input unchanged and untested) ...
Orientation const getOrientation() const
Get detector's orientation in the focal plane.
lsst::geom::Box2I getBBox() const
Get the bounding box.
A base class for image defects.
std::shared_ptr< TransformMap const > getTransformMap() const
Get the transform registry.
table::Key< std::string > physicalType
iterator end()
Iterator access.
bool hasTransform(CameraSys const &cameraSys) const
Can this object convert between PIXELS and the specified camera coordinate system?
bool hasCrosstalk() const
Have we got crosstalk coefficients?
std::vector< lsst::geom::Point2D > getCorners(CameraSys const &cameraSys) const
Get the corners of the detector in the specified camera coordinate system.
#define INSTANTIATE(FROMSYS, TOSYS)
CrosstalkMatrix const getCrosstalk() const
Get the crosstalk coefficients.
CatalogT< AmpInfoRecord > AmpInfoCatalog
table::Key< int > transformMap
table::Point2DKey refPoint
lsst::geom::Point2D getCenter(CameraSys const &cameraSys) const
Get the center of the detector in the specified camera coordinate system.
Camera coordinate system prefix.
void reserve(size_type n)
Increase the capacity of the catalog to the given size.
#define LSST_EXCEPT(type,...)
std::string getName() const
Get the detector name.
Information about a CCD or other imaging detector.
Detector & operator=(Detector const &)=delete
std::shared_ptr< RecordT > const get(size_type i) const
Return a pointer to the record at index i.
int getId() const
Get the detector ID.
io::OutputArchiveHandle OutputArchiveHandle
size_type size() const
Return the number of elements in the catalog.
iterator begin()
Iterator access.
lsst::geom::Extent2D getPixelSize() const
Get size of pixel along (mm)
DetectorType
Type of imaging detector.
ndarray::Array< float const, 2 > CrosstalkMatrix
table::Key< table::Array< float > > crosstalk
static BoxKey addFields(Schema &schema, std::string const &name, std::string const &doc, std::string const &unit)
Add _min_x, _min_y, _max_x, _max_y fields to a Schema, and return a BoxKey that points to them...
std::string getSerial() const
Get the detector serial "number".
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.
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.