lsst.meas.modelfit  13.0-11-g2fa83af+13
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Pages
model.cc
Go to the documentation of this file.
1 // -*- lsst-c++ -*-
2 /*
3  * LSST Data Management System
4  * Copyright 2008-2013 LSST Corporation.
5  *
6  * This product includes software developed by the
7  * LSST Project (http://www.lsst.org/).
8  *
9  * This program is free software: you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation, either version 3 of the License, or
12  * (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the LSST License Statement and
20  * the GNU General Public License along with this program. If not,
21  * see <http://www.lsstcorp.org/LegalNotices/>.
22  */
23 
24 #include "pybind11/pybind11.h"
25 #include "pybind11/stl.h"
26 
27 #include "numpy/arrayobject.h"
28 #include "ndarray/pybind11.h"
29 
33 
34 namespace py = pybind11;
35 using namespace pybind11::literals;
36 
37 namespace lsst {
38 namespace meas {
39 namespace modelfit {
40 namespace {
41 
42 using PyModel = py::class_<Model, std::shared_ptr<Model>>;
43 
44 PYBIND11_PLUGIN(model) {
45  py::module::import("lsst.shapelet");
46  py::module::import("lsst.meas.modelfit.priors");
47  py::module::import("lsst.meas.modelfit.unitSystem");
48 
49  py::module mod("model");
50 
51  if (_import_array() < 0) {
52  PyErr_SetString(PyExc_ImportError, "numpy.core.multiarray failed to import");
53  return nullptr;
54  }
55 
56  PyModel cls(mod, "Model");
57 
58  py::enum_<Model::CenterEnum>(cls, "CenterEnum")
59  .value("FIXED_CENTER", Model::FIXED_CENTER)
60  .value("SINGLE_CENTER", Model::SINGLE_CENTER)
61  .value("MULTI_CENTER", Model::MULTI_CENTER)
62  .export_values();
63 
64  cls.def_static("make", (std::shared_ptr<Model>(*)(Model::BasisVector, Model::NameVector const &,
65  Model::CenterEnum)) &
66  Model::make,
67  "basisVector"_a, "prefixes"_a, "center"_a);
68  cls.def_static("make", (std::shared_ptr<Model>(*)(std::shared_ptr<shapelet::MultiShapeletBasis>,
69  Model::CenterEnum)) &
70  Model::make,
71  "basis"_a, "center"_a);
72  cls.def_static("makeGaussian", &Model::makeGaussian, "center"_a, "radius"_a = 1.0);
73  cls.def("getNonlinearDim", &Model::getNonlinearDim);
74  cls.def("getAmplitudeDim", &Model::getAmplitudeDim);
75  cls.def("getFixedDim", &Model::getFixedDim);
76  cls.def("getBasisCount", &Model::getBasisCount);
77  cls.def("getNonlinearNames", &Model::getNonlinearNames, py::return_value_policy::copy);
78  cls.def("getAmplitudeNames", &Model::getAmplitudeNames, py::return_value_policy::copy);
79  cls.def("getFixedNames", &Model::getFixedNames, py::return_value_policy::copy);
80  cls.def("getBasisVector", &Model::getBasisVector, py::return_value_policy::copy);
81  cls.def("makeShapeletFunction", &Model::makeShapeletFunction);
82  cls.def("adaptPrior", &Model::adaptPrior);
83  cls.def("makeEllipseVector", &Model::makeEllipseVector);
84  cls.def("writeEllipses",
85  (Model::EllipseVector (Model::*)(ndarray::Array<Scalar const, 1, 1> const &,
86  ndarray::Array<Scalar const, 1, 1> const &) const) &
87  Model::writeEllipses,
88  "nonlinear"_a, "fixed"_a);
89  cls.def("readEllipses",
90  (void (Model::*)(Model::EllipseVector const &, ndarray::Array<Scalar, 1, 1> const &,
91  ndarray::Array<Scalar, 1, 1> const &) const) &
92  Model::readEllipses,
93  "ellipses"_a, "nonlinear"_a, "fixed"_a);
94  cls.def("transformParameters", &Model::transformParameters, "transform"_a, "nonlinear"_a, "amplitudes"_a,
95  "fixed"_a);
96 
97  return mod.ptr();
98 }
99 }
100 }
101 }
102 } // namespace lsst::meas::modelfit::anonymous