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-9887: Wrap meas_mosaic with pybind11 instead of swig #6

Merged
merged 1 commit into from
Mar 23, 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: 0 additions & 2 deletions .hgignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ syntax: glob
*.la
*.a
python/hsc/meas/mosaic/version.py
python/hsc/meas/mosaic/mosaicLib.py
python/hsc/meas/mosaic/mosaicLib_wrap.cc
*.cfgc
tests/.tests
tests/testFit
Expand Down
7 changes: 6 additions & 1 deletion python/lsst/meas/mosaic/SConscript
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
# -*- python -*-
from lsst.sconsUtils import scripts
scripts.BasicSConscript.python(['mosaicLib'])
scripts.BasicSConscript.pybind11(['fluxfit',
'matches',
'mosaicfit/mosaicfit',
'shimCameraGeom',
'snapshot',
'spatialCellSource'], addUnderscore=False)
33 changes: 30 additions & 3 deletions python/lsst/meas/mosaic/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,30 @@
import lsst.afw # this is necessary for avoiding segmentation falut.
from mosaicLib import *
from updateExposure import *
#
# 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

from .fluxfit import *
from .matches import *
from .mosaicfit import *
from .shimCameraGeom import *
from .snapshot import *
from .spatialCellSource import *
31 changes: 15 additions & 16 deletions python/lsst/meas/mosaic/checkMosaicTask.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from lsst.meas.mosaic.mosaicTask import MosaicTask
from lsst.meas.mosaic.mosaicTask import MosaicConfig
from lsst.meas.mosaic.mosaicTask import MosaicRunner
import lsst.meas.mosaic.mosaicLib as measMosaic
import lsst.meas.mosaic as measMosaic
import lsst.meas.algorithms as measAlg
import lsst.meas.astrom as measAstrom
import lsst.afw.image as afwImage
Expand Down Expand Up @@ -423,8 +423,8 @@ def check(self, dataRefList, ct=None, debug=False, verbose=False):
ccdSet = self.readCcd(dataRefList)
self.removeNonExistCcd(dataRefList, ccdSet)

sourceSet = measMosaic.SourceGroup()
matchList = measMosaic.SourceMatchGroup()
sourceSet = []
matchList = []
astrom = measAstrom.ANetBasicAstrometryTask(self.config.astrom)
ssVisit = dict()
mlVisit = dict()
Expand Down Expand Up @@ -470,10 +470,10 @@ def check(self, dataRefList, ct=None, debug=False, verbose=False):
packedMatches = dataRef.get('icMatch')
matches = astrom.joinMatchListWithCatalog(packedMatches, icSrces)

matches = [m for m in matches if m.first != None]
matches = [m for m in matches if m[0] != None]

if matches:
refSchema = matches[0].first.schema
refSchema = matches[0][0].schema
if ct:
# Add a "flux" field to the match records which contains the
# colorterm-corrected reference flux. The field name is hard-coded in
Expand All @@ -486,13 +486,13 @@ def check(self, dataRefList, ct=None, debug=False, verbose=False):
table.preallocate(len(matches))
for match in matches:
newMatch = table.makeRecord()
newMatch.assign(match.first, mapper)
match.first = newMatch
newMatch.assign(match[0], mapper)
match[0] = newMatch

key_p = refSchema.find(refSchema.join(ct.primary, "flux")).key
key_s = refSchema.find(refSchema.join(ct.secondary, "flux")).key
refFlux1 = numpy.array([m.first.get(key_p) for m in matches])
refFlux2 = numpy.array([m.first.get(key_s) for m in matches])
refFlux1 = numpy.array([m[0].get(key_p) for m in matches])
refFlux2 = numpy.array([m[0].get(key_s) for m in matches])
refMag1 = -2.5*numpy.log10(refFlux1)
refMag2 = -2.5*numpy.log10(refFlux2)
refMag = ct.transformMags(refMag1, refMag2)
Expand All @@ -518,20 +518,19 @@ def check(self, dataRefList, ct=None, debug=False, verbose=False):
src.setChip(dataRef.dataId['ccd'])
ssVisit[dataRef.dataId['visit']].append(src)
for m in matches:
if m.first != None and m.second != None:
match = measMosaic.SourceMatch(measMosaic.Source(m.first, wcs),
measMosaic.Source(m.second))
match.second.setExp(dataRef.dataId['visit'])
match.second.setChip(dataRef.dataId['ccd'])
if m[0] != None and m[1] != None:
match = (measMosaic.Source(m[0], wcs), measMosaic.Source(m[1]))
match[1].setExp(dataRef.dataId['visit'])
match[1].setChip(dataRef.dataId['ccd'])
mlVisit[dataRef.dataId['visit']].append(match)
wcsDic[dataRef.dataId['visit']][dataRef.dataId['ccd']] = wcs
calibDic[dataRef.dataId['visit']][dataRef.dataId['ccd']] = calib
ffpDic[dataRef.dataId['visit']][dataRef.dataId['ccd']] = ffp
dataRefListUsed.append(dataRef)

for visit in ssVisit.keys():
sourceSet.push_back(ssVisit[visit])
matchList.push_back(mlVisit[visit])
sourceSet.append(ssVisit[visit])
matchList.append(mlVisit[visit])

