Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DM-9190: Cleanup pybind11 remaining code #14

Merged
merged 1 commit into from
Apr 6, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion examples/shapeletBases.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
# see <http://www.lsstcorp.org/LegalNotices/>.
#

from __future__ import print_function
from __future__ import absolute_import, division, print_function
from builtins import range
import lsst.shapelet
from lsst.afw import geom
Expand Down
3 changes: 1 addition & 2 deletions examples/timeModels.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
from __future__ import absolute_import
from __future__ import print_function
from __future__ import absolute_import, division, print_function

import numpy
import pickle
Expand Down
10 changes: 5 additions & 5 deletions python/lsst/shapelet/SConscript
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
# -*- python -*-
from lsst.sconsUtils import scripts
scripts.BasicSConscript.pybind11(["constants",
"shapeletFunction",
scripts.BasicSConscript.pybind11(["constants/constants",
"shapeletFunction/shapeletFunction",
"gaussHermiteProjection",
"gaussHermiteConvolution",
"multiShapeletFunction",
"multiShapeletFunction/multiShapeletFunction",
"multiShapeletBasis",
"matrixBuilder",
"hermiteTransformMatrix",
"radialProfile",
"radialProfile/radialProfile",
"functorKeys",
"basisEvaluator"])
"basisEvaluator"], addUnderscore=False)
19 changes: 17 additions & 2 deletions python/lsst/shapelet/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,23 @@

"""lsst.shapelet
"""
from __future__ import absolute_import
from .shapeletLib import *
from __future__ import absolute_import, division, print_function

import lsst.afw.geom

from .constants import *
from .shapeletFunction import *
from .basisEvaluator import *
from .gaussHermiteProjection import *
from .gaussHermiteConvolution import *
from .multiShapeletFunction import *
from .multiShapeletBasis import *
from .matrixBuilder import *
from .hermiteTransformMatrix import *
from .radialProfile import *
from .functorKeys import *
from .generator import *

from . import tractor
from lsst.afw.geom.ellipses import Quadrupole as EllipseCore

