Skip to content

Commit

Permalink
Merge pull request #72 from lsst/tickets/DM-9188
Browse files Browse the repository at this point in the history
DM-9188: Cleanup pybind11 code in core meas and ip packages
  • Loading branch information
Pim Schellart committed Mar 3, 2017
2 parents cd8204b + 636ac97 commit 91709ef
Show file tree
Hide file tree
Showing 33 changed files with 154 additions and 307 deletions.
2 changes: 1 addition & 1 deletion python/lsst/meas/base/SConscript
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,4 @@ scripts.BasicSConscript.pybind11(['algorithm',
'sdssShape',
'sincCoeffs',
'shapeUtilities',
'transform',])
'transform',], addUnderscore=False)
26 changes: 25 additions & 1 deletion python/lsst/meas/base/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,38 @@
"""lsst..meas.base
"""
from __future__ import absolute_import
# Needed for pybind11-generated docstrings
from lsst.afw.image import Calib, Wcs

from .centroidUtilities import *
from .fluxUtilities import *
from .inputUtilities import *
from .shapeUtilities import *
from .algorithm import *
from .apertureFlux import *
from .blendedness import *
from .circularApertureFlux import *
from .exceptions import *
from .flagHandler import *
from .gaussianCentroid import *
from .gaussianFlux import *
from .naiveCentroid import *
from .peakLikelihoodFlux import *
from .pixelFlags import *
from .psfFlux import *
from .scaledApertureFlux import *
from .sdssCentroid import *
from .sdssShape import *
from .sincCoeffs import *
from .transform import *

from .apCorrRegistry import *
from .pluginRegistry import *
from .baseMeasurement import *
from .pluginsBase import *
from .sfm import *
from .plugins import *
from .classification import *
from .baseLib import *
from .noiseReplacer import *
from .baseMeasurement import *
from .forcedMeasurement import *
Expand Down
13 changes: 3 additions & 10 deletions python/lsst/meas/base/algorithm.cc
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@
* see <https://www.lsstcorp.org/LegalNotices/>.
*/

#include <pybind11/pybind11.h>
//#include <pybind11/stl.h>
#include "pybind11/pybind11.h"

