Skip to content

Commit

Permalink
Merge pull request #31 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 55ab999 + f572898 commit ff248e9
Show file tree
Hide file tree
Showing 9 changed files with 34 additions and 35 deletions.
2 changes: 1 addition & 1 deletion python/lsst/ip/isr/SConscript
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
## -*- python -*-
from lsst.sconsUtils import scripts
scripts.BasicSConscript.pybind11(["applyLookupTable", "isr"])
scripts.BasicSConscript.pybind11(["applyLookupTable", "isr"], addUnderscore=False)
7 changes: 5 additions & 2 deletions python/lsst/ip/isr/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,12 @@
# see <https://www.lsstcorp.org/LegalNotices/>.
#

from .version import *
from .isrLib import *
from __future__ import absolute_import

from .applyLookupTable import *
from .isr import *
from .version import *
from .isrFunctions import *
from .assembleCcdTask import *
from .isrTask import *
from .linearize import *
10 changes: 5 additions & 5 deletions python/lsst/ip/isr/applyLookupTable.cc
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
* the GNU General Public License along with this program. If not,
* see <https://www.lsstcorp.org/LegalNotices/>.
*/
#include <pybind11/pybind11.h>
#include <pybind11/stl.h>
#include "pybind11/pybind11.h"
#include "pybind11/stl.h"
#include "numpy/arrayobject.h"
#include "ndarray/pybind11.h"

