22 #include "pybind11/pybind11.h" 24 #include "ndarray/pybind11.h" 46 namespace lsst {
namespace afw {
namespace image {
namespace {
51 using PyImageFitsReader = py::class_<ImageFitsReader, std::shared_ptr<ImageFitsReader>>;
52 using PyMaskFitsReader = py::class_<MaskFitsReader, std::shared_ptr<MaskFitsReader>>;
53 using PyMaskedImageFitsReader = py::class_<MaskedImageFitsReader, std::shared_ptr<MaskedImageFitsReader>>;
54 using PyExposureFitsReader = py::class_<ExposureFitsReader, std::shared_ptr<ExposureFitsReader>>;
58 template <
typename Class,
typename ...Args>
59 void declareCommonMethods(py::class_<Class, Args...> &
cls) {
60 cls.def(
"readBBox", &Class::readBBox,
"origin"_a=
PARENT);
62 cls.def(
"getFileName", &Class::getFileName);
63 cls.def_property_readonly(
"fileName", &Class::getFileName);
67 template <
typename Class,
typename ...Args>
68 void declareSinglePlaneMethods(py::class_<Class, Args...> & cls) {
69 cls.def(py::init<std::string const &, int>(),
"fileName"_a,
"hdu"_a=
fits::DEFAULT_HDU);
70 cls.def(py::init<fits::MemFileManager&, int>(),
"manager"_a,
"hdu"_a=
fits::DEFAULT_HDU);
72 cls.def(
"readDType", [](Class &
self) {
return py::dtype(
self.readDType()); });
73 cls.def(
"getHdu", &Class::getHdu);
74 cls.def_property_readonly(
"hdu", &Class::getHdu);
79 if (dtype.is(py::none())) {
80 dtype = py::dtype(
self.readDType());
82 return utils::python::TemplateInvoker().apply(
84 return self.template readArray<decltype(t)>(
bbox, origin, allowUnsafe);
87 utils::python::TemplateInvoker::Tag<std::uint16_t, int, float, double, std::uint64_t>()
95 template <
typename Class,
typename ...Args>
96 void declareMultiPlaneMethods(py::class_<Class, Args...> & cls) {
97 cls.def(
"readImageDType", [](Class &
self) {
return py::dtype(
self.readImageDType()); } );
98 cls.def(
"readMaskDType", [](Class &
self) {
return py::dtype(
self.readMaskDType()); });
99 cls.def(
"readVarianceDType", [](Class &
self) {
return py::dtype(
self.readVarianceDType()); });
104 if (dtype.is(py::none())) {
105 dtype = py::dtype(
self.readImageDType());
107 return utils::python::TemplateInvoker().apply(
109 return self.template readImage<decltype(t)>(
bbox, origin, allowUnsafe);
112 utils::python::TemplateInvoker::Tag<std::uint16_t, int, float, double, std::uint64_t>()
121 if (dtype.is(py::none())) {
122 dtype = py::dtype(
self.readImageDType());
124 return utils::python::TemplateInvoker().apply(
126 return self.template readImageArray<decltype(t)>(
bbox, origin, allowUnsafe);
129 utils::python::TemplateInvoker::Tag<std::uint16_t, int, float, double, std::uint64_t>()
137 bool allowUnsafe, py::object dtype) {
138 if (dtype.is(py::none())) {
139 dtype = py::dtype(
self.readMaskDType());
141 return utils::python::TemplateInvoker().apply(
143 return self.template readMask<decltype(t)>(
bbox, origin, conformMasks, allowUnsafe);
146 utils::python::TemplateInvoker::Tag<MaskPixel>()
156 if (dtype.is(py::none())) {
157 dtype = py::dtype(
self.readMaskDType());
159 return utils::python::TemplateInvoker().apply(
161 return self.template readMaskArray<decltype(t)>(
bbox, origin, allowUnsafe);
164 utils::python::TemplateInvoker::Tag<MaskPixel>()
173 if (dtype.is(py::none())) {
174 dtype = py::dtype(
self.readVarianceDType());
176 return utils::python::TemplateInvoker().apply(
178 return self.template readVariance<decltype(t)>(
bbox, origin, allowUnsafe);
181 utils::python::TemplateInvoker::Tag<VariancePixel>()
190 if (dtype.is(py::none())) {
191 dtype = py::dtype(
self.readVarianceDType());
193 return utils::python::TemplateInvoker().apply(
195 return self.template readVarianceArray<decltype(t)>(
bbox, origin, allowUnsafe);
198 utils::python::TemplateInvoker::Tag<VariancePixel>()
205 void declareImageFitsReader(
py::module & mod) {
206 PyImageFitsReader
cls(mod,
"ImageFitsReader");
207 declareCommonMethods(cls);
208 declareSinglePlaneMethods(cls);
213 if (dtype.is(py::none())) {
214 dtype = py::dtype(
self.readDType());
216 return utils::python::TemplateInvoker().apply(
218 return self.read<decltype(t)>(
bbox, origin, allowUnsafe);
221 utils::python::TemplateInvoker::Tag<std::uint16_t, int, float, double, std::uint64_t>()
228 void declareMaskFitsReader(
py::module & mod) {
229 PyMaskFitsReader
cls(mod,
"MaskFitsReader");
230 declareCommonMethods(cls);
231 declareSinglePlaneMethods(cls);
235 bool conformMasks,
bool allowUnsafe, py::object dtype) {
236 if (dtype.is(py::none())) {
237 dtype = py::dtype(
self.readDType());
239 return utils::python::TemplateInvoker().apply(
241 return self.read<decltype(t)>(
bbox, origin, conformMasks, allowUnsafe);
244 utils::python::TemplateInvoker::Tag<MaskPixel>()
253 void declareMaskedImageFitsReader(
py::module & mod) {
254 PyMaskedImageFitsReader
cls(mod,
"MaskedImageFitsReader");
255 cls.def(py::init<std::string const &, int>(),
"fileName"_a,
"hdu"_a=
fits::DEFAULT_HDU);
256 cls.def(py::init<fits::MemFileManager&, int>(),
"manager"_a,
"hdu"_a=
fits::DEFAULT_HDU);
257 declareCommonMethods(cls);
258 declareMultiPlaneMethods(cls);
259 cls.def(
"readPrimaryMetadata", &MaskedImageFitsReader::readPrimaryMetadata);
260 cls.def(
"readImageMetadata", &MaskedImageFitsReader::readImageMetadata);
261 cls.def(
"readMaskMetadata", &MaskedImageFitsReader::readMaskMetadata);
262 cls.def(
"readVarianceMetadata", &MaskedImageFitsReader::readVarianceMetadata);
266 bool conformMasks,
bool needAllHdus,
bool allowUnsafe, py::object dtype) {
267 if (dtype.is(py::none())) {
268 dtype = py::dtype(
self.readImageDType());
270 return utils::python::TemplateInvoker().apply(
272 return self.read<decltype(t)>(
bbox, origin, conformMasks, allowUnsafe);
275 utils::python::TemplateInvoker::Tag<std::uint16_t, int, float, double, std::uint64_t>()
279 "allowUnsafe"_a=
false,
"dtype"_a=py::none()
283 void declareExposureFitsReader(
py::module & mod) {
284 PyExposureFitsReader
cls(mod,
"ExposureFitsReader");
285 cls.def(py::init<std::string const &>(),
"fileName"_a);
286 cls.def(py::init<fits::MemFileManager&>(),
"manager"_a);
287 declareCommonMethods(cls);
288 declareMultiPlaneMethods(cls);
290 cls.def(
"readWcs", &ExposureFitsReader::readWcs);
291 cls.def(
"readFilter", &ExposureFitsReader::readFilter);
292 cls.def(
"readPhotoCalib", &ExposureFitsReader::readPhotoCalib);
293 cls.def(
"readPsf", &ExposureFitsReader::readPsf);
294 cls.def(
"readValidPolygon", &ExposureFitsReader::readValidPolygon);
295 cls.def(
"readApCorrMap", &ExposureFitsReader::readApCorrMap);
296 cls.def(
"readCoaddInputs", &ExposureFitsReader::readCoaddInputs);
297 cls.def(
"readVisitInfo", &ExposureFitsReader::readVisitInfo);
298 cls.def(
"readTransmissionCurve", &ExposureFitsReader::readTransmissionCurve);
299 cls.def(
"readDetector", &ExposureFitsReader::readDetector);
300 cls.def(
"readExposureInfo", &ExposureFitsReader::readExposureInfo);
304 bool conformMasks,
bool allowUnsafe, py::object dtype) {
305 if (dtype.is(py::none())) {
306 dtype = py::dtype(
self.readImageDType());
308 return utils::python::TemplateInvoker().apply(
310 return self.readMaskedImage<decltype(t)>(
bbox, origin, conformMasks, allowUnsafe);
313 utils::python::TemplateInvoker::Tag<std::uint16_t, int, float, double, std::uint64_t>()
322 bool conformMasks,
bool allowUnsafe, py::object dtype) {
323 if (dtype.is(py::none())) {
324 dtype = py::dtype(
self.readImageDType());
326 return utils::python::TemplateInvoker().apply(
328 return self.read<decltype(t)>(
bbox, origin, conformMasks, allowUnsafe);
331 utils::python::TemplateInvoker::Tag<std::uint16_t, int, float, double, std::uint64_t>()
341 py::module::import(
"lsst.daf.base");
342 py::module::import(
"lsst.geom");
343 py::module::import(
"lsst.afw.image.image");
344 py::module::import(
"lsst.afw.image.maskedImage");
345 py::module::import(
"lsst.afw.image.exposure");
346 declareImageFitsReader(mod);
347 declareMaskFitsReader(mod);
348 declareMaskedImageFitsReader(mod);
349 declareExposureFitsReader(mod);
PYBIND11_MODULE(camera, mod)
A base class for image defects.
Backwards-compatibility support for depersisting the old Calib (FluxMag0/FluxMag0Err) objects...
An integer coordinate rectangle.
Implementation of the Photometric Calibration class.
const int DEFAULT_HDU
Specify that the default HDU should be read.
std::shared_ptr< daf::base::PropertyList > readMetadata(std::string const &fileName, int hdu=DEFAULT_HDU, bool strip=false)
Read FITS header.