24#include "pybind11/pybind11.h"
25#include "pybind11/stl.h"
28#include "ndarray/pybind11.h"
47using namespace pybind11::literals;
57using PyImageFitsReader = py::class_<ImageFitsReader, std::shared_ptr<ImageFitsReader>>;
58using PyMaskFitsReader = py::class_<MaskFitsReader, std::shared_ptr<MaskFitsReader>>;
59using PyMaskedImageFitsReader = py::class_<MaskedImageFitsReader, std::shared_ptr<MaskedImageFitsReader>>;
60using PyExposureFitsReader = py::class_<ExposureFitsReader, std::shared_ptr<ExposureFitsReader>>;
64template <
typename Class,
typename... Args>
65void declareCommonMethods(py::class_<Class, Args...> &cls) {
66 cls.def(
"readBBox", &Class::readBBox,
"origin"_a = PARENT);
68 cls.def(
"getFileName", &Class::getFileName);
69 cls.def_property_readonly(
"fileName", &Class::getFileName);
73template <
typename Class,
typename... Args>
74void declareSinglePlaneMethods(py::class_<Class, Args...> &cls) {
77 cls.def(
"readMetadata", &Class::readMetadata);
78 cls.def(
"readDType", [](Class &self) {
return py::dtype(self.readDType()); });
79 cls.def(
"getHdu", &Class::getHdu);
80 cls.def_property_readonly(
"hdu", &Class::getHdu);
85 if (
dtype.is(py::none())) {
86 dtype = py::dtype(self.readDType());
88 return utils::python::TemplateInvoker().apply(
90 return self.template readArray<decltype(t)>(
bbox, origin, allowUnsafe);
93 utils::python::TemplateInvoker::Tag<
std::uint16_t, int, float, double,
97 "dtype"_a = py::none());
101template <
typename Class,
typename... Args>
102void declareMultiPlaneMethods(py::class_<Class, Args...> &cls) {
103 cls.def(
"readImageDType", [](Class &self) {
return py::dtype(self.readImageDType()); });
104 cls.def(
"readMaskDType", [](Class &self) {
return py::dtype(self.readMaskDType()); });
105 cls.def(
"readVarianceDType", [](Class &self) {
return py::dtype(self.readVarianceDType()); });
110 if (
dtype.is(py::none())) {
111 dtype = py::dtype(self.readImageDType());
113 return utils::python::TemplateInvoker().apply(
115 return self.template readImage<decltype(t)>(
bbox, origin, allowUnsafe);
118 utils::python::TemplateInvoker::Tag<
std::uint16_t, int, float, double,
122 "dtype"_a = py::none());
127 if (
dtype.is(py::none())) {
128 dtype = py::dtype(self.readImageDType());
130 return utils::python::TemplateInvoker().apply(
132 return self.template readImageArray<decltype(t)>(
bbox, origin, allowUnsafe);
135 utils::python::TemplateInvoker::Tag<
std::uint16_t, int, float, double,
139 "dtype"_a = py::none());
143 bool allowUnsafe, py::object dtype) {
144 if (
dtype.is(py::none())) {
145 dtype = py::dtype(self.readMaskDType());
147 return utils::python::TemplateInvoker().apply(
149 return self.template readMask<decltype(t)>(
bbox, origin, conformMasks,
152 py::dtype(dtype), utils::python::TemplateInvoker::Tag<MaskPixel>());
155 "allowUnsafe"_a =
false,
"dtype"_a = py::none());
160 if (
dtype.is(py::none())) {
161 dtype = py::dtype(self.readMaskDType());
163 return utils::python::TemplateInvoker().apply(
165 return self.template readMaskArray<decltype(t)>(
bbox, origin, allowUnsafe);
167 py::dtype(dtype), utils::python::TemplateInvoker::Tag<MaskPixel>());
170 "dtype"_a = py::none());
175 if (
dtype.is(py::none())) {
176 dtype = py::dtype(self.readVarianceDType());
178 return utils::python::TemplateInvoker().apply(
180 return self.template readVariance<decltype(t)>(
bbox, origin, allowUnsafe);
182 py::dtype(dtype), utils::python::TemplateInvoker::Tag<VariancePixel>());
185 "dtype"_a = py::none());
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);
197 py::dtype(dtype), utils::python::TemplateInvoker::Tag<VariancePixel>());
200 "dtype"_a = py::none());
203void declareImageFitsReader(lsst::utils::python::WrapperCollection &wrappers) {
204 wrappers.wrapType(PyImageFitsReader(wrappers.module,
"ImageFitsReader"), [](
auto &mod,
auto &cls) {
205 declareCommonMethods(cls);
206 declareSinglePlaneMethods(cls);
209 [](ImageFitsReader &self, lsst::geom::Box2I const &bbox, ImageOrigin origin, bool allowUnsafe,
211 if (dtype.is(py::none())) {
212 dtype = py::dtype(self.readDType());
214 return utils::python::TemplateInvoker().apply(
215 [&](auto t) { return self.read<decltype(t)>(bbox, origin, allowUnsafe); },
217 utils::python::TemplateInvoker::Tag<std::uint16_t, int, float, double,
221 "dtype"_a = py::none());
225void declareMaskFitsReader(lsst::utils::python::WrapperCollection &wrappers) {
226 wrappers.wrapType(PyMaskFitsReader(wrappers.module,
"MaskFitsReader"), [](
auto &mod,
auto &cls) {
227 declareCommonMethods(cls);
228 declareSinglePlaneMethods(cls);
231 [](MaskFitsReader &self, lsst::geom::Box2I const &bbox, ImageOrigin origin, bool conformMasks,
232 bool allowUnsafe, py::object dtype) {
233 if (dtype.is(py::none())) {
234 dtype = py::dtype(self.readDType());
236 return utils::python::TemplateInvoker().apply(
238 return self.read<decltype(t)>(bbox, origin, conformMasks, allowUnsafe);
240 py::dtype(dtype), utils::python::TemplateInvoker::Tag<MaskPixel>());
243 "allowUnsafe"_a =
false,
"dtype"_a = py::none());
248void declareMaskedImageFitsReader(lsst::utils::python::WrapperCollection &wrappers) {
249 wrappers.wrapType(PyMaskedImageFitsReader(wrappers.module,
"MaskedImageFitsReader"), [](
auto &mod,
251 cls.def(py::init<std::string const &, int>(),
"fileName"_a,
"hdu"_a = fits::DEFAULT_HDU);
252 cls.def(py::init<fits::MemFileManager &, int>(),
"manager"_a,
"hdu"_a = fits::DEFAULT_HDU);
253 declareCommonMethods(cls);
254 declareMultiPlaneMethods(cls);
255 cls.def(
"readPrimaryMetadata", &MaskedImageFitsReader::readPrimaryMetadata);
256 cls.def(
"readImageMetadata", &MaskedImageFitsReader::readImageMetadata);
257 cls.def(
"readMaskMetadata", &MaskedImageFitsReader::readMaskMetadata);
258 cls.def(
"readVarianceMetadata", &MaskedImageFitsReader::readVarianceMetadata);
261 [](MaskedImageFitsReader &self, lsst::geom::Box2I const &bbox, ImageOrigin origin,
262 bool conformMasks, bool needAllHdus, bool allowUnsafe, py::object dtype) {
263 if (dtype.is(py::none())) {
264 dtype = py::dtype(self.readImageDType());
266 return utils::python::TemplateInvoker().apply(
268 return self.read<decltype(t)>(bbox, origin, conformMasks, allowUnsafe);
271 utils::python::TemplateInvoker::Tag<std::uint16_t, int, float, double,
275 "needAllHdus"_a =
false,
"allowUnsafe"_a =
false,
"dtype"_a = py::none());
279void declareExposureFitsReader(lsst::utils::python::WrapperCollection &wrappers) {
280 wrappers.wrapType(PyExposureFitsReader(wrappers.module,
"ExposureFitsReader"), [](
auto &mod,
auto &cls) {
281 cls.def(py::init<std::string const &>(),
"fileName"_a);
282 cls.def(py::init<fits::MemFileManager &>(),
"manager"_a);
283 declareCommonMethods(cls);
284 declareMultiPlaneMethods(cls);
285 cls.def(
"readSerializationVersion", &ExposureFitsReader::readSerializationVersion);
286 cls.def(
"readExposureId", &ExposureFitsReader::readExposureId);
287 cls.def(
"readMetadata", &ExposureFitsReader::readMetadata);
288 cls.def(
"readWcs", &ExposureFitsReader::readWcs);
289 cls.def(
"readFilter", &ExposureFitsReader::readFilter);
290 cls.def(
"readPhotoCalib", &ExposureFitsReader::readPhotoCalib);
291 cls.def(
"readPsf", &ExposureFitsReader::readPsf);
292 cls.def(
"readValidPolygon", &ExposureFitsReader::readValidPolygon);
293 cls.def(
"readApCorrMap", &ExposureFitsReader::readApCorrMap);
294 cls.def(
"readCoaddInputs", &ExposureFitsReader::readCoaddInputs);
295 cls.def(
"readVisitInfo", &ExposureFitsReader::readVisitInfo);
296 cls.def(
"readTransmissionCurve", &ExposureFitsReader::readTransmissionCurve);
297 cls.def(
"readComponent", &ExposureFitsReader::readComponent);
298 cls.def(
"readDetector", &ExposureFitsReader::readDetector);
299 cls.def(
"readExposureInfo", &ExposureFitsReader::readExposureInfo);
302 [](ExposureFitsReader &self, lsst::geom::Box2I const &bbox, ImageOrigin origin,
303 bool conformMasks, bool allowUnsafe, py::object dtype) {
304 if (dtype.is(py::none())) {
305 dtype = py::dtype(self.readImageDType());
307 return utils::python::TemplateInvoker().apply(
309 return self.readMaskedImage<decltype(t)>(bbox, origin, conformMasks,
313 utils::python::TemplateInvoker::Tag<std::uint16_t, int, float, double,
317 "allowUnsafe"_a =
false,
"dtype"_a = py::none());
321 bool conformMasks,
bool allowUnsafe, py::object dtype) {
322 if (
dtype.is(py::none())) {
323 dtype = py::dtype(self.readImageDType());
325 return utils::python::TemplateInvoker().apply(
327 return self.read<decltype(t)>(bbox, origin, conformMasks, allowUnsafe);
330 utils::python::TemplateInvoker::Tag<
std::uint16_t,
int,
float,
double,
334 "allowUnsafe"_a =
false,
"dtype"_a = py::none());
338void wrapReaders(lsst::utils::python::WrapperCollection &wrappers) {
340 wrappers.addSignatureDependency(
"lsst.geom");
341 wrappers.addSignatureDependency(
"lsst.afw.image.image");
342 wrappers.addSignatureDependency(
"lsst.afw.image.maskedImage");
343 wrappers.addSignatureDependency(
"lsst.afw.image.exposure");
344 declareImageFitsReader(wrappers);
345 declareMaskFitsReader(wrappers);
346 declareMaskedImageFitsReader(wrappers);
347 declareExposureFitsReader(wrappers);
Implementation of the Photometric Calibration class.
An integer coordinate rectangle.
const int DEFAULT_HDU
Specify that the default HDU should be read.
void wrapReaders(lsst::utils::python::WrapperCollection &)