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) {
75 cls.def(py::init<std::string const &, int>(),
"fileName"_a,
"hdu"_a =
fits::DEFAULT_HDU);
76 cls.def(py::init<fits::MemFileManager &, int>(),
"manager"_a,
"hdu"_a =
fits::DEFAULT_HDU);
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())) {
88 return utils::python::TemplateInvoker().apply(
90 return self.template readArray<decltype(t)>(
bbox, origin, allowUnsafe);
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())) {
113 return utils::python::TemplateInvoker().apply(
115 return self.template readImage<decltype(t)>(
bbox, origin, allowUnsafe);
122 "dtype"_a = py::none());
127 if (
dtype.is(py::none())) {
130 return utils::python::TemplateInvoker().apply(
132 return self.template readImageArray<decltype(t)>(
bbox, origin, allowUnsafe);
139 "dtype"_a = py::none());
143 bool allowUnsafe, py::object
dtype) {
144 if (
dtype.is(py::none())) {
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())) {
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())) {
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())) {
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(
"readFilterLabel", &ExposureFitsReader::readFilterLabel);
290 cls.def(
"readFilter", &ExposureFitsReader::readFilter);
291 cls.def(
"readPhotoCalib", &ExposureFitsReader::readPhotoCalib);
292 cls.def(
"readPsf", &ExposureFitsReader::readPsf);
293 cls.def(
"readValidPolygon", &ExposureFitsReader::readValidPolygon);
294 cls.def(
"readApCorrMap", &ExposureFitsReader::readApCorrMap);
295 cls.def(
"readCoaddInputs", &ExposureFitsReader::readCoaddInputs);
296 cls.def(
"readVisitInfo", &ExposureFitsReader::readVisitInfo);
297 cls.def(
"readTransmissionCurve", &ExposureFitsReader::readTransmissionCurve);
298 cls.def(
"readComponent", &ExposureFitsReader::readComponent);
299 cls.def(
"readDetector", &ExposureFitsReader::readDetector);
300 cls.def(
"readExposureInfo", &ExposureFitsReader::readExposureInfo);
303 [](ExposureFitsReader &self, lsst::geom::Box2I const &bbox, ImageOrigin origin,
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,
314 utils::python::TemplateInvoker::Tag<std::uint16_t, int, float, double,
318 "allowUnsafe"_a =
false,
"dtype"_a = py::none());
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,
335 "allowUnsafe"_a =
false,
"dtype"_a = py::none());
339void wrapReaders(lsst::utils::python::WrapperCollection &wrappers) {
341 wrappers.addSignatureDependency(
"lsst.geom");
342 wrappers.addSignatureDependency(
"lsst.afw.image.image");
343 wrappers.addSignatureDependency(
"lsst.afw.image.maskedImage");
344 wrappers.addSignatureDependency(
"lsst.afw.image.exposure");
345 declareImageFitsReader(wrappers);
346 declareMaskFitsReader(wrappers);
347 declareMaskedImageFitsReader(wrappers);
348 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.