lsst.afw  13.0-39-g3deb52d
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
exposure.cc
Go to the documentation of this file.
1 /*
2  * LSST Data Management System
3  * Copyright 2008-2017 AURA/LSST.
4  *
5  * This product includes software developed by the
6  * LSST Project (http://www.lsst.org/).
7  *
8  * This program is free software: you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation, either version 3 of the License, or
11  * (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the LSST License Statement and
19  * the GNU General Public License along with this program. If not,
20  * see <https://www.lsstcorp.org/LegalNotices/>.
21  */
22 
23 #include "pybind11/pybind11.h"
24 
25 #include <memory>
26 
27 #include "lsst/afw/coord/Coord.h"
28 #include "lsst/afw/detection/Psf.h" // forward-declared by Exposure.h
29 #include "lsst/afw/fits.h"
30 #include "lsst/afw/geom/Box.h"
31 #include "lsst/afw/geom/Point.h"
32 #include "lsst/afw/geom/polygon/Polygon.h" // forward-declared by Exposure.h
33 #include "lsst/afw/image/ApCorrMap.h" // forward-declared by Exposure.h
34 #include "lsst/afw/image/Calib.h" // forward-declared by Exposure.h
35 #include "lsst/afw/image/VisitInfo.h" // forward-declared by Exposure.h
36 #include "lsst/afw/image/Wcs.h" // forward-declared by Exposure.h
39 #include "lsst/afw/table/Catalog.h"
44 
45 namespace py = pybind11;
46 using namespace pybind11::literals;
47 
48 namespace lsst {
49 namespace afw {
50 namespace table {
51 
52 namespace {
53 
54 using PyExposureRecord = py::class_<ExposureRecord, std::shared_ptr<ExposureRecord>, BaseRecord>;
55 using PyExposureTable = py::class_<ExposureTable, std::shared_ptr<ExposureTable>, BaseTable>;
56 using PyExposureCatalog =
57  py::class_<ExposureCatalogT<ExposureRecord>, std::shared_ptr<ExposureCatalogT<ExposureRecord>>,
58  SortedCatalogT<ExposureRecord>>;
59 
60 PyExposureRecord declareExposureRecord(py::module &mod) {
61  PyExposureRecord cls(mod, "ExposureRecord");
62  cls.def("getId", &ExposureRecord::getId);
63  cls.def("setId", &ExposureRecord::setId, "id"_a);
64  cls.def("getBBox", &ExposureRecord::getBBox);
65  cls.def("setBBox", &ExposureRecord::setBBox, "bbox"_a);
66  cls.def("getTable", &ExposureRecord::getTable);
67  cls.def_property_readonly("table", &ExposureRecord::getTable);
68  cls.def("contains",
69  (bool (ExposureRecord::*)(coord::Coord const &, bool) const) & ExposureRecord::contains,
70  "coord"_a, "includeValidPolygon"_a = false);
71  cls.def("contains", (bool (ExposureRecord::*)(geom::Point2D const &, image::Wcs const &, bool) const) &
72  ExposureRecord::contains,
73  "point"_a, "wcs"_a, "includeValidPolygon"_a = false);
74  cls.def("getWcs", &ExposureRecord::getWcs);
75  cls.def("setWcs", &ExposureRecord::setWcs, "wcs"_a);
76  cls.def("getPsf", &ExposureRecord::getPsf);
77  cls.def("setPsf", &ExposureRecord::setPsf, "psf"_a);
78  cls.def("getCalib", &ExposureRecord::getCalib);
79  cls.def("setCalib", &ExposureRecord::setCalib, "calib"_a);
80  cls.def("getApCorrMap", &ExposureRecord::getApCorrMap);
81  cls.def("setApCorrMap", &ExposureRecord::setApCorrMap, "appCorrMap"_a);
82  cls.def("getValidPolygon", &ExposureRecord::getValidPolygon);
83  cls.def("setValidPolygon", &ExposureRecord::setValidPolygon, "polygon"_a);
84  cls.def("getVisitInfo", &ExposureRecord::getVisitInfo);
85  cls.def("setVisitInfo", &ExposureRecord::setVisitInfo, "visitInfo"_a);
86  return cls;
87 }
88 
89 PyExposureTable declareExposureTable(py::module &mod) {
90  PyExposureTable cls(mod, "ExposureTable");
91  cls.def_static("make", &ExposureTable::make);
92  cls.def_static("makeMinimalSchema", &ExposureTable::makeMinimalSchema);
93  cls.def_static("checkSchema", &ExposureTable::checkSchema, "schema"_a);
94 
95  cls.def_static("getIdKey", &ExposureTable::getIdKey);
96  cls.def_static("getBBoxMinKey", &ExposureTable::getBBoxMinKey);
97  cls.def_static("getBBoxMaxKey", &ExposureTable::getBBoxMaxKey);
98 
99  cls.def("clone", &ExposureTable::clone);
100  cls.def("makeRecord", &ExposureTable::makeRecord);
101  cls.def("copyRecord", (std::shared_ptr<ExposureRecord> (ExposureTable::*)(BaseRecord const &)) &
102  ExposureTable::copyRecord);
103  cls.def("copyRecord",
104  (std::shared_ptr<ExposureRecord> (ExposureTable::*)(BaseRecord const &, SchemaMapper const &)) &
105  ExposureTable::copyRecord);
106  return cls;
107 }
108 
109 PyExposureCatalog declareExposureCatalog(py::module &mod) {
110  using Catalog = ExposureCatalogT<ExposureRecord>;
111  table::python::declareSortedCatalog<ExposureRecord>(mod, "Exposure", true);
112 
113  // We need py::dynamic_attr() below to support our Python-side caching of the associated ColumnView.
114  PyExposureCatalog cls(mod, "ExposureCatalog", py::dynamic_attr());
115 
116  cls.def(py::init<Schema const &>(), "schema"_a);
117  cls.def(py::init<std::shared_ptr<ExposureTable> const &>(), "table"_a = std::shared_ptr<ExposureTable>());
118  cls.def(py::init<Catalog const &>(), "other"_a);
119  // Constructor taking C++ iterators not wrapped; we recommend .extend() (defined in pure Python) instead.
120  cls.def_static("readFits", (Catalog(*)(std::string const &, int, int)) & Catalog::readFits, "filename"_a,
121  "hdu"_a = INT_MIN, "flags"_a = 0);
122  cls.def_static("readFits", (Catalog(*)(fits::MemFileManager &, int, int)) & Catalog::readFits,
123  "manager"_a, "hdu"_a = INT_MIN, "flags"_a = 0);
124  // readFits taking Fits objects not wrapped, because Fits objects are not wrapped.
125 
126  cls.def("subset", (Catalog (Catalog::*)(ndarray::Array<bool const, 1> const &) const) & Catalog::subset,
127  "mask"_a);
128  cls.def("subset",
129  (Catalog (Catalog::*)(std::ptrdiff_t, std::ptrdiff_t, std::ptrdiff_t) const) & Catalog::subset,
130  "startd"_a, "stopd"_a, "step"_a);
131  cls.def("subsetContaining",
132  (Catalog (Catalog::*)(coord::Coord const &, bool) const) & Catalog::subsetContaining, "coord"_a,
133  "includeValidPolygon"_a = false);
134  cls.def("subsetContaining",
135  (Catalog (Catalog::*)(geom::Point2D const &, image::Wcs const &, bool) const) &
136  Catalog::subsetContaining,
137  "point"_a, "wcs"_a, "includeValidPolygon"_a = false);
138  return cls;
139 };
140 
141 } // anonymous namespace
142 
143 PYBIND11_PLUGIN(exposure) {
144  py::module mod("exposure");
145  py::module::import("lsst.afw.table.simple");
146  py::module::import("lsst.afw.geom");
147  // afw.image and afw.detection cannot be imported due to circular dependencies
148 
149  auto clsExposureRecord = declareExposureRecord(mod);
150  auto clsExposureTable = declareExposureTable(mod);
151  auto clsExposureColumnView = table::python::declareColumnView<ExposureRecord>(mod, "Exposure");
152  auto clsExposureCatalog = declareExposureCatalog(mod);
153 
154  clsExposureRecord.attr("Table") = clsExposureTable;
155  clsExposureRecord.attr("ColumnView") = clsExposureColumnView;
156  clsExposureRecord.attr("Catalog") = clsExposureCatalog;
157  clsExposureTable.attr("Record") = clsExposureRecord;
158  clsExposureTable.attr("ColumnView") = clsExposureColumnView;
159  clsExposureTable.attr("Catalog") = clsExposureCatalog;
160  clsExposureCatalog.attr("Record") = clsExposureRecord;
161  clsExposureCatalog.attr("Table") = clsExposureTable;
162  clsExposureCatalog.attr("ColumnView") = clsExposureColumnView;
163 
164  return mod.ptr();
165 }
166 }
167 }
168 } // namespace lsst::afw::table
lsst::afw::coord::Coord Coord
Definition: misc.h:33
Implementation of the WCS standard for a any projection.
Definition: Wcs.h:104
PYBIND11_PLUGIN(_cameraPoint)
Definition: cameraPoint.cc:35
Point< double, 2 > Point2D
Definition: Point.h:273
double const _a
Definition: RandomImage.cc:77