24 #include "pybind11/pybind11.h"
25 #include "pybind11/stl.h"
28 #include "ndarray/pybind11.h"
48 using namespace pybind11::literals;
58 using PyImageFitsReader = py::class_<ImageFitsReader, std::shared_ptr<ImageFitsReader>>;
59 using PyMaskFitsReader = py::class_<MaskFitsReader, std::shared_ptr<MaskFitsReader>>;
60 using PyMaskedImageFitsReader = py::class_<MaskedImageFitsReader, std::shared_ptr<MaskedImageFitsReader>>;
61 using PyExposureFitsReader = py::class_<ExposureFitsReader, std::shared_ptr<ExposureFitsReader>>;
65 template <
typename Class,
typename... Args>
66 void declareCommonMethods(py::class_<Class, Args...> &cls) {
67 cls.def(
"readBBox", &Class::readBBox,
"origin"_a =
PARENT);
69 cls.def(
"getFileName", &Class::getFileName);
70 cls.def_property_readonly(
"fileName", &Class::getFileName);
74 template <
typename Class,
typename... Args>
75 void declareSinglePlaneMethods(py::class_<Class, Args...> &cls) {
76 cls.def(py::init<std::string const &, int>(),
"fileName"_a,
"hdu"_a =
fits::DEFAULT_HDU);
77 cls.def(py::init<fits::MemFileManager &, int>(),
"manager"_a,
"hdu"_a =
fits::DEFAULT_HDU);
79 cls.def(
"readDType", [](Class &
self) {
return py::dtype(
self.readDType()); });
80 cls.def(
"getHdu", &Class::getHdu);
81 cls.def_property_readonly(
"hdu", &Class::getHdu);
86 if (
dtype.is(py::none())) {
89 return utils::python::TemplateInvoker().apply(
91 return self.template readArray<decltype(t)>(
bbox, origin, allowUnsafe);
94 utils::python::TemplateInvoker::Tag<
std::uint16_t, int, float, double,
98 "dtype"_a = py::none());
102 template <
typename Class,
typename... Args>
103 void declareMultiPlaneMethods(py::class_<Class, Args...> &cls) {
104 cls.def(
"readImageDType", [](Class &
self) {
return py::dtype(
self.readImageDType()); });
105 cls.def(
"readMaskDType", [](Class &
self) {
return py::dtype(
self.readMaskDType()); });
106 cls.def(
"readVarianceDType", [](Class &
self) {
return py::dtype(
self.readVarianceDType()); });
111 if (
dtype.is(py::none())) {
114 return utils::python::TemplateInvoker().apply(
116 return self.template readImage<decltype(t)>(
bbox, origin, allowUnsafe);
119 utils::python::TemplateInvoker::Tag<
std::uint16_t, int, float, double,
123 "dtype"_a = py::none());
128 if (
dtype.is(py::none())) {
131 return utils::python::TemplateInvoker().apply(
133 return self.template readImageArray<decltype(t)>(
bbox, origin, allowUnsafe);
136 utils::python::TemplateInvoker::Tag<
std::uint16_t, int, float, double,
140 "dtype"_a = py::none());
144 bool allowUnsafe, py::object
dtype) {
145 if (
dtype.is(py::none())) {
148 return utils::python::TemplateInvoker().apply(
150 return self.template readMask<decltype(t)>(
bbox, origin, conformMasks,
153 py::dtype(
dtype), utils::python::TemplateInvoker::Tag<MaskPixel>());
156 "allowUnsafe"_a =
false,
"dtype"_a = py::none());
161 if (
dtype.is(py::none())) {
164 return utils::python::TemplateInvoker().apply(
166 return self.template readMaskArray<decltype(t)>(
bbox, origin, allowUnsafe);
168 py::dtype(
dtype), utils::python::TemplateInvoker::Tag<MaskPixel>());
171 "dtype"_a = py::none());
176 if (
dtype.is(py::none())) {
179 return utils::python::TemplateInvoker().apply(
181 return self.template readVariance<decltype(t)>(
bbox, origin, allowUnsafe);
183 py::dtype(
dtype), utils::python::TemplateInvoker::Tag<VariancePixel>());
186 "dtype"_a = py::none());
191 if (
dtype.is(py::none())) {
194 return utils::python::TemplateInvoker().apply(
196 return self.template readVarianceArray<decltype(t)>(
bbox, origin, allowUnsafe);
198 py::dtype(
dtype), utils::python::TemplateInvoker::Tag<VariancePixel>());
201 "dtype"_a = py::none());
204 void declareImageFitsReader(lsst::utils::python::WrapperCollection &wrappers) {
205 wrappers.wrapType(PyImageFitsReader(wrappers.module,
"ImageFitsReader"), [](
auto &mod,
auto &cls) {
206 declareCommonMethods(cls);
207 declareSinglePlaneMethods(cls);
210 [](ImageFitsReader &self, lsst::geom::Box2I const &bbox, ImageOrigin origin, bool allowUnsafe,
212 if (dtype.is(py::none())) {
213 dtype = py::dtype(self.readDType());
215 return utils::python::TemplateInvoker().apply(
216 [&](auto t) { return self.read<decltype(t)>(bbox, origin, allowUnsafe); },
218 utils::python::TemplateInvoker::Tag<std::uint16_t, int, float, double,
222 "dtype"_a = py::none());
226 void declareMaskFitsReader(lsst::utils::python::WrapperCollection &wrappers) {
227 wrappers.wrapType(PyMaskFitsReader(wrappers.module,
"MaskFitsReader"), [](
auto &mod,
auto &cls) {
228 declareCommonMethods(cls);
229 declareSinglePlaneMethods(cls);
232 [](MaskFitsReader &self, lsst::geom::Box2I const &bbox, ImageOrigin origin, bool conformMasks,
233 bool allowUnsafe, py::object dtype) {
234 if (dtype.is(py::none())) {
235 dtype = py::dtype(self.readDType());
237 return utils::python::TemplateInvoker().apply(
239 return self.read<decltype(t)>(bbox, origin, conformMasks, allowUnsafe);
241 py::dtype(dtype), utils::python::TemplateInvoker::Tag<MaskPixel>());
244 "allowUnsafe"_a =
false,
"dtype"_a = py::none());
249 void declareMaskedImageFitsReader(lsst::utils::python::WrapperCollection &wrappers) {
250 wrappers.wrapType(PyMaskedImageFitsReader(wrappers.module,
"MaskedImageFitsReader"), [](
auto &mod,
252 cls.def(py::init<std::string const &, int>(),
"fileName"_a,
"hdu"_a = fits::DEFAULT_HDU);
253 cls.def(py::init<fits::MemFileManager &, int>(),
"manager"_a,
"hdu"_a = fits::DEFAULT_HDU);
254 declareCommonMethods(cls);
255 declareMultiPlaneMethods(cls);
256 cls.def(
"readPrimaryMetadata", &MaskedImageFitsReader::readPrimaryMetadata);
257 cls.def(
"readImageMetadata", &MaskedImageFitsReader::readImageMetadata);
258 cls.def(
"readMaskMetadata", &MaskedImageFitsReader::readMaskMetadata);
259 cls.def(
"readVarianceMetadata", &MaskedImageFitsReader::readVarianceMetadata);
262 [](MaskedImageFitsReader &self, lsst::geom::Box2I const &bbox, ImageOrigin origin,
263 bool conformMasks, bool needAllHdus, bool allowUnsafe, py::object dtype) {
264 if (dtype.is(py::none())) {
265 dtype = py::dtype(self.readImageDType());
267 return utils::python::TemplateInvoker().apply(
269 return self.read<decltype(t)>(bbox, origin, conformMasks, allowUnsafe);
272 utils::python::TemplateInvoker::Tag<std::uint16_t, int, float, double,
276 "needAllHdus"_a =
false,
"allowUnsafe"_a =
false,
"dtype"_a = py::none());
280 void declareExposureFitsReader(lsst::utils::python::WrapperCollection &wrappers) {
281 wrappers.wrapType(PyExposureFitsReader(wrappers.module,
"ExposureFitsReader"), [](
auto &mod,
auto &cls) {
282 cls.def(py::init<std::string const &>(),
"fileName"_a);
283 cls.def(py::init<fits::MemFileManager &>(),
"manager"_a);
284 declareCommonMethods(cls);
285 declareMultiPlaneMethods(cls);
286 cls.def(
"readSerializationVersion", &ExposureFitsReader::readSerializationVersion);
287 cls.def(
"readExposureId", &ExposureFitsReader::readExposureId);
288 cls.def(
"readMetadata", &ExposureFitsReader::readMetadata);
289 cls.def(
"readWcs", &ExposureFitsReader::readWcs);
290 cls.def(
"readFilter", &ExposureFitsReader::readFilter);
291 cls.def(
"readFilterLabel", &ExposureFitsReader::readFilterLabel);
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(
"readComponent", &ExposureFitsReader::readComponent);
300 cls.def(
"readDetector", &ExposureFitsReader::readDetector);
301 cls.def(
"readExposureInfo", &ExposureFitsReader::readExposureInfo);
304 [](ExposureFitsReader &self, lsst::geom::Box2I const &bbox, ImageOrigin origin,
305 bool conformMasks, bool allowUnsafe, py::object dtype) {
306 if (dtype.is(py::none())) {
307 dtype = py::dtype(self.readImageDType());
309 return utils::python::TemplateInvoker().apply(
311 return self.readMaskedImage<decltype(t)>(bbox, origin, conformMasks,
315 utils::python::TemplateInvoker::Tag<std::uint16_t, int, float, double,
319 "allowUnsafe"_a =
false,
"dtype"_a = py::none());
323 bool conformMasks,
bool allowUnsafe, py::object
dtype) {
324 if (
dtype.is(py::none())) {
325 dtype = py::dtype(self.readImageDType());
327 return utils::python::TemplateInvoker().apply(
329 return self.read<decltype(t)>(bbox, origin, conformMasks, allowUnsafe);
332 utils::python::TemplateInvoker::Tag<
std::uint16_t,
int,
float,
double,
336 "allowUnsafe"_a =
false,
"dtype"_a = py::none());
340 void wrapReaders(lsst::utils::python::WrapperCollection &wrappers) {
342 wrappers.addSignatureDependency(
"lsst.geom");
343 wrappers.addSignatureDependency(
"lsst.afw.image.image");
344 wrappers.addSignatureDependency(
"lsst.afw.image.maskedImage");
345 wrappers.addSignatureDependency(
"lsst.afw.image.exposure");
346 declareImageFitsReader(wrappers);
347 declareMaskFitsReader(wrappers);
348 declareMaskedImageFitsReader(wrappers);
349 declareExposureFitsReader(wrappers);
Implementation of the Photometric Calibration class.
An integer coordinate rectangle.
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.
Backwards-compatibility support for depersisting the old Calib (FluxMag0/FluxMag0Err) objects.
void wrapReaders(lsst::utils::python::WrapperCollection &)
A base class for image defects.