11 changes: 7 additions & 4 deletions python/lsst/shapelet/basisEvaluator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,10 @@ using namespace pybind11::literals;
namespace lsst {
namespace shapelet {

PYBIND11_PLUGIN(_basisEvaluator) {
py::module mod("_basisEvaluator");
PYBIND11_PLUGIN(basisEvaluator) {
py::module::import("lsst.afw.geom");

py::module mod("basisEvaluator");

if (_import_array() < 0) {
PyErr_SetString(PyExc_ImportError, "numpy.core.multiarray failed to import");
Expand Down Expand Up @@ -88,5 +90,6 @@ PYBIND11_PLUGIN(_basisEvaluator) {

return mod.ptr();
}
}
} // lsst::shapelet

} // shapelet
} // lsst
13 changes: 0 additions & 13 deletions python/lsst/shapelet/constants.py

This file was deleted.

27 changes: 27 additions & 0 deletions python/lsst/shapelet/constants/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#
# LSST Data Management System
#
# This product includes software developed by the
# LSST Project (http://www.lsst.org/).
# See the COPYRIGHT file
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the LSST License Statement and
# the GNU General Public License along with this program. If not,
# see <https://www.lsstcorp.org/LegalNotices/>.
#/

from __future__ import absolute_import, division, print_function

from .constants import *
from .constantsContinued import *

Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ using namespace pybind11::literals;
namespace lsst {
namespace shapelet {

PYBIND11_PLUGIN(_constants) {
py::module mod("_constants");
PYBIND11_PLUGIN(constants) {
py::module mod("constants");

py::enum_<BasisTypeEnum>(mod, "BasisTypeEnum")
.value("HERMITE", BasisTypeEnum::HERMITE)
Expand All @@ -45,5 +45,6 @@ PYBIND11_PLUGIN(_constants) {

return mod.ptr();
}
}
} // lsst::shapelet

} // shapelet
} // lsst
16 changes: 16 additions & 0 deletions python/lsst/shapelet/constants/constantsContinued.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
from __future__ import absolute_import, division, print_function

from .constants import BasisTypeEnum

from lsst.utils import continueClass

__all__ = []

@continueClass
class BasisTypeEnum:
# Workaround for broken pickling on Python 2
# Without this fails with: TypeError: lsst.shapelet.constants.BasisTypeEnum.__new__(
# lsst.shapelet.constants.BasisTypeEnum) is not safe, use object.__new__()
def __reduce__(self):
return (BasisTypeEnum, (int(self), ))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any idea if this is still needed? (I'm not sure how old the note is)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, this is (unfortunately) still needed.


14 changes: 8 additions & 6 deletions python/lsst/shapelet/functorKeys.cc
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,9 @@ using namespace pybind11::literals;
namespace lsst {
namespace shapelet {

PYBIND11_PLUGIN(_functorKeys) {
py::module mod("_functorKeys");
PYBIND11_PLUGIN(functorKeys) {
py::module::import("lsst.afw.table");
py::module mod("functorKeys");

py::class_<ShapeletFunctionKey, std::shared_ptr<ShapeletFunctionKey>> clsShapeletFunctionKey(
mod, "ShapeletFunctionKey");
Expand Down Expand Up @@ -74,14 +75,15 @@ PYBIND11_PLUGIN(_functorKeys) {

clsMultiShapeletFunctionKey.def("__eq__", &MultiShapeletFunctionKey::operator==, py::is_operator());
clsMultiShapeletFunctionKey.def("__ne__", &MultiShapeletFunctionKey::operator!=, py::is_operator());
clsMultiShapeletFunctionKey.def(
"__getitem__", [](MultiShapeletFunctionKey &self, int i) { return self[i]; }, py::is_operator());
clsMultiShapeletFunctionKey.def("__getitem__",
[](MultiShapeletFunctionKey &self, int i) { return self[i]; });

clsMultiShapeletFunctionKey.def("get", &MultiShapeletFunctionKey::get);
clsMultiShapeletFunctionKey.def("set", &MultiShapeletFunctionKey::set);
clsMultiShapeletFunctionKey.def("isValid", &MultiShapeletFunctionKey::isValid);

return mod.ptr();
}
}
} // lsst::shapelet

} // shapelet
} // lsst
9 changes: 5 additions & 4 deletions python/lsst/shapelet/gaussHermiteConvolution.cc
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ using namespace pybind11::literals;
namespace lsst {
namespace shapelet {

PYBIND11_PLUGIN(_gaussHermiteConvolution) {
py::module mod("_gaussHermiteConvolution");
PYBIND11_PLUGIN(gaussHermiteConvolution) {
py::module mod("gaussHermiteConvolution");

if (_import_array() < 0) {
PyErr_SetString(PyExc_ImportError, "numpy.core.multiarray failed to import");
Expand All @@ -53,5 +53,6 @@ PYBIND11_PLUGIN(_gaussHermiteConvolution) {

return mod.ptr();
}
}
} // lsst::shapelet

} // shapelet
} // lsst
10 changes: 6 additions & 4 deletions python/lsst/shapelet/gaussHermiteProjection.cc
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,9 @@ using namespace pybind11::literals;
namespace lsst {
namespace shapelet {

PYBIND11_PLUGIN(_gaussHermiteProjection) {
py::module mod("_gaussHermiteProjection");
PYBIND11_PLUGIN(gaussHermiteProjection) {
py::module::import("lsst.afw.geom");
py::module mod("gaussHermiteProjection");

if (_import_array() < 0) {
PyErr_SetString(PyExc_ImportError, "numpy.core.multiarray failed to import");
Expand Down Expand Up @@ -64,5 +65,6 @@ PYBIND11_PLUGIN(_gaussHermiteProjection) {

return mod.ptr();
}
}
} // lsst::shapelet

} // shapelet
} // lsst
4 changes: 2 additions & 2 deletions python/lsst/shapelet/generator.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from __future__ import absolute_import
from __future__ import absolute_import, division, print_function
from builtins import range, object
from ._constants import HERMITE, LAGUERRE, computeSize
from .constants import HERMITE, LAGUERRE, computeSize

class IndexGenerator(object):
"""
Expand Down
11 changes: 7 additions & 4 deletions python/lsst/shapelet/hermiteTransformMatrix.cc
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,10 @@ using namespace pybind11::literals;
namespace lsst {
namespace shapelet {

PYBIND11_PLUGIN(_hermiteTransformMatrix) {
py::module mod("_hermiteTransformMatrix");
PYBIND11_PLUGIN(hermiteTransformMatrix) {
py::module::import("lsst.afw.geom");

py::module mod("hermiteTransformMatrix");

if (_import_array() < 0) {
PyErr_SetString(PyExc_ImportError, "numpy.core.multiarray failed to import");
Expand Down Expand Up @@ -70,5 +72,6 @@ PYBIND11_PLUGIN(_hermiteTransformMatrix) {

return mod.ptr();
}
}
} // lsst::shapelet

} // shapelet
} // lsst
17 changes: 10 additions & 7 deletions python/lsst/shapelet/matrixBuilder.cc
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,9 @@ py::class_<MatrixBuilderFactory<T>, std::shared_ptr<MatrixBuilderFactory<T>>> de
MultiShapeletBasis const &, MultiShapeletFunction const &>(),
"x"_a, "y"_a, "basis"_a, "psf"_a);

cls.def("__call__", (MatrixBuilder<T> (Class::*)() const) & Class::operator(), py::is_operator());
cls.def("__call__", (MatrixBuilder<T> (Class::*)() const) & Class::operator());
cls.def("__call__", (MatrixBuilder<T> (Class::*)(typename Class::Workspace &) const) & Class::operator(),
py::is_operator(), "workspace"_a);
"workspace"_a);

cls.def("getDataSize", &Class::getDataSize);
cls.def("getBasisSize", &Class::getBasisSize);
Expand All @@ -124,10 +124,12 @@ void declareMatrixBuilderTemplates(py::module &mod, std::string const &suffix) {
clsMatrixBuilderFactory.attr("Workspace") = clsMatrixBuilderWorkspace;
clsMatrixBuilderFactory.attr("Builder") = clsMatrixBuilder;
}
}

PYBIND11_PLUGIN(_matrixBuilder) {
py::module mod("_matrixBuilder");
} // <anonymous>

PYBIND11_PLUGIN(matrixBuilder) {
py::module::import("lsst.afw.geom");
py::module mod("matrixBuilder");

if (_import_array() < 0) {
PyErr_SetString(PyExc_ImportError, "numpy.core.multiarray failed to import");
Expand All @@ -139,5 +141,6 @@ PYBIND11_PLUGIN(_matrixBuilder) {

return mod.ptr();
}
}
} // lsst::shapelet

} // shapelet
} // lsst
9 changes: 5 additions & 4 deletions python/lsst/shapelet/multiShapeletBasis.cc
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ using namespace pybind11::literals;
namespace lsst {
namespace shapelet {

PYBIND11_PLUGIN(_multiShapeletBasis) {
py::module mod("_multiShapeletBasis");
PYBIND11_PLUGIN(multiShapeletBasis) {
py::module mod("multiShapeletBasis");

if (_import_array() < 0) {
PyErr_SetString(PyExc_ImportError, "numpy.core.multiarray failed to import");
Expand Down Expand Up @@ -68,5 +68,6 @@ PYBIND11_PLUGIN(_multiShapeletBasis) {

return mod.ptr();
}
}
} // lsst::shapelet

} // shapelet
} // lsst
9 changes: 0 additions & 9 deletions python/lsst/shapelet/multiShapeletFunction.py

This file was deleted.

27 changes: 27 additions & 0 deletions python/lsst/shapelet/multiShapeletFunction/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#
# LSST Data Management System
#
# This product includes software developed by the
# LSST Project (http://www.lsst.org/).
# See the COPYRIGHT file
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the LSST License Statement and
# the GNU General Public License along with this program. If not,
# see <https://www.lsstcorp.org/LegalNotices/>.
#/

from __future__ import absolute_import, division, print_function

from .multiShapeletFunction import *
from .multiShapeletFunctionContinued import *

Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,14 @@ void declareMultiShapeletFunctionEvaluatorMembers(PyClass &cls) {
cls.def("computeMoments", &Class::computeMoments);
cls.def("update", &Class::update);
}
}

PYBIND11_PLUGIN(_multiShapeletFunction) {
py::module mod("_multiShapeletFunction");
} // <anonymous>

PYBIND11_PLUGIN(multiShapeletFunction) {
py::module::import("lsst.afw.geom");
py::module::import("lsst.afw.image");

py::module mod("multiShapeletFunction");

if (_import_array() < 0) {
PyErr_SetString(PyExc_ImportError, "numpy.core.multiarray failed to import");
Expand All @@ -109,5 +113,6 @@ PYBIND11_PLUGIN(_multiShapeletFunction) {

return mod.ptr();
}
}
} // lsst::shapelet

} // shapelet
} // lsst