d_lim = afwGeom.Angle(self.config.radXMatch, afwGeom.arcseconds)
nbrightest = self.config.nBrightest
Expand Down
85 changes: 85 additions & 0 deletions python/lsst/meas/mosaic/fluxfit.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
/*
* LSST Data Management System
* Copyright 2008-2017 AURA/LSST.
*
* This product includes software developed by the
* LSST Project (http:
*
* 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:
*/
#include "pybind11/pybind11.h"
#include "pybind11/stl.h"

#include "lsst/meas/mosaic/fluxfit.h"

namespace py = pybind11;
using namespace pybind11::literals;

namespace lsst {
namespace meas {
namespace mosaic {

PYBIND11_PLUGIN(fluxfit) {
py::module::import("lsst.afw.cameraGeom");
py::module::import("lsst.afw.image");
py::module::import("lsst.daf.base");

py::module mod("fluxfit");

py::class_<FluxFitParams, std::shared_ptr<FluxFitParams>> clsFluxFitParams(mod, "FluxFitParams");

clsFluxFitParams.def_readwrite("order", &FluxFitParams::order);
clsFluxFitParams.def_readwrite("chebyshev", &FluxFitParams::chebyshev);
clsFluxFitParams.def_readwrite("ncoeff", &FluxFitParams::ncoeff);
clsFluxFitParams.def_readwrite("absolute", &FluxFitParams::absolute);
clsFluxFitParams.def_readwrite("u_max", &FluxFitParams::u_max);
clsFluxFitParams.def_readwrite("v_max", &FluxFitParams::v_max);
clsFluxFitParams.def_readwrite("x0", &FluxFitParams::x0);
clsFluxFitParams.def_readwrite("y0", &FluxFitParams::y0);

clsFluxFitParams.def(py::init<int, bool, bool>(), "order"_a, "absolute"_a = false, "chebyshev"_a = false);
clsFluxFitParams.def(py::init<lsst::daf::base::PropertySet::Ptr&>(), "metadata"_a);
clsFluxFitParams.def(py::init<const FluxFitParams&>(), "p"_a);

clsFluxFitParams.def("eval", (double (FluxFitParams::*)(double, double) const) & FluxFitParams::eval,
"u"_a, "v"_a);
clsFluxFitParams.def("getXorder", &FluxFitParams::getXorder);
clsFluxFitParams.def("getYorder", &FluxFitParams::getYorder);
clsFluxFitParams.def("getCoeff", &FluxFitParams::getCoeff);
clsFluxFitParams.def("getIndex", &FluxFitParams::getIndex);

// Workaround because fluxFit uses in/out arguments of STL container types
mod.def("fluxFit", [](bool absolute, bool common, ObsVec matchVec, int nmatch, ObsVec sourceVec,
int nsource, WcsDic wcsDic, CcdSet ccdSet, std::map<int, float> fexp,
std::map<int, float> fchip, FfpSet ffpSet, bool solveCcd) {
fluxFit(absolute, common, matchVec, nmatch, sourceVec, nsource, wcsDic, ccdSet, fexp, fchip, ffpSet,
solveCcd);

return std::make_tuple(matchVec, sourceVec, wcsDic, ccdSet, fexp, fchip, ffpSet);
});
mod.def("convertFluxFitParams", convertFluxFitParams, "ffp"_a, "ccd"_a, "x0"_a = 0.0, "y0"_a = 0.0);
mod.def("metadataFromFluxFitParams", metadataFromFluxFitParams);
mod.def("getFCorImg",
(lsst::afw::image::Image<float>::Ptr(*)(
FluxFitParams::Ptr&, PTR(lsst::afw::cameraGeom::Detector)&, Coeff::Ptr&))getFCorImg);
mod.def("getFCorImg", (lsst::afw::image::Image<float>::Ptr(*)(FluxFitParams::Ptr&, int, int))getFCorImg);
mod.def("getFCorImg", (lsst::afw::image::Image<float>::Ptr(*)(
FluxFitParams::Ptr&, PTR(lsst::afw::cameraGeom::Detector)&))getFCorImg);

return mod.ptr();
}
}
}
}
53 changes: 53 additions & 0 deletions python/lsst/meas/mosaic/matches.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/*
* LSST Data Management System
* Copyright 2008-2017 AURA/LSST.
*
* This product includes software developed by the
* LSST Project (http://www.lsst.org/).
*
* 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/>.
*/
#include "pybind11/pybind11.h"

#include "lsst/meas/mosaic/matches.h"

namespace py = pybind11;
using namespace pybind11::literals;

namespace lsst {
namespace meas {
namespace mosaic {
namespace {

template <typename CatT>
void declareCopyCatalog(py::module& mod) {
mod.def("copyCatalog", copyCatalog<CatT>, "catalog"_a, "target"_a, "targetPrefix"_a = "",
"sourcePrefix"_a = "");
}

} // <anonymous>

PYBIND11_PLUGIN(matches) {
py::module mod("matches");

mod.def("copySchema", copySchema, "schema"_a, "target"_a, "targetPrefix"_a = "", "sourcePrefix"_a = "");
mod.def("matchesFromCatalog", matchesFromCatalog, "catalog"_a);

return mod.ptr();
}

} // mosaic
} // meas
} // lsst
106 changes: 0 additions & 106 deletions python/lsst/meas/mosaic/mosaic.i

This file was deleted.