#include "lsst/afw/image/Wcs.h"
#include "lsst/afw/table/Source.h"
Expand All @@ -35,19 +34,13 @@ namespace lsst {
namespace meas {
namespace base {

PYBIND11_PLUGIN(_algorithm) {
py::module mod("_algorithm", "Python wrapper for afw _algorithm library");
PYBIND11_PLUGIN(algorithm) {
py::module mod("algorithm");

/* Module level */
py::class_<SingleFrameAlgorithm, std::shared_ptr<SingleFrameAlgorithm>> clsSingleFrameAlgorithm(mod, "SingleFrameAlgorithm");
py::class_<SimpleAlgorithm, std::shared_ptr<SimpleAlgorithm>, SingleFrameAlgorithm> clsSimpleAlgorithm(mod, "SimpleAlgorithm");

/* Member types and enums */

/* Constructors */

/* Operators */

/* Members */
python::declareAlgorithm<SingleFrameAlgorithm>(clsSingleFrameAlgorithm);

Expand Down
14 changes: 6 additions & 8 deletions python/lsst/meas/base/apertureFlux.cc
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
* see <https://www.lsstcorp.org/LegalNotices/>.
*/

#include <pybind11/pybind11.h>
#include <pybind11/stl.h>
#include "pybind11/pybind11.h"
#include "pybind11/stl.h"

#include "lsst/pex/config/python.h"
#include "lsst/meas/base/python.h"
Expand Down Expand Up @@ -57,8 +57,8 @@ namespace {
}
}

PYBIND11_PLUGIN(_apertureFlux) {
py::module mod("_apertureFlux", "Python wrapper for afw _apertureFlux library");
PYBIND11_PLUGIN(apertureFlux) {
py::module mod("apertureFlux");

/* Module level */
py::class_<ApertureFluxAlgorithm, std::shared_ptr<ApertureFluxAlgorithm>, SimpleAlgorithm> clsApertureFluxAlgorithm(mod, "ApertureFluxAlgorithm");
Expand All @@ -67,6 +67,8 @@ PYBIND11_PLUGIN(_apertureFlux) {
py::class_<ApertureFluxTransform> clsApertureFluxTransform(mod, "ApertureFluxTransform");

/* Member types and enums */
clsApertureFluxAlgorithm.attr("Control") = clsApertureFluxControl;

// ApertureFluxAlgorithm::Control wrapped in apertureFlux.py
py::enum_<ApertureFluxAlgorithm::FlagBits>(clsApertureFluxAlgorithm, "FlagBits")
.value("FAILURE", ApertureFluxAlgorithm::FlagBits::FAILURE)
Expand All @@ -75,10 +77,6 @@ PYBIND11_PLUGIN(_apertureFlux) {
.value("N_FLAGS", ApertureFluxAlgorithm::FlagBits::N_FLAGS)
.export_values();

/* Constructors */

/* Operators */

/* Members */
python::declareAlgorithm<ApertureFluxAlgorithm,
ApertureFluxControl,
Expand Down
5 changes: 0 additions & 5 deletions python/lsst/meas/base/apertureFlux.py

This file was deleted.

28 changes: 0 additions & 28 deletions python/lsst/meas/base/baseLib.py

This file was deleted.

2 changes: 1 addition & 1 deletion python/lsst/meas/base/baseMeasurement.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
import lsst.pex.config

from .pluginRegistry import PluginMap
from .baseLib import FatalAlgorithmError, MeasurementError
from .exceptions import FatalAlgorithmError, MeasurementError
from .pluginsBase import BasePluginConfig, BasePlugin
from .noiseReplacer import NoiseReplacerConfig

Expand Down
11 changes: 3 additions & 8 deletions python/lsst/meas/base/blendedness.cc
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@
* see <https://www.lsstcorp.org/LegalNotices/>.
*/

#include <pybind11/pybind11.h>
//#include <pybind11/stl.h>
#include "pybind11/pybind11.h"

#include "lsst/pex/config/python.h"
#include "lsst/meas/base/python.h"
Expand All @@ -35,10 +34,8 @@ namespace lsst {
namespace meas {
namespace base {

PYBIND11_PLUGIN(_blendedness) {
py::module mod("_blendedness", "Python wrapper for afw _blendedness library");

/* Module level */
PYBIND11_PLUGIN(blendedness) {
py::module mod("blendedness");

/* Member types and enums */
py::class_<BlendednessAlgorithm, std::shared_ptr<BlendednessAlgorithm>, SimpleAlgorithm> clsBlendednessAlgorithm(mod, "BlendednessAlgorithm");
Expand All @@ -52,8 +49,6 @@ PYBIND11_PLUGIN(_blendedness) {

clsBlendednessControl.def(py::init<>());

/* Operators */

/* Members */
python::declareAlgorithm<BlendednessAlgorithm, BlendednessControl>(
clsBlendednessAlgorithm, clsBlendednessControl);
Expand Down
2 changes: 1 addition & 1 deletion python/lsst/meas/base/catalogCalculation.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

from .pluginsBase import BasePlugin, BasePluginConfig
from .pluginRegistry import PluginRegistry, PluginMap
from .baseLib import FatalAlgorithmError, MeasurementError
from . import FatalAlgorithmError, MeasurementError

# Exceptions that the measurement tasks should always propagate up to their callers
FATAL_EXCEPTIONS = (MemoryError, FatalAlgorithmError)
Expand Down
10 changes: 3 additions & 7 deletions python/lsst/meas/base/centroidUtilities.cc
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,10 @@
* see <https://www.lsstcorp.org/LegalNotices/>.
*/

#include <pybind11/pybind11.h>
//#include <pybind11/stl.h>
#include "pybind11/pybind11.h"

#include "numpy/arrayobject.h"
#include "ndarray/pybind11.h"
#include "ndarray/converter.h"

#include "lsst/meas/base/CentroidUtilities.h"

Expand All @@ -36,8 +34,8 @@ namespace lsst {
namespace meas {
namespace base {

PYBIND11_PLUGIN(_centroidUtilities) {
py::module mod("_centroidUtilities", "Python wrapper for afw _centroidUtilities library");
PYBIND11_PLUGIN(centroidUtilities) {
py::module mod("centroidUtilities");

if (_import_array() < 0) {
PyErr_SetString(PyExc_ImportError, "numpy.core.multiarray failed to import");
Expand All @@ -49,8 +47,6 @@ PYBIND11_PLUGIN(_centroidUtilities) {
py::class_<CentroidResult> clsCentroidResult(mod, "CentroidResult");
py::class_<CentroidResultKey> clsCentroidResultKey(mod, "CentroidResultKey");

/* Member types and enums */

/* Constructors */
clsCentroidChecker.def(py::init<afw::table::Schema &,
std::string const &,
Expand Down
13 changes: 3 additions & 10 deletions python/lsst/meas/base/circularApertureFlux.cc
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@
* see <https://www.lsstcorp.org/LegalNotices/>.
*/

#include <pybind11/pybind11.h>
//#include <pybind11/stl.h>
#include "pybind11/pybind11.h"

#include "lsst/meas/base/CircularApertureFlux.h"

Expand All @@ -32,25 +31,19 @@ namespace lsst {
namespace meas {
namespace base {

PYBIND11_PLUGIN(_circularApertureFlux) {
py::module mod("_circularApertureFlux", "Python wrapper for afw _circularApertureFlux library");
PYBIND11_PLUGIN(circularApertureFlux) {
py::module mod("circularApertureFlux");

/* Module level */
py::class_<CircularApertureFluxAlgorithm, std::shared_ptr<CircularApertureFluxAlgorithm>, ApertureFluxAlgorithm> cls(mod, "CircularApertureFluxAlgorithm");

/* Member types and enums */

/* Constructors */
cls.def(py::init<CircularApertureFluxAlgorithm::Control const &,
std::string const &,
afw::table::Schema &,
daf::base::PropertySet &>(),
"ctrl"_a, "name"_a, "schema"_a, "metadata"_a);

/* Operators */

/* Members */

return mod.ptr();
}

Expand Down
48 changes: 0 additions & 48 deletions python/lsst/meas/base/constants.cc

This file was deleted.

12 changes: 4 additions & 8 deletions python/lsst/meas/base/exceptions.cc
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@
* see <https://www.lsstcorp.org/LegalNotices/>.
*/

#include <pybind11/pybind11.h>
//#include <pybind11/stl.h>
#include "pybind11/pybind11.h"

#include "lsst/meas/base/exceptions.h"
#include "lsst/pex/exceptions/Runtime.h"
Expand All @@ -34,11 +33,12 @@ namespace lsst {
namespace meas {
namespace base {

PYBIND11_PLUGIN(_exceptions) {
PYBIND11_PLUGIN(exceptions) {
using lsst::pex::exceptions::python::declareException;
using lsst::pex::exceptions::DomainError;
using lsst::pex::exceptions::RuntimeError;
py::module mod("_exceptions", "Python wrapper for afw _exceptions library");

py::module mod("exceptions");

/* Module level */
auto clsFatalAlgorithmError = declareException<FatalAlgorithmError, RuntimeError>(
Expand All @@ -48,15 +48,11 @@ PYBIND11_PLUGIN(_exceptions) {
auto clsPixelValueError = declareException<PixelValueError, DomainError>(
mod, "PixelValueError", "DomainError");

/* Member types and enums */

/* Constructors */
clsMeasurementError.def(py::init<std::string const &,
std::size_t>(),
"message"_a, "flagBit"_a);

/* Operators */

/* Members */
clsMeasurementError.def("getFlagBit", &MeasurementError::getFlagBit);

Expand Down
10 changes: 4 additions & 6 deletions python/lsst/meas/base/flagHandler.cc
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
* see <https://www.lsstcorp.org/LegalNotices/>.
*/

#include <pybind11/pybind11.h>
#include <pybind11/stl.h>
#include "pybind11/pybind11.h"
#include "pybind11/stl.h"

#include "lsst/meas/base/FlagHandler.h"

Expand All @@ -32,8 +32,8 @@ namespace lsst {
namespace meas {
namespace base {

PYBIND11_PLUGIN(_flagHandler) {
py::module mod("_flagHandler", "Python wrapper for afw _flagHandler library");
PYBIND11_PLUGIN(flagHandler) {
py::module mod("flagHandler");

/* Module level */
py::class_<FlagDefinition> clsFlagDefinition(mod, "FlagDefinition");
Expand All @@ -47,8 +47,6 @@ PYBIND11_PLUGIN(_flagHandler) {
clsFlagDefinition.def(py::init<>());
clsFlagDefinition.def(py::init<std::string, std::string>(), "_name"_a, "_doc"_a);

/* Operators */

/* Members */
clsFlagDefinition.def_readwrite("doc", &FlagDefinition::doc);
clsFlagDefinition.def_readwrite("name", &FlagDefinition::name);
Expand Down

0 comments on commit 91709ef

Please sign in to comment.