Expand All @@ -36,14 +36,14 @@ namespace isr {
namespace {

template <typename PixelT>
void declareApplyLookupTable(py::module& mod) {
static void declareApplyLookupTable(py::module& mod) {
mod.def("applyLookupTable", &applyLookupTable<PixelT>, "image"_a, "table"_a, "indOffset"_a);
}

} // namespace lsst::ip::isr::<anonymous>

PYBIND11_PLUGIN(_applyLookupTable) {
py::module mod("_applyLookupTable", "Python wrapper for ApplyLookupTable.h");
PYBIND11_PLUGIN(applyLookupTable) {
py::module mod("applyLookupTable");

// Need to import numpy for ndarray and eigen conversions
if (_import_array() < 0) {
Expand Down
2 changes: 1 addition & 1 deletion python/lsst/ip/isr/assembleCcdTask.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
import lsst.pipe.base as pipeBase
from lsstDebug import getDebugFrame
from lsst.afw.display import getDisplay
from .isr import calcEffectiveGain
from .isrFunctions import calcEffectiveGain

__all__ = ["AssembleCcdTask"]

Expand Down
12 changes: 6 additions & 6 deletions python/lsst/ip/isr/isr.cc
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
*/
#include <memory>

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

#include "lsst/ip/isr/isr.h"

Expand All @@ -35,9 +35,9 @@ namespace isr {
namespace {

template <typename PixelT>
void declareCountMaskedPixels(py::module& mod, std::string const& suffix) {
static void declareCountMaskedPixels(py::module& mod, std::string const& suffix) {
py::class_<CountMaskedPixels<PixelT>, std::shared_ptr<CountMaskedPixels<PixelT>>> cls(
mod, ("CountMaskedPixels" + suffix).c_str());
mod, ("CountMaskedPixels" + suffix).c_str());

cls.def("reset", &CountMaskedPixels<PixelT>::reset);
cls.def("apply", &CountMaskedPixels<PixelT>::apply, "image"_a, "bitmask"_a);
Expand All @@ -55,7 +55,7 @@ void declareCountMaskedPixels(py::module& mod, std::string const& suffix) {
* Note that the second (function type) template parameter of `fitOverscanImage` is always `double`.
*/
template <typename PixelT>
void declareAll(py::module& mod, std::string const& suffix) {
static void declareAll(py::module& mod, std::string const& suffix) {
declareCountMaskedPixels<PixelT>(mod, suffix);

mod.def("maskNans", &maskNans<PixelT>, "maskedImage"_a, "maskVal"_a, "allow"_a = 0);
Expand All @@ -65,8 +65,8 @@ void declareAll(py::module& mod, std::string const& suffix) {

} // namespace lsst::ip::isr::<anonymous>

PYBIND11_PLUGIN(_isr) {
py::module mod("_isr", "Python wrapper for _isr library");
PYBIND11_PLUGIN(isr) {
py::module mod("isr");

declareAll<float>(mod, "F");
declareAll<double>(mod, "D");
Expand Down
File renamed without changes.
3 changes: 0 additions & 3 deletions python/lsst/ip/isr/isrLib.py

This file was deleted.

31 changes: 15 additions & 16 deletions python/lsst/ip/isr/isrTask.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,7 @@
from lsst.daf.persistence import ButlerDataRef
from lsstDebug import getDebugFrame
from lsst.afw.display import getDisplay
from . import isr
from .isrLib import maskNans
from . import isrFunctions
from .assembleCcdTask import AssembleCcdTask
from .fringe import FringeTask
from lsst.afw.geom.polygon import Polygon
Expand Down Expand Up @@ -295,7 +294,7 @@ class IsrTask(pipeBase.CmdLineTask):
import lsstDebug
def DebugInfo(name):
di = lsstDebug.getInfo(name) # N.b. lsstDebug.Info(name) would call us recursively
if name == "lsst.ip.isr.isrTask":
if name == "lsst.ip.isrFunctions.isrTask":
di.display = {'postISRCCD':2}
return di
lsstDebug.Info = DebugInfo
Expand Down Expand Up @@ -372,7 +371,7 @@ def run(self, ccdExposure, bias=None, linearizer=None, dark=None, flat=None, def
\param[in] ccdExposure -- lsst.afw.image.exposure of detector data
\param[in] bias -- exposure of bias frame
\param[in] linearizer -- linearizing functor; a subclass of lsst.ip.isr.LinearizeBase
\param[in] linearizer -- linearizing functor; a subclass of lsst.ip.isrFunctions.LinearizeBase
\param[in] dark -- exposure of dark frame
\param[in] flat -- exposure of flatfield
\param[in] defects -- list of detects
Expand Down Expand Up @@ -519,7 +518,7 @@ def biasCorrection(self, exposure, biasExposure):
\param[in,out] exposure exposure to process
\param[in] biasExposure bias exposure of same size as exposure
"""
isr.biasCorrection(exposure.getMaskedImage(), biasExposure.getMaskedImage())
isrFunctions.biasCorrection(exposure.getMaskedImage(), biasExposure.getMaskedImage())

def darkCorrection(self, exposure, darkExposure):
"""!Apply dark correction in place
Expand All @@ -533,7 +532,7 @@ def darkCorrection(self, exposure, darkExposure):
darkScale = darkExposure.getInfo().getVisitInfo().getDarkTime()
if math.isnan(darkScale):
raise RuntimeError("Dark calib darktime is NAN")
isr.darkCorrection(
isrFunctions.darkCorrection(
maskedImage=exposure.getMaskedImage(),
darkMaskedImage=darkExposure.getMaskedImage(),
expScale=expScale,
Expand All @@ -557,7 +556,7 @@ def updateVariance(self, ampExposure, amp):
\param[in] amp amplifier detector information
"""
if not math.isnan(amp.getGain()):
isr.updateVariance(
isrFunctions.updateVariance(
maskedImage=ampExposure.getMaskedImage(),
gain=amp.getGain(),
readNoise=amp.getReadNoise(),
Expand All @@ -569,7 +568,7 @@ def flatCorrection(self, exposure, flatExposure):
\param[in,out] exposure exposure to process
\param[in] flatExposure flatfield exposure same size as exposure
"""
isr.flatCorrection(
isrFunctions.flatCorrection(
maskedImage=exposure.getMaskedImage(),
flatMaskedImage=flatExposure.getMaskedImage(),
scalingType=self.config.flatScalingType,
Expand Down Expand Up @@ -610,7 +609,7 @@ def saturationDetection(self, exposure, amp):
if not math.isnan(amp.getSaturation()):
maskedImage = exposure.getMaskedImage()
dataView = maskedImage.Factory(maskedImage, amp.getRawBBox())
isr.makeThresholdMask(
isrFunctions.makeThresholdMask(
maskedImage=dataView,
threshold=amp.getSaturation(),
growFootprints=0,
Expand All @@ -626,7 +625,7 @@ def saturationInterpolation(self, ccdExposure):
- Call saturationDetection first, so that saturated pixels have been identified in the "SAT" mask.
- Call this after CCD assembly, since saturated regions may cross amplifier boundaries
"""
isr.interpolateFromMask(
isrFunctions.interpolateFromMask(
maskedImage=ccdExposure.getMaskedImage(),
fwhm=self.config.fwhm,
growFootprints=self.config.growSaturationFootprintSize,
Expand All @@ -651,7 +650,7 @@ def suspectDetection(self, exposure, amp):

maskedImage = exposure.getMaskedImage()
dataView = maskedImage.Factory(maskedImage, amp.getRawBBox())
isr.makeThresholdMask(
isrFunctions.makeThresholdMask(
maskedImage=dataView,
threshold=suspectLevel,
growFootprints=0,
Expand All @@ -672,8 +671,8 @@ def maskAndInterpDefect(self, ccdExposure, defectBaseList):
bbox = d.getBBox()
nd = measAlg.Defect(bbox)
defectList.append(nd)
isr.maskPixelsFromDefectList(maskedImage, defectList, maskName='BAD')
isr.interpolateDefectList(
isrFunctions.maskPixelsFromDefectList(maskedImage, defectList, maskName='BAD')
isrFunctions.interpolateDefectList(
maskedImage=maskedImage,
defectList=defectList,
fwhm=self.config.fwhm,
Expand Down Expand Up @@ -701,12 +700,12 @@ def maskAndInterpNan(self, exposure):
# Interpolate over these previously-unmasked NaNs
if numNans > 0:
self.log.warn("There were %i unmasked NaNs", numNans)
nanDefectList = isr.getDefectListFromMask(
nanDefectList = isrFunctions.getDefectListFromMask(
maskedImage=maskedImage,
maskName='UNMASKEDNAN',
growFootprints=0,
)
isr.interpolateDefectList(
isrFunctions.interpolateDefectList(
maskedImage=exposure.getMaskedImage(),
defectList=nanDefectList,
fwhm=self.config.fwhm,
Expand All @@ -731,7 +730,7 @@ def overscanCorrection(self, exposure, amp):
expImage = exposure.getMaskedImage().getImage()
overscanImage = expImage.Factory(expImage, amp.getRawHorizontalOverscanBBox())

isr.overscanCorrection(
isrFunctions.overscanCorrection(
ampMaskedImage=dataView,
overscanImage=overscanImage,
fitType=self.config.overscanFitType,
Expand Down
2 changes: 1 addition & 1 deletion python/lsst/ip/isr/linearize.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
import numpy as np

from lsst.pipe.base import Struct
from .isrLib import applyLookupTable
from .applyLookupTable import applyLookupTable

__all__ = ["LinearizeBase", "LinearizeLookupTable", "LinearizeSquared"]

Expand Down

0 comments on commit ff248e9

Please sign in to comment.