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
sdssShape.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/pex/config/python.h"
28 #include "lsst/meas/base/python.h"
29 
33 
34 namespace py = pybind11;
35 using namespace pybind11::literals;
36 
37 namespace lsst {
38 namespace meas {
39 namespace base {
40 
41 namespace {
42 
43 using PyShapeControl = py::class_<SdssShapeControl>;
44 // TODO decide if we need to mention afw::table::FunctorKey<SdssShapeResult>
45 // and if so, wrap it; if not, document that here
46 using PyShapeResultKey = py::class_<SdssShapeResultKey, std::shared_ptr<SdssShapeResultKey>>;
47 using PyShapeResult = py::class_<SdssShapeResult, std::shared_ptr<SdssShapeResult>, ShapeResult,
48  CentroidResult, FluxResult>;
49 using PyShapeAlgorithm = py::class_<SdssShapeAlgorithm, std::shared_ptr<SdssShapeAlgorithm>, SimpleAlgorithm>;
50 using PyShapeTransform = py::class_<SdssShapeTransform, std::shared_ptr<SdssShapeTransform>, BaseTransform>;
51 
52 PyShapeControl declareShapeControl(py::module &mod) {
53  PyShapeControl cls(mod, "SdssShapeControl");
54 
55  LSST_DECLARE_CONTROL_FIELD(cls, SdssShapeControl, background);
56  LSST_DECLARE_CONTROL_FIELD(cls, SdssShapeControl, maxIter);
57  LSST_DECLARE_CONTROL_FIELD(cls, SdssShapeControl, maxShift);
58  LSST_DECLARE_CONTROL_FIELD(cls, SdssShapeControl, tol1);
59  LSST_DECLARE_CONTROL_FIELD(cls, SdssShapeControl, tol2);
60  LSST_DECLARE_CONTROL_FIELD(cls, SdssShapeControl, doMeasurePsf);
61 
62  cls.def(py::init<>());
63 
64  return cls;
65 }
66 
67 void declareShapeResultKey(py::module &mod) {
68  PyShapeResultKey cls(mod, "SdssShapeResultKey");
69 
70  // TODO decide whether to wrap default constructor and do it or document why not
71  cls.def(py::init<afw::table::SubSchema const &>(), "subSchema"_a);
72 
73  cls.def_static("addFields", &FluxResultKey::addFields, "schema"_a, "name"_a, "doMeasurePsf"_a);
74 
75  cls.def("__eq__", &SdssShapeResultKey::operator==, py::is_operator());
76  cls.def("__ne__", &SdssShapeResultKey::operator!=, py::is_operator());
77 
78  cls.def("get", &SdssShapeResultKey::get, "record"_a);
79  cls.def("set", &SdssShapeResultKey::set, "record"_a, "value"_a);
80  cls.def("getPsfShape", &SdssShapeResultKey::getPsfShape, "record"_a);
81  cls.def("setPsfShape", &SdssShapeResultKey::setPsfShape, "record"_a, "value"_a);
82  cls.def("isValid", &SdssShapeResultKey::isValid);
83  cls.def("getFlagHandler", &SdssShapeResultKey::getFlagHandler);
84 }
85 
86 template <typename ImageT>
87 static void declareComputeMethods(PyShapeAlgorithm &cls) {
88  cls.def_static(
89  "computeAdaptiveMoments",
90  (SdssShapeResult(*)(ImageT const &, geom::Point2D const &, bool, SdssShapeControl const &)) &
91  SdssShapeAlgorithm::computeAdaptiveMoments,
92  "image"_a, "position"_a, "negative"_a = false, "ctrl"_a = SdssShapeControl());
93  cls.def_static(
94  "computeFixedMomentsFlux",
95  (FluxResult(*)(ImageT const &, afw::geom::ellipses::Quadrupole const &, geom::Point2D const &)) &
96  SdssShapeAlgorithm::computeFixedMomentsFlux,
97  "image"_a, "shape"_a, "position"_a);
98 }
99 
100 PyShapeAlgorithm declareShapeAlgorithm(py::module &mod) {
101  PyShapeAlgorithm cls(mod, "SdssShapeAlgorithm");
102 
103  cls.attr("FAILURE") = py::cast(SdssShapeAlgorithm::FAILURE);
104  cls.attr("UNWEIGHTED_BAD") = py::cast(SdssShapeAlgorithm::UNWEIGHTED_BAD);
105  cls.attr("UNWEIGHTED") = py::cast(SdssShapeAlgorithm::UNWEIGHTED);
106  cls.attr("SHIFT") = py::cast(SdssShapeAlgorithm::SHIFT);
107  cls.attr("MAXITER") = py::cast(SdssShapeAlgorithm::MAXITER);
108  cls.attr("PSF_SHAPE_BAD") = py::cast(SdssShapeAlgorithm::PSF_SHAPE_BAD);
109 
110  cls.def(py::init<SdssShapeAlgorithm::Control const &, std::string const &, afw::table::Schema &>(),
111  "ctrl"_a, "name"_a, "schema"_a);
112 
113  declareComputeMethods<afw::image::Image<int>>(cls);
114  declareComputeMethods<afw::image::Image<float>>(cls);
115  declareComputeMethods<afw::image::Image<double>>(cls);
116  declareComputeMethods<afw::image::MaskedImage<int>>(cls);
117  declareComputeMethods<afw::image::MaskedImage<float>>(cls);
118  declareComputeMethods<afw::image::MaskedImage<double>>(cls);
119 
120  cls.def("measure", &SdssShapeAlgorithm::measure, "measRecord"_a, "exposure"_a);
121  cls.def("fail", &SdssShapeAlgorithm::fail, "measRecord"_a, "error"_a = nullptr);
122 
123  return cls;
124 }
125 
126 void declareShapeResult(py::module &mod) {
127  PyShapeResult cls(mod, "SdssShapeResult");
128 
129  cls.def(py::init<>());
130 
131  cls.def_readwrite("instFlux_xx_Cov", &SdssShapeResult::instFlux_xx_Cov);
132  cls.def_readwrite("instFlux_yy_Cov", &SdssShapeResult::instFlux_yy_Cov);
133  cls.def_readwrite("instFlux_xy_Cov", &SdssShapeResult::instFlux_xy_Cov);
134  cls.def_readwrite("flags", &SdssShapeResult::flags);
135 
136  // TODO this method says it's a workaround for Swig which doesn't understand std::bitset
137  cls.def("getFlag", (bool (SdssShapeResult::*)(unsigned int) const) & SdssShapeResult::getFlag, "index"_a);
138  cls.def("getFlag", (bool (SdssShapeResult::*)(std::string const &name) const) & SdssShapeResult::getFlag,
139  "name"_a);
140 }
141 
142 PyShapeTransform declareShapeTransform(py::module &mod) {
143  PyShapeTransform cls(mod, "SdssShapeTransform");
144 
145  cls.def(py::init<SdssShapeTransform::Control const &, std::string const &, afw::table::SchemaMapper &>(),
146  "ctrl"_a, "name"_a, "mapper"_a);
147 
148  cls.def("__call__", &SdssShapeTransform::operator(), "inputCatalog"_a, "outputCatalog"_a, "wcs"_a,
149  "photoCalib"_a);
150 
151  return cls;
152 }
153 
154 } // namespace
155 
156 PYBIND11_MODULE(sdssShape, mod) {
157  py::module::import("lsst.afw.geom");
158  py::module::import("lsst.afw.table");
159  py::module::import("lsst.meas.base.algorithm");
160  py::module::import("lsst.meas.base.flagHandler");
161  py::module::import("lsst.meas.base.centroidUtilities"); // for CentroidResult
162  py::module::import("lsst.meas.base.fluxUtilities"); // for FluxResult
163  py::module::import("lsst.meas.base.shapeUtilities");
164  py::module::import("lsst.meas.base.transform");
165 
166  auto clsShapeControl = declareShapeControl(mod);
167  declareShapeResultKey(mod);
168  auto clsShapeAlgorithm = declareShapeAlgorithm(mod);
169  declareShapeResult(mod);
170  auto clsShapeTransform = declareShapeTransform(mod);
171 
172  clsShapeAlgorithm.attr("Control") = clsShapeControl;
173  clsShapeTransform.attr("Control") = clsShapeControl;
174 
175  python::declareAlgorithm<SdssShapeAlgorithm, SdssShapeControl, SdssShapeTransform>(
176  clsShapeAlgorithm, clsShapeControl, clsShapeTransform);
177 }
178 
179 } // namespace base
180 } // namespace meas
181 } // namespace lsst
python.h
SdssShape.h
std::string
STL class.
lsst::meas::base::PYBIND11_MODULE
PYBIND11_MODULE(sdssShape, mod)
Definition: sdssShape.cc:156
lsst::meas::base.plugins.BaseTransform
BaseTransform
Definition: plugins.py:98
lsst::afw::geom.transform.transformContinued.name
string name
Definition: transformContinued.py:32
lsst::afw::geom.transform.transformContinued.cls
cls
Definition: transformContinued.py:33
lsst.pipe.drivers.visualizeVisit.background
background
Definition: visualizeVisit.py:37
FunctorKey.h
python.h
lsst
A base class for image defects.
Definition: imageAlgorithm.dox:1
ShapeUtilities.h
lsst::geom::Point< double, 2 >
isValid
bool isValid
Definition: fits.cc:399
pybind11
Definition: _GenericMap.cc:40
lsst::ip::isr.fringe.measure
def measure(mi, x, y, size, statistic, stats)
Definition: fringe.py:512
LSST_DECLARE_CONTROL_FIELD
#define LSST_DECLARE_CONTROL_FIELD(WRAPPER, CLASS, NAME)
Macro used to wrap fields declared by LSST_CONTROL_FIELD using Pybind11.
Definition: python.h:50
set
daf::base::PropertySet * set
Definition: fits.cc:912
lsst::meas::modelfit.psf.psfContinued.module
module
Definition: psfContinued.py:42