27#include "pybind11/pybind11.h"
30#include "pybind11/stl.h"
32#include "ndarray/pybind11.h"
43using namespace py::literals;
51using PyDetectorBase = py::classh<DetectorBase, typehandling::Storable>;
52using PyDetector = py::classh<Detector, DetectorBase>;
53using PyDetectorBuilder = py::classh<Detector::Builder, DetectorBase>;
54using PyDetectorPartialRebuilder = py::classh<Detector::PartialRebuilder, Detector::Builder>;
55using PyDetectorInCameraBuilder = py::classh<Detector::InCameraBuilder, Detector::Builder>;
58template <
typename SysT,
typename PyClass>
59void declare1SysMethods(PyClass &cls) {
69template <
typename FromSysT,
typename ToSysT,
typename PyClass>
70void declare2SysMethods(PyClass &cls) {
71 cls.def(
"getTransform",
72 (std::shared_ptr<geom::TransformPoint2ToPoint2>(
Detector::*)(FromSysT
const &, ToSysT
const &)
75 "fromSys"_a,
"toSys"_a);
80 "point"_a,
"fromSys"_a,
"toSys"_a);
82 (std::vector<lsst::geom::Point2D>(
Detector::*)(std::vector<lsst::geom::Point2D>
const &,
83 FromSysT
const &, ToSysT
const &)
const) &
85 "points"_a,
"fromSys"_a,
"toSys"_a);
88void declareDetectorBase(lsst::cpputils::python::WrapperCollection &wrappers) {
89 wrappers.
wrapType(PyDetectorBase(wrappers.
module,
"DetectorBase"), [](
auto &mod,
auto &cls) {
90 cls.def(
"getName", &DetectorBase::getName);
91 cls.def(
"getId", &DetectorBase::getId);
92 cls.def(
"getType", &DetectorBase::getType);
93 cls.def(
"getPhysicalType", &DetectorBase::getPhysicalType);
94 cls.def(
"getSerial", &DetectorBase::getSerial);
95 cls.def(
"getBBox", &DetectorBase::getBBox);
96 cls.def(
"getOrientation", &DetectorBase::getOrientation);
97 cls.def(
"getPixelSize", &DetectorBase::getPixelSize);
98 cls.def(
"hasCrosstalk", &DetectorBase::hasCrosstalk);
99 cls.def(
"getCrosstalk", &DetectorBase::getCrosstalk);
100 cls.def(
"getNativeCoordSys", &DetectorBase::getNativeCoordSys);
101 cls.def(
"makeCameraSys",
102 py::overload_cast<CameraSys const &>(&DetectorBase::makeCameraSys, py::const_),
104 cls.def(
"makeCameraSys",
105 py::overload_cast<CameraSysPrefix const &>(&DetectorBase::makeCameraSys, py::const_),
106 "cameraSysPrefix"_a);
110void declareDetectorBuilder(PyDetector &parent);
111void declareDetectorPartialRebuilder(PyDetector &parent);
112void declareDetectorInCameraBuilder(PyDetector &parent);
114void declareDetector(lsst::cpputils::python::WrapperCollection &wrappers) {
115 wrappers.
wrapType(PyDetector(wrappers.
module,
"Detector"), [](
auto &mod,
auto &cls) {
116 declareDetectorBuilder(cls);
117 declareDetectorPartialRebuilder(cls);
118 declareDetectorInCameraBuilder(cls);
119 cls.def(
"rebuild", &Detector::rebuild);
120 declare1SysMethods<CameraSys>(cls);
121 declare1SysMethods<CameraSysPrefix>(cls);
122 declare2SysMethods<CameraSys, CameraSys>(cls);
123 declare2SysMethods<CameraSys, CameraSysPrefix>(cls);
124 declare2SysMethods<CameraSysPrefix, CameraSys>(cls);
125 declare2SysMethods<CameraSysPrefix, CameraSysPrefix>(cls);
126 cls.def(
"getTransformMap", &Detector::getTransformMap);
127 cls.def(
"getAmplifiers", &Detector::getAmplifiers);
131 [](Detector const &self, std::ptrdiff_t i) {
132 return self[cpputils::python::cppIndex(self.size(), i)];
135 cls.def(
"__getitem__", py::overload_cast<std::string const &>(&Detector::operator[], py::const_),
142void declareDetectorBuilder(PyDetector &parent) {
143 PyDetectorBuilder cls(parent,
"Builder");
157 cls.def(
"__getitem__", py::overload_cast<std::string const &>(&Detector::Builder::operator[], py::const_),
164void declareDetectorPartialRebuilder(PyDetector &parent) {
165 PyDetectorPartialRebuilder cls(parent,
"PartialRebuilder");
166 cls.def(py::init<Detector const &>(),
"detector"_a);
170void declareDetectorInCameraBuilder(PyDetector &parent) {
171 PyDetectorInCameraBuilder cls(parent,
"InCameraBuilder");
174 cls.def(
"setTransformFromPixelsTo",
176 std::shared_ptr<afw::geom::TransformPoint2ToPoint2 const>>(
178 "toSys"_a,
"transform"_a);
179 cls.def(
"setTransformFromPixelsTo",
180 py::overload_cast<
CameraSys const &, std::shared_ptr<afw::geom::TransformPoint2ToPoint2 const>>(
182 "toSys"_a,
"transform"_a);
183 cls.def(
"discardTransformFromPixelsTo",
184 py::overload_cast<CameraSysPrefix const &>(
187 cls.def(
"discardTransformFromPixelsTo",
194 wrappers.
wrapType(py::enum_<DetectorType>(wrappers.
module,
"DetectorType"), [](
auto &mod,
auto &enm) {
195 enm.value(
"SCIENCE", DetectorType::SCIENCE);
196 enm.value(
"FOCUS", DetectorType::FOCUS);
197 enm.value(
"GUIDER", DetectorType::GUIDER);
198 enm.value(
"WAVEFRONT", DetectorType::WAVEFRONT);
200 declareDetectorBase(wrappers);
201 declareDetector(wrappers);
Camera coordinate system; used as a key in in TransformMap.
Camera coordinate system prefix.
A helper class for Detector that allows amplifiers and most fields to be modified.
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.
A representation of a detector in a mosaic camera.
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.
A helper class for subdividing pybind11 module across multiple translation units (i....
void addInheritanceDependency(std::string const &name)
Indicate an external module that provides a base class for a subsequent addType call.
PyType wrapType(PyType cls, ClassWrapperCallback function, bool setModuleName=true)
Add a type (class or enum) wrapper, deferring method and other attribute definitions until finish() i...
pybind11::module module
The module object passed to the PYBIND11_MODULE block that contains this WrapperCollection.
void wrapDetector(lsst::cpputils::python::WrapperCollection &)
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.
Point< double, 2 > Point2D