LSST Applications g042eb84c57+730a74494b,g04e9c324dd+8c5ae1fdc5,g134cb467dc+1f1e3e7524,g199a45376c+0ba108daf9,g1fd858c14a+fa7d31856b,g210f2d0738+f66ac109ec,g262e1987ae+83a3acc0e5,g29ae962dfc+d856a2cb1f,g2cef7863aa+aef1011c0b,g35bb328faa+8c5ae1fdc5,g3fd5ace14f+a1e0c9f713,g47891489e3+0d594cb711,g4d44eb3520+c57ec8f3ed,g4d7b6aa1c5+f66ac109ec,g53246c7159+8c5ae1fdc5,g56a1a4eaf3+fd7ad03fde,g64539dfbff+f66ac109ec,g67b6fd64d1+0d594cb711,g67fd3c3899+f66ac109ec,g6985122a63+0d594cb711,g74acd417e5+3098891321,g786e29fd12+668abc6043,g81db2e9a8d+98e2ab9f28,g87389fa792+8856018cbb,g89139ef638+0d594cb711,g8d7436a09f+80fda9ce03,g8ea07a8fe4+760ca7c3fc,g90f42f885a+033b1d468d,g97be763408+a8a29bda4b,g99822b682c+e3ec3c61f9,g9d5c6a246b+0d5dac0c3d,ga41d0fce20+9243b26dd2,gbf99507273+8c5ae1fdc5,gd7ef33dd92+0d594cb711,gdab6d2f7ff+3098891321,ge410e46f29+0d594cb711,geaed405ab2+c4bbc419c6,gf9a733ac38+8c5ae1fdc5,w.2025.38
LSST Data Management Base Package
Loading...
Searching...
No Matches
_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
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
49
50namespace py = pybind11;
51using namespace pybind11::literals;
52
53namespace lsst {
54namespace afw {
55namespace table {
56
57using cpputils::python::WrapperCollection;
58
59namespace {
60
61using PyExposureRecord = py::classh<ExposureRecord, BaseRecord>;
62using PyExposureTable = py::classh<ExposureTable, BaseTable>;
63using PyExposureCatalog = py::classh<ExposureCatalogT<ExposureRecord>, SortedCatalogT<ExposureRecord>>;
64
65PyExposureRecord declareExposureRecord(WrapperCollection &wrappers) {
66 return wrappers.wrapType(PyExposureRecord(wrappers.module, "ExposureRecord"), [](auto &mod, auto &cls) {
67 cls.def("getId", &ExposureRecord::getId);
68 cls.def("setId", &ExposureRecord::setId, "id"_a);
69 cls.def_property("id", &ExposureRecord::getId, &ExposureRecord::setId);
70 cls.def("getBBox", &ExposureRecord::getBBox);
71 cls.def("setBBox", &ExposureRecord::setBBox, "bbox"_a);
72 // No property for bbox, as it returns by value.
73 cls.def("getTable", &ExposureRecord::getTable);
74 // table has no setter
75 cls.def_property_readonly("table", &ExposureRecord::getTable);
76 cls.def("contains",
77 (bool(ExposureRecord::*)(lsst::geom::SpherePoint const &, bool) const) &
78 ExposureRecord::contains,
79 "coord"_a, "includeValidPolygon"_a = false);
80 cls.def("contains",
81 (bool(ExposureRecord::*)(lsst::geom::Point2D const &, geom::SkyWcs const &, bool) const) &
82 ExposureRecord::contains,
83 "point"_a, "wcs"_a, "includeValidPolygon"_a = false);
84 cls.def("getWcs", &ExposureRecord::getWcs);
85 cls.def("setWcs", &ExposureRecord::setWcs, "wcs"_a);
86 cls.def_property("wcs", &ExposureRecord::getWcs, &ExposureRecord::setWcs);
87 cls.def("getPsf", &ExposureRecord::getPsf);
88 cls.def("setPsf", &ExposureRecord::setPsf, "psf"_a);
89 cls.def_property("psf", &ExposureRecord::getPsf, &ExposureRecord::setPsf);
90
91 cls.def("getPhotoCalib", &ExposureRecord::getPhotoCalib);
92 cls.def("setPhotoCalib", &ExposureRecord::setPhotoCalib, "photoCalib"_a);
93 cls.def_property("photoCalib", &ExposureRecord::getPhotoCalib, &ExposureRecord::setPhotoCalib);
94 cls.def("getApCorrMap", &ExposureRecord::getApCorrMap);
95 cls.def("setApCorrMap", &ExposureRecord::setApCorrMap, "apCorrMap"_a);
96 cls.def_property("apCorrMap", &ExposureRecord::getApCorrMap, &ExposureRecord::setApCorrMap);
97 cls.def("getValidPolygon", &ExposureRecord::getValidPolygon);
98 cls.def("setValidPolygon", &ExposureRecord::setValidPolygon);
99 cls.def_property("validPolygon", &ExposureRecord::getValidPolygon, &ExposureRecord::setValidPolygon);
100 cls.def("getVisitInfo", &ExposureRecord::getVisitInfo);
101 cls.def("setVisitInfo", &ExposureRecord::setVisitInfo, "visitInfo"_a);
102 cls.def_property("visitInfo", &ExposureRecord::getVisitInfo, &ExposureRecord::setVisitInfo);
103 cls.def("getTransmissionCurve", &ExposureRecord::getTransmissionCurve);
104 cls.def("setTransmissionCurve", &ExposureRecord::setTransmissionCurve, "transmissionCurve"_a);
105 cls.def_property("transmissionCurve", &ExposureRecord::getTransmissionCurve,
106 &ExposureRecord::setTransmissionCurve);
107 cls.def("getDetector", &ExposureRecord::getDetector);
108 cls.def("setDetector", &ExposureRecord::setDetector, "detector"_a);
109 cls.def_property("detector", &ExposureRecord::getDetector, &ExposureRecord::setDetector);
110 });
111}
112
113PyExposureTable declareExposureTable(WrapperCollection &wrappers) {
114 return wrappers.wrapType(PyExposureTable(wrappers.module, "ExposureTable"), [](auto &mod, auto &cls) {
115 cls.def_static("make", &ExposureTable::make);
116 cls.def_static("makeMinimalSchema", &ExposureTable::makeMinimalSchema);
117 cls.def_static("checkSchema", &ExposureTable::checkSchema, "schema"_a);
118
119 cls.def_static("getIdKey", &ExposureTable::getIdKey);
120 cls.def_static("getBBoxMinKey", &ExposureTable::getBBoxMinKey);
121 cls.def_static("getBBoxMaxKey", &ExposureTable::getBBoxMaxKey);
122
123 cls.def("clone", &ExposureTable::clone);
124 cls.def("makeRecord", &ExposureTable::makeRecord);
125 cls.def("copyRecord", (std::shared_ptr<ExposureRecord>(ExposureTable::*)(BaseRecord const &)) &
126 ExposureTable::copyRecord);
127 cls.def("copyRecord", (std::shared_ptr<ExposureRecord>(ExposureTable::*)(BaseRecord const &,
128 SchemaMapper const &)) &
129 ExposureTable::copyRecord);
130 });
131}
132
133PyExposureCatalog declareExposureCatalog(WrapperCollection &wrappers) {
135 table::python::declareSortedCatalog<ExposureRecord>(wrappers, "Exposure", true);
136
137 // We need py::dynamic_attr() in class definition to support our Python-side caching
138 // of the associated ColumnView.
139 return wrappers.wrapType(
140 PyExposureCatalog(wrappers.module, "ExposureCatalog", py::dynamic_attr()),
141 [](auto &mod, auto &cls) {
142 cls.def(py::init<Schema const &>(), "schema"_a);
143 cls.def(py::init<std::shared_ptr<ExposureTable> const &>(),
144 "table"_a = std::shared_ptr<ExposureTable>());
145 cls.def(py::init<Catalog const &>(), "other"_a);
146 // Constructor taking C++ iterators not wrapped; we recommend .extend() (defined in pure
147 // Python) instead.
148 cls.def_static("readFits", (Catalog(*)(std::string const &, int, int)) & Catalog::readFits,
149 "filename"_a, "hdu"_a = fits::DEFAULT_HDU, "flags"_a = 0);
150 cls.def_static("readFits", (Catalog(*)(fits::MemFileManager &, int, int)) & Catalog::readFits,
151 "manager"_a, "hdu"_a = fits::DEFAULT_HDU, "flags"_a = 0);
152 // readFits taking Fits objects not wrapped, because Fits objects are not wrapped.
153 cls.def("subset",
154 (Catalog(Catalog::*)(ndarray::Array<bool const, 1> const &) const) & Catalog::subset,
155 "mask"_a);
156 cls.def("subset",
157 (Catalog(Catalog::*)(std::ptrdiff_t, std::ptrdiff_t, std::ptrdiff_t) const) &
158 Catalog::subset,
159 "startd"_a, "stopd"_a, "step"_a);
160 cls.def("subsetContaining",
161 (Catalog(Catalog::*)(lsst::geom::SpherePoint const &, bool) const) &
162 Catalog::subsetContaining,
163 "coord"_a, "includeValidPolygon"_a = false);
164 cls.def("subsetContaining",
165 (Catalog(Catalog::*)(lsst::geom::Point2D const &, geom::SkyWcs const &, bool) const) &
166 Catalog::subsetContaining,
167 "point"_a, "wcs"_a, "includeValidPolygon"_a = false);
168 });
169};
170
171} // anonymous namespace
172
174 // wrappers.addSignatureDependency("lsst.afw.geom");
175 // TODO: afw.geom, afw.image, and afw.detection cannot be imported due to
176 // circular dependencies until at least afw.image uses WrapperCollection
177 // in DM-20703
178
179 auto clsExposureRecord = declareExposureRecord(wrappers);
180 auto clsExposureTable = declareExposureTable(wrappers);
181 auto clsExposureColumnView = table::python::declareColumnView<ExposureRecord>(wrappers, "Exposure");
182 auto clsExposureCatalog = declareExposureCatalog(wrappers);
183
184 clsExposureRecord.attr("Table") = clsExposureTable;
185 clsExposureRecord.attr("ColumnView") = clsExposureColumnView;
186 clsExposureRecord.attr("Catalog") = clsExposureCatalog;
187 clsExposureTable.attr("Record") = clsExposureRecord;
188 clsExposureTable.attr("ColumnView") = clsExposureColumnView;
189 clsExposureTable.attr("Catalog") = clsExposureCatalog;
190 clsExposureCatalog.attr("Record") = clsExposureRecord;
191 clsExposureCatalog.attr("Table") = clsExposureTable;
192 clsExposureCatalog.attr("ColumnView") = clsExposureColumnView;
193}
194
195} // namespace table
196} // namespace afw
197} // namespace lsst
Implementation of the Photometric Calibration class.
PyType wrapType(PyType cls, ClassWrapperCallback function, bool setModuleName=true)
Add a type (class or enum) wrapper, deferring method and other attribute definitions until finish() i...
Definition python.h:391
pybind11::module module
The module object passed to the PYBIND11_MODULE block that contains this WrapperCollection.
Definition python.h:448
Custom catalog class for ExposureRecord/Table.
Definition Exposure.h:310
Custom catalog class for record/table subclasses that are guaranteed to have an ID,...
A helper class for subdividing pybind11 module across multiple translation units (i....
Definition python.h:242
PySortedCatalog< Record > declareSortedCatalog(cpputils::python::WrapperCollection &wrappers, std::string const &name, bool isBase=false)
Wrap an instantiation of lsst::afw::table::SortedCatalogT<Record>.
PyColumnView< Record > declareColumnView(cpputils::python::WrapperCollection &wrappers, std::string const &name, bool isBase=false)
Declare member and static functions for a given instantiation of lsst::afw::table::ColumnViewT<Record...
Definition columnView.h:52
void wrapExposure(WrapperCollection &wrappers)
Definition _exposure.cc:173