LSSTApplications  19.0.0-14-gb0260a2+72efe9b372,20.0.0+7927753e06,20.0.0+8829bf0056,20.0.0+995114c5d2,20.0.0+b6f4b2abd1,20.0.0+bddc4f4cbe,20.0.0-1-g253301a+8829bf0056,20.0.0-1-g2b7511a+0d71a2d77f,20.0.0-1-g5b95a8c+7461dd0434,20.0.0-12-g321c96ea+23efe4bbff,20.0.0-16-gfab17e72e+fdf35455f6,20.0.0-2-g0070d88+ba3ffc8f0b,20.0.0-2-g4dae9ad+ee58a624b3,20.0.0-2-g61b8584+5d3db074ba,20.0.0-2-gb780d76+d529cf1a41,20.0.0-2-ged6426c+226a441f5f,20.0.0-2-gf072044+8829bf0056,20.0.0-2-gf1f7952+ee58a624b3,20.0.0-20-geae50cf+e37fec0aee,20.0.0-25-g3dcad98+544a109665,20.0.0-25-g5eafb0f+ee58a624b3,20.0.0-27-g64178ef+f1f297b00a,20.0.0-3-g4cc78c6+e0676b0dc8,20.0.0-3-g8f21e14+4fd2c12c9a,20.0.0-3-gbd60e8c+187b78b4b8,20.0.0-3-gbecbe05+48431fa087,20.0.0-38-ge4adf513+a12e1f8e37,20.0.0-4-g97dc21a+544a109665,20.0.0-4-gb4befbc+087873070b,20.0.0-4-gf910f65+5d3db074ba,20.0.0-5-gdfe0fee+199202a608,20.0.0-5-gfbfe500+d529cf1a41,20.0.0-6-g64f541c+d529cf1a41,20.0.0-6-g9a5b7a1+a1cd37312e,20.0.0-68-ga3f3dda+5fca18c6a4,20.0.0-9-g4aef684+e18322736b,w.2020.45
LSSTDataManagementBasePackage
_exposure.cc
Go to the documentation of this file.
1 /*
2  * This file is part of afw.
3  *
4  * Developed for the LSST Data Management System.
5  * This product includes software developed by the LSST Project
6  * (https://www.lsst.org).
7  * See the COPYRIGHT file at the top-level directory of this distribution
8  * for details of code ownership.
9  *
10  * This program is free software: you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation, either version 3 of the License, or
13  * (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with this program. If not, see <https://www.gnu.org/licenses/>.
22  */
23 
24 #include "pybind11/pybind11.h"
25 #include "ndarray/pybind11.h"
26 
27 #include <memory>
28 
29 #include "lsst/utils/python.h"
30 
31 #include "lsst/afw/detection/Psf.h" // forward-declared by Exposure.h
32 #include "lsst/afw/fits.h"
33 #include "lsst/geom/Box.h"
34 #include "lsst/geom/Point.h"
35 #include "lsst/afw/geom/polygon/Polygon.h" // forward-declared by Exposure.h
36 #include "lsst/afw/geom/SkyWcs.h" // forward-declared by Transform.h
37 #include "lsst/afw/image/ApCorrMap.h" // forward-declared by Exposure.h
38 #include "lsst/afw/image/PhotoCalib.h" // forward-declared by Exposure.h
39 #include "lsst/afw/image/VisitInfo.h" // forward-declared by Exposure.h
40 #include "lsst/afw/image/TransmissionCurve.h" // forward-declared by Exposure.h
41 #include "lsst/afw/cameraGeom/Detector.h" // forward-declared by Exposure.h
44 #include "lsst/afw/table/Catalog.h"
49 
50 namespace py = pybind11;
51 using namespace pybind11::literals;
52 
53 namespace lsst {
54 namespace afw {
55 namespace table {
56 
57 using utils::python::WrapperCollection;
58 
59 namespace {
60 
61 using PyExposureRecord = py::class_<ExposureRecord, std::shared_ptr<ExposureRecord>, BaseRecord>;
62 using PyExposureTable = py::class_<ExposureTable, std::shared_ptr<ExposureTable>, BaseTable>;
63 using PyExposureCatalog =
64  py::class_<ExposureCatalogT<ExposureRecord>, std::shared_ptr<ExposureCatalogT<ExposureRecord>>,
65  SortedCatalogT<ExposureRecord>>;
66 
67 PyExposureRecord declareExposureRecord(WrapperCollection &wrappers) {
68  return wrappers.wrapType(PyExposureRecord(wrappers.module, "ExposureRecord"), [](auto &mod, auto &cls) {
69  cls.def("getId", &ExposureRecord::getId);
70  cls.def("setId", &ExposureRecord::setId, "id"_a);
71  cls.def("getBBox", &ExposureRecord::getBBox);
72  cls.def("setBBox", &ExposureRecord::setBBox, "bbox"_a);
73  cls.def("getTable", &ExposureRecord::getTable);
74  cls.def_property_readonly("table", &ExposureRecord::getTable);
75  cls.def("contains",
76  (bool (ExposureRecord::*)(lsst::geom::SpherePoint const &, bool) const) &
77  ExposureRecord::contains,
78  "coord"_a, "includeValidPolygon"_a = false);
79  cls.def("contains",
80  (bool (ExposureRecord::*)(lsst::geom::Point2D const &, geom::SkyWcs const &, bool) const) &
81  ExposureRecord::contains,
82  "point"_a, "wcs"_a, "includeValidPolygon"_a = false);
83  cls.def("getWcs", &ExposureRecord::getWcs);
84  cls.def("setWcs", &ExposureRecord::setWcs, "wcs"_a);
85  cls.def("getPsf", &ExposureRecord::getPsf);
86  cls.def("setPsf", &ExposureRecord::setPsf, "psf"_a);
87 
88  cls.def("getPhotoCalib", &ExposureRecord::getPhotoCalib);
89  cls.def("setPhotoCalib", &ExposureRecord::setPhotoCalib, "photoCalib"_a);
90  cls.def("getApCorrMap", &ExposureRecord::getApCorrMap);
91  cls.def("setApCorrMap", &ExposureRecord::setApCorrMap, "apCorrMap"_a);
92  cls.def("getValidPolygon", &ExposureRecord::getValidPolygon);
93 
94  // Workaround for DM-10289.
95  cls.def("setValidPolygon",
96  [](ExposureRecord &self, py::object polygon) {
97  if (polygon.is(py::none())) {
98  self.setValidPolygon(nullptr);
99  } else {
100  self.setValidPolygon(py::cast<std::shared_ptr<afw::geom::polygon::Polygon>>(polygon));
101  }
102  },
103  "polygon"_a);
104 
105  cls.def("getVisitInfo", &ExposureRecord::getVisitInfo);
106  cls.def("setVisitInfo", &ExposureRecord::setVisitInfo, "visitInfo"_a);
107  cls.def("getTransmissionCurve", &ExposureRecord::getTransmissionCurve);
108  cls.def("setTransmissionCurve", &ExposureRecord::setTransmissionCurve, "transmissionCurve"_a);
109  cls.def("getDetector", &ExposureRecord::getDetector);
110  cls.def("setDetector", &ExposureRecord::setDetector, "detector"_a);
111  });
112 }
113 
114 PyExposureTable declareExposureTable(WrapperCollection &wrappers) {
115  return wrappers.wrapType(PyExposureTable(wrappers.module, "ExposureTable"), [](auto &mod, auto &cls) {
116  cls.def_static("make", &ExposureTable::make);
117  cls.def_static("makeMinimalSchema", &ExposureTable::makeMinimalSchema);
118  cls.def_static("checkSchema", &ExposureTable::checkSchema, "schema"_a);
119 
120  cls.def_static("getIdKey", &ExposureTable::getIdKey);
121  cls.def_static("getBBoxMinKey", &ExposureTable::getBBoxMinKey);
122  cls.def_static("getBBoxMaxKey", &ExposureTable::getBBoxMaxKey);
123 
124  cls.def("clone", &ExposureTable::clone);
125  cls.def("makeRecord", &ExposureTable::makeRecord);
126  cls.def("copyRecord", (std::shared_ptr<ExposureRecord>(ExposureTable::*)(BaseRecord const &)) &
127  ExposureTable::copyRecord);
128  cls.def("copyRecord", (std::shared_ptr<ExposureRecord>(ExposureTable::*)(BaseRecord const &,
129  SchemaMapper const &)) &
130  ExposureTable::copyRecord);
131  });
132 }
133 
134 PyExposureCatalog declareExposureCatalog(WrapperCollection &wrappers) {
135  using Catalog = ExposureCatalogT<ExposureRecord>;
136  table::python::declareSortedCatalog<ExposureRecord>(wrappers, "Exposure", true);
137 
138  // We need py::dynamic_attr() in class definition to support our Python-side caching
139  // of the associated ColumnView.
140  return wrappers.wrapType(
141  PyExposureCatalog(wrappers.module, "ExposureCatalog", py::dynamic_attr()),
142  [](auto &mod, auto &cls) {
143  cls.def(py::init<Schema const &>(), "schema"_a);
144  cls.def(py::init<std::shared_ptr<ExposureTable> const &>(),
145  "table"_a = std::shared_ptr<ExposureTable>());
146  cls.def(py::init<Catalog const &>(), "other"_a);
147  // Constructor taking C++ iterators not wrapped; we recommend .extend() (defined in pure
148  // Python) instead.
149  cls.def_static("readFits", (Catalog(*)(std::string const &, int, int)) & Catalog::readFits,
150  "filename"_a, "hdu"_a = fits::DEFAULT_HDU, "flags"_a = 0);
151  cls.def_static("readFits", (Catalog(*)(fits::MemFileManager &, int, int)) & Catalog::readFits,
152  "manager"_a, "hdu"_a = fits::DEFAULT_HDU, "flags"_a = 0);
153  // readFits taking Fits objects not wrapped, because Fits objects are not wrapped.
154 
155  cls.def("subset",
156  (Catalog(Catalog::*)(ndarray::Array<bool const, 1> const &) const) & Catalog::subset,
157  "mask"_a);
158  cls.def("subset",
159  (Catalog(Catalog::*)(std::ptrdiff_t, std::ptrdiff_t, std::ptrdiff_t) const) &
160  Catalog::subset,
161  "startd"_a, "stopd"_a, "step"_a);
162  cls.def("subsetContaining",
163  (Catalog(Catalog::*)(lsst::geom::SpherePoint const &, bool) const) &
164  Catalog::subsetContaining,
165  "coord"_a, "includeValidPolygon"_a = false);
166  cls.def("subsetContaining",
167  (Catalog(Catalog::*)(lsst::geom::Point2D const &, geom::SkyWcs const &, bool) const) &
168  Catalog::subsetContaining,
169  "point"_a, "wcs"_a, "includeValidPolygon"_a = false);
170  });
171 };
172 
173 } // anonymous namespace
174 
176  // wrappers.addSignatureDependency("lsst.afw.geom");
177  // TODO: afw.geom, afw.image, and afw.detection cannot be imported due to
178  // circular dependencies until at least afw.image uses WrapperCollection
179  // in DM-20703
180 
181  auto clsExposureRecord = declareExposureRecord(wrappers);
182  auto clsExposureTable = declareExposureTable(wrappers);
183  auto clsExposureColumnView = table::python::declareColumnView<ExposureRecord>(wrappers, "Exposure");
184  auto clsExposureCatalog = declareExposureCatalog(wrappers);
185 
186  clsExposureRecord.attr("Table") = clsExposureTable;
187  clsExposureRecord.attr("ColumnView") = clsExposureColumnView;
188  clsExposureRecord.attr("Catalog") = clsExposureCatalog;
189  clsExposureTable.attr("Record") = clsExposureRecord;
190  clsExposureTable.attr("ColumnView") = clsExposureColumnView;
191  clsExposureTable.attr("Catalog") = clsExposureCatalog;
192  clsExposureCatalog.attr("Record") = clsExposureRecord;
193  clsExposureCatalog.attr("Table") = clsExposureTable;
194  clsExposureCatalog.attr("ColumnView") = clsExposureColumnView;
195 }
196 
197 } // namespace table
198 } // namespace afw
199 } // namespace lsst
std::shared_ptr
STL class.
Psf.h
TransmissionCurve.h
Box.h
python.h
fits.h
lsst::afw
Definition: imageAlgorithm.dox:1
SkyWcs.h
lsst::afw::table::wrapExposure
void wrapExposure(WrapperCollection &wrappers)
Definition: _exposure.cc:175
lsst::afw::geom.transform.transformContinued.cls
cls
Definition: transformContinued.py:33
BaseRecord.h
Point.h
columnView.h
lsst::utils::python::WrapperCollection
A helper class for subdividing pybind11 module across multiple translation units (i....
Definition: python.h:242
catalog.h
lsst
A base class for image defects.
Definition: imageAlgorithm.dox:1
Polygon.h
PhotoCalib.h
Implementation of the Photometric Calibration class.
sortedCatalog.h
ApCorrMap.h
BaseTable.h
pybind11
Definition: _GenericMap.cc:40
Catalog.h
Exposure.h
Detector.h
VisitInfo.h