27#include "pybind11/pybind11.h"
30#include "pybind11/stl.h"
32#include "ndarray/pybind11.h"
44using namespace py::literals;
52using PyDetectorBase = py::class_<DetectorBase, std::shared_ptr<DetectorBase>>;
53using PyDetector = py::class_<Detector, DetectorBase, std::shared_ptr<Detector>, typehandling::Storable>;
54using PyDetectorBuilder = py::class_<Detector::Builder, DetectorBase, std::shared_ptr<Detector::Builder>>;
55using PyDetectorPartialRebuilder = py::class_<Detector::PartialRebuilder, Detector::Builder,
57using PyDetectorInCameraBuilder =
58 py::class_<Detector::InCameraBuilder, Detector::Builder, std::shared_ptr<Detector::InCameraBuilder>>;
61template <
typename SysT,
typename PyClass>
62void declare1SysMethods(
PyClass &cls) {
72template <
typename FromSysT,
typename ToSysT,
typename PyClass>
73void declare2SysMethods(
PyClass &cls) {
74 cls.def(
"getTransform",
78 "fromSys"_a,
"toSys"_a);
83 "point"_a,
"fromSys"_a,
"toSys"_a);
86 FromSysT
const &, ToSysT
const &)
const) &
88 "points"_a,
"fromSys"_a,
"toSys"_a);
91void declareDetectorBase(lsst::utils::python::WrapperCollection &wrappers) {
92 wrappers.wrapType(PyDetectorBase(wrappers.module,
"DetectorBase"), [](
auto &mod,
auto &cls) {
93 cls.def(
"getName", &DetectorBase::getName);
94 cls.def(
"getId", &DetectorBase::getId);
95 cls.def(
"getType", &DetectorBase::getType);
96 cls.def(
"getPhysicalType", &DetectorBase::getPhysicalType);
97 cls.def(
"getSerial", &DetectorBase::getSerial);
98 cls.def(
"getBBox", &DetectorBase::getBBox);
99 cls.def(
"getOrientation", &DetectorBase::getOrientation);
100 cls.def(
"getPixelSize", &DetectorBase::getPixelSize);
101 cls.def(
"hasCrosstalk", &DetectorBase::hasCrosstalk);
102 cls.def(
"getCrosstalk", &DetectorBase::getCrosstalk);
103 cls.def(
"getNativeCoordSys", &DetectorBase::getNativeCoordSys);
104 cls.def(
"makeCameraSys",
105 py::overload_cast<CameraSys const &>(&DetectorBase::makeCameraSys, py::const_),
107 cls.def(
"makeCameraSys",
108 py::overload_cast<CameraSysPrefix const &>(&DetectorBase::makeCameraSys, py::const_),
109 "cameraSysPrefix"_a);
113void declareDetectorBuilder(PyDetector &parent);
114void declareDetectorPartialRebuilder(PyDetector &parent);
115void declareDetectorInCameraBuilder(PyDetector &parent);
117void declareDetector(lsst::utils::python::WrapperCollection &wrappers) {
118 wrappers.wrapType(PyDetector(wrappers.module,
"Detector"), [](
auto &mod,
auto &cls) {
119 declareDetectorBuilder(cls);
120 declareDetectorPartialRebuilder(cls);
121 declareDetectorInCameraBuilder(cls);
122 cls.def(
"rebuild", &Detector::rebuild);
123 declare1SysMethods<CameraSys>(cls);
124 declare1SysMethods<CameraSysPrefix>(cls);
125 declare2SysMethods<CameraSys, CameraSys>(cls);
126 declare2SysMethods<CameraSys, CameraSysPrefix>(cls);
127 declare2SysMethods<CameraSysPrefix, CameraSys>(cls);
128 declare2SysMethods<CameraSysPrefix, CameraSysPrefix>(cls);
129 cls.def(
"getTransformMap", &Detector::getTransformMap);
130 cls.def(
"getAmplifiers", &Detector::getAmplifiers);
134 [](Detector const &self, std::ptrdiff_t i) {
135 return self[utils::python::cppIndex(self.size(), i)];
138 cls.def(
"__getitem__", py::overload_cast<std::string const &>(&Detector::operator[], py::const_),
145void declareDetectorBuilder(PyDetector &parent) {
146 PyDetectorBuilder cls(parent,
"Builder");
160 cls.def(
"__getitem__", py::overload_cast<std::string const &>(&Detector::Builder::operator[], py::const_),
167void declareDetectorPartialRebuilder(PyDetector &parent) {
168 PyDetectorPartialRebuilder cls(parent,
"PartialRebuilder");
169 cls.def(py::init<Detector const &>(),
"detector"_a);
173void declareDetectorInCameraBuilder(PyDetector &parent) {
174 PyDetectorInCameraBuilder cls(parent,
"InCameraBuilder");
177 cls.def(
"setTransformFromPixelsTo",
178 py::overload_cast<CameraSysPrefix
const &,
181 "toSys"_a,
"transform"_a);
182 cls.def(
"setTransformFromPixelsTo",
185 "toSys"_a,
"transform"_a);
186 cls.def(
"discardTransformFromPixelsTo",
187 py::overload_cast<CameraSysPrefix const &>(
190 cls.def(
"discardTransformFromPixelsTo",
196 wrappers.addInheritanceDependency(
"lsst.afw.typehandling");
197 wrappers.wrapType(py::enum_<DetectorType>(wrappers.module,
"DetectorType"), [](
auto &mod,
auto &enm) {
198 enm.value(
"SCIENCE", DetectorType::SCIENCE);
199 enm.value(
"FOCUS", DetectorType::FOCUS);
200 enm.value(
"GUIDER", DetectorType::GUIDER);
201 enm.value(
"WAVEFRONT", DetectorType::WAVEFRONT);
203 declareDetectorBase(wrappers);
204 declareDetector(wrappers);
void setSerial(std::string const &serial)
Set the detector serial "number".
void setBBox(lsst::geom::Box2I const &bbox)
Set the bounding box.
void setPhysicalType(std::string const &physicalType)
Set the detector's physical type.
void setCrosstalk(CrosstalkMatrix const &crosstalk)
Set the crosstalk coefficients.
std::vector< std::shared_ptr< Amplifier::Builder > > const & getAmplifiers() const
Return the sequence of Amplifier::Builders directly.
void setType(DetectorType type)
Set the purpose of this detector.
void unsetCrosstalk()
Remove the crosstalk coefficient matrix.
void append(std::shared_ptr< Amplifier::Builder > builder)
Append a new amplifier.
std::size_t size() const
Return the number of amplifiers (renamed to len in Python).
void clear()
Remove all amplifiers.
void setOrientation(Orientation const &orientation)
Set the orientation of the detector in the focal plane.
void setTransformFromPixelsTo(CameraSysPrefix const &toSys, std::shared_ptr< afw::geom::TransformPoint2ToPoint2 const > transform)
Set the transformation from PIXELS to the given coordinate system.
bool discardTransformFromPixelsTo(CameraSysPrefix const &toSys)
Remove any transformation from PIXELS to the given coordinate system.
void setPixelSize(lsst::geom::Extent2D const &pixelSize)
Set the pixel size (in mm).
std::shared_ptr< Detector const > finish() const
Construct a new Detector from the current state of the Builder.
bool hasTransform(CameraSys const &cameraSys) const
Can this object convert between PIXELS and the specified camera coordinate system?
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,...
std::size_t size() const
Get the number of amplifiers.
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::vector< lsst::geom::Point2D > getCorners(CameraSys const &cameraSys) const
Get the corners of the detector in the specified camera coordinate system.
lsst::geom::Point2D getCenter(CameraSys const &cameraSys) const
Get the center of the detector in the specified camera coordinate system.
void wrapDetector(lsst::utils::python::WrapperCollection &)
py::class_< PixelAreaBoundedField, std::shared_ptr< PixelAreaBoundedField >, BoundedField > PyClass
void addPersistableMethods(pybind11::class_< Class, Args... > &cls)
Add table::io::Persistable and PersistableFacade methods to the pybind11 wrapper for a class.
std::size_t cppIndex(std::ptrdiff_t size, std::ptrdiff_t i)
Compute a C++ index from a Python index (negative values count from the end) and range-check.
A base class for image defects.